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