Class ActorGraphModel

  • All Implemented Interfaces:
    GraphModel, ChangeListener
    Direct Known Subclasses:
    GTFrameController.GTActorGraphModel

    public class ActorGraphModel
    extends AbstractBasicGraphModel
    This class represents one level of hierarchy of a Ptolemy II model. The graph model represents attributes, ports, entities and relations as nodes. Entities and attributes are represented in the model by the icon that is used to visually depict them. Relations are represented in the model by its vertices (which are visual elements that generally exist in multiple places in a visual rendition). Ports represent themselves in the model.

    In the terminology of diva, the graph elements are "nodes" (icons, vertices, and ports), and the "edges" link them. Edges are represented in the model by instances of the Link class. Edges may link a port and a vertex, or a port and another port. For visual simplicity, both types of edges are represented by an instance of the Link class. If an edge is placed between a port and a vertex then the Link represents a Ptolemy II link between the port and the vertex's Relation. However, if an edge is placed between two ports, then it represents a relation (with no vertex) and links from the relation to each port (in Ptolemy II, this is called a "connection").

    This model uses a ptolemy change listener to detect changes to the model that do not originate from this model. 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, Bert Rodiers
    Pt.AcceptedRating:
    Red (johnr)
    Pt.ProposedRating:
    Yellow (neuendor)
    • Constructor Detail

      • ActorGraphModel

        public ActorGraphModel​(NamedObj composite)
        Construct a new graph model whose root is the given composite entity.
        Parameters:
        composite - The top-level composite entity for the model.
    • Method Detail

      • changeExecuted

        public void changeExecuted​(ChangeRequest change)
        This implementation will delegate to the implementation in the parent class and will additionally update the model in case it is necessary. This is typically the case when a link is created to another link. If this existing link has a vertex as head or tail, we will connect with the vertex, otherwise we will remove the old link, create a new vertex, link the head and tail of the existing link with the vertex and link the new link with the vertex. It is possible to link with an existing link. If this existing link has a vertex as head or tail, we will connect with the vertex, otherwise we will remove the old link, create a new vertex, link the head and tail of the existing link with the vertex and link the new link with the vertex. In the latter case the parent class won't call _update as a result of an optimization, and hence we do it here.
        Specified by:
        changeExecuted in interface ChangeListener
        Overrides:
        changeExecuted in class AbstractBasicGraphModel
        Parameters:
        change - The change that has been executed.
      • disconnectEdge

        public 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.
        Specified by:
        disconnectEdge in class AbstractBasicGraphModel
        Parameters:
        eventSource - The source of the event that will be dispatched, e.g. the view that made this call.
        edge - The edge.
      • getCompositeModel

        public CompositeModel getCompositeModel​(java.lang.Object composite)
        Return the model for the given composite object. In this class, return an instance of CompositePtolemyModel if the object is the root object of this graph model, and return an instance of IconModel if the object is a location contained by an entity. Otherwise return null.
        Overrides:
        getCompositeModel in class AbstractBasicGraphModel
        Parameters:
        composite - A composite object.
        Returns:
        A model of a composite node.
      • getDeleteEdgeMoML

        public java.lang.String getDeleteEdgeMoML​(java.lang.Object edge)
        Return a MoML String that will delete the given edge from the Ptolemy model.
        Specified by:
        getDeleteEdgeMoML in class AbstractBasicGraphModel
        Parameters:
        edge - The edge.
        Returns:
        A valid MoML string.
      • getDeleteNodeMoML

        public java.lang.String getDeleteNodeMoML​(java.lang.Object node)
        Return a MoML String that will delete the given node from the Ptolemy model.
        Specified by:
        getDeleteNodeMoML in class AbstractBasicGraphModel
        Parameters:
        node - The node.
        Returns:
        A valid MoML string.
      • getEdgeModel

        public EdgeModel getEdgeModel​(java.lang.Object edge)
        Return the model for the given edge object. If the object is not an edge, then return null.
        Specified by:
        getEdgeModel in class ModularGraphModel
        Parameters:
        edge - An object which is assumed to be in this graph model.
        Returns:
        An instance of LinkModel if the object is a Link. Otherwise return null.
      • getLinkModel

        public ActorGraphModel.LinkModel getLinkModel()
        Return the model for edge objects that are instance of Link. This will return the same object as getEdgeModel() when the argument is a link.
        Returns:
        The model for links.
      • getNodeModel

        public NodeModel getNodeModel​(java.lang.Object node)
        Return the node model for the given object. If the object is not a node, then return null. The argument should be either an instance of Port or Vertex, or it implements Locatable.
        Overrides:
        getNodeModel in class AbstractBasicGraphModel
        Parameters:
        node - An object which is assumed to be in this graph model.
        Returns:
        The node model for the specified node, or null if there is none.
      • 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 case, if the node is icon, the semantic object is an entity. If it is a vertex or a link, the semantic object is a relation. If it is a port, then the semantic object is the port itself.
        Specified by:
        getSemanticObject in interface GraphModel
        Overrides:
        getSemanticObject in class AbstractBasicGraphModel
        Parameters:
        element - A graph element.
        Returns:
        The semantic object associated with this element, or null if the object is not recognized.
        See Also:
        AbstractBasicGraphModel.setSemanticObject(Object, Object)
      • removeNode

        public 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.
        Specified by:
        removeNode in class AbstractBasicGraphModel
        Parameters:
        eventSource - The source of the event that will be dispatched, e.g. the view that made this call.
        node - The node.
      • _getLinkSet

        protected java.util.Set<?> _getLinkSet()
        Get an unmodifiable copy of the link set.
        Returns:
        The link set.
      • _removeLink

        protected void _removeLink​(Link link)
        Remove a link from the link set. This function is not made synchronized. Concurrent modification on the link set should be avoided.
        Parameters:
        link - The link to be removed.
      • _update

        protected boolean _update()
        Update the graph model. This is called whenever a change request is executed. In this class the internal set of link objects is created to represent each of the links in the graph, and to remove any link objects that are incorrect (e.g., do not have both ends in the model). This method is usually called just before issuing a graph event. If this method returns false, then the graph event should not be issued, because further changes are necessary.
        Overrides:
        _update in class AbstractBasicGraphModel
        Returns:
        True if the model was successfully updated, or false if further change requests were queued.