Class AutoCompleteComboViewer

  • All Implemented Interfaces:
    EventListener, IInputProvider, IInputSelectionProvider, IPostSelectionProvider, ISelectionProvider, org.eclipse.swt.events.FocusListener, org.eclipse.swt.events.KeyListener, org.eclipse.swt.events.ModifyListener, org.eclipse.swt.internal.SWTEventListener

    public class AutoCompleteComboViewer
    extends ComboViewer
    implements org.eclipse.swt.events.ModifyListener, org.eclipse.swt.events.FocusListener, org.eclipse.swt.events.KeyListener
    ComboViewer extension with auto complete support.

    By default, eontent to proposal associations will be defined by ILabelProvider of this combo viewer. Clients may override with buildProposals(Iterable). Iterable input is expected for this viewer.

    SWT.DROP_DOWN style is automatically appended to viewer.

    • Constructor Detail

      • AutoCompleteComboViewer

        public AutoCompleteComboViewer​(org.eclipse.swt.widgets.Composite parent)
        Constructor of AutoCompleteComboViewer.
        Parameters:
        parent - the parent control, cannot be null
      • AutoCompleteComboViewer

        public AutoCompleteComboViewer​(org.eclipse.swt.widgets.Composite parent,
                                       int style)
        Constructor of AutoCompleteComboViewer.
        Parameters:
        parent - the parent control, cannot be null
        style - the SWT style bits
    • Method Detail

      • modifyText

        public void modifyText​(org.eclipse.swt.events.ModifyEvent event)
        Specified by:
        modifyText in interface org.eclipse.swt.events.ModifyListener
      • keyPressed

        public void keyPressed​(org.eclipse.swt.events.KeyEvent event)
        Specified by:
        keyPressed in interface org.eclipse.swt.events.KeyListener
      • keyReleased

        public void keyReleased​(org.eclipse.swt.events.KeyEvent event)
        Specified by:
        keyReleased in interface org.eclipse.swt.events.KeyListener
      • focusGained

        public void focusGained​(org.eclipse.swt.events.FocusEvent event)
        Specified by:
        focusGained in interface org.eclipse.swt.events.FocusListener
      • focusLost

        public void focusLost​(org.eclipse.swt.events.FocusEvent event)
        Specified by:
        focusLost in interface org.eclipse.swt.events.FocusListener
      • isAllowed

        protected boolean isAllowed​(char character)
        Returns whether the given control character is allowed for auto complete popup providing.
        Parameters:
        character - the control character to check
        Returns:
        whether the given control character is allowed for auto complete popup providing
      • buildProposals

        protected com.google.common.collect.Multimap<String,​Object> buildProposals​(Iterable<Object> input)
        Build proposals for the viewer auto completion. Default implementation uses ILabelProvider to get proposal text. Allows non-unique input object text presentation. Returns multi map:
        • key - string representation for the target object
        • value - the target object
        Parameters:
        input - an iterable input of the viewer, cannot be null, can be empty
        Returns:
        proposals multi map for the viewer auto completion, never null
      • getLabelText

        protected String getLabelText​(Object object)
        Returns label text for the given input object.
        Parameters:
        object - the input object to get label text for, cannot be null
        Returns:
        the label text for the given input object, never null
      • initializeAutoComplete

        protected void initializeAutoComplete()
        Initialize auto completion support for this viewer.
      • extractSelection

        protected IStructuredSelection extractSelection​(String typedValue)
        Try to extract IStructuredSelection from given text input. Can return structured selection with item from current input of combo viewer or empty selection.
        Parameters:
        typedValue - text input to extract structured selection from, cannot be null
        Returns:
        extracted structured selection, never null, can be empty
      • ensureEnabled

        protected void ensureEnabled()
        Enable auto complete if it is not already enabled.
      • ensureDisabled

        protected void ensureDisabled()
        Disable auto complete if it is enabled.