private void setSuggestBoxHandlers() {
ArrayList<Widget> widgets = display.getQueryWidgits();
for (Widget widget : widgets) {
if (widget instanceof TermSuggestBox) {
final TermSuggestBox suggestBox = (TermSuggestBox) widget;
suggestBox.addKeyUpHandler(new KeyUpHandler() {
@Override
public void onKeyUp(KeyUpEvent event) {
if ( !objectText.equals(suggestBox.getText()) && (suggestBox.getText().length()) > 2) {
uploadSuggestBox(suggestBox);
objectText = suggestBox.getText();
}
else{
display.setSuggestBoxObject(result, suggestBox);
}
}
});
suggestBox.addSelectionHandler(new SelectionHandler<SuggestOracle.Suggestion>() {
@Override
public void onSelection(SelectionEvent<SuggestOracle.Suggestion> event) {
String selection = event.getSelectedItem().getReplacementString();
//suggestBox.setText(selection.substring(selection.indexOf("-") + 2, selection.length()));
suggestBox.setText(selection.substring(0,selection.indexOf("(") - 1));
int index = display.getQueryWidgits().lastIndexOf(suggestBox);
String[] queryType = manQuery.split(" ");
manQuery = "";
for (int i = 0; i < queryType.length; i++) {
if (i == index) {
manQuery = manQuery + selection.substring(selection.indexOf("(")+1,selection.length()-1).replace(":", "_");
} else {
manQuery = manQuery + queryType[i];
}
manQuery = manQuery + " ";
}
}
});
}
if (widget instanceof RelationSuggestBox) {
final RelationSuggestBox suggestBox = (RelationSuggestBox) widget;
suggestBox.addKeyUpHandler(new KeyUpHandler() {
@Override
public void onKeyUp(KeyUpEvent event) {
uploadSuggestBox(suggestBox);
display.setSuggestBoxObject(result, suggestBox);
}
});
suggestBox.addSelectionHandler(new SelectionHandler<SuggestOracle.Suggestion>() {
@Override
public void onSelection(SelectionEvent<SuggestOracle.Suggestion> event) {
String selection = event.getSelectedItem().getReplacementString();
selection = selection.split(" ")[0];
suggestBox.setText(selection);
int index = display.getQueryWidgits().lastIndexOf(suggestBox);
String[] queryType = manQuery.split(" ");
manQuery = "";
for (int i = 0; i < queryType.length; i++) {