Class ContainerSpinnerDataBinding<T,V>

java.lang.Object
com.amalgamasimulation.desktop.binding.widgets.AbstractSpinnerDataBinding<V>
com.amalgamasimulation.desktop.binding.widgets.ContainerSpinnerDataBinding<T,V>
Type Parameters:
T - The type of the container object
V - The type of the bound value within the container
All Implemented Interfaces:
AbstractDataBinding<V>, ContainerDataBinding<T,V>
Direct Known Subclasses:
EmfSpinnerDataBinding

public class ContainerSpinnerDataBinding<T,V> extends AbstractSpinnerDataBinding<V> implements ContainerDataBinding<T,V>
Spinner binding to a value of the object in a container. While the container is empty, the spinner shows its minimum and does not send values.
Author:
Ionov Ivan
See Also:
  • Field Details

    • containerObservable

      protected org.eclipse.core.databinding.observable.value.IObservableValue<T> containerObservable
    • modelChangeListener

      protected org.eclipse.core.databinding.observable.value.IValueChangeListener<Object> modelChangeListener
    • valueExtractor

      protected Function<T,V> valueExtractor
    • handler

      protected BiConsumer<T,V> handler
  • Constructor Details

    • ContainerSpinnerDataBinding

      public ContainerSpinnerDataBinding()
  • Method Details

    • getValue

      public V getValue()
      Description copied from interface: AbstractDataBinding
      Gets the current value from the binding.
      Specified by:
      getValue in interface AbstractDataBinding<T>
      Returns:
      The current value of type V
    • doAction

      public void doAction(V newValue)
      Description copied from interface: AbstractDataBinding
      Performs an action when the value changes.
      Specified by:
      doAction in interface AbstractDataBinding<T>
      Parameters:
      newValue - The new value being set
    • executeToTarget

      public void executeToTarget()
      Description copied from class: AbstractSpinnerDataBinding
      Shows the model value in the spinner. null is shown as the minimum of the spinner. The spinner clips a value out of range itself, so shownSelection is read from the spinner after setSelection instead of being taken from toSelection. If digits is above zero, the decimal separator is read from the text of the spinner: it stands before the last digits characters. It is read here because the spinner takes the separator from the Windows settings, and the shown text is the only way to learn it. At the end the error icon is updated. Called at the end of createBinding and of every executeToModel, when the spinner is enabled (enable) and when the section is updated.
      Specified by:
      executeToTarget in interface AbstractDataBinding<T>
      Overrides:
      executeToTarget in class AbstractSpinnerDataBinding<V>
    • executeToModel

      public void executeToModel()
      Description copied from class: AbstractSpinnerDataBinding
      Sends the number the user set in the spinner to the model and shows the model value again. The typing flags are reset before the write because executeToTarget calls setSelection, and its Modify must not count as typing. After Enter, isKeyPressed is still set by the Enter key itself. The number is not written if it is null (the text is not a number or the number is out of range), if it equals shownSelection, or if the value fails the validation. executeToTarget is always called, even if nothing was written: it puts the model value back in place of invalid text and updates the icon. Where the number comes from and why is described in the class Javadoc.
      Specified by:
      executeToModel in interface AbstractDataBinding<T>
      Overrides:
      executeToModel in class AbstractSpinnerDataBinding<V>
    • valueExtractor

      public ContainerSpinnerDataBinding<T,V> valueExtractor(Function<T,V> valueExtractor)
    • handler

      public ContainerSpinnerDataBinding<T,V> handler(BiConsumer<T,V> handler)
    • containerObservable

      public ContainerSpinnerDataBinding<T,V> containerObservable(org.eclipse.core.databinding.observable.value.IObservableValue<T> containerObservable)
    • createBinding

      public void createBinding()
      Description copied from class: AbstractSpinnerDataBinding
      Creates the error icon, sets the range and digits of the spinner, subscribes to its events and shows the model value. The arrow step is set to 1 and the page step to 10 in selection units; the section may replace them with its own after createBinding. Throws IllegalArgumentException if digits is below 0 or the minimum is greater than the maximum, because the spinner would ignore such values without an error. The tooltip of the icon is set here once, so validation must be called before createBinding. The listeners and the order of their events are described in the class Javadoc.
      Specified by:
      createBinding in interface AbstractDataBinding<T>
      Overrides:
      createBinding in class AbstractSpinnerDataBinding<V>
    • getContainer

      public org.eclipse.core.databinding.observable.value.IObservableValue<T> getContainer()
      Description copied from interface: ContainerDataBinding
      Gets the observable container that holds the bound value.
      Specified by:
      getContainer in interface ContainerDataBinding<T,V>
      Returns:
      An IObservableValue representing the container object. The container itself is observable and will notify listeners of changes.