---------- Forwarded message ----------
From: yunhui song <[EMAIL PROTECTED]>
Date: Sun, Oct 26, 2008 at 8:26 PM
Subject: Re: PureMVC
To: Google-Web-Toolkit@googlegroups.com


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










On Sun, Oct 26, 2008 at 6:50 PM, Thomas Broyer <[EMAIL PROTECTED]> wrote:

>
>
> On 27 oct, 00:09, "yunhui song" <[EMAIL PROTECTED]> wrote:
> > Hi,
> >
> >   Actually, Gin is used to implements Ioc Container. It can bind
> everything
> > not only event Listener.
> >
> >   Guice or Spring can do that naturally, but because GWT can not support
> > Java reflection, such as forClass("className").getInstance. So Gin use
> > generic and annotation to do that.
>
> Sorry, I should have been clearer: I know what Guice (and Gin) and
> Spring are. Just that they cannot AFAIK inject listeners (i.e. call
> some addXListener method, eventually several times on a single
> instance). Of course you can use method injection with a
> setXListeners(List<XListener>) method (should be supported by Gin as
> of today) but I wouldn't call it "injecting event listeners"; or
> inject event sources or event targets but that's not flexible at all
> (why having "event listeners" in this case, just keep references to
> the injected widgets and call the appropriate methods on them)
>
> >   I have a open source project to do that.  GinModule and GindInjector
> are
> > key players for that.
> >   please check out here, that's a real world project.
> >    http://openorg.googlecode.com/svn/trunk/magpie
>
> I've seen some widgets be injected other widgets but not a single
> event listener (or I missed something).
> >
>


-- 
Sammi
http://code.google.com/p/openorg



-- 
Sammi
http://code.google.com/p/openorg

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to Google-Web-Toolkit@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to