pl.edu.agh.cast.model.visual.backward
Class Diagram

java.lang.Object
  extended by pl.edu.agh.cast.model.visual.backward.ModelElement
      extended by pl.edu.agh.cast.model.visual.backward.Diagram
All Implemented Interfaces:
PropertyChangeListener, Serializable, EventListener, IPropertyChangeProvider, IDataProvider, AttributeValueContainer, IDiagram

public class Diagram
extends ModelElement
implements IDiagram, PropertyChangeListener

Diagram, which consists of of Nodes and Connections.

Author:
AGH CAST Team
See Also:
Serialized Form

Field Summary
static String CHILD
          Name of the Diagram node added/removed event.
static String CHILDREN
          Name of the Diagram nodes (multiple) added/removed event.
static String CONNECTION
          Name of the Diagram connections changed event.
protected  ConnectionGroupAttributeManager connectionGroupAttributeManager
          Connection group attribute manager.
static String DESELECT
          Name of the Diagram nodes deselected event.
protected  DiagramAttributeManager diagramAttributeManager
          Diagram attribute manager.
static String DUMMY_ID
          Default, dummy id of diagrams editor.
protected  org.eclipse.core.resources.IFile file
          File this diagram is stored in.
static String FILE
          Name of the Diagram file changed event.
protected static org.apache.log4j.Logger log
          Logger for this class.
static String NAME
          Name of the Diagram name changed event.
protected  NodeAttributeManager nodeAttributeManager
          Node attribute manager.
protected  IDiagramSettings settings
          Diagram settings.
protected  VisualModelCachingFactory visualModelFactory
          Caching factory of visual elements.
 
Fields inherited from class pl.edu.agh.cast.model.visual.backward.ModelElement
ATTRIBUTE_CHANGE, attributeValues
 
Constructor Summary
Diagram(Collection<IDataSet> model)
          Constructs new diagram from model.
Diagram(Collection<IDataSet> model, org.eclipse.core.runtime.IProgressMonitor monitor)
          Constructs new diagram from model.
Diagram(Collection<IDataSet> model, org.eclipse.core.runtime.IProgressMonitor monitor, boolean enhancable)
          Constructs new diagram from model.
 
Method Summary
 void addAttributesFromEntities(Collection<IEntity> entities, Collection<String> attributes, Map<String,AttributeMergePolicy> mergePolicies, String nodeType, org.eclipse.core.runtime.IProgressMonitor monitor)
          Adds attributes from a collection of entities to the diagram with join on entity and node IDs.
 void addAttributesFromEntities(Collection<IEntity> entities, Collection<String> attributes, Map<String,AttributeMergePolicy> mergePolicies, String nodeType, String sourceJoinAttribute, String targetJoinAttribute, org.eclipse.core.runtime.IProgressMonitor monitor)
          Adds attributes from a collection of entities to the diagram.
 Connection addConnection(Connection c)
          Adds a Connection to the diagram.
 void addConnections(Collection<Connection> connections)
          Adds multiple Connections.
protected  void addConnectionsForNode(Node node)
          Adds connections of a given node to the diagram.
 Node addNode(Node node)
          Adds a Node to the model.
protected  Node addNodeInternal(Node node)
          Adds a node to the model.
 Collection<Node> addNodes(Collection<Node> nodes)
          Adds Nodes to the model.
 void deselect()
          Removes selection in diagram edit part.
 Connection findConnection(String sourceNodeId, String targetNodeId, Date date)
          Returns the Connection matching given criteria.
 Node findNode(String nodeId)
          Returns the Node with given id.
 IRelation findRelation(Connection conn)
          Finds IRelation for given connection.
protected  void firePropertyChange(String property, Object oldValue, Object newValue)
          Notifies about property change.
 AttributeManager getAttributeManager()
          Returns attribute manager for this container.
 Collection<Connection> getConnections()
          Returns a collection of Connections.
 String getDisplayName()
          Returns the display name of the diagram.
 IDataSet getDomainModel()
          Returns all model data (packaged as one IDataSet) kept in the diagram.
 org.eclipse.core.resources.IFile getFile()
          Return file in which this diagram is stored.
 NodeAttributeManager getNodeAttributeManager()
          Returns the NodeAttributeManager of this diagram.
 Collection<Node> getNodes()
          Returns a collection of all diagram Nodes.
 IDiagramSettings getSettings()
          Returns diagram settings.
 List<Statistic> getStatistics()
          Returns statistics for current diagram.
 List<Statistic> getStatistics(org.eclipse.core.runtime.IProgressMonitor monitor)
          Returns statistics for current diagram.
protected  VisualModelCachingFactory getVisualModelFactory()
          Returns caching factory of visual elements.
 boolean isEnhancable()
          Checks if the nodes of this diagram may be enhanced with attributes of entities from another IDataSet.
 void propertyChange(PropertyChangeEvent evt)
          
protected  Object readResolve()
           
 void removeConnection(Connection connection)
          Removes a Connection from the model.
 void removeNode(Node node)
          Removes a Node from the diagram.
 void removeNodes(Collection<Node> nodes)
          Removes Nodes from the model.
 void setDisplayName(String displayName)
          Sets the display name of the diagram.
 void setFile(org.eclipse.core.resources.IFile file)
          Set the file in which this diagram is stored.
 void setSettings(IDiagramSettings settings)
          Sets diagram settings.
 void setSuppressEvents(boolean newSuppressEvents)
          Suppresses all events fired by this diagram.
 String toString()
          
 
Methods inherited from class pl.edu.agh.cast.model.visual.backward.ModelElement
addPropertyChangeListener, bindToAttributeManager, copyAttributes, copyAttributeValues, getAllValues, getAttributeValue, getMid, isAttributeEditable, isAttributeSettable, isSaved, removePropertyChangeListener, removePropertyValue, setAttributeValue, setAttributeValue, setMid, setSaved
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface pl.edu.agh.cast.data.model.property.IPropertyChangeProvider
addPropertyChangeListener, removePropertyChangeListener
 
Methods inherited from interface pl.edu.agh.cast.model.visual.backward.AttributeValueContainer
getAllValues, getAttributeValue, isAttributeEditable, removePropertyValue, setAttributeValue, setAttributeValue
 

Field Detail

DUMMY_ID

public static final String DUMMY_ID
Default, dummy id of diagrams editor.

See Also:
Constant Field Values

NAME

public static final String NAME
Name of the Diagram name changed event.

See Also:
Constant Field Values

FILE

public static final String FILE
Name of the Diagram file changed event.

See Also:
Constant Field Values

CHILD

public static final String CHILD
Name of the Diagram node added/removed event.

See Also:
Constant Field Values

CONNECTION

public static final String CONNECTION
Name of the Diagram connections changed event.

See Also:
Constant Field Values

CHILDREN

public static final String CHILDREN
Name of the Diagram nodes (multiple) added/removed event.

See Also:
Constant Field Values

DESELECT

public static final String DESELECT
Name of the Diagram nodes deselected event.

See Also:
Constant Field Values

log

protected static org.apache.log4j.Logger log
Logger for this class.


file

protected transient org.eclipse.core.resources.IFile file
File this diagram is stored in.


settings

protected IDiagramSettings settings
Diagram settings.


nodeAttributeManager

protected NodeAttributeManager nodeAttributeManager
Node attribute manager.


connectionGroupAttributeManager

protected ConnectionGroupAttributeManager connectionGroupAttributeManager
Connection group attribute manager.


diagramAttributeManager

protected DiagramAttributeManager diagramAttributeManager
Diagram attribute manager.


visualModelFactory

protected final VisualModelCachingFactory visualModelFactory
Caching factory of visual elements.

Constructor Detail

Diagram

public Diagram(Collection<IDataSet> model)
Constructs new diagram from model.

Parameters:
model - base model

Diagram

public Diagram(Collection<IDataSet> model,
               org.eclipse.core.runtime.IProgressMonitor monitor)
Constructs new diagram from model. Reports progress using a progress monitor.

Parameters:
model - base model
monitor - non-null progress monitor
Throws:
IllegalArgumentException - if progress monitor is null

Diagram

public Diagram(Collection<IDataSet> model,
               org.eclipse.core.runtime.IProgressMonitor monitor,
               boolean enhancable)
Constructs new diagram from model. Reports progress using a progress monitor.

Parameters:
model - base model
monitor - non-null progress monitor
enhancable - whether this Diagram may be enhanced (see IDiagram.isEnhancable())
Throws:
IllegalArgumentException - if progress monitor is null
Method Detail

readResolve

protected Object readResolve()
Overrides:
readResolve in class ModelElement

toString

public String toString()

Overrides:
toString in class Object
See Also:
Object.toString()

getFile

public org.eclipse.core.resources.IFile getFile()
Return file in which this diagram is stored.

Specified by:
getFile in interface IDiagram
Returns:
the file containing this diagram
See Also:
IDiagram.getFile()

setFile

public void setFile(org.eclipse.core.resources.IFile file)
Set the file in which this diagram is stored.

Specified by:
setFile in interface IDiagram
Parameters:
file - the file to store the diagram in
See Also:
IDiagram.setFile(org.eclipse.core.resources.IFile)

setDisplayName

public void setDisplayName(String displayName)
Sets the display name of the diagram.

Specified by:
setDisplayName in interface IDiagram
Parameters:
displayName - the name of the diagram
See Also:
IDiagram.setDisplayName(java.lang.String)

getDisplayName

public String getDisplayName()
Returns the display name of the diagram.

Specified by:
getDisplayName in interface IDiagram
Returns:
the name of the diagram
See Also:
IDiagram.getDisplayName()

getStatistics

public List<Statistic> getStatistics()
Returns statistics for current diagram.

Specified by:
getStatistics in interface IDiagram
Returns:
statistics for current diagram
See Also:
IDiagram.getStatistics()

getStatistics

public List<Statistic> getStatistics(org.eclipse.core.runtime.IProgressMonitor monitor)
Returns statistics for current diagram. Uses IProgressMonitor.

Specified by:
getStatistics in interface IDiagram
Parameters:
monitor - non-null progress monitor
Returns:
statistics for current diagram
See Also:
IDiagram.getStatistics(org.eclipse.core.runtime.IProgressMonitor)

getSettings

public IDiagramSettings getSettings()
Returns diagram settings.

Specified by:
getSettings in interface IDiagram
Returns:
diagram settings
See Also:
IDiagram.getSettings()

setSettings

public void setSettings(IDiagramSettings settings)
Sets diagram settings.

Specified by:
setSettings in interface IDiagram
Parameters:
settings - diagram settings
See Also:
IDiagram.setSettings(pl.edu.agh.cast.model.visual.backward.IDiagramSettings)

addNode

public Node addNode(Node node)
Adds a Node to the model.

Specified by:
addNode in interface IDiagram
Parameters:
node - the node to add
Returns:
the node that was actually added to the diagram (useful for undo)
See Also:
IDiagram.addNode(pl.edu.agh.cast.model.visual.backward.Node)

addNodes

public Collection<Node> addNodes(Collection<Node> nodes)
Adds Nodes to the model.

Specified by:
addNodes in interface IDiagram
Parameters:
nodes - collection of nodes to add
Returns:
collection of nodes that were actually added to the diagram (doesn't include nodes already present in the diagram); this information can be used to undo the adding operation
See Also:
IDiagram.addNodes(java.util.Collection)

addNodeInternal

protected Node addNodeInternal(Node node)
Adds a node to the model.

Parameters:
node - node to add

addConnectionsForNode

protected void addConnectionsForNode(Node node)
Adds connections of a given node to the diagram.

Parameters:
node - the node

addConnection

public Connection addConnection(Connection c)
Adds a Connection to the diagram.

Specified by:
addConnection in interface IDiagram
Parameters:
c - connection to add
Returns:
non-null, added connection
See Also:
IDiagram.addConnection(pl.edu.agh.cast.model.visual.backward.Connection)

addConnections

public void addConnections(Collection<Connection> connections)
Adds multiple Connections. Calls IDiagram.addConnection(pl.edu.agh.cast.model.visual.backward.Connection).

Specified by:
addConnections in interface IDiagram
Parameters:
connections - collection of connections to add
See Also:
IDiagram.addConnections(java.util.Collection)

removeNode

public void removeNode(Node node)
Removes a Node from the diagram. Node must have been created by this diagram's factory (i.e. must be a diagram's node).

Specified by:
removeNode in interface IDiagram
Parameters:
node - the node to remove
See Also:
IDiagram.removeNode(pl.edu.agh.cast.model.visual.backward.Node)

removeNodes

public void removeNodes(Collection<Node> nodes)
Removes Nodes from the model. Nodes must have been created by this diagram's factory (i.e. must be diagram's nodes).

Specified by:
removeNodes in interface IDiagram
Parameters:
nodes - collection of nodes to remove
See Also:
IDiagram.removeNodes(java.util.Collection)

removeConnection

public void removeConnection(Connection connection)
Removes a Connection from the model. Connection must have been created by this diagram's factory (i.e. must be a diagram's connection).

Specified by:
removeConnection in interface IDiagram
Parameters:
connection - connection to add
See Also:
IDiagram.removeConnection(pl.edu.agh.cast.model.visual.backward.Connection)

getNodeAttributeManager

public NodeAttributeManager getNodeAttributeManager()
Returns the NodeAttributeManager of this diagram.

Specified by:
getNodeAttributeManager in interface IDiagram
Returns:
NodeAttributeManager of this diagram
See Also:
IDiagram.getNodeAttributeManager()

getNodes

public Collection<Node> getNodes()
Returns a collection of all diagram Nodes.

Specified by:
getNodes in interface IDiagram
Returns:
collection of Nodes
See Also:
IDiagram.getNodes()

getConnections

public Collection<Connection> getConnections()
Returns a collection of Connections. This can throw UnsupportedOperationException if diagram does not have information about single connections.

Specified by:
getConnections in interface IDiagram
Returns:
collection of Connections
See Also:
IDiagram.getConnections()

getVisualModelFactory

protected final VisualModelCachingFactory getVisualModelFactory()
Returns caching factory of visual elements.

Returns:
caching factory of visual elements

findNode

public Node findNode(String nodeId)
Returns the Node with given id.

Specified by:
findNode in interface IDiagram
Parameters:
nodeId - id of the node to find
Returns:
node with given id
See Also:
IDiagram.findNode(java.lang.String)

findConnection

public Connection findConnection(String sourceNodeId,
                                 String targetNodeId,
                                 Date date)
Returns the Connection matching given criteria.

Specified by:
findConnection in interface IDiagram
Parameters:
sourceNodeId - id of the connection source node
targetNodeId - id of the connection target node
date - date of the connection
Returns:
connection matching given criteria
See Also:
IDiagram.findConnection(java.lang.String, java.lang.String, java.util.Date)

addAttributesFromEntities

public void addAttributesFromEntities(Collection<IEntity> entities,
                                      Collection<String> attributes,
                                      Map<String,AttributeMergePolicy> mergePolicies,
                                      String nodeType,
                                      org.eclipse.core.runtime.IProgressMonitor monitor)
Adds attributes from a collection of entities to the diagram with join on entity and node IDs. For details see #addAttributesFromEntities(Collection, Map, String, String, String)

Specified by:
addAttributesFromEntities in interface IDiagram
Parameters:
entities - collection of entities to add attributes from
attributes - collection of attributes from entities that should be added to nodes
mergePolicies - map of AttributeMergePolicy policies
nodeType - type of nodes that the attributes should be added to, if null then all types are taken into account
monitor - progress monitor for this task, if null then NullProgressMonitor is used
See Also:
IDiagram.addAttributesFromEntities(java.util.Collection, java.util.Collection, java.util.Map, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)

addAttributesFromEntities

public void addAttributesFromEntities(Collection<IEntity> entities,
                                      Collection<String> attributes,
                                      Map<String,AttributeMergePolicy> mergePolicies,
                                      String nodeType,
                                      String sourceJoinAttribute,
                                      String targetJoinAttribute,
                                      org.eclipse.core.runtime.IProgressMonitor monitor)
Adds attributes from a collection of entities to the diagram. The join between the entities and nodes is performed on the sourceJoinAttribute of entities and targetJoinAttribute of diagram nodes. For each Node node of type nodeType from the current Diagram, if there is an entity (of type IEntity) such that:
 node.getAttributeValue(targetJoinAttribute).equals(entity.getAttribute(sourceJoinAttribute));
 
then the attributes from the entity are added to the node. The sourceJoinAttribute entity attribute should be unique across the entities collection, in order for the results to be deterministic. In order to resolve conflicts where the same attribute is present in both entity and node, instances AttributeMergePolicy can be used. These policies should be supplied in a map with entity attribute IDs as keys. A null key defines the default policy, otherwise AttributeMergePolicy.MERGE_POLICY_ALWAYS_SECOND is used.

Specified by:
addAttributesFromEntities in interface IDiagram
Parameters:
entities - collection of entities to add attributes from
attributes - collection of attributes from entities that should be added to nodes
mergePolicies - map of AttributeMergePolicy policies
nodeType - type of nodes that the attributes should be added to, if null then all types are taken into account
sourceJoinAttribute - id of the entity attribute to join on
targetJoinAttribute - id of the node attribute to join on
monitor - progress monitor for this task, if null then NullProgressMonitor is used
See Also:
IDiagram.addAttributesFromEntities(java.util.Collection, java.util.Collection, java.util.Map, java.lang.String, java.lang.String, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)

propertyChange

public void propertyChange(PropertyChangeEvent evt)

Specified by:
propertyChange in interface PropertyChangeListener
Overrides:
propertyChange in class ModelElement
See Also:
ModelElement.propertyChange(java.beans.PropertyChangeEvent)

deselect

public void deselect()
Removes selection in diagram edit part.

Specified by:
deselect in interface IDiagram
See Also:
IDiagram.deselect()

getDomainModel

public IDataSet getDomainModel()
Returns all model data (packaged as one IDataSet) kept in the diagram.

Specified by:
getDomainModel in interface IDiagram
Returns:
IDataSet containing diagram model data
See Also:
IDiagram.getDomainModel()

findRelation

public IRelation findRelation(Connection conn)
Finds IRelation for given connection.

Specified by:
findRelation in interface IDiagram
Parameters:
conn - the connection which was made of the relation
Returns:
the relation which was the base for given connection
See Also:
IDiagram.findRelation(pl.edu.agh.cast.model.visual.backward.Connection)

getAttributeManager

public AttributeManager getAttributeManager()
Returns attribute manager for this container.

Specified by:
getAttributeManager in interface AttributeValueContainer
Specified by:
getAttributeManager in class ModelElement
Returns:
attribute manager for this container
See Also:
ModelElement.getAttributeManager()

isEnhancable

public boolean isEnhancable()
Checks if the nodes of this diagram may be enhanced with attributes of entities from another IDataSet. For details see #addAttributesFromEntities(Collection, Collection, Map, String, String, String) .

Specified by:
isEnhancable in interface IDiagram
Returns:
whether this diagram may be enhanced
See Also:
IDiagram.isEnhancable()

setSuppressEvents

public void setSuppressEvents(boolean newSuppressEvents)
Suppresses all events fired by this diagram.

Specified by:
setSuppressEvents in interface IDiagram
Parameters:
newSuppressEvents - new value of suppression flag

firePropertyChange

protected void firePropertyChange(String property,
                                  Object oldValue,
                                  Object newValue)
Notifies about property change.

Overrides:
firePropertyChange in class ModelElement
Parameters:
property - name of the property
oldValue - old value of the property
newValue - new value of the property
See Also:
ModelElement.firePropertyChange(java.lang.String, java.lang.Object, java.lang.Object)


Copyright © 2007-2009 IISG AGH-UST Krakow, Poland. All Rights Reserved.