Package ptolemy.vergil.basic
Class AbstractBasicGraphModel
- java.lang.Object
-
- diva.graph.AbstractGraphModel
-
- diva.graph.modular.ModularGraphModel
-
- ptolemy.vergil.basic.AbstractBasicGraphModel
-
- All Implemented Interfaces:
GraphModel
,ChangeListener
- Direct Known Subclasses:
ActorGraphModel
,FSMGraphModel
,OntologyGraphModel
,OntologySolverGraphModel
public abstract class AbstractBasicGraphModel extends ModularGraphModel implements ChangeListener
This base class provides some common services for visual notations for Ptolemy II models. It assumes that the semantic object of a particular graph object is fixed, and provides facilities for making changes to the model via a change request. It supports visible attributes.This class uses a change listener to detect changes to the Ptolemy model that do not originate from this class. These changes are propagated as structure changed graph events to all graphListeners registered with this model. This mechanism allows a graph visualization of a ptolemy model to remain synchronized with the state of a mutating model.
- Since:
- Ptolemy II 2.0
- Version:
- $Id$
- Author:
- Steve Neuendorffer, Contributor: Edward A. Lee
- Pt.AcceptedRating:
- Red (johnr)
- Pt.ProposedRating:
- Yellow (neuendor)
-
-
Field Summary
-
Fields inherited from class diva.graph.AbstractGraphModel
_graphListeners
-
-
Constructor Summary
Constructors Constructor Description AbstractBasicGraphModel(NamedObj composite)
Create a graph model for the specified Ptolemy II model.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected Locatable
_getLocation(NamedObj object)
Return the location attribute contained in the given object, or a new location contained in the given object if there was no location.protected boolean
_update()
Update the graph model.void
changeExecuted(ChangeRequest change)
Notify the listener that a change has been successfully executed.void
changeFailed(ChangeRequest change, java.lang.Exception exception)
Notify the listener that the change has failed with the specified exception.abstract void
disconnectEdge(java.lang.Object eventSource, java.lang.Object edge)
Disconnect an edge from its two endpoints and notify graph listeners with an EDGE_HEAD_CHANGED and an EDGE_TAIL_CHANGED event whose source is the given source.CompositeModel
getCompositeModel(java.lang.Object composite)
Return the model for the given composite object.abstract java.lang.String
getDeleteEdgeMoML(java.lang.Object edge)
Return a MoML String that will delete the given edge from the Ptolemy model.abstract java.lang.String
getDeleteNodeMoML(java.lang.Object node)
Return a MoML String that will delete the given node from the Ptolemy model.NodeModel
getNodeModel(java.lang.Object node)
Return the node model for the given object.java.lang.Object
getProperty(java.lang.Object object, java.lang.String propertyName)
Return the property of the object associated with the given property name.NamedObj
getPtolemyModel()
Return the Ptolemy II model associated with this graph model.java.lang.Object
getSemanticObject(java.lang.Object element)
Return the semantic object corresponding to the given node, edge, or composite.boolean
isNode(java.lang.Object object)
Return true if the given object is a node in this model, which in this case means that it is an instance of Locatable.void
removeListeners()
Remove any listeners we have created.abstract void
removeNode(java.lang.Object eventSource, java.lang.Object node)
Delete a node from its parent graph and notify graph listeners with a NODE_REMOVED event.void
setProperty(java.lang.Object object, java.lang.String propertyName, java.lang.Object value)
Set the property of the given graph object associated with the given property name to the given value.void
setSemanticObject(java.lang.Object object, java.lang.Object semantic)
Set the semantic object corresponding to the given node, edge, or composite.-
Methods inherited from class diva.graph.modular.ModularGraphModel
containsNode, getEdgeModel, getHead, getNodeCount, getParent, getRoot, getTail, inEdges, isComposite, isDirected, isEdge, nodes, nodesAfterEdges, nodesBeforeEdges, outEdges
-
Methods inherited from class diva.graph.AbstractGraphModel
addGraphListener, dispatchGraphEvent, removeGraphListener, setDispatchEnabled
-
-
-
-
Constructor Detail
-
AbstractBasicGraphModel
public AbstractBasicGraphModel(NamedObj composite)
Create a graph model for the specified Ptolemy II model. Note that the argument need not be a CompositeEntity, although if it is not, then it is a rather trivial graph that only has hierarchy. I.e., there can be no links.- Parameters:
composite
- The Ptolemy II model.
-
-
Method Detail
-
changeExecuted
public void changeExecuted(ChangeRequest change)
Notify the listener that a change has been successfully executed. If the originator of this change is not this graph model, then issue a graph event to indicate that the structure of the graph has changed.- Specified by:
changeExecuted
in interfaceChangeListener
- Parameters:
change
- The change that has been executed.
-
changeFailed
public void changeFailed(ChangeRequest change, java.lang.Exception exception)
Notify the listener that the change has failed with the specified exception.- Specified by:
changeFailed
in interfaceChangeListener
- Parameters:
change
- The change that has failed.exception
- The exception that was thrown.
-
disconnectEdge
public abstract void disconnectEdge(java.lang.Object eventSource, java.lang.Object edge)
Disconnect an edge from its two endpoints and notify graph listeners with an EDGE_HEAD_CHANGED and an EDGE_TAIL_CHANGED event whose source is the given source.- Parameters:
eventSource
- The source of the event that will be dispatched, e.g. the view that made this call.edge
- The edge that is to be disconnected.
-
getDeleteEdgeMoML
public abstract java.lang.String getDeleteEdgeMoML(java.lang.Object edge)
Return a MoML String that will delete the given edge from the Ptolemy model.- Parameters:
edge
- The edge that is to be disconnected.- Returns:
- A valid MoML string.
-
getDeleteNodeMoML
public abstract java.lang.String getDeleteNodeMoML(java.lang.Object node)
Return a MoML String that will delete the given node from the Ptolemy model.- Parameters:
node
- The edge that is to be disconnected.- Returns:
- A valid MoML string.
-
getCompositeModel
public CompositeModel getCompositeModel(java.lang.Object composite)
Return the model for the given composite object. In this base class, return an instance of CompositePtolemyModel if the object is the root object of this graph model. Otherwise return null.- Specified by:
getCompositeModel
in classModularGraphModel
- Parameters:
composite
- A composite object.- Returns:
- An instance of CompositePtolemyModel if the object is the root object of this graph model. Otherwise return null.
-
getNodeModel
public NodeModel getNodeModel(java.lang.Object node)
Return the node model for the given object. If the object is an attribute, then return an attribute model. Otherwise, return null.- Specified by:
getNodeModel
in classModularGraphModel
- Parameters:
node
- An object which is assumed to be in this graph model.- Returns:
- An instance of the inner class AttributeNodeModel if the object is an instance of Locatable whose container is an instance of Attribute, and otherwise, null.
-
getProperty
public java.lang.Object getProperty(java.lang.Object object, java.lang.String propertyName)
Return the property of the object associated with the given property name. In this implementation properties are stored in variables of the graph object (which is always a Ptolemy NamedObj). If no variable with the given name exists in the object, then return null. Otherwise retrieve the token from the variable. If the token is an instance of ObjectToken, then get the value from the token and return it. Otherwise, return the result of calling toString on the token.- Specified by:
getProperty
in interfaceGraphModel
- Specified by:
getProperty
in classModularGraphModel
- Parameters:
object
- The graph object, which is assumed to be an instance of NamedObj.propertyName
- The name of the new property.- Returns:
- The property of the object associated with the given property name.
- See Also:
setProperty(Object, String, Object)
-
getPtolemyModel
public NamedObj getPtolemyModel()
Return the Ptolemy II model associated with this graph model.- Returns:
- The Ptolemy II model.
-
getSemanticObject
public java.lang.Object getSemanticObject(java.lang.Object element)
Return the semantic object corresponding to the given node, edge, or composite. A "semantic object" is an object associated with a node in the graph. In this base class, if the argument is an instance of Port, then return the port. If the argument is an instance of Locatable, then return the container of the Locatable.- Specified by:
getSemanticObject
in interfaceGraphModel
- Specified by:
getSemanticObject
in classModularGraphModel
- Parameters:
element
- A graph element.- Returns:
- The semantic object associated with this element, or null if the object is not recognized.
- See Also:
setSemanticObject(Object, Object)
-
isNode
public boolean isNode(java.lang.Object object)
Return true if the given object is a node in this model, which in this case means that it is an instance of Locatable.- Specified by:
isNode
in interfaceGraphModel
- Overrides:
isNode
in classModularGraphModel
- Parameters:
object
- The object to test for being a node (vs. an edge).- Returns:
- True if the given object is a node in this model.
-
removeNode
public abstract void removeNode(java.lang.Object eventSource, java.lang.Object node)
Delete a node from its parent graph and notify graph listeners with a NODE_REMOVED event.- Parameters:
eventSource
- The source of the event that will be dispatched, e.g. the view that made this call.node
- The node to be removed.
-
setProperty
public void setProperty(java.lang.Object object, java.lang.String propertyName, java.lang.Object value)
Set the property of the given graph object associated with the given property name to the given value. In this implementation properties are stored in variables of the graph object (which is always a Ptolemy NamedObj). If no variable with the given name exists in the graph object, then create a new variable contained by the graph object with the given name. If the value is a string, then set the expression of the variable to that string. Otherwise create a new object token contained the value and place that in the variable instead. The operation is performed in a ptolemy change request.- Specified by:
setProperty
in interfaceGraphModel
- Specified by:
setProperty
in classModularGraphModel
- Parameters:
object
- The graph object.propertyName
- The property name.value
- The new value of the property.- See Also:
getProperty(Object, String)
-
setSemanticObject
public void setSemanticObject(java.lang.Object object, java.lang.Object semantic)
Set the semantic object corresponding to the given node, edge, or composite. The semantic objects in this graph model are fixed, so this method throws an UnsupportedOperationException.- Specified by:
setSemanticObject
in interfaceGraphModel
- Specified by:
setSemanticObject
in classModularGraphModel
- Parameters:
object
- The graph object that represents a node or an edge.semantic
- The semantic object to associate with the given graph object.- See Also:
getSemanticObject(Object)
-
removeListeners
public void removeListeners()
Remove any listeners we have created. The frame displaying this graph model should call this function when the frame is closed.
-
_getLocation
protected Locatable _getLocation(NamedObj object)
Return the location attribute contained in the given object, or a new location contained in the given object if there was no location.- Parameters:
object
- The object for which a location is needed.- Returns:
- The location of the object, or a new location if none.
-
_update
protected boolean _update()
Update the graph model. This is called whenever a change request is executed. This base class checks each of the contained nodes, and if any has a semantic object with no container, then that node is removed. Subclasses will override this to update internal data structures that may be cached.- Returns:
- True if the graph model changes (always true in this base class).
-
-