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

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

Introduction

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

Prototype

@Deprecated
public TextBoxBase getTextBox() 

Source Link

Document

Get the text box associated with this suggest box.

Usage

From source file:cc.kune.core.client.sitebar.search.SearchBoxFactory.java

License:GNU Affero Public License

/**
 * Creates the.//  w ww.  j  av  a  2s  .com
 *
 * @param i18n
 *          the i18n
 * @param searchOnlyUsers
 *          the search only users
 * @param showNoResult
 *          the show no result
 * @param id
 *          the id
 * @param callback
 *          the callback
 * @return the multivalue suggest box
 */
public static MultivalueSuggestBox create(final I18nTranslationService i18n, final boolean searchOnlyUsers,
        final boolean showNoResult, final String id, final OnEntitySelectedInSearch callback) {
    final MultivalueSuggestBox multivalueSBox = new MultivalueSuggestBox(i18n, showNoResult,
            getSearchUrl(searchOnlyUsers), false, new OnExactMatch() {
                @Override
                public void onExactMatch(final String match) {
                    // NotifyUser.info(match);
                }
            }) {

        @Override
        public void onSelection(
                final com.google.gwt.event.logical.shared.SelectionEvent<com.google.gwt.user.client.ui.SuggestOracle.Suggestion> event) {
            super.onSelection(event);
            final Suggestion suggestion = event.getSelectedItem();
            if (suggestion instanceof OptionSuggestion) {
                final OptionSuggestion osugg = (OptionSuggestion) suggestion;
                final String value = osugg.getValue();
                if (!OptionSuggestion.NEXT_VALUE.equals(value)
                        && !OptionSuggestion.PREVIOUS_VALUE.equals(value)) {
                    callback.onSeleted(value);
                    this.getSuggestBox().setValue("", false);
                }
            }
        };
    };

    final String siteCommonName = i18n.getSiteCommonName();
    final SuggestBox suggestBox = multivalueSBox.getSuggestBox();
    Tooltip.to(suggestBox,
            searchOnlyUsers ? i18n.t("Type something to search for users in [%s]", siteCommonName)
                    : i18n.t("Type something to search for users and groups in [%s]", siteCommonName));
    final TextBoxBase textBox = suggestBox.getTextBox();
    textBox.setDirection(i18n.isRTL() ? Direction.RTL : Direction.LTR);
    textBox.getElement().setId(id);
    return multivalueSBox;
}

From source file:com.ephesoft.dcma.gwt.rv.client.view.TableExtractionView.java

License:Open Source License

private void setTableList(final FlexTable flexTable, final List<Row> rows, final List<Column> columnList,
        final DataTable inputDataTable, final Document inputDocument) {
    selectedDataTableName = inputDataTable.getName();
    int index = 1;
    for (Row row : rows) {
        final int presentRowNumber = index;
        if (row != null && row.getColumns() != null && row.getColumns().getColumn() != null
                && !row.getColumns().getColumn().isEmpty()) {
            final List<Column> columns = row.getColumns().getColumn();
            int index1 = 0;
            final ArrayList<Coordinates> rowCoordinates = new ArrayList<Coordinates>();
            rowCoordinates.add(row.getRowCoordinates());
            for (final Column column : columnList) {
                final int presentColumnNumber = index1;
                final Column selectedColumn = columns.get(index1);
                columnPattern = tableNameVsColumnPattern.get(inputDataTable.getName());
                List<String> alternateValuesSet = getAlternateValueSet(selectedColumn);
                MultiWordSuggestOracle oracle = setMultiWordOracle(selectedColumn.getValue(),
                        alternateValuesSet);
                final SuggestBox suggestBox = new SuggestBox(oracle);
                suggestBox.addStyleName("tableViewListBox");
                suggestBox.setWidth("100%");

                final RegExValidatableWidget<SuggestBox> validatableSuggestBox = new RegExValidatableWidget<SuggestBox>(
                        suggestBox);// ww w . j a  v a  2 s  .  c  o  m

                if ((columnPattern != null && columnPattern.size() > index1)
                        && (!row.isMannualExtraction() || selectedColumn.isValidationRequired())) {
                    validatableSuggestBox.addValidator(new RegExValidator(validatableSuggestBox,
                            columnPattern.get(index1), suggestBox, presenter.rpcService));
                }

                suggestBox.addValueChangeHandler(new ValueChangeHandler<String>() {

                    @Override
                    public void onValueChange(final ValueChangeEvent<String> event) {
                        selectedColumn.setValue(event.getValue());
                        selectedColumn.setValid(validatableSuggestBox.validate());
                        validatableSuggestBox.toggleValidDateBox();
                    }
                });

                suggestBox.getTextBox().addFocusHandler(new FocusHandler() {

                    @Override
                    public void onFocus(FocusEvent event) {
                        TableExtractionView.this
                                .fireEvent(new ValidationFieldChangeEvent(selectedColumn, rowCoordinates));
                        if (event.getSource() instanceof TextBox) {
                            selectedTextBox = (TextBox) event.getSource();
                        }
                        selectedRowNumber = presentRowNumber;
                        selectedColumnNumber = presentColumnNumber;
                        selectedDocument = inputDocument;
                        if (selectedDataTableName != null) {
                            clearSelectedRowStyle(tableNameVsViewMap.get(selectedDataTableName));
                        }
                        if (!presenter.isManualTableExtraction()) {
                            selDataTable = inputDataTable;
                        }
                        selectedDataTableName = inputDataTable.getName();
                        addSelectedRowStyle(flexTable, rows, columnList, selectedRowNumber);
                    }
                });

                suggestBox.addSelectionHandler(new SelectionHandler<Suggestion>() {

                    @Override
                    public void onSelection(SelectionEvent<Suggestion> suggestion) {
                        String inputString = suggestion.getSelectedItem().getReplacementString();
                        setSuggestBoxEvents(selectedColumn, inputString, validatableSuggestBox);
                        ValueChangeEvent.fire(suggestBox, inputString);
                        Row currRow = rows.get(selectedRowNumber - 1);
                        Column currColumn = currRow.getColumns().getColumn().get(selectedColumnNumber);
                        List<Coordinates> coorList = new ArrayList<Coordinates>();
                        coorList.add(currRow.getRowCoordinates());
                        TableExtractionView.this
                                .fireEvent(new ValidationFieldChangeEvent(currColumn, coorList));
                    }
                });

                suggestBox.setText(selectedColumn.getValue());
                if (!selectedColumn.isValid()) {
                    validatableSuggestBox.getWidget().addStyleName("dateBoxFormatError");
                }
                if (row.isMannualExtraction()) {
                    ValueChangeEvent.fire(suggestBox, selectedColumn.getValue());
                }
                flexTable.setWidget(index, index1, validatableSuggestBox.getWidget());
                index1++;
            }
            index++;
        }
    }
}

From source file:com.ephesoft.dcma.gwt.rv.client.view.TableExtractionView.java

License:Open Source License

/**
 * This method performs insert,delete and delete all operation on table.
 * //from  w w w .j  av a 2s  .c om
 * @param action {@link Action} action selected by user
 * @param radioButtonNumber {@link Integer} 0 for insert row before selected row, 1 for insert row after selected row
 * @param button {@link Button} button where focus is set after action is performed
 */
public void insertDeleteRow(final Action action, final int radioButtonNumber, final Button button) {

    List<DataTable> dataTablesList = selectedDocument.getDataTables().getDataTable();
    if (dataTablesList == null || dataTablesList.isEmpty()) {
        TableExtractionView.this.fireEvent(new TableViewDisplayEvent(0));
        return;
    }
    for (final DataTable dataTable : dataTablesList) {
        int focusRow = 0;
        if (dataTable.getName().equals(selectedDataTableName)) {
            HeaderRow headerRow = dataTable.getHeaderRow();
            if (dataTable != null && headerRow != null && headerRow.getColumns() != null
                    && headerRow.getColumns().getColumn() != null
                    && !headerRow.getColumns().getColumn().isEmpty()) {
                FlexTable selectedView = tableNameVsViewMap.get(selectedDataTableName);
                final List<Column> columnList = headerRow.getColumns().getColumn();
                selectedView.clear();
                if (action == Action.DELETE) {
                    dataTable.getRows().getRow().remove(selectedRowNumber - 1);
                    selectedView.removeRow(selectedRowNumber);
                    focusRow = selectedRowNumber;
                } else if (action == Action.INSERT) {
                    Row row = createNewRow(columnList);
                    if (dataTable.getRows().getRow() == null || dataTable.getRows().getRow().isEmpty()) {
                        selectedRowNumber = 1;
                        dataTable.getRows().getRow().add(0, row);
                        focusRow = 1;
                    } else {
                        if (radioButtonNumber == 0) {
                            dataTable.getRows().getRow().add(selectedRowNumber - 1, row);
                            focusRow = selectedRowNumber;
                        } else if (radioButtonNumber == 1) {
                            dataTable.getRows().getRow().add(selectedRowNumber, row);
                            focusRow = selectedRowNumber + 1;
                        }
                    }
                } else if (action == Action.DELETE_ALL) {
                    dataTable.getRows().getRow().clear();
                    selectedView.removeAllRows();
                }
                if (dataTable.getRows().getRow().size() != 0) {
                    addHeaderColumns(headerRow.getColumns().getColumn(), selectedView);
                    createTableList(selectedView, dataTable.getRows().getRow(), columnList, dataTable,
                            selectedDocument);
                } else {
                    selectedRowNumber = 0;
                    setEmptyTableView(selectedView, headerRow);
                    if (button != null) {
                        setFocus(button);
                    }
                }
                if (dataTable.getRows().getRow().size() > selectedRowNumber - 1
                        && !dataTable.getRows().getRow().isEmpty()) {
                    SuggestBox suggestBox = (SuggestBox) selectedView.getWidget(focusRow, 0);
                    suggestBox.getTextBox().setFocus(true);
                } else if (!dataTable.getRows().getRow().isEmpty()) {
                    SuggestBox suggestBox = (SuggestBox) selectedView.getWidget(selectedRowNumber - 1, 0);
                    suggestBox.getTextBox().setFocus(true);
                }
                break;
            }
        }
    }

}

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);
                    }//from  www .j  av  a  2s  .  c  om
                });
            }

        });
        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;
}