Package org.eclipse.core.commands
Class State
- java.lang.Object
-
- org.eclipse.core.commands.common.EventManager
-
- org.eclipse.core.commands.State
-
- Direct Known Subclasses:
PersistentState
public class State extends EventManager
A piece of state information that can be shared between objects, and might be persisted between sessions. This can be used for commands that toggle between two states and wish to pass this state information between different handlers.
This state object can either be used as a single state object shared between several commands, or one state object per command -- depending on the needs of the application.
Clients may instantiate or extend this class.
- Since:
- 3.2
-
-
Constructor Summary
Constructors Constructor Description State()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addListener(IStateListener listener)
Adds a listener to changes for this state.void
dispose()
Disposes of this state.protected void
fireStateChanged(Object oldValue)
Notifies listeners to this state that it has changed in some way.String
getId()
Returns the identifier for this state.Object
getValue()
The current value associated with this state.void
removeListener(IStateListener listener)
Removes a listener to changes from this state.void
setId(String id)
Sets the identifier for this object.void
setValue(Object value)
Sets the value for this state object.-
Methods inherited from class org.eclipse.core.commands.common.EventManager
addListenerObject, clearListeners, getListeners, isListenerAttached, removeListenerObject
-
-
-
-
Method Detail
-
addListener
public void addListener(IStateListener listener)
Adds a listener to changes for this state.- Parameters:
listener
- The listener to add; must not benull
.
-
dispose
public void dispose()
Disposes of this state. This allows the state to unregister itself with any managers or as a listener.
-
fireStateChanged
protected final void fireStateChanged(Object oldValue)
Notifies listeners to this state that it has changed in some way.- Parameters:
oldValue
- The old value; may be anything.
-
getId
public final String getId()
Returns the identifier for this state.- Returns:
- The id; may be
null
.
-
getValue
public Object getValue()
The current value associated with this state. This can be any type of object, but implementations will usually restrict this value to a particular type.- Returns:
- The current value; may be anything.
-
removeListener
public void removeListener(IStateListener listener)
Removes a listener to changes from this state.- Parameters:
listener
- The listener to remove; must not benull
.
-
setId
public void setId(String id)
Sets the identifier for this object. This method should only be called by the command framework. Clients should not call this method.- Parameters:
id
- The id; must not benull
.
-
setValue
public void setValue(Object value)
Sets the value for this state object.- Parameters:
value
- The value to set; may be anything.
-
-