You could use a GWT HandlerManager as an "Event Registry" that both
widgets reference.

See 
http://google-web-toolkit.googlecode.com/svn/javadoc/1.6/index.html?overview-summary.html

Basically the "User List" widget fires "setCurrentUser" events (with
the user as a payload) on the HandlerManager and the "Edit widget"
registers a handler to handle those events.

If the HandlerManager code is a bit too much you could write your own
EventRegistry (see rough sample below). Note you also need to make the
Event and Listener classes. This is a -very- simplified
HandlerManager.

- Add listeners with eventRegistry.addListener(SomeEvent.class,
someListener);
- Fire events with eventRegistry.fireEvent(new SomeEvent());
- Need to remove listeners, but I'll leave that code up to you

public class EventRegistry {
    private Map<Class<? extends Event>, List<Listener>> registry = new
HashMap<Class<? extends Event>, List<Listener>>();

    public void fireEvent(Event event) {
        Class<? extends Event> eventClass = event.getClass();

        if (registry.get(eventClass) != null) {
            // Prevent newly add listeners cause concurrent
modification exceptions by copying to new List
            List<Listener> listeners = new ArrayList<Listener>
(registry.get(eventClass));

            for (Listener listener : listeners)  {
                    listener.handleEvent(event);
                }
            }
        }
    }

    public void addListener(Class<? extends Event> eventClass,
Listener listener) {
        List<Listener> listeners = registry.get(eventClass);
        if (listeners == null) {
            listeners = new ArrayList<Listener>();
            registry.put(eventClass, listeners);
        }

        if (!listeners.contains(listener)) {
            listeners.add(listener);
        }
    }
 }
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to