Class SuggestBoxNewEditor

java.lang.Object
com.google.gwt.user.client.ui.UIObject
com.google.gwt.user.client.ui.Widget
com.google.gwt.user.client.ui.Composite
com.google.gwt.user.client.ui.AbstractSuggestBoxNewEditor
de.knightsoftnet.mtwidgets.client.ui.widget.SuggestBoxNewEditor
All Implemented Interfaces:
com.google.gwt.event.dom.client.HasAllKeyHandlers, com.google.gwt.event.dom.client.HasKeyDownHandlers, com.google.gwt.event.dom.client.HasKeyPressHandlers, com.google.gwt.event.dom.client.HasKeyUpHandlers, com.google.gwt.event.logical.shared.HasAttachHandlers, com.google.gwt.event.logical.shared.HasSelectionHandlers<com.google.gwt.user.client.ui.SuggestOracle.Suggestion>, com.google.gwt.event.logical.shared.HasValueChangeHandlers<String>, com.google.gwt.event.shared.HasHandlers, com.google.gwt.user.client.EventListener, com.google.gwt.user.client.TakesValue<String>, com.google.gwt.user.client.ui.Focusable, com.google.gwt.user.client.ui.HasAnimation, com.google.gwt.user.client.ui.HasEnabled, com.google.gwt.user.client.ui.HasText, com.google.gwt.user.client.ui.HasValue<String>, com.google.gwt.user.client.ui.HasVisibility, com.google.gwt.user.client.ui.IsRenderable, com.google.gwt.user.client.ui.IsWidget, org.gwtproject.editor.client.IsEditor<org.gwtproject.editor.client.LeafValueEditor<String>>, org.gwtproject.editor.client.TakesValue<String>
Direct Known Subclasses:
SuggestBoxWithEditorErrors

public class SuggestBoxNewEditor extends AbstractSuggestBoxNewEditor implements org.gwtproject.editor.client.IsEditor<org.gwtproject.editor.client.LeafValueEditor<String>>, org.gwtproject.editor.client.TakesValue<String>
A SuggestBoxNewEditor is a text box or text area which displays a pre-configured set of selections that match the user's input.

Each SuggestBoxNewEditor is associated with a single SuggestOracle. The SuggestOracle is used to provide a set of selections given a specific query string.

By default, the SuggestBoxNewEditor uses a MultiWordSuggestOracle as its oracle. Below we show how a MultiWordSuggestOracle can be configured:

 MultiWordSuggestOracle oracle = new MultiWordSuggestOracle();
 oracle.add("Cat");
 oracle.add("Dog");
 oracle.add("Horse");
 oracle.add("Canary");

 SuggestBoxNewEditor box = new SuggestBoxNewEditor(oracle);
 

Using the example above, if the user types "C" into the text widget, the oracle will configure the suggestions with the "Cat" and "Canary" suggestions. Specifically, whenever the user types a key into the text widget, the value is submitted to the MultiWordSuggestOracle.

Note that there is no method to retrieve the "currently selected suggestion" in a SuggestBoxNewEditor, because there are points in time where the currently selected suggestion is not defined. For example, if the user types in some text that does not match any of the SuggestBoxNewEditor's suggestions, then the SuggestBoxNewEditor will not have a currently selected suggestion. It is more useful to know when a suggestion has been chosen from the SuggestBoxNewEditor's list of suggestions. A SuggestBoxNewEditor fires SelectionEvents whenever a suggestion is chosen, and handlers for these events can be added using the AbstractSuggestBoxNewEditor.addSelectionHandler(SelectionHandler) method.

SuggestBox example image

CSS Style Rules

.gwt-SuggestBox
the suggest box itself
See Also:
  • Constructor Details

  • Method Details

    • wrap

      public static SuggestBoxNewEditor wrap(com.google.gwt.user.client.ui.SuggestOracle oracle, com.google.gwt.dom.client.Element element)
      Creates a SuggestBoxNewEditor widget that wraps an existing <input type='text'> element.

      This element must already be attached to the document. If the element is removed from the document, you must call RootPanel.detachNow(Widget).

      Parameters:
      oracle - the suggest box oracle to use
      element - the element to be wrapped
    • getBoxAsFoucsWidget

      protected com.google.gwt.user.client.ui.FocusWidget getBoxAsFoucsWidget()
      Specified by:
      getBoxAsFoucsWidget in class AbstractSuggestBoxNewEditor
    • asEditor

      public org.gwtproject.editor.client.LeafValueEditor<String> asEditor()
      Returns a TakesValueEditor backed by the SuggestBoxNewEditor.
      Specified by:
      asEditor in interface org.gwtproject.editor.client.IsEditor<org.gwtproject.editor.client.LeafValueEditor<String>>
    • getTabIndex

      public int getTabIndex()
      Specified by:
      getTabIndex in interface com.google.gwt.user.client.ui.Focusable
      Specified by:
      getTabIndex in class AbstractSuggestBoxNewEditor
    • getText

      public String getText()
      Specified by:
      getText in interface com.google.gwt.user.client.ui.HasText
      Specified by:
      getText in class AbstractSuggestBoxNewEditor
    • getValue

      public String getValue()
      Specified by:
      getValue in interface com.google.gwt.user.client.ui.HasValue<String>
      Specified by:
      getValue in interface com.google.gwt.user.client.TakesValue<String>
      Specified by:
      getValue in interface org.gwtproject.editor.client.TakesValue<String>
      Specified by:
      getValue in class AbstractSuggestBoxNewEditor
    • getValueBox

      @Ignore public ValueBoxBaseWithEditorErrors<String> getValueBox()
      Get the ValueBoxBaseWithEditorErrors associated with this suggest box.
      Returns:
      this suggest box's value box
    • isEnabled

      public boolean isEnabled()
      Gets whether this widget is enabled.
      Specified by:
      isEnabled in interface com.google.gwt.user.client.ui.HasEnabled
      Returns:
      true if the widget is enabled
    • setAccessKey

      public void setAccessKey(char key)
      Specified by:
      setAccessKey in interface com.google.gwt.user.client.ui.Focusable
      Specified by:
      setAccessKey in class AbstractSuggestBoxNewEditor
    • setEnabled

      public void setEnabled(boolean enabled)
      Sets whether this widget is enabled.
      Specified by:
      setEnabled in interface com.google.gwt.user.client.ui.HasEnabled
      Overrides:
      setEnabled in class AbstractSuggestBoxNewEditor
      Parameters:
      enabled - true to enable the widget, false to disable it
    • setFocus

      public void setFocus(boolean focused)
      Specified by:
      setFocus in interface com.google.gwt.user.client.ui.Focusable
      Specified by:
      setFocus in class AbstractSuggestBoxNewEditor
    • setTabIndex

      public void setTabIndex(int index)
      Specified by:
      setTabIndex in interface com.google.gwt.user.client.ui.Focusable
    • setText

      public void setText(String text)
      Specified by:
      setText in interface com.google.gwt.user.client.ui.HasText
    • setValue

      public void setValue(String newValue)
      Specified by:
      setValue in interface com.google.gwt.user.client.ui.HasValue<String>
      Specified by:
      setValue in interface com.google.gwt.user.client.TakesValue<String>
      Specified by:
      setValue in interface org.gwtproject.editor.client.TakesValue<String>
    • setValue

      public void setValue(String value, boolean fireEvents)
      Specified by:
      setValue in interface com.google.gwt.user.client.ui.HasValue<String>
    • addEventsToTextBox

      protected void addEventsToTextBox(com.google.gwt.event.shared.EventHandler events)
      Specified by:
      addEventsToTextBox in class AbstractSuggestBoxNewEditor