eu.beesoft.gantt
Class GanttModel

java.lang.Object
  extended by javax.swing.tree.DefaultTreeModel
      extended by eu.beesoft.gaia.swing.TreeTableModel
          extended by eu.beesoft.gantt.GanttModel
All Implemented Interfaces:
java.io.Serializable, javax.swing.tree.TreeModel

public abstract class GanttModel
extends TreeTableModel

Model for JGantt component. It supports data binding and object lazy loading.

You need implement these methods:

If you want to paint in the chart component some texts (if you use LabelLayer), you need override these methods:

Data binding is implemented by Miner class. All you need to do is to set property name to gantt column (via GanttColumn.setBinding(String) ). Then methods getValueAt() and setValueAt() can work fully automatically. If your domain objects are not suitable for data binding, override methods getValueAt() and setValueAt(). You can also subclass Miner class and set it to GanttModel by method setMiner(Miner).

Lazy loading is one of the interesting features of this model. We employ here the possibilities of ExplorableTreeNode, which is an ancestor of GanttNode. When node is expanded and was not explored still, method explore(GanttNode) is invoked. Override this method to loading children of your domain object.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class javax.swing.tree.DefaultTreeModel
asksAllowsChildren, listenerList, root
 
Constructor Summary
GanttModel()
          Creates a new instance of GanttModel.
 
Method Summary
abstract  TimelineObject createObject(TimelineObject parent, int index, UndoStep undo)
          Creates a new domain object and adds it as child to parent (you don't need to care about treetable nodes).
abstract  boolean deleteObject(TimelineObject object, UndoStep undo)
          Removes given object from its parent on domain objects level (you don't need to care about treetable nodes).
 void explore(GanttNode node)
          This method is called by GanttNode in lazy loading mode.
 JGantt getGantt()
          Returns a JGantt instance for this model.
 GanttNode getGanttNode(TimelineObject userObject)
          Returns GanttNode which uses given userObject as its user object.
 java.lang.String getChartHeaderText(java.util.Date date, TimeUnit timeUnit, boolean isMajorHeader)
          Returns text for drawing in chart header - name of month, week number, and so on.
 java.lang.String getLabel(TimelineObject object)
          Returns label text for given object.
 Miner getMiner()
          Returns the current instance of Miner used by this GanttModel.
 java.lang.String getTooltipText(TimelineObject object)
          Returns tooltip text for given object.
 java.lang.Object getValueAt(TreeTableNode node, int column)
          Returns value from given node and for given column.
 boolean isUpdateMode()
          Returns true if model is in update mode.
 boolean isWeekend(java.util.Date date)
          Returns true if given date is saturday or sunday.
abstract  boolean moveObject(TimelineObject object, TimelineObject newContainer, int newIndex, UndoStep undo)
          Moves given object on domain objects level (you don't need to care about treetable nodes).
 void nodeChanged(javax.swing.tree.TreeNode node)
          Listener method to receive informations about node representation in the tree.
 void setMiner(Miner miner)
          Sets a new instance of Miner for use by this GanttModel.
 void setRoot(javax.swing.tree.TreeNode node)
          Sets a new root node for this model.
 void setRootObject(TimelineObject object)
          Sets a new root node with a given object as its user-object for this model .
 void setUpdateMode(boolean updateMode)
          Sets value for update mode.
 void setValueAt(TreeTableNode node, int column, java.lang.Object value)
          Sets given value to the user object in the node and column.
 
Methods inherited from class eu.beesoft.gaia.swing.TreeTableModel
getColumnClass, getColumnCount, getColumnName, isCellEditable, isLeaf
 
Methods inherited from class javax.swing.tree.DefaultTreeModel
addTreeModelListener, asksAllowsChildren, fireTreeNodesChanged, fireTreeNodesInserted, fireTreeNodesRemoved, fireTreeStructureChanged, getChild, getChildCount, getIndexOfChild, getListeners, getPathToRoot, getPathToRoot, getRoot, getTreeModelListeners, insertNodeInto, 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
 

Constructor Detail

GanttModel

public GanttModel()
Creates a new instance of GanttModel. Creates and initializes a default Miner instance.

Method Detail

getGantt

public JGantt getGantt()
Returns a JGantt instance for this model.

Returns:
instance of JGantt for this model

getMiner

public Miner getMiner()
Returns the current instance of Miner used by this GanttModel.

Returns:
instance of Miner

setMiner

public void setMiner(Miner miner)
Sets a new instance of Miner for use by this GanttModel. The Miner class is designated to obtain property value on method or field level from any object. You can subclass Miner class to reach your requirements.

Parameters:
miner - - instance of Miner to set

setRoot

public void setRoot(javax.swing.tree.TreeNode node)
Sets a new root node for this model. Node must be an instance of GanttNode or null.

Overrides:
setRoot in class TreeTableModel
Parameters:
node - - root node for this model

setRootObject

public void setRootObject(TimelineObject object)
Sets a new root node with a given object as its user-object for this model .

Parameters:
object - - user object for new root node

explore

public void explore(GanttNode node)
This method is called by GanttNode in lazy loading mode.

In this implementation does nothing. You must override it to give it some functionality.

In the typical implementation:

Parameters:
node - - node to explore

getValueAt

public java.lang.Object getValueAt(TreeTableNode node,
                                   int column)
Returns value from given node and for given column.

If the JGantt is not fully initialized yet, it returns null. If column = 0, returns node.

Otherwise this method uses reflection and data binding via Miner class to get property value from node user object. If no binding set, it returns null. See comment to method setMiner(Miner).

If you don't want to use reflection to get value from user object, override this method for your needs.

Overrides:
getValueAt in class TreeTableModel
Parameters:
node - - the node whose value is to be queried
column - - the column whose value is to be queried
Returns:
the value Object of the node at the specified cell

setValueAt

public void setValueAt(TreeTableNode node,
                       int column,
                       java.lang.Object value)
Sets given value to the user object in the node and column.

Does nothing,if:

Otherwise this method uses reflection and data binding via Miner class to set value to the property of node's user object.

If you don't want to use reflection to set value to the user object, override this method for your needs.

Overrides:
setValueAt in class TreeTableModel
Parameters:
node - - the node whose value is to be queried
column - - the column whose value is to be queried
value - - value to assign to cell

isUpdateMode

public boolean isUpdateMode()
Returns true if model is in update mode.

Returns:
the updateMode

setUpdateMode

public void setUpdateMode(boolean updateMode)
Sets value for update mode.
Update mode is intended for mass update of more nodes and objects. When update mode is set, no updates to chart are invoked. One mass chart update is executed when update mode is set to false.

Parameters:
updateMode - the updateMode to set

nodeChanged

public void nodeChanged(javax.swing.tree.TreeNode node)
Listener method to receive informations about node representation in the tree. Notifies ChartComponent.

Overrides:
nodeChanged in class javax.swing.tree.DefaultTreeModel
Parameters:
node - - the changed node

getGanttNode

public GanttNode getGanttNode(TimelineObject userObject)
Returns GanttNode which uses given userObject as its user object.

Parameters:
userObject - - user object of wanted gantt node

isWeekend

public boolean isWeekend(java.util.Date date)
Returns true if given date is saturday or sunday.

Parameters:
date - - Date to examine
Returns:
true if given date is weekend day

createObject

public abstract TimelineObject createObject(TimelineObject parent,
                                            int index,
                                            UndoStep undo)
Creates a new domain object and adds it as child to parent (you don't need to care about treetable nodes). Register all modified objects to undo before any change.

Parameters:
parent - - the parent of the created object
index - - index in the parent children list, where to insert created object
undo - - register for undo / redo operations
Returns:
newly created object or null if no one was created

deleteObject

public abstract boolean deleteObject(TimelineObject object,
                                     UndoStep undo)
Removes given object from its parent on domain objects level (you don't need to care about treetable nodes). Register object, its parent and all modified objects to undo before any change.

Parameters:
object - - object to remove
undo - - register for undo / redo operations
Returns:
true if object was deleted

moveObject

public abstract boolean moveObject(TimelineObject object,
                                   TimelineObject newContainer,
                                   int newIndex,
                                   UndoStep undo)
Moves given object on domain objects level (you don't need to care about treetable nodes). Register all modified objects to undo before any change.

Parameters:
object - - object to move
newContainer - - new parent for object (may be the same as current)
newIndex - - index in the new parent children list, where to move object
undo - - register for undo / redo operations
Returns:
true if object was moved

getChartHeaderText

public java.lang.String getChartHeaderText(java.util.Date date,
                                           TimeUnit timeUnit,
                                           boolean isMajorHeader)
Returns text for drawing in chart header - name of month, week number, and so on. There is implemented a basic support only, you can override this to meet your needs.

Parameters:
date - - date to process (date related to the header column)
timeUnit - - TimeUnit constant used for header
isMajorHeader - - true if text is required for major header, false for minor header
Returns:
text for displaying in chart header

getLabel

public java.lang.String getLabel(TimelineObject object)
Returns label text for given object. This text uses LabelLayer to paint additional info to timeline object. Typically, for task is name of the assignee probably the best result.

Parameters:
object - - object to get label text about
Returns:
label text or null

getTooltipText

public java.lang.String getTooltipText(TimelineObject object)
Returns tooltip text for given object.

Parameters:
object - - object to get tooltip text about
Returns:
tooltip text or null