1 19 20 package org.netbeans.modules.tasklist.usertasks.treetable; 21 22 import java.awt.event.ActionEvent ; 23 import javax.swing.AbstractAction ; 24 import javax.swing.event.ListSelectionEvent ; 25 import javax.swing.event.ListSelectionListener ; 26 import javax.swing.tree.TreePath ; 27 import org.netbeans.modules.tasklist.usertasks.util.UTUtils; 28 import org.openide.util.NbBundle; 29 30 35 public class ExpandCollapseAction extends AbstractAction implements 36 ListSelectionListener { 37 private TreeTable tt; 38 private boolean expand; 39 40 46 public ExpandCollapseAction(boolean expand, TreeTable tt) { 47 super(NbBundle.getMessage(ExpandCollapseAction.class, 48 expand ? "Expand" : "Collapse")); this.tt = tt; 50 this.expand = expand; 51 tt.getSelectionModel().addListSelectionListener(this); 52 } 53 54 public void actionPerformed(ActionEvent e) { 55 TreePath tp = tt.getSelectedPath(); 56 if (expand) 57 tt.expandPath(tp); 58 else 59 tt.getTree().collapsePath(tp); 60 tt.select(tp); 61 } 62 63 public void valueChanged(ListSelectionEvent e) { 64 TreePath tp = tt.getSelectedPath(); 65 if (tp != null) { 66 boolean expanded = tt.getTree().isExpanded(tp); 67 boolean children = tt.getTree().getModel().getChildCount( 68 tp.getLastPathComponent()) > 0; 69 setEnabled(children && (expanded != this.expand)); 70 } else { 71 setEnabled(false); 72 } 73 } 74 } 75 | Popular Tags |