Class ComboBoxEditingSupport<T,V>

java.lang.Object
org.eclipse.jface.viewers.EditingSupport
com.amalgamasimulation.desktop.binding.editingsupports.GenericEditingSupport<T,V>
com.amalgamasimulation.desktop.binding.editingsupports.ComboBoxEditingSupport<T,V>
Type Parameters:
T - type of row value
V - type of column value (cell value)
Direct Known Subclasses:
AutoCompleteComboBoxEditingSupport, EMFComboBoxEditingSupport, EnumComboBoxEditingSupport

public class ComboBoxEditingSupport<T,V> extends GenericEditingSupport<T,V>
Class is used to enable editing a table cell via a combobox with a list of values.
Author:
Ionov Ivan
  • Field Details

    • valueExtractor

      protected Function<T,V> valueExtractor
      Function that returns the value from the container object
    • nameExtractor

      protected Function<V,String> nameExtractor
      Function to get the value that will be shown in the cell
    • selectionListener

      protected BiConsumer<T,V> selectionListener
      A function that will be executed after losing focus on the combo box editor or after pressing the Enter button
    • notSetLiteral

      protected String notSetLiteral
      Element on top of other elements in the combo box to clear the table cell value.
    • maxComboBoxElementsCount

      protected int maxComboBoxElementsCount
      Limitation on the number of elements in the combo box. With a large number of elements in the combo box, it becomes more difficult to find the right one and also negatively affects the operation of the combo box.
    • sortedElements

      protected List<V> sortedElements
      Sorted and filtered list items
    • readOnlyComboBox

      protected boolean readOnlyComboBox
  • Constructor Details

    • ComboBoxEditingSupport

      public ComboBoxEditingSupport(org.eclipse.jface.viewers.ColumnViewer viewer, org.eclipse.swt.widgets.Composite parent)
  • Method Details

    • sortAndFilterElements

      protected void sortAndFilterElements(T element)
    • createComboBoxCellEditor

      protected org.eclipse.jface.viewers.ComboBoxCellEditor createComboBoxCellEditor()
    • getCellEditorInternal

      protected org.eclipse.jface.viewers.CellEditor getCellEditorInternal(T element)
      Specified by:
      getCellEditorInternal in class GenericEditingSupport<T,V>
    • getValueInternal

      protected Object getValueInternal(T element)
      Specified by:
      getValueInternal in class GenericEditingSupport<T,V>
    • setValueInternal

      protected void setValueInternal(T element, V value)
      Specified by:
      setValueInternal in class GenericEditingSupport<T,V>
    • initializeCellEditorValueInternal

      protected void initializeCellEditorValueInternal(org.eclipse.jface.viewers.CellEditor cellEditor, org.eclipse.jface.viewers.ViewerCell cell, T element)
      Overrides:
      initializeCellEditorValueInternal in class GenericEditingSupport<T,V>
    • enableNullElement

      public ComboBoxEditingSupport<T,V> enableNullElement(String notSetLiteral)
      Add an element on top of other elements in the combo box to clear the table cell value.
      Parameters:
      notSetLiteral - the label of the new combo box element that clears the cell value (typical values are: "", etc.)
      Returns:
      this object
    • setFilter

      public ComboBoxEditingSupport<T,V> setFilter(BiPredicate<T,V> filter)
      Add a filter. Only matching items will be displayed in the combo box.
      Note that there may be at most one filter. If you call this method several times, only the last method call will be effective.
      Returns:
      this object
    • setComparator

      public ComboBoxEditingSupport<T,V> setComparator(Comparator<V> comparator)
      Add a comparator that is used to sort combo box values.
      Note that there may be at most one comparator. If you call this method several times, only the last method call will be effective.
      Returns:
      this object
    • setNameExtractor

      public ComboBoxEditingSupport<T,V> setNameExtractor(Function<V,String> nameExtractor)
      Set up the combo box elements naming. The name extractor.
      Parameters:
      nameExtractor - function that converts a combo box element to a String displayed in the combo box
      Returns:
      this object
    • setMaxComboBoxElementsCount

      public ComboBoxEditingSupport<T,V> setMaxComboBoxElementsCount(int maxComboBoxElementsCount)
      Set up the maxComboBoxElementsCount
      Parameters:
      maxComboBoxElementsCount - limitation on the number of elements in the combo box
      Returns:
      this object
    • setValueExtractor

      public ComboBoxEditingSupport<T,V> setValueExtractor(Function<T,V> valueExtractor)
      Set up the value Extractor
      Parameters:
      valueExtractor - Function that returns the value from the container object
      Returns:
      this object
    • setSelectionListener

      public ComboBoxEditingSupport<T,V> setSelectionListener(BiConsumer<T,V> selectionListener)
      Set up the selectionListener
      Parameters:
      selectionListener - function that will be executed after losing focus on the combo box editor or after pressing the Enter button
      Returns:
      this object
    • setElements

      public ComboBoxEditingSupport<T,V> setElements(Function<T,List<V>> elementsExtractor)
      Set up the value elementsExtractor
      Parameters:
      elementsExtractor - List of elements to be shown in the combo box
      Returns:
      this object
    • setElements

      public ComboBoxEditingSupport<T,V> setElements(List<V> elements)
      Set up the value elements
      Parameters:
      elements - List of elements to be shown in the combo box
      Returns:
      this object