List of usage examples for com.google.gwt.user.client.ui SuggestBox setValue
public void setValue(String newValue)
From source file:de.uni_koeln.spinfo.maalr.webapp.ui.common.client.ConfigurableSearchArea.java
License:Apache License
private Widget buildOracle(final UiField field) { MultiWordSuggestOracle oracle = new MultiWordSuggestOracle() { @Override//from w w w. j a v a 2 s .c o m public void requestSuggestions(final Request request, final Callback callback) { service.getSuggestions(field.getId(), request.getQuery(), request.getLimit(), new AsyncCallback<List<String>>() { @Override public void onFailure(Throwable caught) { } @Override public void onSuccess(List<String> result) { Response response = new Response(); List<Suggestion> suggestions = new ArrayList<Suggestion>(); for (String string : result) { suggestions.add(new MultiWordSuggestion(string, string)); } response.setSuggestions(suggestions); callback.onSuggestionsReady(request, response); } }); } }; final SuggestBox box = new SuggestBox(oracle); box.setValue(field.getInitialValue()); box.getValueBox().addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { String old = oracleHistory.get(field.getId()); if (old != null) { box.getValueBox().setText(old); } box.getValueBox().selectAll(); box.showSuggestionList(); } }); box.addKeyDownHandler(new KeyDownHandler() { @Override public void onKeyDown(KeyDownEvent event) { if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) { box.getValueBox().selectAll(); event.stopPropagation(); event.preventDefault(); box.setFocus(true); fireDelayedUpdate(); } } }); box.addKeyUpHandler(new KeyUpHandler() { @Override public void onKeyUp(KeyUpEvent event) { if (box.getValue() == null || box.getValue().trim().length() == 0) { currentValues.remove(field.getId()); } else { currentValues.put(field.getId(), box.getValue()); } oracleHistory.put(field.getId(), box.getValue()); //fireDelayedUpdate(); } }); box.addSelectionHandler(new SelectionHandler<SuggestOracle.Suggestion>() { @Override public void onSelection(SelectionEvent<Suggestion> event) { String string = event.getSelectedItem().getReplacementString(); if (box.getValue() == null || box.getValue().trim().length() == 0) { currentValues.remove(field.getId()); } else { currentValues.put(field.getId(), string); } fireDelayedUpdate(); } }); return box; }
From source file:fast.servicescreen.client.gui.CTextChangeHandler.java
License:Open Source License
public static SuggestBox createSuggestBox(CObject obj, String attrName, MultiWordSuggestOracle oracle) { CTextChangeHandler handler = new CTextChangeHandler(); SuggestBox suggestBox = new SuggestBox(oracle); handler.setTarget(obj);/* w w w . ja v a 2 s.co m*/ handler.setTargetAttrName(attrName); handler.setSuggestBox(suggestBox); String oldValue = (String) obj.get(attrName); suggestBox.setValue(oldValue); suggestBox.addSelectionHandler(handler); obj.addPropertyChangeListener(attrName, handler); return suggestBox; }
From source file:fast.servicescreen.client.gui.RuleGUI.java
License:Open Source License
protected TreeItem createRuleEditor(FASTMappingRule nextRule, TreeItem treeParent) { // "from" attribute // new SuggestBox TextBox fromBox = CTextChangeHandler.createWidthTextBox(nextRule, "3cm", "sourceTagname"); // "kind" attribute MultiWordSuggestOracle oracle = new MultiWordSuggestOracle(); ArrayList<String> words = new ArrayList<String>(); words.add("createObject"); words.add("fillAttributes"); words.add("dummyRule"); for (String word : words) oracle.add(word);//from w w w . j av a 2 s . c om oracle.setDefaultSuggestionsFromText(words); SuggestBox kindBox = CTextChangeHandler.createWidthSuggestBox(nextRule, "3cm", "kind", oracle); // "target" attribute MultiWordSuggestOracle typeOracle = new MultiWordSuggestOracle(); ServiceDesigner serviceDesigner = (ServiceDesigner) buildingBlock.get("serviceDesigner"); fillTypesOracle(nextRule, typeOracle, serviceDesigner); final SuggestBox targetBox = CTextChangeHandler.createWidthSuggestBox(nextRule, "3cm", "targetElemName", typeOracle); ; targetBox.setValue(nextRule.getTargetElemName()); targetBox.setWidth("3cm"); Grid ruleRow = new Grid(1, 3); ruleRow.setWidget(0, 0, fromBox); ruleRow.setWidget(0, 1, kindBox); ruleRow.setWidget(0, 2, targetBox); // add listeners for oracle relevant changes UpdateTargetBoxOracleHandler handler = new UpdateTargetBoxOracleHandler(nextRule, typeOracle, serviceDesigner); kindBox.addSelectionHandler(handler); if (treeParent != null) { Grid parentGrid = (Grid) treeParent.getWidget(); if (parentGrid != null) { SuggestBox parentTargetBox = (SuggestBox) parentGrid.getWidget(0, 2); // the target box of the parent parentTargetBox.addSelectionHandler(handler); } } //adding a RulefieldsListener (and handler) to rule fields fromBox.addChangeHandler(rulefieldListener); kindBox.addSelectionHandler(rulefieldListener); targetBox.addSelectionHandler(rulefieldListener); fromBox.addValueChangeHandler(new ValueChangeHandler<String>() { @Override public void onValueChange(ValueChangeEvent<String> event) { updateFactsTree(); } }); TreeItem result = treeParent.addItem(ruleRow); result.setUserObject(nextRule); return result; }
From source file:org.bonitasoft.console.client.view.ItemFilterEditor.java
License:Open Source License
protected SimplePanel createNaturalSearchElement(HTML aSearchScopeExplanations) { DecoratorPanel theNaturalSearchPanel = new DecoratorPanel(); theNaturalSearchPanel.setStylePrimaryName(ROUNDED_STYLE); final SuggestBox theSearchSB = new SuggestBox(mySearchOracle); HorizontalPanel theNaturalSearch = new HorizontalPanel(); final Image theMagnifyIcon = new Image(PICTURE_PLACE_HOLDER); theMagnifyIcon.setStylePrimaryName(CSSClassManager.SEARCH_ICON); if (aSearchScopeExplanations != null) { final DecoratedPopupPanel theExplanationsPopup = new DecoratedPopupPanel(true, false); theExplanationsPopup.setWidget(aSearchScopeExplanations); theMagnifyIcon.addMouseOverHandler(new MouseOverHandler() { public void onMouseOver(MouseOverEvent aEvent) { theExplanationsPopup.setPopupPositionAndShow(new PopupPanel.PositionCallback() { public void setPosition(int anOffsetWidth, int anOffsetHeight) { int left = theMagnifyIcon.getAbsoluteLeft() - (anOffsetWidth / 2); int top = theMagnifyIcon.getAbsoluteTop() + theMagnifyIcon.getHeight() + 7; theExplanationsPopup.setPopupPosition(left, top); }// www . jav a 2 s .c o m }); } }); theMagnifyIcon.addMouseOutHandler(new MouseOutHandler() { public void onMouseOut(MouseOutEvent aEvent) { theExplanationsPopup.hide(); } }); } final Image theActionIcon = new Image(PICTURE_PLACE_HOLDER); theActionIcon.setStylePrimaryName(CSSClassManager.SEARCH_CLEAR_ICON); theActionIcon.setVisible(false); theActionIcon.addClickHandler(new ClickHandler() { public void onClick(ClickEvent aEvent) { theSearchSB.setValue(null); theActionIcon.setVisible(false); clearFilterPatternAndNotify(); } }); final DecoratedPopupPanel theClearTooltip = new DecoratedPopupPanel(true, false); theClearTooltip.setWidget(new HTML(constants.clearFilter())); theActionIcon.addMouseOverHandler(new MouseOverHandler() { public void onMouseOver(MouseOverEvent aEvent) { theClearTooltip.setPopupPositionAndShow(new PopupPanel.PositionCallback() { public void setPosition(int anOffsetWidth, int anOffsetHeight) { int left = theActionIcon.getAbsoluteLeft() - (anOffsetWidth / 2); int top = theActionIcon.getAbsoluteTop() + theActionIcon.getHeight() + 7; theClearTooltip.setPopupPosition(left, top); } }); } }); // theActionIcon.addMouseMoveHandler(new MouseMoveHandler() { // // public void onMouseMove(MouseMoveEvent aEvent) { // theClearTooltip.setPopupPositionAndShow(new PopupPanel.PositionCallback() // { // public void setPosition(int anOffsetWidth, int anOffsetHeight) { // int left = theActionIcon.getAbsoluteLeft() - (anOffsetWidth / 2); // int top = theActionIcon.getAbsoluteTop() + theActionIcon.getHeight() + 7; // theClearTooltip.setPopupPosition(left, top); // } // }); // } // // }); theActionIcon.addMouseOutHandler(new MouseOutHandler() { public void onMouseOut(MouseOutEvent aEvent) { theClearTooltip.hide(); } }); theSearchSB.getTextBox().addKeyDownHandler(new KeyDownHandler() { public void onKeyDown(KeyDownEvent anEvent) { int theKey = anEvent.getNativeKeyCode(); if (KeyCodes.KEY_ENTER == theKey) { if (performNaturalSearch(theSearchSB)) { theActionIcon.setVisible(true); } else { theActionIcon.setVisible(false); } } } }); theSearchSB.getTextBox().addBlurHandler(new BlurHandler() { public void onBlur(BlurEvent aEvent) { theSearchSB.setValue(myFilter.getSearchPattern()); if (theSearchSB.getValue() == null || theSearchSB.getValue().length() == 0) { theActionIcon.setVisible(false); } else { theActionIcon.setVisible(true); } } }); theNaturalSearch.add(theMagnifyIcon); theNaturalSearch.add(theSearchSB); theNaturalSearch.add(theActionIcon); theNaturalSearchPanel.add(theNaturalSearch); return theNaturalSearchPanel; }
From source file:org.bonitasoft.forms.client.view.widget.FormFieldWidget.java
License:Open Source License
/** * Create a {@link SuggestBox} widget//ww w. j a va2s . co m * * @param widgetData * the widget data object * @param fieldValue * the widget value * @return a {@link SuggestBox} */ @SuppressWarnings("unchecked") protected SuggestBox createSuggestBox(final ReducedFormWidget widgetData, final FormFieldValue fieldValue) { final TextBox textBox = new TextBox(); textBox.setEnabled(!widgetData.isReadOnly()); final DefaultSuggestionDisplay suggestionDisplay = new DefaultSuggestionDisplay(); final String popupStyle = widgetData.getItemsStyle(); if (popupStyle != null && popupStyle.length() > 0) { suggestionDisplay.setPopupStyleName(popupStyle); } suggestionsMap = new TreeMap<String, String>(); final MultiWordSuggestOracle oracle = new MultiWordSuggestOracle(); // this fix the reordering of numbers final Comparator<String> numberComparator = new Comparator<String>() { @Override public int compare(final String o1, final String o2) { if (stringIsDouble(o1) && stringIsDouble(o2)) { return Double.valueOf(o1).compareTo(Double.valueOf(o2)); } return o1.compareTo(o2); } private boolean stringIsDouble(final String str) { return str.matches("^(([0-9]*)|(([0-9]*)[\\.,\\,]([0-9]*)))$"); } }; oracle.setComparator(numberComparator); String labelValue = null; final String fieldValueStr = getStringValue(fieldValue); widgetData.getAvailableValues(); for (final ReducedFormFieldAvailableValue availableValue : widgetData.getAvailableValues()) { final String label = availableValue.getLabel(); final String value = availableValue.getValue(); suggestionsMap.put(label, value); oracle.add(label); if (value != null && value.equals(fieldValueStr)) { labelValue = label; } } final SuggestBox suggestBox = new SuggestBox(oracle, textBox, suggestionDisplay); suggestBox.addValueChangeHandler(this); suggestBox.addSelectionHandler(this); if (labelValue != null) { suggestBox.setValue(labelValue); } else { suggestBox.setValue(fieldValueStr); } if (widgetData.getMaxItems() > 0) { suggestBox.setLimit(widgetData.getMaxItems() - 1); } return suggestBox; }