Tuesday, November 30, 2010

Re: GWT 2.1 Activities – nesting? YAGNI ? - an example of where you NEED it !

You can get the history working if you use widgets, as long as you let
everything react on a Place somehow. As far as I know, when a place is
shown, it is recorded in the history properly. We had an
implementation which didn't listen to the place but handled the
drawing ourselves, and that didn't work properly (always full a redraw
of the screen, etc).

This might help. We have places like below. Our left panel looks to
the instanceof, and our middle panel looks at the instanceof _and_ to
the getToken() of the place. That works pretty well. So, for example
for our PlaceContact we have a ContactsLeft (-activity and -view)
which always shows when a PlaceContact is chosen. For the middle in
our screen, we have several activity-view combinations that react on
PlaceContact, depending on which getToken() is called.

[ We might even extend our places to include references to specific
entities, now our URL looks like #contact:edit but we might extend it
to #contact:edit:3342 . Unfortunately there is no standarised aproach
for this. ]

public class PlaceContact extends Place {
public final static String LIST = "list";
public final static String ADD = "add";
public final static String EDIT = "edit";

public final static String DEFAULT = LIST;

private String token;

public PlaceContact() {
this.token = DEFAULT;
}

public PlaceContact(String token) {
this.token = token;
}

public String getToken() {
return token;
}

@Prefix("contact")
public static class Tokenizer implements PlaceTokenizer<PlaceContact>
{

@Override
public String getToken(PlaceContact place) {
return place.getToken();
}

@Override
public PlaceContact getPlace(String token) {
return new PlaceContact(token);
}

}

}


our ActivityMapper left:

if (place instanceof PlaceContact) {
return activityContactLeft.get();
} else if (place instanceof .....
.....


our ActivityMapper middle:

if (place instanceof PlaceContact) {
PlaceContact placeContact = (PlaceContact) place;
if (placeContact.getToken().equals(PlaceContact.LIST)) {
return activityContactList.get();
} else if (placeContact.getToken().equals(PlaceContact.ADD)) {
.......

Best,
Niels

On 30 nov, 06:28, zixzigma <zixzi...@gmail.com> wrote:
> Thank you for your comments.
>
> >>So you would have one main activity for each major area with one view
> >>and could have multiple widgets that accomplish what your individual
> >>activities could?
>
> I had thought about this, but my concern is by doing so, we lose the
> navigation/history/bookmarking.
>
> in the case of West Region having West North, West Main and West
> South,
> lets say we place three widgets in the West Region, and treat the
> entire region as a single activity,
>
> when we click an item in one of the regions (West Main for example),
>  selection of an item fires an event on eventBus,
> the widget in West South is listening for this event, and upon
> receiving,
> populates itself with contextual data related to item selected in West
> Main, however
> since we are not using activities and places, the history token doesnt
> get updated,
> and we lose the history which results in poor/broken navigation.
>
> more over, since we are not using Activities/Places for these sub-
> regions (west_north, west_main, west_south),
> we can not use placeController.go(new place), for communicating
> events, and have to resort to manually creating event handling
> (GwtEvent, etc)
>
> what is your view on this ? can we get the history working if we use
> widgets ( old style Presenter/Views) and not activities ?
>
> >>or maybe create an
> >>activity that kinda wraps many other activities:
>
> i think it should be possible and is what is referred to as Composite
> Activity in google's documentation.
> However I am not sure whether it is considered a good practice.
> This concept is briefly mentioned in Google's MVP tutorialhttp://code.google.com/webtoolkit/doc/latest/DevGuideMvpActivitiesAnd...
>
> in the very last paragraph, the most important part, which is sadly
> left out causing confusiong:
>
> "What about apps with multiple panels in the same window whose state
> should all be saved together in a single URL? GWT 2.1 does not attempt
> to provide a generic implementation of a composite Place; however,
> your app could create a CompositePlace, CompositeActivity, and
> CompositePlace.Tokenizer classes that delegate to the constituent
> members. In this case, only the composite objects would need to be
> registered with your app's ActivityMapper and PlaceHistoryMapper."
>
> do you have any idea on CompositePlace , its relation to Composite
> Activity, and how we can map a Composite Place to its corresponding
> Activities ?
>
> thank you

--
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 google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment