KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > terracotta > dso > editors > chooser > FieldNavigator


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package org.terracotta.dso.editors.chooser;
5
6 import org.eclipse.jdt.core.IJavaProject;
7
8 import org.dijon.DialogResource;
9
10 import com.tc.admin.common.XTreeNode;
11 import org.terracotta.dso.editors.tree.FieldNode;
12 import org.terracotta.dso.editors.tree.JavaProjectModel;
13 import org.terracotta.dso.editors.tree.TypeNode;
14
15 import javax.swing.event.TreeSelectionEvent JavaDoc;
16 import javax.swing.event.TreeSelectionListener JavaDoc;
17 import javax.swing.tree.TreePath JavaDoc;
18
19 public class FieldNavigator extends JavaProjectNavigator {
20   public FieldNavigator(java.awt.Frame JavaDoc frame) {
21     super(frame);
22   }
23   
24   public void load(DialogResource dialogRes) {
25     super.load(dialogRes);
26     setTitle("Field Navigator");
27     
28     m_packageTree.addTreeSelectionListener(new TreeSelectionListener JavaDoc() {
29       public void valueChanged(TreeSelectionEvent JavaDoc e) {
30         TreePath JavaDoc newPath = e.getNewLeadSelectionPath();
31         
32         if(newPath == null) {
33           return;
34         }
35         
36         Object JavaDoc lastNode = newPath.getLastPathComponent();
37         
38         if(lastNode instanceof TypeNode) {
39           TypeNode typeNode = (TypeNode)lastNode;
40           int childCount = typeNode.getChildCount();
41           XTreeNode childNode;
42           
43           for(int i = 0; i < childCount; i++) {
44             childNode = (XTreeNode)typeNode.getChildAt(i);
45             
46             if(childNode instanceof FieldNode) {
47               TreePath JavaDoc childPath = new TreePath JavaDoc(childNode.getPath());
48               
49               if(m_packageTree.isPathSelected(childPath)) {
50                 m_packageTree.removeSelectionPath(childPath);
51               }
52             }
53           }
54         }
55         else if(lastNode instanceof FieldNode) {
56           FieldNode fieldNode = (FieldNode)lastNode;
57           TypeNode typeNode = (TypeNode)fieldNode.getParent();
58           
59           if(typeNode != null) {
60             TreePath JavaDoc typePath = new TreePath JavaDoc(typeNode.getPath());
61             
62             if(m_packageTree.isPathSelected(typePath)) {
63               m_packageTree.removeSelectionPath(typePath);
64             }
65           }
66         }
67       }
68     });
69   }
70
71   public JavaProjectModel createModel(IJavaProject javaProject) {
72     return new JavaProjectModel(javaProject, true, false, true);
73   }
74
75   public String JavaDoc[] getSelectedFieldNames() {
76     return getSelectedFields();
77   }
78 }
79
Popular Tags