Example usage for com.google.gwt.user.client.ui SuggestBox getValue

List of usage examples for com.google.gwt.user.client.ui SuggestBox getValue

Introduction

In this page you can find the example usage for com.google.gwt.user.client.ui SuggestBox getValue.

Prototype

public String getValue() 

Source Link

Usage

From source file:com.googlesource.gerrit.plugins.reviewers.client.ReviewersScreen.java

License:Apache License

Panel createInputPanel() {
    Grid inputGrid = new Grid(2, 2);

    final NpTextBox filterBox = new NpTextBox();
    filterBox.getElement().setPropertyString("placeholder", "filter");
    inputGrid.setText(0, 0, "Filter: ");
    inputGrid.setWidget(0, 1, filterBox);

    // TODO(davido): Remove hard coded start suggest char 3
    final ReviewerSuggestOracle oracle = new ReviewerSuggestOracle(3, projectName);
    final SuggestBox reviewerBox = new SuggestBox(oracle, new NpTextBox());
    reviewerBox.getElement().setPropertyString("placeholder", "reviewer");
    inputGrid.setText(1, 0, "Reviewer: ");
    inputGrid.setWidget(1, 1, reviewerBox);

    Button addButton = new Button("Add");
    addButton.setStyleName("reviewers-addButton");
    addButton.addClickHandler(new ClickHandler() {
        @Override/*from   w w  w  . ja v  a2  s .co  m*/
        public void onClick(final ClickEvent event) {
            ReviewerEntry e = new ReviewerEntry(filterBox.getValue(), reviewerBox.getValue());
            if (!rEntries.contains(e) && !e.filter.isEmpty() && !e.reviewer.isEmpty()) {
                doSave(Action.ADD, e);
            }
            filterBox.setText("");
            reviewerBox.setText("");
        }
    });
    filterBox.setEnabled(isOwner);
    reviewerBox.setEnabled(isOwner);
    addButton.setEnabled(isOwner);

    Panel p = new VerticalPanel();
    p.setStyleName("reviewers-inputPanel");
    p.add(inputGrid);
    p.add(addButton);
    return p;
}

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 .  jav a2 s .  c  om
        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:net.opentsdb.tsd.client.MetricForm.java

License:Open Source License

public void autoSuggestTag(final String tag) {
    // First try to see if the tag is already in the table.
    final int nrows = tagtable.getRowCount();
    int unused_row = -1;
    for (int row = 1; row < nrows; row++) {
        final SuggestBox tagname = ((SuggestBox) tagtable.getWidget(row, 1));
        final SuggestBox tagvalue = ((SuggestBox) tagtable.getWidget(row, 2));
        final String thistag = tagname.getValue();
        if (thistag.equals(tag)) {
            return; // This tag is already in the table.
        }//from w ww . j a  va 2  s.c om
        if (thistag.isEmpty() && tagvalue.getValue().isEmpty()) {
            unused_row = row;
        }
    }
    if (unused_row >= 0) {
        ((SuggestBox) tagtable.getWidget(unused_row, 1)).setValue(tag);
    } else {
        addTag(tag);
    }
}

From source file:org.bonitasoft.console.client.view.ItemFilterEditor.java

License:Open Source License

protected boolean performNaturalSearch(SuggestBox aSuggestBox) {
    final String theSearchPattern = aSuggestBox.getValue();
    boolean isSearching = false;
    if (theSearchPattern != null && theSearchPattern.length() > 0) {
        myFilter.setSearchPattern(theSearchPattern);
        myFilter.setStartingIndex(0);/*  w ww.  ja v a 2s  .c om*/
        mySearchOracle.add(theSearchPattern);
        myChanges.fireModelChange(FILTER_UPDATED_PROPERTY, null, myFilter);
        isSearching = true;
    } else {
        if (myFilter.getSearchPattern() == null || myFilter.getSearchPattern().length() == 0) {
            if (myMessageDataSource != null) {
                myMessageDataSource.addWarningMessage(messages.searchPatternEmpty());
            }
        } else {
            // clear pattern filter
            clearFilterPatternAndNotify();
        }
    }
    return isSearching;
}

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);
                    }// w  ww .  j ava 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

/**
 * Retrieve the value of the field under the form of a {@link FormFieldValue} object. This conversion is needed because RPC
 * calls do not support the type 'Object'.
 *
 * @return a {@link FormFieldValue} object
 *//*from w  w  w  . jav a2 s .  co  m*/
@SuppressWarnings("unchecked")
public FormFieldValue getValue() {

    long attachmentId = -1;
    String attachmentName = null;
    Serializable value = null;
    String valueType = null;
    String format = null;
    String displayedValue = null;
    switch (widgetType) {
    case TEXTBOX:
        final TextBox textBox = (TextBox) fieldWidget;
        value = textBox.getValue();
        valueType = SupportedFieldTypes.JAVA_STRING_CLASSNAME;
        break;
    case TEXTAREA:
        final TextArea textArea = (TextArea) fieldWidget;
        value = textArea.getValue();
        valueType = SupportedFieldTypes.JAVA_STRING_CLASSNAME;
        break;
    case TEXT:
        final HTML text = (HTML) fieldWidget;
        value = text.getHTML();
        valueType = SupportedFieldTypes.JAVA_STRING_CLASSNAME;
        break;
    case RICH_TEXTAREA:
        final RichTextWidget richTextWidget = (RichTextWidget) fieldWidget;
        value = richTextWidget.getValue();
        valueType = SupportedFieldTypes.JAVA_STRING_CLASSNAME;
        break;
    case PASSWORD:
        final PasswordTextBox passwordTextBox = (PasswordTextBox) fieldWidget;
        value = passwordTextBox.getValue();
        valueType = SupportedFieldTypes.JAVA_STRING_CLASSNAME;
        break;
    case CHECKBOX:
        final CheckBox checkBox = (CheckBox) fieldWidget;
        value = checkBox.getValue();
        valueType = SupportedFieldTypes.JAVA_BOOLEAN_CLASSNAME;
        break;
    case RADIOBUTTON_GROUP:
        final RadioButtonGroupWidget radioButtonGroupWidget = (RadioButtonGroupWidget) fieldWidget;
        value = radioButtonGroupWidget.getValue();
        valueType = SupportedFieldTypes.JAVA_STRING_CLASSNAME;
        break;
    case LISTBOX_SIMPLE:
        final ListBox listBox = (ListBox) fieldWidget;
        final int index = listBox.getSelectedIndex();
        if (index > -1) {
            value = listBox.getValue(index);
        }
        valueType = SupportedFieldTypes.JAVA_STRING_CLASSNAME;
        break;
    case LISTBOX_MULTIPLE:
        value = new ArrayList<String>();
        final ListBox listBoxMulti = (ListBox) fieldWidget;
        for (int i = 0; i < listBoxMulti.getItemCount(); i++) {
            if (listBoxMulti.isItemSelected(i)) {
                ((List<String>) value).add(listBoxMulti.getValue(i));
            }
        }
        valueType = SupportedFieldTypes.JAVA_COLLECTION_CLASSNAME;
        break;
    case SUGGESTBOX:
        final SuggestBox suggestBox = (SuggestBox) fieldWidget;
        displayedValue = suggestBox.getValue();
        value = suggestionsMap.get(displayedValue);
        if (value == null) {
            value = displayedValue;
        }
        valueType = SupportedFieldTypes.JAVA_STRING_CLASSNAME;
        break;
    case SUGGESTBOX_ASYNC:
        final AsyncSuggestBoxWidget formAsyncSuggestBoxWidget = (AsyncSuggestBoxWidget) fieldWidget;
        value = formAsyncSuggestBoxWidget.getValue();
        valueType = SupportedFieldTypes.JAVA_STRING_CLASSNAME;
        break;
    case CHECKBOX_GROUP:
        value = new ArrayList<String>();
        final CheckboxGroupWidget checkboxGroupWidget = (CheckboxGroupWidget) fieldWidget;
        for (final String checkboxGroupValue : checkboxGroupWidget.getValue()) {
            ((List<String>) value).add(checkboxGroupValue);
        }
        valueType = SupportedFieldTypes.JAVA_COLLECTION_CLASSNAME;
        break;
    case DATE:
        final DateBox dateBox = (DateBox) fieldWidget;
        final String strValue = dateBox.getTextBox().getValue();
        final Date dtValue = dateBox.getValue();
        if (strValue != null && strValue.length() > 0 && dtValue == null) {
            value = strValue;
            valueType = SupportedFieldTypes.JAVA_STRING_CLASSNAME;
        } else {
            value = dtValue;
            valueType = SupportedFieldTypes.JAVA_DATE_CLASSNAME;
        }
        break;
    case DURATION:
        final DurationWidget duration = (DurationWidget) fieldWidget;
        value = duration.getValue();
        valueType = SupportedFieldTypes.JAVA_LONG_CLASSNAME;
        break;
    case FILEUPLOAD:
        final FileUploadWidget fileUpload = (FileUploadWidget) fieldWidget;
        attachmentName = fileUpload.getAttachmentName();
        attachmentId = fileUpload.getAttachmentId();
        value = fileUpload.getValue();
        displayedValue = fileUpload.getDisplayedValue();
        valueType = fileUpload.getValueType();
        break;
    case TABLE:
        final TableWidget table = (TableWidget) fieldWidget;
        value = (Serializable) table.getValue();
        valueType = SupportedFieldTypes.JAVA_COLLECTION_CLASSNAME;
        break;
    case EDITABLE_GRID:
        final EditableGridWidget grid = (EditableGridWidget) fieldWidget;
        value = (Serializable) grid.getValue();
        valueType = SupportedFieldTypes.JAVA_COLLECTION_CLASSNAME;
        break;
    case HIDDEN:
        final Hidden hidden = (Hidden) fieldWidget;
        value = hidden.getValue();
        valueType = SupportedFieldTypes.JAVA_STRING_CLASSNAME;
        break;
    default:
        break;
    }
    if (displayFormat != null) {
        format = displayFormat.getPattern();
    } else {
        format = DateTimeFormat.getFormat(PredefinedFormat.DATE_LONG).getPattern();
    }
    final FormFieldValue formFieldValue = new FormFieldValue(value, valueType, format, fieldOutputType);
    if (WidgetType.FILEUPLOAD.equals(widgetType)) {
        formFieldValue.setDocumentName(attachmentName);
        formFieldValue.setDocumentId(attachmentId);
        formFieldValue.setDisplayedValue(displayedValue);
        formFieldValue.setDocument(true);
    }
    return formFieldValue;
}

From source file:org.gatein.management.gadget.client.Application.java

License:Open Source License

/**
 * Create the user management content tab
 *
 * @return a {@code Widget} for the user management tab
 *///from  ww w  .j  a va2  s . c  o  m
private Widget getUserManagementTab() {
    AbsolutePanel userManagementPanel = new AbsolutePanel();
    userManagementPanel.setSize("855px", "304px");

    DecoratorPanel decoratorPanelEast = new DecoratorPanel();
    userManagementPanel.add(decoratorPanelEast, 0, 10);
    decoratorPanelEast.setSize("245px", "295px");

    AbsolutePanel absolutePanelEast = new AbsolutePanel();
    decoratorPanelEast.setWidget(absolutePanelEast);
    absolutePanelEast.setSize("235px", "285px");

    Label lblNewLabel = new Label("Enter a username :");
    lblNewLabel.setDirectionEstimator(true);
    absolutePanelEast.add(lblNewLabel, 10, 10);
    lblNewLabel.setSize("205px", "29px");

    final SuggestBox suggestBox = new SuggestBox(new RPCSuggestOracle());
    absolutePanelEast.add(suggestBox, 10, 45);
    suggestBox.setSize("210px", "21px");

    final InlineHTML userHeader = new InlineHTML("Select user");
    userHeader.setStyleName("header-style");
    final HTML userDetails = new HTML("No user selected", true);
    final Button exportBtn = new Button("Export site");

    Button showUserbtn = new Button("Show", new ClickHandler() {

        public void onClick(ClickEvent event) {
            String username = suggestBox.getValue();
            gtnService.getUserSite(getPortalContainerName(), username, new AsyncCallback<TreeNode>() {

                public void onFailure(Throwable caught) {
                    exportBtn.setEnabled(false);
                    userHeader.setHTML("Failed to access remote server");
                    userDetails.setHTML(caught.getMessage());
                }

                public void onSuccess(TreeNode node) {
                    if (node.isExportable()) {
                        exportBtn.setEnabled(true);
                        Application.this.exportHref = DOWNLOAD_ACTION_URL + "?pc=" + getPortalContainerName()
                                + "&ownerType=" + node.getType() + "&ownerId=" + node.getSiteName();
                    } else {
                        exportBtn.setEnabled(false);
                        Application.this.exportHref = "#";
                    }

                    userHeader.setHTML("&raquo; User site &raquo; " + node.getSiteName());
                    userDetails.setHTML(node.getNodeInfo());
                }
            });
        }
    });
    absolutePanelEast.add(showUserbtn, 69, 251);

    DecoratorPanel decoratorPanelCenter = new DecoratorPanel();
    userManagementPanel.add(decoratorPanelCenter, 251, 10);
    decoratorPanelCenter.setSize("584px", "295px");

    AbsolutePanel absolutePanelCenter = new AbsolutePanel();
    absolutePanelCenter.setSize("587px", "285px");
    decoratorPanelCenter.setWidget(absolutePanelCenter);

    exportBtn.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            frame.setUrl(exportHref);
        }
    });
    exportBtn.setEnabled(false);
    absolutePanelCenter.add(exportBtn, 10, 251);

    absolutePanelCenter.add(userHeader, 10, 10);
    userHeader.setSize("567px", "29px");

    absolutePanelCenter.add(userDetails, 10, 101);
    userDetails.setSize("567px", "144px");

    InlineHTML nlnhtmlNewInlinehtml = new InlineHTML("<hr />");
    absolutePanelCenter.add(nlnhtmlNewInlinehtml, 10, 45);
    nlnhtmlNewInlinehtml.setSize("567px", "2px");

    return userManagementPanel;
}

From source file:tsd.client.MetricForm.java

License:Open Source License

public void autoSuggestTag(final String tag) {
    // First try to see if the tag is already in the table.
    final int nrows = tagtable.getRowCount();
    int unused_row = -1;
    for (int row = 1; row < nrows; row++) {
        final SuggestBox tagname = ((SuggestBox) tagtable.getWidget(row, 1));
        final SuggestBox tagvalue = ((SuggestBox) tagtable.getWidget(row, 2));
        final String thistag = tagname.getValue();
        if (thistag.equals(tag)) {
            return; // This tag is already in the table.
        }/* w w  w  .  j  a  va 2s.c  om*/
        if (thistag.isEmpty() && tagvalue.getValue().isEmpty()) {
            unused_row = row;
            break;
        }
    }
    if (unused_row >= 0) {
        ((SuggestBox) tagtable.getWidget(unused_row, 1)).setValue(tag);
    } else {
        addTag(tag);
    }
}

From source file:uk.ac.ebi.fg.annotare2.web.gwt.editor.client.view.experiment.design.SampleColumnEditor.java

License:Apache License

private void validateEfoTerm(final SuggestBox suggestBox, final AsyncCallback<OntologyTerm> asyncCallback) {
    suggestBox.removeStyleName(INVALID_TEXT_BOX_STYLE);
    String value = suggestBox.getValue();
    value = value.trim();//ww w .j a  va  2  s. co m
    if (value.isEmpty()) {
        asyncCallback.onSuccess(null);
        return;
    }
    efoSuggestService.getTermByLabel(value,
            new ReportingAsyncCallback<OntologyTerm>(FailureMessage.UNABLE_TO_LOAD_EFO) {
                @Override
                public void onSuccess(OntologyTerm term) {
                    if (term == null) {
                        suggestBox.addStyleName(INVALID_TEXT_BOX_STYLE);
                        asyncCallback.onSuccess(null);
                    } else {
                        suggestBox.setValue(term.getLabel(), false);
                        asyncCallback.onSuccess(term);
                    }
                }
            });
}