searchTextItem = new TextItem("search", MSG.common_button_search());
searchTextItem.setShowTitle(false);
searchTextItem.setWidth(SEARCH_WIDTH);
searchTextItem.setBrowserSpellCheck(false);
searchTextItem.addKeyUpHandler(new KeyUpHandler() {
public void onKeyUp(final KeyUpEvent keyUpEvent) {
Log.debug("onKeyUp search Mode: " + searchMode + " key: " + keyUpEvent.getKeyName());
keyUpEvent.cancel();
if (IGNORED_KEYS.contains(keyUpEvent.getKeyName())) {
return;
}
if (keyUpEvent.getKeyName().equals("Enter")) {
if (getSearchMode().equals(SearchMode.SAVED_SEARCH_MODE)) {
return;
}
String currentSearchTerm = (String) keyUpEvent.getItem().getValue();
currentSearchTerm = (null == currentSearchTerm) ? "" : currentSearchTerm; // avoid NPEs
Log.debug("onKeyUp search Mode Enter key pressed");
// stop any duplicate searches
if (!currentSearchTerm.equalsIgnoreCase(lastSearchTerm)) {
getSearchStrategy().searchReturnKeyHandler(keyUpEvent);
searchTextItem.focusInItem();
lastSearchTerm = currentSearchTerm;
} else {
hideList();
}
} else if (keyUpEvent.getKeyName().equals("Escape")) {
searchTextItem.setValue(lastSearchTerm);
hideList();
} else {
if (null == searchDelayTimer) {
searchDelayTimer = new Timer() {
public void run() {
getSearchStrategy().searchKeyUpHandler(keyUpEvent);
pickListGrid.show();
}
};
} else {
searchDelayTimer.cancel();
}
// wait for some typing quiet time before performing a search
searchDelayTimer.schedule(SEARCH_KEYUP_DELAY);
}
}
});
pickListGrid.addClickHandler(new com.smartgwt.client.widgets.events.ClickHandler() {
@Override
public void onClick( com.smartgwt.client.widgets.events.ClickEvent clickEvent) {
pickListGrid.focus();
}
});
searchTextItem.addClickHandler(new com.smartgwt.client.widgets.form.fields.events.ClickHandler() {
@Override
public void onClick(com.smartgwt.client.widgets.form.fields.events.ClickEvent clickEvent) {
if (pickListGrid.isVisible()) {
hideList();
} else {
showList();
}
}
});
searchTextItem.addFocusHandler( new FocusHandler() {
@Override
public void onFocus(FocusEvent event) {
showList();
}
});
searchTextItem.addBlurHandler( new BlurHandler() {
@Override
public void onBlur(BlurEvent event) {
Timer t = new Timer() {
public void run() {
if (!pickListGrid.containsFocus()) {
hideList();
}
}
};
t.schedule(500);
}
});
searchTextForm.setFields(searchTextItem);
addMember(searchTextForm);
searchTextItem.setTooltip(MSG.view_searchBar_buttonTooltip());
searchTextItem.setHint("Search");
searchTextItem.setShowHintInField(true);
saveSearchButton = new ToolStripButton();
saveSearchButton.setIcon(IconEnum.STAR_OFF.getIcon16x16Path());
saveSearchButton.setTooltip(MSG.view_searchBar_savedSearch_buttonTooltip());
saveSearchButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
toggleFavoriteSearch();
}
});
addButton(saveSearchButton);
DynamicForm saveSearchTextForm = new DynamicForm();
saveSearchTextForm.setAutoWidth();
saveSearchTextItem = new TextItem("savedSearchName");
saveSearchTextItem.setShowTitle(false);
saveSearchTextItem.setWidth(SAVED_SEARCH_WIDTH);
saveSearchTextForm.setFields(saveSearchTextItem);
addMember(saveSearchTextForm);
saveSearchTextItem.hide();
saveSearchTextItem.addKeyUpHandler(new KeyUpHandler() {
@Override
public void onKeyUp(KeyUpEvent keyUpEvent) {
if (keyUpEvent.getKeyName().equals("Enter")) {
saveFavoriteSearch();
}