Class MenuActionComboBox<T>

java.lang.Object
org.eclipse.core.commands.common.EventManager
org.eclipse.jface.action.AbstractAction
org.eclipse.jface.action.Action
com.e1c.langtool.ui.common.combo.MenuActionComboBox<T>
All Implemented Interfaces:
IComboBox<T>, org.eclipse.jface.action.IAction, org.eclipse.jface.action.IMenuCreator

public class MenuActionComboBox<T> extends org.eclipse.jface.action.Action implements IComboBox<T>, org.eclipse.jface.action.IAction, org.eclipse.jface.action.IMenuCreator
The implementation of combobox based on Action with dropdown menu.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
    The factory is used to create items for MenuActionComboBox.
    static class 
    The base implementation of contribution item factory.
  • Field Summary

    Fields inherited from interface org.eclipse.jface.action.IAction

    AS_CHECK_BOX, AS_DROP_DOWN_MENU, AS_PUSH_BUTTON, AS_RADIO_BUTTON, AS_UNSPECIFIED, CHECKED, DESCRIPTION, ENABLED, HANDLED, IMAGE, RESULT, TEXT, TOOL_TIP_TEXT
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new combobox.
    Creates a new combobox with default item factory MenuActionComboBox.ItemFactory that initialized by this combobox and the given label provider.
    MenuActionComboBox(ILabelProvider labelProvider, List<T> content)
    Creates a new combobox with default item factory MenuActionComboBox.ItemFactory that initialized by this combobox and the given label provider.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addItem(int index, T item)
    Adds the new item at the given zero-relative index.
    void
    addItem(T item)
    Adds the new item to the end of this combo.
    void
    addSelectionListener(org.eclipse.swt.events.SelectionListener selectionListener)
    Adds the listener that will be notified when the methods select(int) or deselect() are called.
    void
    Removes all items from this combobox.
    int
    Returns the number of items contained in this combobox.
    void
    Deselects the currently selected item.
    void
     
    getItem(int index)
    Returns item at the given zero-relative index.
    org.eclipse.swt.widgets.Menu
    getMenu(org.eclipse.swt.widgets.Control parent)
     
    org.eclipse.swt.widgets.Menu
    getMenu(org.eclipse.swt.widgets.Menu parent)
     
    int
    Returns the index of currently selected item or -1 if there is not any selected item.
    Returns the currently selected item or Optional.empty() if there is not any selected item.
    int
    indexOf(T item)
    Returns the index of the given item or -1 if the given item is not found.
    void
    removeItem(int index)
    Removes the item at the given zero-relative index.
    void
    removeSelectionListener(org.eclipse.swt.events.SelectionListener selectionListener)
    Removes the given selection listener from the collection of listeners for this combobox.
    void
    select(int index)
    Selects the item at the zero-relative index.

    Methods inherited from class org.eclipse.jface.action.Action

    convertAccelerator, convertAccelerator, findKeyCode, findKeyString, findModifier, findModifierString, getAccelerator, getActionDefinitionId, getDescription, getDisabledImageDescriptor, getHelpListener, getHoverImageDescriptor, getId, getImageDescriptor, getMenuCreator, getStyle, getText, getToolTipText, isChecked, isEnabled, isHandled, notifyResult, removeAcceleratorText, removeMnemonics, run, runWithEvent, setAccelerator, setActionDefinitionId, setChecked, setDescription, setDisabledImageDescriptor, setEnabled, setHelpListener, setHoverImageDescriptor, setId, setImageDescriptor, setMenuCreator, setText, setToolTipText

    Methods inherited from class org.eclipse.jface.action.AbstractAction

    addPropertyChangeListener, firePropertyChange, firePropertyChange, removePropertyChangeListener

    Methods inherited from class org.eclipse.core.commands.common.EventManager

    addListenerObject, clearListeners, getListeners, isListenerAttached, removeListenerObject

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.eclipse.jface.action.IAction

    addPropertyChangeListener, getAccelerator, getActionDefinitionId, getDescription, getDisabledImageDescriptor, getHelpListener, getHoverImageDescriptor, getId, getImageDescriptor, getMenuCreator, getStyle, getText, getToolTipText, isChecked, isEnabled, isHandled, removePropertyChangeListener, run, runWithEvent, setAccelerator, setActionDefinitionId, setChecked, setDescription, setDisabledImageDescriptor, setEnabled, setHelpListener, setHoverImageDescriptor, setId, setImageDescriptor, setMenuCreator, setText, setToolTipText
  • Constructor Details

    • MenuActionComboBox

      public MenuActionComboBox(MenuActionComboBox.IContributionItemFactory<T> itemFactory)
      Creates a new combobox.
      Parameters:
      itemFactory - the factory to create items for dropdown menu
    • MenuActionComboBox

      public MenuActionComboBox(ILabelProvider labelProvider)
      Creates a new combobox with default item factory MenuActionComboBox.ItemFactory that initialized by this combobox and the given label provider.
      Parameters:
      labelProvider - the label provider is used for item factory
      See Also:
    • MenuActionComboBox

      public MenuActionComboBox(ILabelProvider labelProvider, List<T> content)
      Creates a new combobox with default item factory MenuActionComboBox.ItemFactory that initialized by this combobox and the given label provider. Also this constructor creates a combobox with content is provided by the given list.

      Note that methods of this class are not thread safe, so be careful with concurrent modification issues using an external list to store items.

      Parameters:
      labelProvider - the label provider is used for item factory
      content - a list to provide elements
      See Also:
  • Method Details

    • addSelectionListener

      public void addSelectionListener(org.eclipse.swt.events.SelectionListener selectionListener)
      Adds the listener that will be notified when the methods select(int) or deselect() are called.
      Parameters:
      selectionListener - the listener which should be notified
      See Also:
    • removeSelectionListener

      public void removeSelectionListener(org.eclipse.swt.events.SelectionListener selectionListener)
      Removes the given selection listener from the collection of listeners for this combobox.
      Parameters:
      selectionListener - the listener which should no longer be notified
    • dispose

      public void dispose()
      Specified by:
      dispose in interface org.eclipse.jface.action.IMenuCreator
    • getMenu

      public org.eclipse.swt.widgets.Menu getMenu(org.eclipse.swt.widgets.Control parent)
      Specified by:
      getMenu in interface org.eclipse.jface.action.IMenuCreator
    • getMenu

      public org.eclipse.swt.widgets.Menu getMenu(org.eclipse.swt.widgets.Menu parent)
      Specified by:
      getMenu in interface org.eclipse.jface.action.IMenuCreator
    • deselect

      public void deselect()
      Description copied from interface: IComboBox
      Deselects the currently selected item. It does nothing if there is not any selected item.

      Note that after deselecting method IComboBox.getSelectionIndex() returns -1 and IComboBox.getSelectionItem() returns empty Optional

      Specified by:
      deselect in interface IComboBox<T>
      See Also:
    • select

      public void select(int index)
      Description copied from interface: IComboBox
      Selects the item at the zero-relative index.
      Specified by:
      select in interface IComboBox<T>
      Parameters:
      index - the index of the item to select
    • indexOf

      public int indexOf(T item)
      Description copied from interface: IComboBox
      Returns the index of the given item or -1 if the given item is not found.

      It starts to search item in the list and returns the index of the first founded item that equals to the given object.

      Specified by:
      indexOf in interface IComboBox<T>
      Parameters:
      item - element to search for
      Returns:
      the index of the first occurence of then given item or -1 if the given item is not found.
    • addItem

      public void addItem(int index, T item)
      Description copied from interface: IComboBox
      Adds the new item at the given zero-relative index.
      Specified by:
      addItem in interface IComboBox<T>
      Parameters:
      index - the index to add item in range from 0 to IComboBox.count().
      item - the new item to add
    • addItem

      public void addItem(T item)
      Description copied from interface: IComboBox
      Adds the new item to the end of this combo.
      Specified by:
      addItem in interface IComboBox<T>
      Parameters:
      item - the new item to add
    • removeItem

      public void removeItem(int index)
      Description copied from interface: IComboBox
      Removes the item at the given zero-relative index.
      Specified by:
      removeItem in interface IComboBox<T>
      Parameters:
      index - the index of item to remove
    • clear

      public void clear()
      Description copied from interface: IComboBox
      Removes all items from this combobox.
      Specified by:
      clear in interface IComboBox<T>
    • getItem

      public T getItem(int index)
      Description copied from interface: IComboBox
      Returns item at the given zero-relative index.
      Specified by:
      getItem in interface IComboBox<T>
      Parameters:
      index - the index of the item to return
      Returns:
      the item at the given index
    • count

      public int count()
      Description copied from interface: IComboBox
      Returns the number of items contained in this combobox.
      Specified by:
      count in interface IComboBox<T>
      Returns:
      the number of items contained in this combobox
    • getSelectionIndex

      public int getSelectionIndex()
      Description copied from interface: IComboBox
      Returns the index of currently selected item or -1 if there is not any selected item.
      Specified by:
      getSelectionIndex in interface IComboBox<T>
      Returns:
      the index of currently selected item or -1 if there is not any selected item
    • getSelectionItem

      public Optional<T> getSelectionItem()
      Description copied from interface: IComboBox
      Returns the currently selected item or Optional.empty() if there is not any selected item.
      Specified by:
      getSelectionItem in interface IComboBox<T>
      Returns:
      the currently selected item or Optional.empty() if there is not any selected item.
      See Also: