]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/common/ui/ITree.java
1. Restructure module description on main UI
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / common / ui / ITree.java
CommitLineData
a13899c5 1/** @file\r
2 \r
3 The file is used to override JTree to provides customized interfaces \r
4 \r
5 Copyright (c) 2006, Intel Corporation\r
6 All rights reserved. This program and the accompanying materials\r
7 are licensed and made available under the terms and conditions of the BSD License\r
8 which accompanies this distribution. The full text of the license may be found at\r
9 http://opensource.org/licenses/bsd-license.php\r
10 \r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13 \r
14 **/\r
15\r
16package org.tianocore.frameworkwizard.common.ui;\r
17\r
18import javax.swing.JTree;\r
19import javax.swing.tree.DefaultMutableTreeNode;\r
20import javax.swing.tree.DefaultTreeModel;\r
21import javax.swing.tree.TreeNode;\r
22import javax.swing.tree.TreePath;\r
23\r
79cb6fdb 24import org.tianocore.frameworkwizard.common.Identifications.Identification;\r
a13899c5 25\r
26/**\r
27 The class is used to override JTree to provides customized interfaces \r
28 It extends JTree\r
29 \r
30\r
31\r
32 **/\r
33public class ITree extends JTree {\r
34 ///\r
35 /// Define class Serial Version UID\r
36 ///\r
37 private static final long serialVersionUID = -7907086164518295327L;\r
38 \r
39 //\r
40 // Define class members\r
41 //\r
42 DefaultTreeModel treeModel = null;\r
43\r
44 /**\r
45 This is the default constructor\r
46 \r
47 **/\r
48 public ITree() {\r
49 super();\r
50 }\r
51\r
52 /**\r
53 This is the overrided constructor\r
54 Init class members with input data\r
55 \r
56 @param iDmtRoot The root node of the tree\r
57 \r
58 **/\r
59 public ITree(IDefaultMutableTreeNode iDmtRoot) {\r
60 super(iDmtRoot);\r
61 treeModel = (DefaultTreeModel)this.getModel();\r
62 }\r
63\r
64 /**\r
65 Get category of selected node\r
66 \r
67 @return The category of selected node\r
68 \r
69 **/\r
70 public int getSelectCategory() {\r
71 int intCategory = 0;\r
72 TreePath path = this.getSelectionPath();\r
73 IDefaultMutableTreeNode node = (IDefaultMutableTreeNode) path.getLastPathComponent();\r
74 intCategory = node.getCategory();\r
75 return intCategory;\r
76 }\r
77\r
78 /**\r
79 Get operation of selected node\r
80 \r
81 @return The operation of selected node\r
82 \r
83 **/\r
84 public int getSelectOperation() {\r
85 int intOperation = 0;\r
86 TreePath path = this.getSelectionPath();\r
87 IDefaultMutableTreeNode node = (IDefaultMutableTreeNode) path.getLastPathComponent();\r
88 intOperation = node.getOperation();\r
89 return intOperation;\r
90 }\r
91\r
92 /**\r
93 Get selectLoaction of selected node\r
94 \r
95 @return The selectLoaction of selected node\r
96 \r
97 **/\r
98 public int getSelectLoaction() {\r
99 int intLocation = 0;\r
100 TreePath path = this.getSelectionPath();\r
101 IDefaultMutableTreeNode node = (IDefaultMutableTreeNode) path.getLastPathComponent();\r
102 intLocation = node.getLocation();\r
103 return intLocation;\r
104 }\r
105\r
106 /**\r
107 Main class, reserved for test\r
108 \r
109 @param args\r
110 \r
111 **/\r
112 public static void main(String[] args) {\r
113 // TODO Auto-generated method stub\r
114 }\r
115\r
116 /**\r
117 Add input node as child node for current selected node\r
118 \r
119 @param strNewNode The name of the node which need be added\r
120 \r
121 **/\r
122 public void addNode(String strNewNode) {\r
123 DefaultMutableTreeNode parentNode = null;\r
124 DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(strNewNode);\r
125 newNode.setAllowsChildren(true);\r
126 TreePath parentPath = this.getSelectionPath();\r
127\r
128 /**\r
129 * Get parent node of new node\r
130 */\r
131 parentNode = (DefaultMutableTreeNode) (parentPath.getLastPathComponent());\r
132\r
133 /**\r
134 * Insert new node\r
135 */\r
136 treeModel.insertNodeInto(newNode, parentNode, parentNode.getChildCount());\r
137 this.scrollPathToVisible(new TreePath(newNode.getPath()));\r
138 }\r
139\r
140 /**\r
141 Add input node as child node for current selected node\r
142 \r
143 @param newNode The node need be added\r
144 \r
145 **/\r
146 public void addNode(IDefaultMutableTreeNode newNode) {\r
147 IDefaultMutableTreeNode parentNode = null;\r
148 newNode.setAllowsChildren(true);\r
149 TreePath parentPath = this.getSelectionPath();\r
150 parentNode = (IDefaultMutableTreeNode) (parentPath.getLastPathComponent());\r
151 treeModel.insertNodeInto(newNode, parentNode, parentNode.getChildCount());\r
152 this.scrollPathToVisible(new TreePath(newNode.getPath()));\r
153 }\r
154 \r
155 /**\r
156 Add input node as child node for current selected node\r
157 \r
158 @param newNode The node need be added\r
159 \r
160 **/\r
161 public void addNode(IDefaultMutableTreeNode parentNode, IDefaultMutableTreeNode newNode) {\r
162 treeModel.insertNodeInto(newNode, parentNode, parentNode.getChildCount());\r
163 this.scrollPathToVisible(new TreePath(newNode.getPath()));\r
164 }\r
165\r
166 /**\r
167 Remove the selected node\r
168 \r
169 @param strRemovedNode\r
170 \r
171 **/\r
172 public void removeSelectedNode() {\r
173 TreePath treePath = this.getSelectionPath();\r
174 removeNodeByPath(treePath);\r
175 }\r
176 \r
177 /**\r
178 Remove the node by tree path\r
179 \r
180 @param strRemovedNode\r
181 \r
182 **/\r
183 public void removeNodeByPath(TreePath treePath) {\r
184 if (treePath != null) {\r
185 DefaultMutableTreeNode selectionNode = (DefaultMutableTreeNode) treePath.getLastPathComponent();\r
186 TreeNode parent = (TreeNode) selectionNode.getParent();\r
187 if (parent != null) {\r
188 treeModel.removeNodeFromParent(selectionNode);\r
189 }\r
190 }\r
191 }\r
192 \r
193 /**\r
194 Remove all child nodes under current node\r
195 \r
196 **/\r
197 public void removeNodeChildrenByPath(TreePath treePath) {\r
198 if (treePath != null) {\r
199 DefaultMutableTreeNode currentNode = (DefaultMutableTreeNode) treePath.getLastPathComponent();\r
200 for (int index = currentNode.getChildCount() - 1; index > -1; index--) {\r
201 treeModel.removeNodeFromParent((DefaultMutableTreeNode)currentNode.getChildAt(index));\r
202 }\r
203 }\r
204 }\r
205\r
206 /**\r
207 Remove all nodes of the tree\r
208 \r
209 **/\r
210 public void removeAllNode() {\r
211 DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) treeModel.getRoot();\r
212 rootNode.removeAllChildren();\r
213 treeModel.reload();\r
214 }\r
215 \r
216 public IDefaultMutableTreeNode getSelectNode() {\r
217 TreePath treepath = this.getSelectionPath();\r
218 IDefaultMutableTreeNode selectionNode = null;\r
219 if (treepath != null) {\r
220 selectionNode = (IDefaultMutableTreeNode) treepath.getLastPathComponent();\r
221 }\r
222 return selectionNode;\r
223 }\r
224 \r
225 public IDefaultMutableTreeNode getNodeById(IDefaultMutableTreeNode node, Identification id) {\r
226 for (int index = 0; index < node.getChildCount(); index++) {\r
227 IDefaultMutableTreeNode iNode = (IDefaultMutableTreeNode) node.getChildAt(index);\r
228 if (iNode.getId().equals(id)) {\r
229 return iNode;\r
230 }\r
231 }\r
232 return null;\r
233 }\r
234 \r
235 public IDefaultMutableTreeNode getNodeById(IDefaultMutableTreeNode node, Identification id, int category) {\r
236 for (int index = 0; index < node.getChildCount(); index++) {\r
237 IDefaultMutableTreeNode iNode = (IDefaultMutableTreeNode) node.getChildAt(index);\r
238 if (iNode.getId().equals(id) && iNode.getCategory() == category) {\r
239 return iNode;\r
240 }\r
92e29378 241 IDefaultMutableTreeNode childNode = getNodeById(iNode, id, category);\r
242 if (childNode != null) {\r
243 return childNode;\r
244 }\r
a13899c5 245 }\r
246 return null;\r
247 }\r
248 \r
249 public TreePath getPathOfNode(IDefaultMutableTreeNode node) {\r
92e29378 250 if (node != null) {\r
251 TreePath treePath = new TreePath(treeModel.getPathToRoot(node));\r
252 return treePath; \r
253 }\r
254 return null;\r
a13899c5 255 }\r
256}\r