DockLayoutPanel MVP and events

108 views
Skip to first unread message

xworker

unread,
Jul 8, 2010, 4:39:12 AM7/8/10
to Google Web Toolkit
Hi

Very new to GWT and MVP. Trying to expand the contacts example with a
DockLayoutPanel with a tree navigation in the west section. Using MVP
and ui:bindings.

Got an DockLayoutPanelView and Presenter. Inside is a tree component
to the west and a content component in center. How will I get the
events from the tree component?

My DockViewPresenter:

public class DockPresenter implements Presenter {



public interface Display {
Widget asWidget();
}

private final ContactsServiceAsync rpcService;
private final HandlerManager eventBus;
private final Display display;
private ContactsPresenter contactsPresenter;
private TreePresenter treePresenter;

public DockPresenter(ContactsServiceAsync rpcService,
HandlerManager eventBus, Display view) {
this.rpcService = rpcService;
this.eventBus = eventBus;
this.display = view;

contactsPresenter = new ContactsPresenter(rpcService, eventBus,
new ContactsView());
treePresenter = new TreePresenter(rpcService, eventBus, new
MyTree());
}

public void bind() {
contactsPresenter.bind();
treePresenter.bind();
}

public void go(final HasWidgets container) {
bind();
container.clear();
container.add(display.asWidget());

}
}



As you can see I am creating the two presenters for the content and
the tree, but I dont know how to get the events (clicks, selections)
from them. They seem to be swallowed be the dock. I'm guessing I
should register handlers in the bind() method, but how? When
navigating to the tree component without the dock, events works fine.

TreePresenter:

public class TreePresenter implements Presenter {


public interface Display {

HasSelectionHandlers<TreeItem> getTree();
Widget asWidget();
}

private final ContactsServiceAsync rpcService;
private final HandlerManager eventBus;
private final Display display;

public TreePresenter(ContactsServiceAsync rpcService, HandlerManager
eventBus, Display view) {
this.rpcService = rpcService;
this.eventBus = eventBus;
this.display = view;


}



public void bind() {


display.getTree().addSelectionHandler(new
SelectionHandler<TreeItem>() {

public void onSelection(SelectionEvent<TreeItem> event) {
TreeItem item = (TreeItem) event.getSelectedItem();
GWT.log("Node selected "+item.getText());
}

});

}

Thanks

Thomas Broyer

unread,
Jul 14, 2010, 11:07:27 AM7/14/10
to Google Web Toolkit


On 8 juil, 10:39, xworker <blomqvist.andr...@gmail.com> wrote:
> Hi
>
> Very new to GWT and MVP. Trying to expand the contacts example with a
> DockLayoutPanel with a tree navigation in the west section. Using MVP
> and ui:bindings.
>
> Got an DockLayoutPanelView and Presenter. Inside is a tree component
> to the west and a content component in center. How will I get the
> events from the tree component?

The generally adopted way of doing things in GWT is to have custom
events go through the event bus. In this case, you're talking about
"navigation", so maybe the concept of "place" would be better than
"just" some custom event. I encourage you to look at gwt-platform, gwt-
presenter and other MVP frameworks for GWT, and/or look at the
Activity concept from the upcoming GWT 2.1.

Using actvities, you'd have an ActivityManager managing your "center".
The tree would use the PlaceController.goTo to navigate to a new
"place". An ActivityMapper (that you passed to the ActivityManager in
the constructor) would map the place to an Activity (a presenter), and
the ActivityManager will manage the current Activity for the display
it manages, i.e.it will stop() the current activity if its ok
(willStop returns true) and then only start the new Activity, which
will call the Display back to show its view.
The tree would probably also listen to PlaceChangeEvent on the event
bus to update the selected item depending on the current place (in
case some other component calls the PlaceController.goTo)

Nirmal

unread,
Jul 15, 2010, 2:22:41 PM7/15/10
to Google Web Toolkit
Thanks Thomas, your explanation puts the new Activity/Place into
perspective.

I have a question; how does the PlaceChange Event gets fired??


Regards,
Nirmal

Thomas Broyer

unread,
Jul 15, 2010, 6:20:59 PM7/15/10
to Google Web Toolkit


On 15 juil, 20:22, Nirmal <nirmaljpa...@gmail.com> wrote:
> Thanks Thomas, your explanation puts the new Activity/Place into
> perspective.
>
> I have a question; how does the PlaceChange Event gets fired??

As of 2.1M2, PlaceController still isn't bound to History, so only
PlaceController#goTo will fire first a PlaceChangeRequestedEvent
(which can be rejected) and then (if the first hasn't been rejected by
listeners) a PlaceChangeEvent.

xworker

unread,
Jul 21, 2010, 4:15:20 AM7/21/10
to Google Web Toolkit
Hi Thomas

Thanks for your reply, I have started to look into the ActivityManager
and Place patterns, but have not found lots of documentation. Is there
any examples?
Is gwt-p going to be standard for 2.1 or will google release there own
implementation?

Thanks
> > Thanks- Dölj citerad text -
>
> - Visa citerad text -

Thomas Broyer

unread,
Jul 21, 2010, 6:52:45 AM7/21/10
to Google Web Toolkit


On 21 juil, 10:15, xworker <blomqvist.andr...@gmail.com> wrote:
> Hi Thomas
>
> Thanks for your reply, I have started to look into the ActivityManager
> and Place patterns, but have not found lots of documentation. Is there
> any examples?

You could look at the "Scaffold" app in bikeshed (in the SVN repo),
but it's a bit convoluted as it's code generated by Spring Roo.
The basic idea is:
- create activities, which will generally be your presenters; and in
the start() method, make sure you call the Display back with the view
(which should implement IsWidget); you generally do this in the
onSuccess of a GWT-RPC or RequestFactory call.
- create places, which can really by whatever you like (you'll be the
one responsible for instantiating them), you can make singletons, or
"parameterized" places (arguments in the constructor, and property
accessors).
- create an ActivityMapper to map places to activities (i.e. for a
given "screen region")
- create an ActivityManager with the mapper created above and the
event bus
- setup the activitymanager's display with a display that knows where
to show the activities' widgets (the "screen region", removing the
previous widget before adding the new one)
- call goTo on a PlaceController (created with the very same eventbus
as the activitymanager) to go from place to place

Repeat the ActivityMapper/ActivityManager/Display steps for each
"screen region" of your app. Keep in mind that a Place is
"global" ("where am I?") whereas an activity is the "response" to this
place in a specific "screen region".

> Is gwt-p going to be standard for 2.1 or will google release there own
> implementation?

There's no relation between GWTP and GWT (other than GWTP relying on
GWT). Activities and Places *are* Google's "own implementation".

Frank B?lviken

unread,
Jan 3, 2011, 8:40:40 AM1/3/11
to google-we...@googlegroups.com
Hi,

Does it exist any sample-project app which demonstrate this, with dependency-injection like GIN?
I've successfully implemented this in a simple app where the activity takes the whole screen. But what I would like is
a navigationmenu left, header, footer and main content in the center of the screen. Any help would be greatly appriciated.

Sincerly,
Frank B
Reply all
Reply to author
Forward
0 new messages