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

java.lang.Object
  extended by javax.swing.tree.DefaultMutableTreeNode
      extended by com.dlsc.flexgantt.model.treetable.DefaultMutableTreeTableNode<T>
          extended by com.dlsc.flexgantt.model.gantt.DefaultGanttChartNode<T,S>
Type Parameters:
T - the type of the wrapped user / business object
S - the type of the timeline objects
All Implemented Interfaces:
IGanttChartNode<S>, IMutableTreeTableNode, ITreeTableNode, java.io.Serializable, java.lang.Cloneable, java.util.Comparator, javax.swing.tree.MutableTreeNode, javax.swing.tree.TreeNode
Direct Known Subclasses:
DefaultResourceNode

public class DefaultGanttChartNode<T,S extends ITimelineObject>
extends DefaultMutableTreeTableNode<T>
implements IGanttChartNode<S>

The default implementation of IGanttChartNode that can be used in combination with the DefaultGanttChartModel. A Gantt chart node is an extension of a tree table node and provides the information that is required to populate the right-hand side of the Gantt chart with data. Gantt chart nodes can wrap the actual model objects of the application's domain model. The type of these user / business objects can be made known to the node via the use of Generics. Doing so allows for a type-specific method to retrieve the user object (see DefaultMutableTreeTableNode.getTypedUserObject().

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

Field Summary
 
Fields inherited from class javax.swing.tree.DefaultMutableTreeNode
allowsChildren, children, EMPTY_ENUMERATION, parent, userObject
 
Constructor Summary
DefaultGanttChartNode()
          Constructs a new Gantt chart node.
DefaultGanttChartNode(boolean allowsChildren)
          Constructs a new Gantt chart node.
DefaultGanttChartNode(T userObject)
          Constructs a new Gantt chart node.
DefaultGanttChartNode(T userObject, boolean allowsChildren)
          Constructs a new Gantt chart node.
 
Method Summary
 void addTimelineObject(ILayer layer, S timelineObject)
          Adds a timeline object to the node for the given layer.
 void addTimelineObjects(ILayer layer, java.util.Collection<S> timelineObjects)
          Adds a collection of timeline objects to the node.
 void addTimelineObjects(ILayer layer, S[] timelineObjects)
          Adds the timeline objects on the node for the given layer.
 void clearTimelineObjects(ILayer layer)
          Removes all timeline objects (currently shown on the given layer) from the node.
 int getDropActions(S timelineObject, long timePoint)
          Returns the drop actions that can be performed on the node related to timeline objects.
 int getLineCount()
          Returns how many lines will be shown within the row that is occuupied by the Gantt chart node.
 int getLineHeight(int lineIndex, int rowHeight)
          Returns the height of the line with the given index based on the given row height.
 int getLineLocation(int lineIndex, int rowHeight)
          Returns the location of the line with the given index based on the given row height.
 java.util.List<S> getTimelineObjects()
          Returns a list of all timeline objects on all layers.
 java.util.List<S> getTimelineObjects(ILayer layer)
          Returns a list of all timeline objects that are associated with the given layer.
 java.util.Iterator<S> getTimelineObjectsIterator(ILayer layer, ITimeSpan span)
          Returns an iterator for all timeline objects on the given layer for the given time span.
 java.util.Iterator<S> getTimelineObjectsIterator(ITimeSpan span)
          Returns an iterator for all timeline objects on all layers for the given time span.
 boolean isSelectable(ITimeSpan span)
          Determines whether the given time span can be selected for the node.
 void removeTimelineObject(ILayer layer, S timelineObject)
          Removes the given timeline object from the node.
 void removeTimelineObjects(ILayer layer, java.util.Collection<S> timelineObjects)
          Removes a collection of objects from the node.
 void removeTimelineObjects(ILayer layer, S[] timelineObjects)
          Removes the given timeline objects from the node.
 void setLineCount(int count)
          Specifies how many lines will be shown within the node's row.
 void setTimelineObject(ILayer layer, S timelineObject)
          Sets a single timeline object on the node for the given layer.
 void setTimelineObjects(ILayer layer, java.util.Collection<S> timelineObjects)
          Sets the timeline objects on the node for the given layer.
 void setTimelineObjects(ILayer layer, S[] timelineObjects)
          Sets the timeline objects on the node for the given layer.
 void sortTimelineObjects(ILayer layer)
          Sorts the timeline objects that are located on the hierarchy / tree node.
 void validateTimelineObjectList(ILayer layer)
          A debugging method to validate the list used for the given layer.
 
Methods inherited from class com.dlsc.flexgantt.model.treetable.DefaultMutableTreeTableNode
add, compare, compare, getColumnValue, getComparator, getDragActions, getDropActions, getKey, getKeyComparator, getRowHeaderValue, getRowHeight, getRowHeightMaximum, getRowHeightMinimum, getToolTipText, getTypedUserObject, getUserObject, insert, isDeletable, isKeyEditable, isResizable, isRowLineVisible, isSelectable, isSorting, isValueEditable, setColumnValue, setComparator, setDeletable, setDragActions, setKey, setKeyComparator, setKeyEditable, setResizable, setRowHeaderValue, setRowHeight, setRowHeightMaximum, setRowHeightMinimum, setRowLineVisible, setSelectable, setToolTipText, setTypedUserObject, setUserObject, setValueEditable, sort
 
Methods inherited from class javax.swing.tree.DefaultMutableTreeNode
breadthFirstEnumeration, children, clone, depthFirstEnumeration, getAllowsChildren, getChildAfter, getChildAt, getChildBefore, getChildCount, getDepth, getFirstChild, getFirstLeaf, getIndex, getLastChild, getLastLeaf, getLeafCount, getLevel, getNextLeaf, getNextNode, getNextSibling, getParent, getPath, getPathToRoot, getPreviousLeaf, getPreviousNode, getPreviousSibling, getRoot, getSharedAncestor, getSiblingCount, getUserObjectPath, isLeaf, isNodeAncestor, isNodeChild, isNodeDescendant, isNodeRelated, isNodeSibling, isRoot, pathFromAncestorEnumeration, postorderEnumeration, preorderEnumeration, remove, remove, removeAllChildren, removeFromParent, setAllowsChildren, setParent, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.dlsc.flexgantt.model.treetable.ITreeTableNode
getColumnValue, getDragActions, getDropActions, getKey, getRowHeaderValue, getRowHeight, getRowHeightMaximum, getRowHeightMinimum, getToolTipText, isDeletable, isKeyEditable, isResizable, isRowLineVisible, isSelectable, isValueEditable, setColumnValue, setKey, setRowHeaderValue, setRowHeight, sort
 
Methods inherited from interface javax.swing.tree.TreeNode
children, getAllowsChildren, getChildAt, getChildCount, getIndex, getParent, isLeaf
 
Methods inherited from interface javax.swing.tree.MutableTreeNode
remove, remove, removeFromParent, setParent
 
Methods inherited from interface java.util.Comparator
equals
 

Constructor Detail

DefaultGanttChartNode

public DefaultGanttChartNode(T userObject,
                             boolean allowsChildren)
Constructs a new Gantt chart node.

Parameters:
userObject - the wrapped user / business / domain model object
allowsChildren - if TRUE the node will be asked for its children and a node expansion icon will be displayed in the tree table
Since:
1.0

DefaultGanttChartNode

public DefaultGanttChartNode(T userObject)
Constructs a new Gantt chart node. The node does allow children to be added and shown.

Parameters:
userObject - the wrapped user / business / domain model object
Since:
1.0

DefaultGanttChartNode

public DefaultGanttChartNode(boolean allowsChildren)
Constructs a new Gantt chart node.

Parameters:
allowsChildren - if TRUE the node will be asked for its children and a node expansion icon will be displayed in the tree table
Since:
1.0

DefaultGanttChartNode

public DefaultGanttChartNode()
Constructs a new Gantt chart node. The node does allow children to be added and shown.

Since:
1.0
Method Detail

addTimelineObject

public void addTimelineObject(ILayer layer,
                              S timelineObject)
Adds a timeline object to the node for the given layer.

Parameters:
layer - the layer to which the timeline object gets added
timelineObject - the timeline object that gets added
Since:
1.0
See Also:
removeTimelineObject(ILayer, ITimelineObject), addTimelineObjects(ILayer, Collection)

setTimelineObjects

public void setTimelineObjects(ILayer layer,
                               java.util.Collection<S> timelineObjects)
Sets the timeline objects on the node for the given layer. Previously added objects are being removed.

Parameters:
layer - the layer on which the timeline objects will be shown
timelineObjects - the collection of timeline objects being set on the node
Since:
1.0
See Also:
addTimelineObject(ILayer, ITimelineObject), addTimelineObjects(ILayer, ITimelineObject[])

setTimelineObjects

public void setTimelineObjects(ILayer layer,
                               S[] timelineObjects)
Sets the timeline objects on the node for the given layer. Previously added objects are being removed.

Parameters:
layer - the layer on which the timeline objects will be shown
timelineObjects - the array of timeline objects being set on the node
Since:
1.0
See Also:
addTimelineObject(ILayer, ITimelineObject), addTimelineObjects(ILayer, Collection)

setTimelineObject

public void setTimelineObject(ILayer layer,
                              S timelineObject)
Sets a single timeline object on the node for the given layer. Previously added objects are being removed.

Parameters:
layer - the layer on which the timeline objects will be shown
timelineObject - the timeline object being set on the node for the given layer
Since:
1.0
See Also:
addTimelineObjects(ILayer, Collection)

addTimelineObjects

public void addTimelineObjects(ILayer layer,
                               java.util.Collection<S> timelineObjects)
Description copied from interface: IGanttChartNode
Adds a collection of timeline objects to the node. The objects have to be stored in a data structure that is mapped to the given layer.

Specified by:
addTimelineObjects in interface IGanttChartNode<S extends ITimelineObject>
Parameters:
layer - the layer to which the objects will be added
timelineObjects - the objects that will be added
See Also:
IGanttChartNode.removeTimelineObjects(ILayer, Collection)

addTimelineObjects

public void addTimelineObjects(ILayer layer,
                               S[] timelineObjects)
Adds the timeline objects on the node for the given layer.

Parameters:
layer - the layer on which the timeline objects will be shown
timelineObjects - the collection of timeline objects being added
Since:
1.0
See Also:
addTimelineObject(ILayer, ITimelineObject), addTimelineObjects(ILayer, Collection)

removeTimelineObject

public void removeTimelineObject(ILayer layer,
                                 S timelineObject)
Removes the given timeline object from the node.

Parameters:
layer - the layer on which the timeline object is currently shown
timelineObject - the object that gets removed
Since:
1.0
See Also:
removeTimelineObjects(ILayer, Collection), removeTimelineObjects(ILayer, ITimelineObject[])

removeTimelineObjects

public void removeTimelineObjects(ILayer layer,
                                  java.util.Collection<S> timelineObjects)
Description copied from interface: IGanttChartNode
Removes a collection of objects from the node. The objects have to be stored inside a data structure that is mapped to the given layer.

Specified by:
removeTimelineObjects in interface IGanttChartNode<S extends ITimelineObject>
Parameters:
layer - the layer in which the timeline objects are currently shown
timelineObjects - the objects to remove
See Also:
IGanttChartNode.addTimelineObjects(ILayer, Collection)

removeTimelineObjects

public void removeTimelineObjects(ILayer layer,
                                  S[] timelineObjects)
Removes the given timeline objects from the node.

Parameters:
layer - the layer on which the timeline object is currently shown
timelineObjects - the objects that gets removed
Since:
1.0
See Also:
removeTimelineObject(ILayer, ITimelineObject), removeTimelineObjects(ILayer, Collection)

getTimelineObjects

public java.util.List<S> getTimelineObjects()
Description copied from interface: IGanttChartNode
Returns a list of all timeline objects on all layers.

Specified by:
getTimelineObjects in interface IGanttChartNode<S extends ITimelineObject>
Returns:
all timeline objects
See Also:
IGanttChartNode.getTimelineObjects(ILayer)

getTimelineObjects

public java.util.List<S> getTimelineObjects(ILayer layer)
Description copied from interface: IGanttChartNode
Returns a list of all timeline objects that are associated with the given layer.

Specified by:
getTimelineObjects in interface IGanttChartNode<S extends ITimelineObject>
Parameters:
layer - the layer for which to return the timeline objects
Returns:
all timeline objects for the given layer
See Also:
IGanttChartNode.getTimelineObjectsIterator(ILayer, ITimeSpan), IGanttChartNode.addTimelineObjects(ILayer, Collection), IGanttChartNode.removeTimelineObjects(ILayer, Collection)

getTimelineObjectsIterator

public java.util.Iterator<S> getTimelineObjectsIterator(ITimeSpan span)
Returns an iterator for all timeline objects on all layers for the given time span.

Parameters:
span - the time span for which to return the timeline objects
Returns:
an iterator for all layers and the given time span
Since:
1.0
See Also:
getTimelineObjects(ILayer), getTimelineObjects()

getTimelineObjectsIterator

public java.util.Iterator<S> getTimelineObjectsIterator(ILayer layer,
                                                        ITimeSpan span)
Description copied from interface: IGanttChartNode
Returns an iterator for all timeline objects on the given layer for the given time span.

Specified by:
getTimelineObjectsIterator in interface IGanttChartNode<S extends ITimelineObject>
Parameters:
layer - the layer for which to return the timeline objects
span - the time span for which to return the timeline objects
Returns:
an iterator for the given layer and time span
See Also:
IGanttChartNode.getTimelineObjects(ILayer), IGanttChartNode.getTimelineObjects()

clearTimelineObjects

public void clearTimelineObjects(ILayer layer)
Description copied from interface: IGanttChartNode
Removes all timeline objects (currently shown on the given layer) from the node.

Specified by:
clearTimelineObjects in interface IGanttChartNode<S extends ITimelineObject>
Parameters:
layer - the layer from which to remove all timeline objects

isSelectable

public boolean isSelectable(ITimeSpan span)
Description copied from interface: IGanttChartNode
Determines whether the given time span can be selected for the node.

Specified by:
isSelectable in interface IGanttChartNode<S extends ITimelineObject>
Parameters:
span - the time span to check for selectability
Returns:
TRUE if the given time span can be selected

setLineCount

public void setLineCount(int count)
Specifies how many lines will be shown within the node's row. Timeline objects can be placed on any one of these lines.

Parameters:
count - the numer of lines shown within the node's row
Since:
1.0
See Also:
getLineCount()

getLineCount

public int getLineCount()
Description copied from interface: IGanttChartNode
Returns how many lines will be shown within the row that is occuupied by the Gantt chart node. Timeline objects can be placed on these lines so that they do not overlap each other even when their time spans do intersect.

Specified by:
getLineCount in interface IGanttChartNode<S extends ITimelineObject>
Returns:
the number of 'inner' lines within the Gantt chart row

getLineLocation

public int getLineLocation(int lineIndex,
                           int rowHeight)
Description copied from interface: IGanttChartNode
Returns the location of the line with the given index based on the given row height. In most cases this method will simply divide the row height by the total number of lines (see IGanttChartNode.getLineCount()) and multiply it with the line index. This way all lines will be distributed equally across the total height of the row.

Specified by:
getLineLocation in interface IGanttChartNode<S extends ITimelineObject>
Parameters:
lineIndex - the index of the line for which to return a location (if the total line count is 4 then the indices will be 0, 1, 2, 3)
rowHeight - the total height of the Gantt chart row (this value can vary depending on whether the user or the application resized the row)
Returns:
the y-coordinate of the line (within the interval [0, rowHeight])

getLineHeight

public int getLineHeight(int lineIndex,
                         int rowHeight)
Description copied from interface: IGanttChartNode
Returns the height of the line with the given index based on the given row height. In most cases this method will simply divide the row height by the total number of lines (see IGanttChartNode.getLineCount()) but applications are free to let lines overlap if so desired.

Specified by:
getLineHeight in interface IGanttChartNode<S extends ITimelineObject>
Parameters:
lineIndex - the index of the line for which to return the height (if the total line count is 4 then the indices will be 0, 1, 2, 3)
rowHeight - the total height of the Gantt chart row (this value can vary depending on whether the user or the application resized the row)
Returns:
the height of the line (within the interval [0, rowHeight])

sortTimelineObjects

public void sortTimelineObjects(ILayer layer)
Sorts the timeline objects that are located on the hierarchy / tree node. This can be an important feature if (for example) the time span of one of the timeline objects has changed (the node has to maintain a list of timeline objects that are always sorted based on their start time).

Parameters:
layer - the layer on which to sort the timeline objects
Since:
1.0

validateTimelineObjectList

public void validateTimelineObjectList(ILayer layer)
A debugging method to validate the list used for the given layer. The method checks whether the timeline objects stored in the layer's list are actually sorted based on their start time. The sorted list is a precondition of the entire framework that must be fulfilled at any time.

Parameters:
layer - the layer to validate
Since:
1.0

getDropActions

public int getDropActions(S timelineObject,
                          long timePoint)
Description copied from interface: IGanttChartNode
Returns the drop actions that can be performed on the node related to timeline objects. Timeline objects can be allowed to be moved onto the node or copied to the node or both. The supported drop actions can be specified by using the constants defined in DnDConstants. Possible values are: Declaring the drop actions is only half of the work needed for correct drag and drop behaviour. A timeline object might be droppable onto the node but it also needs to be draggable.This behaviour is defined by calling ITimelineObject.getDragActions().

Specified by:
getDropActions in interface IGanttChartNode<S extends ITimelineObject>
Parameters:
timelineObject - the timeline object that might get dropped onto this node
timePoint - the time point where the timeline object might get dropped
Returns:
the supported drop actions (move, copy, or both)
See Also:
DefaultDragAndDropCommand, IDragAndDropPolicy.getDragActions(Object, Object, IGanttChartModel)