HomeFlexGanttDocumentation (Online)

TreeTable

Most of the left-hand side of a Gantt chart is implemented in the TreeTable class. This class has a very high complexity and a large number of methods. The following sections try to group the methods. Not every method will be covered in detail. It is only important to understand in which context they are being used. Additionally it is important to know, that the column headers are not a part of TreeTable, but of the TreeTableHeader component.

Selecting Rows / Selection Model

The user needs to be able to select one or more rows in order to execute actions and commands based on this selection. TreeTable uses its own selection model for this purpose. This model implements the ITreeTableSelectionModel interface. TreeTable uses an instance of type DefaultTreeTableSelectionModel. Methods are available for getting and setting the selection model.

 ITreeTableSelectionModel TreeTable.getSelectionModel();
void TreeTable.setSelectionModel(ITreeTableSelectionModel);

As it is common in Swing, interested parties can register listeners with the selection mmodel. These listeners will receive events, whenever the selection state of the model / table changes.

 void TreeTable.addTreeSelectionListener(TreeSelectionListener);
void TreeTable.removeTreeSelectionListener(TreeSelectionListener);

The selection behaviour of a tree table can vary, depending on the application type or the current state of the application. Sometimes the user is only allowed to select a single row at a time, sometimes maybe several in different places, sometimes maybe only a range. This behaviour can be specified by setting a selection mode:

void TreeTable.setSelectionMode(int);
int TreeTable.getSelectionMode();

The allowed values for this method are defined in the TreeSelectionModel interface. They are:

TreeSelectionModel.SINGLE_TREE_SELECTION
TreeSelectionModel.CONTIGUOUS_TREE_SELECTION
TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION

A long list of methods are available for creating, removing, or querying selections. Most of these methods delegate to the actual selection model:

void TreeTable.selectAll();
void TreeTable.clearSelection();
void TreeTable.setSelectionPath(TreePath);
void TreeTable.setSelectionPaths(TreePath[]);
void TreeTable.addSelectionPath(TreePath);
void TreeTable.removeSelectionPath(TreePath);
void TreeTable.addSelectionPaths(TreePath[]);
void TreeTable.removeSelectionPaths(TreePath[]);
void TreeTable.addSelectionRow(int);
void TreeTable.addSelectionRows(int[]);
void TreeTable.setSelectionRow(int);
void TreeTable.setSelectionRows(int[]);
TreePath TreeTable.getSelectionPath();
TreePath[] TreeTable.getSelectionPaths();
void TreeTable.setSelectionInterval(int, int);
void TreeTable.addSelectionInterval(int, int);
void TreeTable.removeSelectionInterval(int, int);
boolean TreeTable.isPathSelected(TreePath);
boolean TreeTable.isRowSelected(int);
intTreeTable.getSelectionCount();

Editing Cell Values

The TreeTable class allows the user to edit the value in any cell via so-called component cell editors. As is common in Swing these are mapped to object types, meaning that the type of the value determines, which editor instance will be used. If the cell does not contain a value, then the table column will be queried for the value type. TreeTable defines several editors by default. The following table shows the mapping from object type to editor type.

Object TypeEditor Type
Object com.dlsc.flexgantt.swing.treetable.TreeTable$GenericEditor
Boolean com.dlsc.flexgantt.swing.treetable.TreeTable$BooleanEditor
Date com.dlsc.flexgantt.swing.treetable.TreeTable$DateEditor
Calendar com.dlsc.flexgantt.swing.treetable.TreeTable$CalendarEditor
Number com.dlsc.flexgantt.swing.treetable.TreeTable$NumberEditor
Color com.dlsc.flexgantt.swing.treetable.TreeTable$ColorEditor
Enum com.dlsc.flexgantt.swing.treetable.TreeTable$EnumEditor

One can see that the default editors are all implemented as inner classes of TreeTable. To define your own editors simply register them with the table:

void TreeTable.setCellEditor(Class, ITreeTableCellEditor);
ITreeTableCellEditor TreeTable.getCellEditor(int, int);
ITreeTableCellEditor TreeTable.getCellEditor(Class);

The following table lists several methods defined by TreeTable and related to editing:

MethodDescription
isEditingEnabled()
setEditingEnabled(boolean)
Determines and enables / disables the editing feature.
isCellEditable(int, int) Determines if a given cell is editable.
editCellAt(int, int)
editCellAt(int, int, EventObject)
Starts an edit operation in the given cell.
editCellFocused(InputEvent) Starts an edit operation in the currently focused cell.
isEditing() Determines if editing is currently happening.
getCellEditor() Returns the currently used cell editor component.

 

Indenting Nodes

TreeTable has direct support for indenting tree nodes. Indentation means that a tree node will be assigned to a new parent node. This might result in a deeper or less deep nesting of the target node.

Indenting a Node

Indentation can be turned on and off via the following API:

void TreeTable.setIndentEnabled(boolean);
boolean TreeTable.isIndentEnabled();

Once enabled nodes can be indented by the user interactively by moving the mouse cursor to the left edge of a key column value, or programmatically, by calling the appropriate methods provided by TreeTable:

void TreeTable.indentNodes(TreePath[]);
void TreeTable.outdentNodes(TreePath[]);

Calling these methods triggers the execution of commands by the command stack of the Gantt chart in a separate thread. The default command will directly assign a new parent node to the out/indented nodes. Applications are free to replace the default command with their own implementation (e.g. a call to the business layer, which then triggers an update in the UI).

Creating and Deleting Nodes

Nodes can be created and deleted if this feature is enabled, which can be done with the help of the following methods:

void TreeTable.setCreationEnabled(boolean);
boolean TreeTable.isCreationEnabled();
void TreeTable.setDeletionEnabled(boolean);
boolean TreeTable.isDeletionEnabled();

Whether the "create new node / row" is enabled can be seen directly inside the UI. A little arrow pointing to the right will be visible below the last row used. Users can create new nodes by simply entering a value in the key column position.

Adding a Node

The actual work needed to create a new node and to attach it to the model happens in a policy and in the command returned by it.

Another option to create a new node is by inserting a row between two already existing rows in the table:

void TreeTable.insertNode(int);

The following method can be used to delete a node:

void TreeTable.deleteSelectedNodes();

Row Heights

Every row in a TreeTable can have its own individual height. This height can be interactively adjusted by the user. He only needs to move the mouse cursor on top of one of the horizontal lines inside the TreeTableRowHeader component to the left of the table. The cursor will change its shape and becomes a resize cursor. The height can then be altered with a drag gesture. This feature, too, can be turned on and off:

void TreeTable.setResizingEnabled(boolean);
boolean TreeTable.isResizingEnabled();

Table Columns

The primary class for dealing with table columns is AbstractGanttChart but TreeTable also provides a set of methods related to them. Most of them delegate to either the column model, the AbstractGanttChart class or to the TreeTableHeader class. Later one is the only component, which is aware of the position and the width of the columns.

MethodDescription
setColumnModel(IColumnModel)
getColumnModel()
Returns the value column for the given index. Delegates to TreeTableHeader.
getKeyColumn() Returns the key column. Delegates to AbstractGanttChart.
getColumn(int) Returns the value column for the given index. Delegates to TreeTableHeader.
getColumnIndex(TreeTableColumn) Returns the index of the given column. Delegates to the column model.
getColumnCount() Returns the total number of currently used columns (does not include "available" columns). Delegates to the column model.
getKeyColumnPosition() Returns the position of the key column. Delegates to AbstractGanttChart.
getColumnIndexAt(int) Returns the index of the column at the given x-coordinate. Delegates to TreeTableHeader.
getColumnAt(int) Returns the column at the given x-coordinate. Delegates to TreeTableHeader.

Table columns are not only important for the layout but also for the editing behaviour. Every column defines the type of objects shown in its table cells. This type determines which editor will be used for editing the cell values if no value is currently shown inside the cell. If a value is shown, then the type of this value will be used for editor lookup operations.

Listener and Events

Special listeners can be attached to the tree table, which will receive events whenever a tree node gets opened or closed. Listeners that implement the TreeExpansionListener interface can be registered with the table via these methods:

void TreeTable.addTreeExpansionListener(TreeExpansionListener);
void TreeTable.removeTreeExpansionListener(TreeExpansionListener);

A very similar listener is the TreeWillExpandListener. Objects implementing this type receive expand / collapse events even before the actual operation happens (after the user click, before the UI update). This makes it possible for the listener to veto the operation or to implement a lazy loading approach for children nodes. Lazy loading creates the neccessary data structures "just-in-time", which results in shorter start-up times and less initial memory consumption.

The following methods of TreeTable can be used to add TreeWillExpandListener instances:

void TreeTable.addTreeWillExpandListener(TreeWillExpandListener);
void TreeTable.removeTreeWillExpandListener(TreeWillExpandListener);

Drag & Drop

TreeTable supports drag and drop (DnD) functionality. However, the code has been moved out of it into the class TreeTableDragAndDropManager. Hence, the number of methods related to DnD found in TreeTable is rather small. Drag and drop can be turned on/off:

void TreeTable.setDraggingEnabled(boolean);
boolean TreeTable.isDraggingEnabled();

The tree table visualizes valid and invalid drop locations with two different colors. These can be controlled via the following methods:

Color TreeTable.getDropColorValid();
void TreeTable.setDropColorValid(Color);
Color TreeTable.getDropColorInvalid();
void TreeTable.setDropColorInvalid(Color);


Invalid Drop Color

Valid Drop Color


As mentioned before most of the DnD functionality is inside the TreeTableDragAndDropManager class. This class is used internally only and does not present any public API. Applications can control the DnD behaviour of the tree table with the help of a policy.

Focus

One cell in the tree table always has the focus. This focused cell can be identified by a thicker border.

Focused Cell

 

The focus state is managed by the class CellFocusManager. It keeps track of the row and column of the currently focused cell. Additionally it offers methods to move the focus to the next, previous, upper, lower, first, and last row. The TreeTable class has methods for looking up the focused cell and the cell focus manager instance:

CellFocusManager TreeTable.getCellFocusManager();
int TreeTable.getFocusedRow();
int TreeTable.getFocusedColumn();

 

 

 

Award Winning

FlexGantt is one of the best-selling components at ComponentSource.

 

Trial Download

Download a free and feature-complete 30 day trial version of FlexGantt to conduct a proper evaluation.

We are sure that FlexGantt will be able to convince you of its suitability for your planning and scheduling application.

Free download

Who's Online

We have 27 guests and no members online