01: // The contents of this file are subject to the Mozilla Public License Version
02: // 1.1
03: //(the "License"); you may not use this file except in compliance with the
04: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
05: //
06: //Software distributed under the License is distributed on an "AS IS" basis,
07: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
08: //for the specific language governing rights and
09: //limitations under the License.
10: //
11: //The Original Code is "The Columba Project"
12: //
13: //The Initial Developers of the Original Code are Frederik Dietz and Timo
14: // Stich.
15: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16: //
17: //All Rights Reserved.
18: package org.columba.addressbook.gui.action;
19:
20: import javax.swing.event.TreeSelectionEvent;
21: import javax.swing.event.TreeSelectionListener;
22: import javax.swing.tree.TreePath;
23:
24: import org.columba.addressbook.folder.AddressbookFolder;
25: import org.columba.addressbook.folder.AddressbookTreeNode;
26: import org.columba.addressbook.gui.frame.AddressbookFrameMediator;
27: import org.columba.api.gui.frame.IFrameMediator;
28: import org.columba.core.gui.action.AbstractColumbaAction;
29:
30: /**
31: * Action which is listening for tree selection changes.
32: *
33: * @author fdietz
34: */
35: public abstract class DefaultTreeAction extends AbstractColumbaAction
36: implements TreeSelectionListener {
37: private AddressbookTreeNode treeNode;
38:
39: /**
40: * @param frameMediator
41: * @param name
42: */
43: public DefaultTreeAction(IFrameMediator frameMediator, String name) {
44: super (frameMediator, name);
45:
46: // register interest on tree selection changes
47: ((AddressbookFrameMediator) frameMediator)
48: .addTreeSelectionListener(this );
49: }
50:
51: /**
52: * Enable or disable action on tree selection changes.
53: * <p>
54: * Actions should overwrite this method if they need more fine-grained
55: * control.
56: *
57: */
58: public void valueChanged(TreeSelectionEvent e) {
59: TreePath path = e.getNewLeadSelectionPath();
60:
61: // remember last selected folder treenode
62: if (path != null) {
63: treeNode = (AddressbookTreeNode) path
64: .getLastPathComponent();
65: }
66:
67: // enable, if more than zero treenodes selected
68: if ((path != null) && (treeNode instanceof AddressbookFolder)) {
69: setEnabled(true);
70: } else {
71: setEnabled(false);
72: }
73: }
74:
75: /**
76: * @return Returns the treeNode.
77: */
78: public AddressbookTreeNode getTreeNode() {
79: return treeNode;
80: }
81: }
|