01: /**
02: * Miroslav Popov, Aug 2, 2005
03: */package org.enhydra.jawe.components.simplenavigator.actions;
04:
05: import java.awt.event.ActionEvent;
06:
07: import javax.swing.JMenuItem;
08: import javax.swing.tree.TreePath;
09:
10: import org.enhydra.jawe.ActionBase;
11: import org.enhydra.jawe.JaWEComponent;
12: import org.enhydra.jawe.JaWEManager;
13: import org.enhydra.jawe.components.XPDLTreeUtil;
14: import org.enhydra.jawe.components.simplenavigator.SimpleNavigator;
15: import org.enhydra.jawe.components.simplenavigator.SimpleNavigatorPanel;
16:
17: /**
18: * @author Miroslav Popov
19: */
20: public class CollapseAll extends ActionBase {
21:
22: public CollapseAll(JaWEComponent jawecomponent) {
23: super (jawecomponent);
24: }
25:
26: public void enableDisableAction() {
27: if (JaWEManager.getInstance().getJaWEController()
28: .getMainPackage() != null) {
29: setEnabled(true);
30: } else {
31: setEnabled(false);
32: }
33: }
34:
35: public void actionPerformed(ActionEvent e) {
36: SimpleNavigator tcon = (SimpleNavigator) jawecomponent;
37:
38: SimpleNavigatorPanel panel = (SimpleNavigatorPanel) (tcon
39: .getView());
40:
41: TreePath tp = null;
42: if (e.getSource() instanceof JMenuItem) {
43: tp = panel.getTree().getPathForLocation(
44: panel.getMouseClickLocation().x,
45: panel.getMouseClickLocation().y);
46: }
47: int clevel = -1;
48: if (tp == null) {
49: tp = panel.getTree().getSelectionPath();
50: if (tp == null) {
51: tp = new TreePath(panel.getTree().getModel().getRoot());
52: clevel = 1;
53: }
54: }
55: panel.getTree().removeTreeSelectionListener(tcon);
56: XPDLTreeUtil.expandOrCollapsToLevel(panel.getTree(), tp,
57: clevel, false);
58: if (clevel == 1) {
59: panel.getTree().clearSelection();
60: }
61: panel.getTree().addTreeSelectionListener(tcon);
62: }
63: }
|