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:
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
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();
}
});