*
* @param options Provides a configuration for displaying and executing the
* SearchControl's searches
*/
public SearchControl(SearchControlOptions options) {
SimplePanel contents = new SimplePanel();
initWidget(contents);
setStyleName("gwt-SearchControl");
// Associate the backing JSO with this facade object.
SEARCH_CONTROL.bind(jsoPeer, this);
// Wire up the search callback every time
SEARCH_CONTROL.setSearchCompleteCallback(this, null,
new SearchControlCompleteCallback() {
public void onSearchResult(SearchControl control, Search search) {
assert control == SearchControl.this;
for (Result result : search.getResults()) {
resultListeners.fireResult(search, result);
}
}
});
// If no keep label is explicity set, don't bother wiring up the callback.
if (options.keepLabel != null) {
KeepCallback keepCallback = new KeepCallback() {
public void onKeep(Result result) {
keepListeners.fireKeep(SearchControl.this, result);
}
};
// keepLabel may be either a String or a KeepLabel
if (options.keepLabel instanceof String) {
SEARCH_CONTROL.setOnKeepCallback(this, null, keepCallback,
(String) options.keepLabel);
} else if (options.keepLabel instanceof KeepLabel) {
SEARCH_CONTROL.setOnKeepCallback(this, null, keepCallback,
((KeepLabel) options.keepLabel).getValue());
}
}
// Explicitly set the linkTarget if one is defined.
if (options.linkTarget != null) {
SEARCH_CONTROL.setLinkTarget(this, options.linkTarget.getValue());
}
// Set the timeoutInterval if necessary
if (options.timeoutInterval != null) {
SEARCH_CONTROL.setTimeoutInterval(this,
options.timeoutInterval.getValue());
}
// Add all Searches to the control
for (Search search : options.searchers) {
GsearcherOptions searchOptions = options.searcherOptions.get(search);
SEARCH_CONTROL.addSearcher(this, search, searchOptions);
}
// Build the UI.
SEARCH_CONTROL.draw(this, contents.getElement(), options.drawOptions);
}