KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > addressbook > gui > action > DefaultTreeAction


1 // The contents of this file are subject to the Mozilla Public License Version
2
// 1.1
3
//(the "License"); you may not use this file except in compliance with the
4
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
5
//
6
//Software distributed under the License is distributed on an "AS IS" basis,
7
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8
//for the specific language governing rights and
9
//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 JavaDoc;
21 import javax.swing.event.TreeSelectionListener JavaDoc;
22 import javax.swing.tree.TreePath JavaDoc;
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 implements
36         TreeSelectionListener JavaDoc {
37     private AddressbookTreeNode treeNode;
38
39     /**
40      * @param frameMediator
41      * @param name
42      */

43     public DefaultTreeAction(IFrameMediator frameMediator, String JavaDoc 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 JavaDoc e) {
59         TreePath JavaDoc path = e.getNewLeadSelectionPath();
60
61         // remember last selected folder treenode
62
if (path != null) {
63             treeNode = (AddressbookTreeNode) path.getLastPathComponent();
64         }
65
66         // enable, if more than zero treenodes selected
67
if ( (path != null) && ( treeNode instanceof AddressbookFolder ) ){
68             setEnabled(true);
69         } else {
70             setEnabled(false);
71         }
72     }
73
74     /**
75      * @return Returns the treeNode.
76      */

77     public AddressbookTreeNode getTreeNode() {
78         return treeNode;
79     }
80 }
Popular Tags