Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding/modifying SuggestOracle after construction of SuggestBox in GWT

Tags:

java

gwt

All of the information that I can find for SuggestBox and MultiWordSuggestOracle suggests that the only way to set an oracle for a suggest box is when it is constructed. I don't think this makes sense, though, since there is a default constructor that does not accept an oracle and creates one for you, presumably empty. That doesn't do much good. What I'm looking for would be methods like setSuggestOracle(MultiWordSuggestOracle) or addToSuggestOracle(String), but I can't find anything in the documentation suggesting how to do this.

like image 680
Joshua Clark Avatar asked Jan 04 '12 21:01

Joshua Clark


1 Answers

It doesn't look like you can change the instance of the SuggestOracle after the SuggestBox has been created, but you can access it with SuggetBox::getSuggestOracle(). From there you would have to cast to the implementing class to make changes to it; the SuggestOracle base class itself doesn't provide anything. So something like:

SuggestOracle oracle = new MultiWordSuggestOracle();
SuggestBox box = new SuggestBox(oracle);

try {
  MultiWordSuggestOracle multiWordOracle = (MultiWordSuggestOracle)box.getOracle();
  multiWordOracle.add("This awesome suggestion.");
} catch (ClassCastException e ) {
  // the oracle was not what you thought it was
}
like image 99
Dusty Campbell Avatar answered Oct 31 '22 16:10

Dusty Campbell