Suggestion, SuggestionHandler, and DTO (Issue 1086)

29 views
Skip to first unread message

Richard Bondi

unread,
Sep 13, 2007, 3:17:31 PM9/13/07
to Google Web Toolkit
Dear All,

The javadoc for com.google.gwt.user.client.ui.Suggestion describes
clearly how to have a type-head oracle (like MultiWordSuggestOracle)
return not just a String, but a DTO. (It's a really good javadoc,
thanks GWT team.)

On thing it leaves out, though, is: How do I get my own DTO-wrapping
Suggestions into an oracle in the first place, so that the oracle can
give them to the SuggestBox, and so to my SuggestionHandler?

My problem is:

Ideally, I'd just extend MultiWordSuggestOracle to handle DTOs rather
than Strings. But it is *final* (why???). So in fact using it somehow
(encapsulating it or whatever) is so ugly, it is easier to bypass all
the work done for issue 1086 to support DTO Suggestions, as follows:

Instead, if I'm lucky enough that the oracle display string is unique
for each DTO, I can keep a HashMap with unique String keys to each of
my DTOs. Each unique string goes into the MultiWordSuggestOracle.
Then, on suggestionHandler.onSuggestionSelected(SuggestionEvent
event), I extract the unique string, look up the corresponding DTO in
my map, and I'm on my way.

This just seems like a waste of all the effort done for Issue
http://code.google.com/p/google-web-toolkit/issues/detail?id=1086. If
MultiWordSuggestOracle were not final, it would be easy to extend just
one method and slip my HashMap in there. Am I missing something? Is
there some way to get DTOs *into* an oracle that I am missing here?

Thanks,
/r:b:

Richard Bondi

unread,
Sep 13, 2007, 3:21:26 PM9/13/07
to Google Web Toolkit
Correction: the javadoc is located in
com.google.gwt.user.client.ui.SuggestOracle, on the interface
Suggestion.
/r:b:

On Sep 13, 3:17 pm, Richard Bondi <rbo...@gmail.com> wrote:
> Dear All,
>
> The javadoc for com.google.gwt.user.client.ui.Suggestion describes
> clearly how to have a type-head oracle (like MultiWordSuggestOracle)
> return not just a String, but a DTO. (It's a really good javadoc,
> thanks GWT team.)
>
> On thing it leaves out, though, is: How do I get my own DTO-wrapping
> Suggestions into an oracle in the first place, so that the oracle can
> give them to the SuggestBox, and so to my SuggestionHandler?
>
> My problem is:
>
> Ideally, I'd just extend MultiWordSuggestOracle to handle DTOs rather
> than Strings. But it is *final* (why???). So in fact using it somehow
> (encapsulating it or whatever) is so ugly, it is easier to bypass all
> the work done for issue 1086 to support DTO Suggestions, as follows:
>
> Instead, if I'm lucky enough that the oracle display string is unique
> for each DTO, I can keep a HashMap with unique String keys to each of
> my DTOs. Each unique string goes into the MultiWordSuggestOracle.
> Then, on suggestionHandler.onSuggestionSelected(SuggestionEvent
> event), I extract the unique string, look up the corresponding DTO in
> my map, and I'm on my way.
>

> This just seems like a waste of all the effort done for Issuehttp://code.google.com/p/google-web-toolkit/issues/detail?id=1086. If

walrus

unread,
Sep 14, 2007, 4:05:09 AM9/14/07
to Google Web Toolkit
It is pretty simple. You don't have to extend MultiWordSuggestOracle.
Extend MultiWordSuggestOracle.MultiWordSuggestion, adding a reference
to your DTO to that class.

private static class MySuggestion extends
MultiWordSuggestOracle.MultiWordSuggestion {
private final ID id;

public MySuggestion(String name, ID id) {
super(name, name);
this.id = id;
}

public ID getId() {
return id;
}
}


Feed MySuggestion objects to SelectorOracle.requestSuggestions(). Then
cast the return value of SuggestionEvent.getSelectedSuggestion() to
class MySuggestion.

suggestBox.addEventHandler(new SuggestionHandler() {
public void onSuggestionSelected(SuggestionEvent event) {
MySuggestion node = (MySuggestion)
event.getSelectedSuggestion();
}
});

Reply all
Reply to author
Forward
0 new messages