| | | | Browse by category |
Question
How to obtain the activity on which a Collapse/Expand event occurs in the Gantt Table?
Answer
You need to install a TreeExpansionListener
on the IlvJTree
, and listen for the treeExpanded
and treeCollapsed
.
The Path
of the TreeExpansionEvent
contains the list of activities that was concerned by this collapse / expand event, and the last component of this path is the activity you are looking for.
This is implemented in the small class below:
IlvJTable table = _chart.getTable();
IlvJTree tree = table.getTreeColumn(table.getColumn("Name")).getTree();
tree.addTreeExpansionListener( new javax.swing.event.TreeExpansionListener() {
public void treeExpanded(javax.swing.event.TreeExpansionEvent event) {
TreePath path = event.getPath();
if (path.getLastPathComponent() instanceof IlvGeneralActivity)
{
IlvGeneralActivity expandedActivity =
(IlvGeneralActivity)path.getLastPathComponent();
System.out.println("Tree expanded on: "
+ expandedActivity.getName());
}
}
public void treeCollapsed(javax.swing.event.TreeExpansionEvent event) {
TreePath path = event.getPath();
if (path.getLastPathComponent() instanceof IlvGeneralActivity)
{
IlvGeneralActivity collapsedActivity =
(IlvGeneralActivity)path.getLastPathComponent();
System.out.println("Tree collapsed on: "
+ collapsedActivity.getName());
}
}
} );