public abstract class ChangeRequest
extends java.lang.Object
A typical use of this class is to define an anonymous inner class that implements the _execute() method to bring about the desired change. The instance of that anonymous inner class is then queued with an instance of NamedObj using its requestChange() method. The execute() method must be called only once; attempting to call it multiple times will trigger an exception.
Concrete derived classes can be defined to implement mutations of a certain kind or in a certain way. Instances of these classes should be queued with a NamedObj, just like an anonymous inner class extending this class. MoMLChangeRequest is such a concrete derived class, where the mutation is specified as MoML code.
ChangeListener
Green (neuendor) |
Green (eal) |
Constructor and Description |
---|
ChangeRequest(java.lang.Object source,
java.lang.String description)
Construct a request with the specified source and description.
|
ChangeRequest(java.lang.Object source,
java.lang.String description,
boolean isStructuralChange)
Construct a request with the specified source and description.
|
Modifier and Type | Method and Description |
---|---|
protected abstract void |
_execute()
Execute the change.
|
void |
addChangeListener(ChangeListener listener)
Add a new change listener to this request.
|
void |
execute()
Execute the change.
|
java.lang.String |
getDescription()
Get the description that was specified in the constructor.
|
NamedObj |
getLocality()
If a change is localized to a particular object and objects
that it contains, then that object should be returned by
this method.
|
java.lang.Object |
getSource()
Get the source that was specified in the constructor.
|
boolean |
isErrorReported()
Return true if setErrorReported() has been called with a true
argument.
|
boolean |
isPersistent()
Return false if the change represented by this request has been
asserted to be non-persistent by calling setPersistent(false),
and return true otherwise.
|
boolean |
isStructuralChange()
Return whether this change request is a structural change request.
|
void |
removeChangeListener(ChangeListener listener)
Remove the given change listener from this request.
|
void |
setDescription(java.lang.String description)
Set the description.
|
void |
setErrorReported(boolean reported)
Call with a true argument to indicate that an error has been
reported to the user.
|
void |
setListeners(java.util.List listeners)
Specify a list of listeners to be notified when changes are
successfully executed, or when an attempt to execute them results
in an exception.
|
void |
setPersistent(boolean persistent)
Assert whether the change represented by this request is
persistent.
|
void |
waitForCompletion()
Wait for execution (or failure) of this change request.
|
public ChangeRequest(java.lang.Object source, java.lang.String description)
source
- The source of the change request.description
- A description of the change request.ChangeRequest(Object, String, boolean)
public ChangeRequest(java.lang.Object source, java.lang.String description, boolean isStructuralChange)
source
- The source of the change request.description
- A description of the change request.isStructuralChange
- Specifies whether this change is a structural
one.public void addChangeListener(ChangeListener listener)
listener
- The listener to add.removeChangeListener(ChangeListener)
public final void execute()
This method should be called exactly once, by the object that the change request was queued with. Attempting to call this method more than once will throw an exception.
public java.lang.String getDescription()
setDescription(String)
public NamedObj getLocality()
public java.lang.Object getSource()
public boolean isErrorReported()
public boolean isPersistent()
This method returns true unless setPersistent() has been called with an argument false. It is up to the creator of the change request to call that method to ensure that the change is not persistent. There is no automatic detection of whether the change is persistent.
setPersistent(boolean)
public boolean isStructuralChange()
public void removeChangeListener(ChangeListener listener)
listener
- The listener to be removed.addChangeListener(ChangeListener)
public void setDescription(java.lang.String description)
description
- The description.getDescription()
public void setErrorReported(boolean reported)
reported
- True if an error has been reported.public void setListeners(java.util.List listeners)
The class copies the given list, so that in the process of handling notifications from this class, more listeners can be added to the list of listeners in the top-level object.
Note that an alternative to using listeners is to call waitForCompletion(), although this may cause undesirable synchronization between the different threads.
listeners
- A list of instances of ChangeListener or
instances of WeakReference referring to instances of
ChangeListener.ChangeListener
,
NamedObj
public void setPersistent(boolean persistent)
It is up to the creator of the change request to call this method to assure that the change is not persistent. Calling this method with a false argument does not make the change non-persistent. It merely asserts that it is. There is no automatic detection of whether the change is persistent. By default, the change is assumed to be persistent, so unless this is called with argument false, a UI will likely mark the model modified upon execution of the change request.
persistent
- False to indicate that the change represented
by this request is not persistent.isPersistent()
public final void waitForCompletion() throws java.lang.Exception
Note that using this method may cause the model to deadlock and not be able to proceed. This is especially true if it is called from the Swing thread, and any actors in the model (such as plotters) wait for swing events.
java.lang.Exception
- If the execution of the change request
throws it.protected abstract void _execute() throws java.lang.Exception
java.lang.Exception
- If the change fails.