KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > swing > resourcetree > TreeListener


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19 package org.openharmonise.him.swing.resourcetree;
20
21 import javax.swing.event.TreeExpansionEvent JavaDoc;
22 import javax.swing.event.TreeSelectionEvent JavaDoc;
23 import javax.swing.event.TreeSelectionListener JavaDoc;
24 import javax.swing.event.TreeWillExpandListener JavaDoc;
25 import javax.swing.tree.ExpandVetoException JavaDoc;
26 import javax.swing.tree.TreePath JavaDoc;
27
28 import org.openharmonise.him.context.StateHandler;
29 import org.openharmonise.vfs.*;
30 import org.openharmonise.vfs.context.*;
31
32
33 /**
34  * The tree listener is mostly to deal with tree expansion events where
35  * it populates the children of a branch.
36  *
37  * @author Matthew Large
38  * @version $Revision: 1.1 $
39  *
40  */

41 public class TreeListener
42     implements TreeSelectionListener JavaDoc, TreeWillExpandListener JavaDoc {
43
44     /**
45      * Wait identifier for the state handler.
46      */

47     private static final String JavaDoc ACTION_OPEN_TREE = "OPEN_TREE_NODE";
48
49     
50     public TreeListener() {
51         super();
52     }
53
54     /* (non-Javadoc)
55      * @see javax.swing.event.TreeSelectionListener#valueChanged(javax.swing.event.TreeSelectionEvent)
56      */

57     public void valueChanged(TreeSelectionEvent JavaDoc e) {
58         TreePath JavaDoc path = e.getNewLeadSelectionPath();
59         if(path!=null) {
60             Object JavaDoc obj = path.getLastPathComponent();
61             if( obj instanceof TreeNode) {
62                 String JavaDoc filepath = ((TreeNode)obj).getFilePath();
63                 AbstractVirtualFileSystem vfs = ((TreeNode)obj).getVFS();
64             }
65         }
66     }
67
68     /* (non-Javadoc)
69      * @see javax.swing.event.TreeWillExpandListener#treeWillExpand(javax.swing.event.TreeExpansionEvent)
70      */

71     public void treeWillExpand(TreeExpansionEvent JavaDoc event)
72         throws ExpandVetoException JavaDoc {
73         Object JavaDoc obj = event.getPath().getLastPathComponent();
74         if( obj instanceof TreeNode ) {
75             StateHandler.getInstance().addWait(ACTION_OPEN_TREE);
76             try {
77                 ((TreeNode)obj).populateChildren();
78             } catch(Exception JavaDoc e) {
79                 e.printStackTrace();
80             } finally {
81                 StateHandler.getInstance().removeWait(ACTION_OPEN_TREE);
82             }
83         }
84
85     }
86
87     /* (non-Javadoc)
88      * @see javax.swing.event.TreeWillExpandListener#treeWillCollapse(javax.swing.event.TreeExpansionEvent)
89      */

90     public void treeWillCollapse(TreeExpansionEvent JavaDoc event)
91         throws ExpandVetoException JavaDoc {
92         // NO-OP
93
}
94
95 }
96
Popular Tags