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

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

public class Diagram
extends ModelElement
implements IDiagram, java.beans.PropertyChangeListener

Author:
fox
See Also:
Serialized Form

Field Summary
protected  ConnectionGroupAttributeManager _connectionGroupAttributeManager
           
protected  DiagramAttributeManager _diagramAttributeManager
           
protected  org.eclipse.core.resources.IFile _file
           
protected  NodeAttributeManager _nodeAttributeManager
           
protected  IDiagramSettings _settings
           
protected  VisualModelCachingFactory _visualModelFactory
           
static java.lang.String CHILD
           
static java.lang.String CHILDREN
           
static java.lang.String CONNECTION
           
static java.lang.String DESELECT
           
static java.lang.String DUMMY_ID
           
static java.lang.String FILE
           
static java.lang.String NAME
           
 
Fields inherited from class pl.edu.agh.cast.model.visual.ModelElement
_attributeValues, ATTRIBUTE_CHANGE
 
Constructor Summary
Diagram(java.util.Collection<pl.edu.agh.cast.model.base.IDataSet> model)
          Constructs new diagram from model.
Diagram(java.util.Collection<pl.edu.agh.cast.model.base.IDataSet> model, org.eclipse.core.runtime.IProgressMonitor monitor)
          Constructs new diagram from model.
Diagram(java.util.Collection<pl.edu.agh.cast.model.base.IDataSet> model, org.eclipse.core.runtime.IProgressMonitor monitor, boolean enhancable)
          Constructs new diagram from model.
 
Method Summary
 void addAttributesFromEntities(java.util.Collection<pl.edu.agh.cast.model.base.IEntity> entities, java.util.Collection<java.lang.String> attributes, java.util.Map<java.lang.String,AttributeMergePolicy> mergePolicies, java.lang.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(java.util.Collection<pl.edu.agh.cast.model.base.IEntity> entities, java.util.Collection<java.lang.String> attributes, java.util.Map<java.lang.String,AttributeMergePolicy> mergePolicies, java.lang.String nodeType, java.lang.String sourceJoinAttribute, java.lang.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(java.util.Collection<Connection> connections)
          Adds many 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
 java.util.Collection<Node> addNodes(java.util.Collection<Node> nodes)
          Adds nodes to the model.
 void deselect()
           
 Connection findConnection(java.lang.String sourceNodeId, java.lang.String targetNodeId, java.util.Date date)
           
 Node findNode(java.lang.String nodeId)
           
 pl.edu.agh.cast.model.base.IRelation findRelation(Connection conn)
          Finds relation for given connection
protected  void firePropertyChange(java.lang.String property, java.lang.Object oldValue, java.lang.Object newValue)
           
 AttributeManager getAttributeManager()
          Returns element's attribute manager
 java.util.Collection<Connection> getConnections()
          This can throw UnsupportedOperationException if diagram does not have information about single connections.
 java.lang.String getDisplayName()
           
 pl.edu.agh.cast.model.base.IDataSet getDomainModel()
          Returns all model data (packaged as one DataSet) kept in the diagram.
 org.eclipse.core.resources.IFile getFile()
          Reterun file in which this diagram is stored.
 NodeAttributeManager getNodeAttributeManager()
           
 java.util.Collection<Node> getNodes()
           
 IDiagramSettings getSettings()
           
 java.util.List<Statistic> getStatistics()
           
 java.util.List<Statistic> getStatistics(org.eclipse.core.runtime.IProgressMonitor monitor)
           
protected  VisualModelCachingFactory getVisualModelFactory()
           
 boolean isEnhancable()
          Checks if the nodes of this diagram may be enhanced with attributes of entities from another IDataSet.
 void propertyChange(java.beans.PropertyChangeEvent evt)
           
protected  java.lang.Object readResolve()
           
 void removeConnection(Connection connection)
          Removes a connection from the model.
 void removeNode(Node node)
          Removes a node from the model.
 void removeNodes(java.util.Collection<Node> nodes)
          Removes nodes from the model.
 void setDisplayName(java.lang.String displayName)
          Set 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)
           
 void setSuppressEvents(boolean newSuppressEvents)
          Suppresses all events fired by this diagram.
 java.lang.String toString()
           
 
Methods inherited from class pl.edu.agh.cast.model.visual.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.model.IPropertyChangeProvider
addPropertyChangeListener, removePropertyChangeListener
 
Methods inherited from interface pl.edu.agh.cast.model.visual.AttributeValueContainer
getAllValues, getAttributeValue, isAttributeEditable, removePropertyValue, setAttributeValue, setAttributeValue
 

Field Detail

DUMMY_ID

public static final java.lang.String DUMMY_ID
See Also:
Constant Field Values

NAME

public static final java.lang.String NAME
See Also:
Constant Field Values

FILE

public static final java.lang.String FILE
See Also:
Constant Field Values

CHILD

public static final java.lang.String CHILD
See Also:
Constant Field Values

CONNECTION

public static final java.lang.String CONNECTION
See Also:
Constant Field Values

CHILDREN

public static final java.lang.String CHILDREN
See Also:
Constant Field Values

DESELECT

public static final java.lang.String DESELECT
See Also:
Constant Field Values

_file

protected transient org.eclipse.core.resources.IFile _file

_settings

protected IDiagramSettings _settings

_nodeAttributeManager

protected NodeAttributeManager _nodeAttributeManager

_connectionGroupAttributeManager

protected ConnectionGroupAttributeManager _connectionGroupAttributeManager

_diagramAttributeManager

protected DiagramAttributeManager _diagramAttributeManager

_visualModelFactory

protected final VisualModelCachingFactory _visualModelFactory
Constructor Detail

Diagram

public Diagram(java.util.Collection<pl.edu.agh.cast.model.base.IDataSet> model)
Constructs new diagram from model.

Parameters:
model - base model

Diagram

public Diagram(java.util.Collection<pl.edu.agh.cast.model.base.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:
java.lang.IllegalArgumentException - if progress monitor is null

Diagram

public Diagram(java.util.Collection<pl.edu.agh.cast.model.base.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 - weather this Diagram may be enhanced (see IDiagram.isEnhancable())
Throws:
java.lang.IllegalArgumentException - if progress monitor is null
Method Detail

readResolve

protected java.lang.Object readResolve()
Overrides:
readResolve in class ModelElement

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getFile

public org.eclipse.core.resources.IFile getFile()
Description copied from interface: IDiagram
Reterun file in which this diagram is stored.

Specified by:
getFile in interface IDiagram
Returns:
The file containing this diagram.

setFile

public void setFile(org.eclipse.core.resources.IFile file)
Description copied from interface: IDiagram
Set the file in which this diagram is stored.

Specified by:
setFile in interface IDiagram
Parameters:
file - The file to store the diagram in.

setDisplayName

public void setDisplayName(java.lang.String displayName)
Description copied from interface: IDiagram
Set display name of the diagram

Specified by:
setDisplayName in interface IDiagram
Parameters:
displayName - new name

getDisplayName

public java.lang.String getDisplayName()
Specified by:
getDisplayName in interface IDiagram
Returns:
The name of the diagram.

getStatistics

public java.util.List<Statistic> getStatistics()
Specified by:
getStatistics in interface IDiagram
Returns:
Statistics for current diagram.

getStatistics

public java.util.List<Statistic> getStatistics(org.eclipse.core.runtime.IProgressMonitor monitor)
Specified by:
getStatistics in interface IDiagram
Parameters:
monitor - non-null progress monitor
Returns:
Statistics for current diagram.

getSettings

public IDiagramSettings getSettings()
Specified by:
getSettings in interface IDiagram
Returns:

setSettings

public void setSettings(IDiagramSettings settings)
Specified by:
setSettings in interface IDiagram

addNode

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

Specified by:
addNode in interface IDiagram
Parameters:
node - is the node to add
Returns:
node that was actually added to the diagram; useful for undo

addNodes

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

Specified by:
addNodes in interface IDiagram
Returns:
list 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

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 -

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

addConnections

public void addConnections(java.util.Collection<Connection> connections)
Adds many connections. Calls #addConnection

Specified by:
addConnections in interface IDiagram

removeNode

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

Specified by:
removeNode in interface IDiagram
Throws:
java.lang.IllegalArgumentException - if node is not a child of the diagram

removeNodes

public void removeNodes(java.util.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
Throws:
java.lang.IllegalArgumentException - if any of the nodes is not a child of the diagram

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
Throws:
java.lang.IllegalArgumentException - if connection is not a child of the diagram

getNodeAttributeManager

public NodeAttributeManager getNodeAttributeManager()
Specified by:
getNodeAttributeManager in interface IDiagram

getNodes

public java.util.Collection<Node> getNodes()
Specified by:
getNodes in interface IDiagram

getConnections

public java.util.Collection<Connection> getConnections()
Description copied from interface: IDiagram
This can throw UnsupportedOperationException if diagram does not have information about single connections.

Specified by:
getConnections in interface IDiagram
Returns:

getVisualModelFactory

protected final VisualModelCachingFactory getVisualModelFactory()

findNode

public Node findNode(java.lang.String nodeId)
Specified by:
findNode in interface IDiagram

findConnection

public Connection findConnection(java.lang.String sourceNodeId,
                                 java.lang.String targetNodeId,
                                 java.util.Date date)
Specified by:
findConnection in interface IDiagram

addAttributesFromEntities

public void addAttributesFromEntities(java.util.Collection<pl.edu.agh.cast.model.base.IEntity> entities,
                                      java.util.Collection<java.lang.String> attributes,
                                      java.util.Map<java.lang.String,AttributeMergePolicy> mergePolicies,
                                      java.lang.String nodeType,
                                      org.eclipse.core.runtime.IProgressMonitor monitor)
Description copied from interface: IDiagram
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

addAttributesFromEntities

public void addAttributesFromEntities(java.util.Collection<pl.edu.agh.cast.model.base.IEntity> entities,
                                      java.util.Collection<java.lang.String> attributes,
                                      java.util.Map<java.lang.String,AttributeMergePolicy> mergePolicies,
                                      java.lang.String nodeType,
                                      java.lang.String sourceJoinAttribute,
                                      java.lang.String targetJoinAttribute,
                                      org.eclipse.core.runtime.IProgressMonitor monitor)
Description copied from interface: IDiagram
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

propertyChange

public void propertyChange(java.beans.PropertyChangeEvent evt)
Specified by:
propertyChange in interface java.beans.PropertyChangeListener
Overrides:
propertyChange in class ModelElement

deselect

public void deselect()
Specified by:
deselect in interface IDiagram

getDomainModel

public pl.edu.agh.cast.model.base.IDataSet getDomainModel()
Description copied from interface: IDiagram
Returns all model data (packaged as one DataSet) kept in the diagram.

Specified by:
getDomainModel in interface IDiagram
Returns:
DataSet containing diagram model data.

findRelation

public pl.edu.agh.cast.model.base.IRelation findRelation(Connection conn)
Description copied from interface: IDiagram
Finds relation 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

getAttributeManager

public AttributeManager getAttributeManager()
Description copied from class: ModelElement
Returns element's attribute manager

Specified by:
getAttributeManager in interface AttributeValueContainer
Specified by:
getAttributeManager in class ModelElement

isEnhancable

public boolean isEnhancable()
Description copied from interface: IDiagram
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:
weather this diagram may be enhanced

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(java.lang.String property,
                                  java.lang.Object oldValue,
                                  java.lang.Object newValue)
Overrides:
firePropertyChange in class ModelElement


Copyright © 2007-2008 AGH University of Science and Technology. All Rights Reserved.