]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/common/ui/ITree.java
Changed spelling to manifest
[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 public class ITree extends JTree {
32 ///
33 /// Define class Serial Version UID
34 ///
35 private static final long serialVersionUID = -7907086164518295327L;
36
37 //
38 // Define class members
39 //
40 DefaultTreeModel treeModel = null;
41
42 /**
43 This is the default constructor
44
45 **/
46 public ITree() {
47 super();
48 }
49
50 /**
51 This is the overrided constructor
52 Init class members with input data
53
54 @param iDmtRoot The root node of the tree
55
56 **/
57 public ITree(IDefaultMutableTreeNode iDmtRoot) {
58 super(iDmtRoot);
59 treeModel = (DefaultTreeModel) this.getModel();
60 }
61
62 /**
63 Get category of selected node
64
65 @return The category of selected node
66
67 **/
68 public int getSelectCategory() {
69 int intCategory = 0;
70 TreePath path = this.getSelectionPath();
71 IDefaultMutableTreeNode node = (IDefaultMutableTreeNode) path.getLastPathComponent();
72 intCategory = node.getCategory();
73 return intCategory;
74 }
75
76 /**
77 Add input node as child node for current selected node
78
79 @param strNewNode The name of the node which need be added
80
81 **/
82 public void addNode(String strNewNode) {
83 DefaultMutableTreeNode parentNode = null;
84 DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(strNewNode);
85 newNode.setAllowsChildren(true);
86 TreePath parentPath = this.getSelectionPath();
87
88 /**
89 * Get parent node of new node
90 */
91 parentNode = (DefaultMutableTreeNode) (parentPath.getLastPathComponent());
92
93 /**
94 * Insert new node
95 */
96 treeModel.insertNodeInto(newNode, parentNode, parentNode.getChildCount());
97 this.scrollPathToVisible(new TreePath(newNode.getPath()));
98 }
99
100 /**
101 Add input node as child node for current selected node
102
103 @param newNode The node need be added
104
105 **/
106 public void addNode(IDefaultMutableTreeNode newNode) {
107 IDefaultMutableTreeNode parentNode = null;
108 newNode.setAllowsChildren(true);
109 TreePath parentPath = this.getSelectionPath();
110 parentNode = (IDefaultMutableTreeNode) (parentPath.getLastPathComponent());
111 treeModel.insertNodeInto(newNode, parentNode, parentNode.getChildCount());
112 this.scrollPathToVisible(new TreePath(newNode.getPath()));
113 }
114
115 /**
116 Add input node as child node for current selected node
117
118 @param newNode The node need be added
119
120 **/
121 public void addNode(IDefaultMutableTreeNode parentNode, IDefaultMutableTreeNode newNode) {
122 treeModel.insertNodeInto(newNode, parentNode, parentNode.getChildCount());
123 this.scrollPathToVisible(new TreePath(newNode.getPath()));
124 }
125
126 /**
127 Remove the selected node
128
129 @param strRemovedNode
130
131 **/
132 public void removeSelectedNode() {
133 TreePath treePath = this.getSelectionPath();
134 removeNodeByPath(treePath);
135 }
136
137 /**
138 Remove the node by tree path
139
140 @param strRemovedNode
141
142 **/
143 public void removeNodeByPath(TreePath treePath) {
144 if (treePath != null) {
145 DefaultMutableTreeNode selectionNode = (DefaultMutableTreeNode) treePath.getLastPathComponent();
146 TreeNode parent = (TreeNode) selectionNode.getParent();
147 if (parent != null) {
148 treeModel.removeNodeFromParent(selectionNode);
149 }
150 }
151 }
152
153 /**
154 Return a node by input tree path
155
156 @param treePath
157 @return
158
159 **/
160 public IDefaultMutableTreeNode getNodeByPath(TreePath treePath) {
161 if (treePath != null) {
162 IDefaultMutableTreeNode selectionNode = (IDefaultMutableTreeNode) treePath.getLastPathComponent();
163 return selectionNode;
164 }
165 return null;
166 }
167
168 /**
169 Remove all child nodes under current node
170
171 **/
172 public void removeNodeChildrenByPath(TreePath treePath) {
173 if (treePath != null) {
174 DefaultMutableTreeNode currentNode = (DefaultMutableTreeNode) treePath.getLastPathComponent();
175 for (int index = currentNode.getChildCount() - 1; index > -1; index--) {
176 treeModel.removeNodeFromParent((DefaultMutableTreeNode) currentNode.getChildAt(index));
177 }
178 }
179 }
180
181 /**
182 Remove all nodes of the tree
183
184 **/
185 public void removeAllNode() {
186 DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) treeModel.getRoot();
187 rootNode.removeAllChildren();
188 treeModel.reload();
189 }
190
191 public IDefaultMutableTreeNode getSelectNode() {
192 TreePath treepath = this.getSelectionPath();
193 IDefaultMutableTreeNode selectionNode = null;
194 if (treepath != null) {
195 selectionNode = (IDefaultMutableTreeNode) treepath.getLastPathComponent();
196 }
197 return selectionNode;
198 }
199
200 public IDefaultMutableTreeNode getNodeById(IDefaultMutableTreeNode node, Identification id) {
201 for (int index = 0; index < node.getChildCount(); index++) {
202 IDefaultMutableTreeNode iNode = (IDefaultMutableTreeNode) node.getChildAt(index);
203 if (iNode.getId().equals(id)) {
204 return iNode;
205 }
206 }
207 return null;
208 }
209
210 public IDefaultMutableTreeNode getNodeById(IDefaultMutableTreeNode node, Identification id, int category) {
211 for (int index = 0; index < node.getChildCount(); index++) {
212 IDefaultMutableTreeNode iNode = (IDefaultMutableTreeNode) node.getChildAt(index);
213 if (iNode.getId().equals(id) && iNode.getCategory() == category) {
214 return iNode;
215 }
216 IDefaultMutableTreeNode childNode = getNodeById(iNode, id, category);
217 if (childNode != null) {
218 return childNode;
219 }
220 }
221 return null;
222 }
223
224 public TreePath getPathOfNode(IDefaultMutableTreeNode node) {
225 if (node != null) {
226 TreePath treePath = new TreePath(treeModel.getPathToRoot(node));
227 return treePath;
228 }
229 return null;
230 }
231 }