Getting the activity on which a Collapse/Expand event occurs in the Gantt table

Article ID: 2409
Last updated: 29 May, 2018
Article ID: 2409
Last updated: 29 May, 2018
Revision: 3
Views: 723
Posted: 20 Nov, 2012
by Dean J.
Updated: 29 May, 2018
by Gargani A.

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());
     }
  }
} );

This article was:   Helpful | Not helpful
Report an issue
Article ID: 2409
Last updated: 29 May, 2018
Revision: 3
Views: 723
Posted: 20 Nov, 2012 by Dean J.
Updated: 29 May, 2018 by Gargani A.
Also listed in


Others in this category