com.dlsc.flexgantt.model.gantt
Class DefaultGanttChartModel<T extends IGanttChartNode<S>,S extends ITimelineObject>

java.lang.Object
  extended by javax.swing.tree.DefaultTreeModel
      extended by com.dlsc.flexgantt.model.treetable.DefaultTreeTableModel<T>
          extended by com.dlsc.flexgantt.model.gantt.DefaultGanttChartModel<T,S>
Type Parameters:
T - the type of the hierarchy (Gantt chart) nodes
S - the type of the timeline objects
All Implemented Interfaces:
IGanttChartModel<T,S>, ITreeTableModel<T>, java.io.Serializable, javax.swing.tree.TreeModel

public class DefaultGanttChartModel<T extends IGanttChartNode<S>,S extends ITimelineObject>
extends DefaultTreeTableModel<T>
implements IGanttChartModel<T,S>

The default implementation of a Gantt chart model. For detailed information on its usage please read the comments on IGanttChartModel.

Since:
1.0
Author:
Dirk Lemmermann
See Also:
Serialized Form

Field Summary
 
Fields inherited from class javax.swing.tree.DefaultTreeModel
asksAllowsChildren, listenerList, root
 
Constructor Summary
DefaultGanttChartModel(T node)
          Constructs a new Gantt chart model.
DefaultGanttChartModel(T node, boolean asksAllowsChildren)
          Constructs a new Gantt chart model.
 
Method Summary
 void addGanttChartModelListener(IGanttChartModelListener l)
          Adds a listener to the model.
 void addLayer(ILayer layer)
          Adds a layer to the model.
 void addRelationship(IRelationship<S> relationship)
          Adds a single relationship to the model.
 void addRelationships(java.util.Collection<IRelationship<S>> relationships)
          Adds a collection of relationships to the model.
 void addTimelineObject(T node, ILayer layer, S timelineObject)
          Adds a single timeline object to the timeline of the given tree node.
 void addTimelineObjects(T node, ILayer layer, java.util.Collection<S> timelineObjects)
          Adds a collection of objects to the timeline of the given tree node.
 void clearRelationships()
          Removes all relationships from the model.
 void clearTimelineObjects()
          Removes all timeline objects from all nodes and all layers.
 void clearTimelineObjects(ILayer layer)
          Removes all timeline objects from the given layer for all nodes.
 void clearTimelineObjects(T node)
          Removes all timeline objects from the given tree node from all layers.
 void clearTimelineObjects(T node, ILayer layer)
          Removes all timeline objects from the given tree node and layer.
 void fireGanttChartChanged(GanttChartModelEvent evt)
          Fires the given event to the model listeners.
 java.util.Iterator<S> getChildrenTimelineObjects(S parent)
          Returns an iterator over the children of the given parent timeline object.
 java.util.Iterator<ILayer> getLayers()
          Returns an iterator over the layers used by the model.
 java.util.Iterator<IRelationship<S>> getRelationships()
          Returns all relationships so that they can be visualized by the RelationshipLayer.
 java.util.Iterator<IRelationship<S>> getRelationships(S obj)
          Returns those relationships that have the given timeline object either as a source or as a target object.
 TimelineObjectPath getTimelineObjectPath(T node, S timelineObject, ILayer layer)
          Returns a timeline object path for the given node and object.
 java.util.Iterator<S> getTimelineObjectsIterator(T node, ILayer layer, ITimeSpan span)
          Returns an Iterator that can be used to iterate over all timeline objects stored on the given node and layer within the given time span.
 ITimeSpan getTimeSpan(S timelineObject)
          Returns the time span of the given timeline object.
 boolean isParentTimelineObject(S timelineObject)
          Determines whether the given timeline object is a parent timeline object.
 void removeGanttChartModelListener(IGanttChartModelListener l)
          Removes a listener from the model.
 void removeLayer(ILayer layer)
          Removes a layer from the model.
 void removeRelationship(IRelationship relationship)
          Removes a single relationship from the model.
 void removeRelationships(java.util.Collection<IRelationship> rel)
          Removes a collection of relationships from the model.
 void removeTimelineObject(T node, ILayer layer, S timelineObject)
          Removes a single timeline object from the given node and layer.
 void removeTimelineObjects(T node, ILayer layer, java.util.Collection<S> timelineObjects)
          Removes a collection of objects from the given tree node and layer.
 void setRelationships(java.util.Collection<IRelationship<S>> relationships)
          Sets all relationships at once.
 void setTimeSpan(S timelineObject, ITimeSpan span)
          Sets a new time span on the given timeline object.
 void timelineObjectChanged(S timelineObject)
          Triggers a GanttChartModelEvent that informs listeners that the given timeline object has been changed.
 
Methods inherited from class com.dlsc.flexgantt.model.treetable.DefaultTreeTableModel
addTreeTableModelListener, fireTreeNodeKeyChanged, fireTreeNodeValuesChanged, getColumnValue, getKey, getRoot, getRowHeaderValue, removeTreeTableModelListener, setColumnValue, setKey, setRoot, setRoot, setRowHeaderValue, sort, sort, sort, sort
 
Methods inherited from class javax.swing.tree.DefaultTreeModel
addTreeModelListener, asksAllowsChildren, fireTreeNodesChanged, fireTreeNodesInserted, fireTreeNodesRemoved, fireTreeStructureChanged, getChild, getChildCount, getIndexOfChild, getListeners, getPathToRoot, getPathToRoot, getTreeModelListeners, insertNodeInto, isLeaf, nodeChanged, nodesChanged, nodeStructureChanged, nodesWereInserted, nodesWereRemoved, reload, reload, removeNodeFromParent, removeTreeModelListener, setAsksAllowsChildren, valueForPathChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.dlsc.flexgantt.model.treetable.ITreeTableModel
addTreeTableModelListener, getColumnValue, getKey, getRowHeaderValue, removeTreeTableModelListener, setColumnValue, setKey, sort
 
Methods inherited from interface javax.swing.tree.TreeModel
addTreeModelListener, getChild, getChildCount, getIndexOfChild, getRoot, isLeaf, removeTreeModelListener, valueForPathChanged
 

Constructor Detail

DefaultGanttChartModel

public DefaultGanttChartModel(T node,
                              boolean asksAllowsChildren)
Constructs a new Gantt chart model.

Parameters:
node - the root node
asksAllowsChildren - if true, the node is allowed to have child nodes -- otherwise, it is always a leaf node
Since:
1.0

DefaultGanttChartModel

public DefaultGanttChartModel(T node)
Constructs a new Gantt chart model.

Parameters:
node - the root node
Since:
1.0
Method Detail

addLayer

public void addLayer(ILayer layer)
Adds a layer to the model.

Parameters:
layer - the layer to add
Since:
1.0

removeLayer

public void removeLayer(ILayer layer)
Removes a layer from the model.

Parameters:
layer - the layer to remove
Since:
1.0

getLayers

public java.util.Iterator<ILayer> getLayers()
Description copied from interface: IGanttChartModel
Returns an iterator over the layers used by the model. The layer container has to create one TimelineObjectLayer for each layer model definition.

Specified by:
getLayers in interface IGanttChartModel<T extends IGanttChartNode<S>,S extends ITimelineObject>
Returns:
the stack of layers required by the model in order to display all of its timeline objects
See Also:
IGanttChartModel.getTimelineObjectsIterator(Object, ILayer, ITimeSpan)

addGanttChartModelListener

public void addGanttChartModelListener(IGanttChartModelListener l)
Description copied from interface: IGanttChartModel
Adds a listener to the model. The listener will be informed when any of the following situations occurs:

Specified by:
addGanttChartModelListener in interface IGanttChartModel<T extends IGanttChartNode<S>,S extends ITimelineObject>
Parameters:
l - the new listener
See Also:
IGanttChartModel.removeGanttChartModelListener(IGanttChartModelListener), GanttChartModelEvent

removeGanttChartModelListener

public void removeGanttChartModelListener(IGanttChartModelListener l)
Description copied from interface: IGanttChartModel
Removes a listener from the model.

Specified by:
removeGanttChartModelListener in interface IGanttChartModel<T extends IGanttChartNode<S>,S extends ITimelineObject>
Parameters:
l - the listener to remove
See Also:
IGanttChartModel.addGanttChartModelListener(IGanttChartModelListener)

fireGanttChartChanged

public void fireGanttChartChanged(GanttChartModelEvent evt)
Fires the given event to the model listeners.

Parameters:
evt - the model event to be issued to the listeners
Since:
1.0
See Also:
addGanttChartModelListener(IGanttChartModelListener), removeGanttChartModelListener(IGanttChartModelListener)

addTimelineObject

public void addTimelineObject(T node,
                              ILayer layer,
                              S timelineObject)
Adds a single timeline object to the timeline of the given tree node. As objects can be displayed on different layers a reference to a layer has to be passed to this method as well. Calling this method will cause a GanttChartModelEvent to be fired where the ID of the event is equal to GanttChartModelEvent.ID.TIMELINE_OBJECTS_ADDED.

Parameters:
node - the tree node on which to add objects
layer - the layer where the objects shall appear
timelineObject - the object to add
Since:
1.0
See Also:
removeTimelineObjects(IGanttChartNode, ILayer, Collection), clearTimelineObjects(IGanttChartNode, ILayer), IGanttChartModel.getTimelineObjectsIterator(Object, ILayer, ITimeSpan)

addTimelineObjects

public void addTimelineObjects(T node,
                               ILayer layer,
                               java.util.Collection<S> timelineObjects)
Adds a collection of objects to the timeline of the given tree node. As objects can be displayed on different layers a reference to a layer has to be passed to this method as well. Calling this method will cause a GanttChartModelEvent to be fired where the ID of the event is equal to GanttChartModelEvent.ID.TIMELINE_OBJECTS_ADDED.

Parameters:
node - the tree node on which to add objects
layer - the layer where the objects shall appear
timelineObjects - the objects to add
Since:
1.0
See Also:
removeTimelineObjects(IGanttChartNode, ILayer, Collection), clearTimelineObjects(IGanttChartNode, ILayer), IGanttChartModel.getTimelineObjectsIterator(Object, ILayer, ITimeSpan)

clearTimelineObjects

public void clearTimelineObjects(T node,
                                 ILayer layer)
Removes all timeline objects from the given tree node and layer. A call to this method will cause a GanttChartModelEvent to be fired with the ID equal to GanttChartModelEvent.ID.TIMELINE_OBJECTS_REMOVED.

Parameters:
node - the node on which to remove all timeline objects
layer - the layer on which to remove all timeline objects
Since:
1.0
See Also:
removeTimelineObjects(IGanttChartNode, ILayer, Collection), clearTimelineObjects(), clearTimelineObjects(ILayer), clearTimelineObjects(IGanttChartNode)

clearTimelineObjects

public void clearTimelineObjects(T node)
Removes all timeline objects from the given tree node from all layers. A call to this method will cause a GanttChartModelEvent to be fired with the ID equal to GanttChartModelEvent.ID.TIMELINE_OBJECTS_REMOVED.

Parameters:
node - the node on which to remove all timeline objects
Since:
1.0
See Also:
removeTimelineObjects(IGanttChartNode, ILayer, Collection), clearTimelineObjects(), clearTimelineObjects(ILayer), clearTimelineObjects(IGanttChartNode, ILayer)

clearTimelineObjects

public void clearTimelineObjects(ILayer layer)
Removes all timeline objects from the given layer for all nodes. A call to this method will cause a GanttChartModelEvent to be fired with the ID equal to GanttChartModelEvent.ID.TIMELINE_OBJECTS_REMOVED.

Parameters:
layer - the layer on which to remove all timeline objects
Since:
1.0
See Also:
removeTimelineObjects(IGanttChartNode, ILayer, Collection), clearTimelineObjects(), clearTimelineObjects(IGanttChartNode), clearTimelineObjects(IGanttChartNode, ILayer)

clearTimelineObjects

public void clearTimelineObjects()
Removes all timeline objects from all nodes and all layers. A call to this method will cause a GanttChartModelEvent to be fired with the ID equal to GanttChartModelEvent.ID.TIMELINE_OBJECTS_REMOVED.

Since:
1.0
See Also:
removeTimelineObjects(IGanttChartNode, ILayer, Collection), clearTimelineObjects(ILayer), clearTimelineObjects(IGanttChartNode), clearTimelineObjects(IGanttChartNode, ILayer)

getTimelineObjectsIterator

public java.util.Iterator<S> getTimelineObjectsIterator(T node,
                                                        ILayer layer,
                                                        ITimeSpan span)
Description copied from interface: IGanttChartModel
Returns an Iterator that can be used to iterate over all timeline objects stored on the given node and layer within the given time span. This method is not allowed to return NULL.

Specified by:
getTimelineObjectsIterator in interface IGanttChartModel<T extends IGanttChartNode<S>,S extends ITimelineObject>
Parameters:
node - the tree node for which to return an iterator
layer - the layer for which to return an iterator
span - the time span for which to return an iterator
Returns:
an iterator for iterating over timeline objects stored on the given node, layer and time span

getTimeSpan

public ITimeSpan getTimeSpan(S timelineObject)
Description copied from interface: IGanttChartModel
Returns the time span of the given timeline object. The span doesn't necessarily has to be stored directly on the object but might be retrieved by some other means. However, DefaultGanttChartModel does store the span on the internally used IGanttChartNode instances.

Specified by:
getTimeSpan in interface IGanttChartModel<T extends IGanttChartNode<S>,S extends ITimelineObject>
Parameters:
timelineObject - the object for which to return the time span
Returns:
the time span used by the given timeline object

removeTimelineObject

public void removeTimelineObject(T node,
                                 ILayer layer,
                                 S timelineObject)
Removes a single timeline object from the given node and layer. A call to this method will cause a GanttChartModelEvent to be fired with ID equal to GanttChartModelEvent.ID.TIMELINE_OBJECTS_REMOVED.

Parameters:
node - the tree node from which to remove objects
layer - the layer from which to remove objects
timelineObject - the object that will be removed
Since:
1.0
See Also:
removeTimelineObjects(IGanttChartNode, ILayer, Collection)

removeTimelineObjects

public void removeTimelineObjects(T node,
                                  ILayer layer,
                                  java.util.Collection<S> timelineObjects)
Removes a collection of objects from the given tree node and layer. A call to this method will cause a GanttChartModelEvent to be fired with ID equal to GanttChartModelEvent.ID.TIMELINE_OBJECTS_REMOVED.

Parameters:
node - the tree node from which to remove objects
layer - the layer from which to remove objects
timelineObjects - the objects that will be removed
Since:
1.0
See Also:
addTimelineObjects(IGanttChartNode, ILayer, Collection), clearTimelineObjects(IGanttChartNode, ILayer)

setTimeSpan

public void setTimeSpan(S timelineObject,
                        ITimeSpan span)
Sets a new time span on the given timeline object. Calling this method will cause a GanttChartModelEvent to be fired where the ID is equal to GanttChartModelEvent.ID.TIMELINE_OBJECT_CHANGED.

Parameters:
timelineObject - the target timeline object
span - the new time span
Since:
1.0
See Also:
IGanttChartModel.getTimeSpan(Object)

addRelationship

public void addRelationship(IRelationship<S> relationship)
Adds a single relationship to the model. A relationship defines a source object and path, a target object and path that will be used by the RelationshipLayer to draw the lines and arrows between timeline objects. Calling this method will cause a GanttChartModelEvent to be thrown (ID equals GanttChartModelEvent.ID.RELATIONSHIP_ADDED).

Parameters:
relationship - the relationship object to add
Since:
1.0
See Also:
addRelationships(Collection)

addRelationships

public void addRelationships(java.util.Collection<IRelationship<S>> relationships)
Adds a collection of relationships to the model. Each relationship defines a source object and path, a target object and path that will be used by the RelationshipLayer to draw the lines and arrows between timeline objects. Calling this method will cause a GanttChartModelEvent to be thrown where the ID is equal to GanttChartModelEvent.ID.RELATIONSHIP_ADDED.

Parameters:
relationships - the relationships that need to be added
Since:
1.0
See Also:
removeRelationships(Collection), clearRelationships()

clearRelationships

public void clearRelationships()
Removes all relationships from the model. Calling this method will cause a GanttChartModelEvent to be thrown where the ID is equal to GanttChartModelEvent.ID.RELATIONSHIP_REMOVED.

Since:
1.0
See Also:
getRelationships(), addRelationships(Collection), removeRelationships(Collection)

getRelationships

public java.util.Iterator<IRelationship<S>> getRelationships()
Description copied from interface: IGanttChartModel
Returns all relationships so that they can be visualized by the RelationshipLayer.

Specified by:
getRelationships in interface IGanttChartModel<T extends IGanttChartNode<S>,S extends ITimelineObject>
Returns:
all relationships currently known to the model

setRelationships

public void setRelationships(java.util.Collection<IRelationship<S>> relationships)
Sets all relationships at once.

Parameters:
relationships - the new relationsips to use
Since:
1.0

getRelationships

public java.util.Iterator<IRelationship<S>> getRelationships(S obj)
Description copied from interface: IGanttChartModel
Returns those relationships that have the given timeline object either as a source or as a target object. This method gets called when the timeline object is currently visible and the RelationshipLayer wants to figure out which lines need to be drawn.

Specified by:
getRelationships in interface IGanttChartModel<T extends IGanttChartNode<S>,S extends ITimelineObject>
Parameters:
obj - the object for which to return relationships
Returns:
all relationships where the given object is either the source or the target

removeRelationship

public void removeRelationship(IRelationship relationship)
Removes a single relationship from the model.

Parameters:
relationship - the relationship to remove
Since:
1.0
See Also:
removeRelationships(Collection)

removeRelationships

public void removeRelationships(java.util.Collection<IRelationship> rel)
Removes a collection of relationships from the model. Calling this method will cause a GanttChartModelEvent to be thrown where the ID is equal to GanttChartModelEvent.ID.RELATIONSHIP_REMOVED.

Parameters:
rel - the relationships to remove
Since:
1.0
See Also:
getRelationships(), addRelationships(Collection), clearRelationships()

timelineObjectChanged

public void timelineObjectChanged(S timelineObject)
Triggers a GanttChartModelEvent that informs listeners that the given timeline object has been changed.

Parameters:
timelineObject - the object that was modified
Since:
1.0

getTimelineObjectPath

public TimelineObjectPath getTimelineObjectPath(T node,
                                                S timelineObject,
                                                ILayer layer)
Returns a timeline object path for the given node and object.

Parameters:
node - the Gantt chart node
timelineObject - the timeline object
layer - the layer on which the timeline object is displayed
Returns:
a timeline object path
Since:
1.0

getChildrenTimelineObjects

public java.util.Iterator<S> getChildrenTimelineObjects(S parent)
Description copied from interface: IGanttChartModel
Returns an iterator over the children of the given parent timeline object.

Specified by:
getChildrenTimelineObjects in interface IGanttChartModel<T extends IGanttChartNode<S>,S extends ITimelineObject>
Parameters:
parent - the parent timeline object
Returns:
an iterator used for iterating over the list of children timeline objects associated with the given parent timeline object

isParentTimelineObject

public boolean isParentTimelineObject(S timelineObject)
Description copied from interface: IGanttChartModel
Determines whether the given timeline object is a parent timeline object. A parent timeline object references children timeline objects. This concept is often used to display the union of several time spans of timeline objects (summary).

Specified by:
isParentTimelineObject in interface IGanttChartModel<T extends IGanttChartNode<S>,S extends ITimelineObject>
Parameters:
timelineObject - the timeline object to check
Returns:
TRUE if the given timeline object is a parent of one or more children timeline objects
See Also:
IGanttChartModel.getChildrenTimelineObjects(Object)