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 objectV- 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 Summary
FieldsModifier and TypeFieldDescriptionprotected org.eclipse.core.databinding.observable.value.IObservableValue<T> protected BiConsumer<T, V> protected org.eclipse.core.databinding.observable.value.IValueChangeListener<Object> Fields inherited from class com.amalgamasimulation.desktop.binding.widgets.AbstractSpinnerDataBinding
canBeNull, controlDecoration, digits, fromNumber, maximum, minimum, spinner, toNumber, validation, validationMessage -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncontainerObservable(org.eclipse.core.databinding.observable.value.IObservableValue<T> containerObservable) voidCreates the error icon, sets the range anddigitsof the spinner, subscribes to its events and shows the model value.voidPerforms an action when the value changes.voidSends the number the user set in the spinner to the model and shows the model value again.voidShows the model value in the spinner.org.eclipse.core.databinding.observable.value.IObservableValue<T> Gets the observable container that holds the bound value.getValue()Gets the current value from the binding.handler(BiConsumer<T, V> handler) valueExtractor(Function<T, V> valueExtractor) Methods inherited from class com.amalgamasimulation.desktop.binding.widgets.AbstractSpinnerDataBinding
canBeNull, converter, digits, enable, range, setControl, toSelection, validationMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.amalgamasimulation.desktop.binding.widgets.AbstractDataBinding
createControlDecoration, enable, setControl
-
Field Details
-
containerObservable
-
modelChangeListener
protected org.eclipse.core.databinding.observable.value.IValueChangeListener<Object> modelChangeListener -
valueExtractor
-
handler
-
-
Constructor Details
-
ContainerSpinnerDataBinding
public ContainerSpinnerDataBinding()
-
-
Method Details
-
getValue
Description copied from interface:AbstractDataBindingGets the current value from the binding.- Specified by:
getValuein interfaceAbstractDataBinding<T>- Returns:
- The current value of type V
-
doAction
Description copied from interface:AbstractDataBindingPerforms an action when the value changes.- Specified by:
doActionin interfaceAbstractDataBinding<T>- Parameters:
newValue- The new value being set
-
executeToTarget
public void executeToTarget()Description copied from class:AbstractSpinnerDataBindingShows the model value in the spinner. null is shown as the minimum of the spinner. The spinner clips a value out of range itself, soshownSelectionis read from the spinner aftersetSelectioninstead of being taken fromtoSelection. Ifdigitsis above zero, the decimal separator is read from the text of the spinner: it stands before the lastdigitscharacters. 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 ofcreateBindingand of everyexecuteToModel, when the spinner is enabled (enable) and when the section is updated.- Specified by:
executeToTargetin interfaceAbstractDataBinding<T>- Overrides:
executeToTargetin classAbstractSpinnerDataBinding<V>
-
executeToModel
public void executeToModel()Description copied from class:AbstractSpinnerDataBindingSends 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 becauseexecuteToTargetcallssetSelection, and its Modify must not count as typing. After Enter,isKeyPressedis 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 equalsshownSelection, or if the value fails the validation.executeToTargetis 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:
executeToModelin interfaceAbstractDataBinding<T>- Overrides:
executeToModelin classAbstractSpinnerDataBinding<V>
-
valueExtractor
-
handler
-
containerObservable
public ContainerSpinnerDataBinding<T,V> containerObservable(org.eclipse.core.databinding.observable.value.IObservableValue<T> containerObservable) -
createBinding
public void createBinding()Description copied from class:AbstractSpinnerDataBindingCreates the error icon, sets the range anddigitsof 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 aftercreateBinding. Throws IllegalArgumentException ifdigitsis 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, sovalidationmust be called beforecreateBinding. The listeners and the order of their events are described in the class Javadoc.- Specified by:
createBindingin interfaceAbstractDataBinding<T>- Overrides:
createBindingin classAbstractSpinnerDataBinding<V>
-
getContainer
Description copied from interface:ContainerDataBindingGets the observable container that holds the bound value.- Specified by:
getContainerin interfaceContainerDataBinding<T,V> - Returns:
- An
IObservableValuerepresenting the container object. The container itself is observable and will notify listeners of changes.
-