Class WritableValue<T>
- java.lang.Object
-
- org.eclipse.core.databinding.observable.AbstractObservable
-
- org.eclipse.core.databinding.observable.value.AbstractObservableValue<T>
-
- org.eclipse.core.databinding.observable.value.WritableValue<T>
-
- Type Parameters:
T- the type of value being observed
- All Implemented Interfaces:
IObservable,IObservableValue<T>
public class WritableValue<T> extends AbstractObservableValue<T>
Mutable (writable) implementation ofIObservableValuethat will maintain a value and fire change events when the value changes.This class is thread safe. All state accessing methods must be invoked from the
current realm. Methods for adding and removing listeners may be invoked from any thread.- Since:
- 1.0
-
-
Constructor Summary
Constructors Constructor Description WritableValue()Constructs a new instance with the default realm, anullvalue type, and anullvalue.WritableValue(Realm realm)Constructs a new instance with the providedrealm, anullvalue type, and anullinitial value.WritableValue(Realm realm, T initialValue, Object valueType)Constructs a new instance.WritableValue(T initialValue, Object valueType)Constructs a new instance with the default realm.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddListener(Object listenerType, IObservablesListener listener)protected Objectclone()TdoGetValue()voiddoSetValue(T value)Template method for setting the value of the observable.protected voidfireEvent(ObservableEvent event)protected voidfirstListenerAdded()RealmgetRealm()ObjectgetValueType()The value type of this observable value, ornullif this observable value is untyped.protected booleanhasListeners()protected voidlastListenerRemoved()protected voidremoveListener(Object listenerType, IObservablesListener listener)static <T2> WritableValue<T2>withValueType(Object elementType)-
Methods inherited from class org.eclipse.core.databinding.observable.value.AbstractObservableValue
addValueChangeListener, fireChange, fireValueChange, getValue, isStale, removeValueChangeListener, setValue
-
Methods inherited from class org.eclipse.core.databinding.observable.AbstractObservable
addChangeListener, addDisposeListener, addStaleListener, checkRealm, dispose, fireStale, isDisposed, removeChangeListener, removeDisposeListener, removeStaleListener
-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.eclipse.core.databinding.observable.IObservable
addChangeListener, addDisposeListener, addStaleListener, dispose, getRealm, isDisposed, removeChangeListener, removeDisposeListener, removeStaleListener
-
-
-
-
Constructor Detail
-
WritableValue
public WritableValue()
Constructs a new instance with the default realm, anullvalue type, and anullvalue.
-
WritableValue
public WritableValue(T initialValue, Object valueType)
Constructs a new instance with the default realm.- Parameters:
initialValue- can benullvalueType- can benull
-
WritableValue
public WritableValue(Realm realm)
Constructs a new instance with the providedrealm, anullvalue type, and anullinitial value.- Parameters:
realm- the realm
-
-
Method Detail
-
doGetValue
public T doGetValue()
- Specified by:
doGetValuein classAbstractObservableValue<T>
-
doSetValue
public void doSetValue(T value)
Description copied from class:AbstractObservableValueTemplate method for setting the value of the observable. By default the method throws anUnsupportedOperationException.- Overrides:
doSetValuein classAbstractObservableValue<T>- Parameters:
value- The value to set.
-
getValueType
public Object getValueType()
Description copied from interface:IObservableValueThe value type of this observable value, ornullif this observable value is untyped.- Returns:
- the value type, or
null
-
withValueType
public static <T2> WritableValue<T2> withValueType(Object elementType)
- Type Parameters:
T2- the type of observed value of the created instance- Parameters:
elementType- can benull- Returns:
- new instance with the default realm and a value of
null
-
addListener
protected void addListener(Object listenerType, IObservablesListener listener)
- Parameters:
listenerType- arbitrary object to identify a type of the listenerlistener- the listener to add; notnull
-
removeListener
protected void removeListener(Object listenerType, IObservablesListener listener)
- Parameters:
listenerType- arbitrary object to identify a type of the listenerlistener- the listener to remove; notnull
-
hasListeners
protected boolean hasListeners()
-
fireEvent
protected void fireEvent(ObservableEvent event)
-
firstListenerAdded
protected void firstListenerAdded()
-
lastListenerRemoved
protected void lastListenerRemoved()
-
getRealm
public Realm getRealm()
- Returns:
- Returns the realm.
-
clone
protected Object clone() throws CloneNotSupportedException
- Overrides:
clonein classObject- Throws:
CloneNotSupportedException
-
-