Hi Thomas,
I've seen some widgets be injected other widgets but not a single
event listener (or I missed something).
It's true that for my project I only injected some widgets on a main
panel. That's the project specific choice. Because it's more easy to
do that.
I'am not very clear your use case now. Let me have a guess for the use
case:
1. We have two widgets w1 and w2, both of them would fire Event
clickEvent.
2. We need one Event Listener named CommonEventListener, we expect it
can be used to process clickEvent fired from both w1 and w2.
3. We hope the container, that is Gin to inject when system
initialize. So refractor the code like.
W1 w1 = new W1();
w1.addClickEventListener(new CommonEventListener(p1,p2){});
W2 w2 = new W2();
w2.addClickEventListener(new CommonEventListener(p1,p2){});
by:
CommonEventListener aCommonEventListener =
injector.getCommonEventListener();
W1 w1 = injector.getW1();
w1.addClickEventListener(aCommonEventListener);
W2 w2 = injector.getW2();
w2.addClickEventListener(aCommonEventListener);
Because polymorphism is not usable in GWT, we can not use W1 or W2's
common interface or base class as CommonEventListener. My suggestion
is:
private W1 w1;
private W2 w2;
@inject
public CommonEventListener(W1 w1,W2 w2){
//w1 and w2 should be created by ginmodule as singleton instance.
this.w1 = w1;
this.w2 = w2;
}
public void onClick(Event e){
if(e.getSource() == w1){
//w1.update();
}else if(e.getSource() == w2){
//w2.update();
}
}
I don't think it's an perfect solution(you must change the parameter,
as you said, use List<T> is same like ). But it should be able to
manage the listener and ui creation by container and unit test could
be implemented easily.
Hope that is not confusing.
Sammi
http://code.google.com/p/openorg
On Oct 26, 8:33 pm, "yunhui song" <[EMAIL PROTECTED]> wrote:
> Hi Thomas,
>
> > I've seen some widgets be injected other widgets but not a single
>
> event listener (or I missed something).
>
> It's true that for my project I only injected some widgets on a main panel.
> That's the project specific choice. Because it's more easy to do that.
>
> I'am not very clear your use case now. Let me have a guess for the use case:
>
> 1. We have two widgets w1 and w2, both of them would fire Event clickEvent.
>
> 2. We need one Event Listener named CommonEventListener, we expect it can be
> used to process clickEvent fired from both w1 and w2.
>
> 3. We hope the container, that is Gin to inject when system initialize. So
> refractor the code like.
> W1 w1 = new W1();
> w1.addClickEventListener(new CommonEventListener(p1,p2){});
>
> W2 w2 = new W2();
> w2.addClickEventListener(new CommonEventListener(p1,p2){});
> by:
>
> CommonEventListener aCommonEventListener =
> injector.getCommonEventListener();
> W1 w1 = injector.getW1();
> w1.addClickEventListener(aCommonEventListener);
> W2 w2 = injector.getW2();
> w2.addClickEventListener(aCommonEventListener);
>
> Because polymorphism is not usable in GWT, we can not use W1 or W2's common
> interface or base class as CommonEventListener. My suggestion is:
>
> private W1 w1;
> private W2 w2;
> @inject
> public CommonEventListener(W1 w1,W2 w2){
> //w1 and w2 should be created by ginmodule as singleton instance.
> this.w1 = w1;
> this.w2 = w2;
>
> }
>
> public void onClick(Event e){
> if(e.getSource() == w1){
> //w1.update();
> }else if(e.getSource() == w2){
> //w2.update();
> }
>
> }
>
> I don't think it's an perfect solution(you must change the parameter, as you
> said, use List<T> is same like ). But it should be able to manage the
> listener and ui creation by container and unit test could be implemented
> easily.
>
> Hope that is not confusing.
>
> Sammi
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---