itemBox
.getElement()
.setAttribute(
"style",
"outline-color: -moz-use-text-color; outline-style: none; outline-width: medium;");
final SuggestBox box = new SuggestBox(getSuggestions(), itemBox);
box.getElement().setId("suggestion_box");
item.add(box);
list.add(item);
// this needs to be on the itemBox rather than box, or backspace will
// get executed twice
itemBox.addKeyDownHandler(new KeyDownHandler() {
public void onKeyDown(KeyDownEvent event) {
if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
// only allow manual entries with @ signs (assumed email
// addresses)
if (itemBox.getValue().contains("@"))
deselectItem(itemBox, list);
}
// handle backspace
if (event.getNativeKeyCode() == KeyCodes.KEY_BACKSPACE) {
if ("".equals(itemBox.getValue().trim())) {
ListItem li = (ListItem) list.getWidget(list
.getWidgetCount() - 2);
Paragraph p = (Paragraph) li.getWidget(0);
if (itemsSelected.contains(p.getText())) {
itemsSelected.remove(p.getText());
GWT.log("Removing selected item '" + p.getText()
+ "'", null);
GWT.log("Remaining: " + itemsSelected, null);
}
list.remove(li);
itemBox.setFocus(true);
}
}
}
});
box
.addSelectionHandler(new SelectionHandler<SuggestOracle.Suggestion>() {
public void onSelection(SelectionEvent selectionEvent) {
deselectItem(itemBox, list);
}
});