]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/ModuleEditor/src/org/tianocore/packaging/common/ui/ITree.java
Initial import.
[mirror_edk2.git] / Tools / Source / ModuleEditor / src / org / tianocore / packaging / 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.packaging.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 /**
25 The class is used to override JTree to provides customized interfaces
26 It extends JTree
27
28 @since ModuleEditor 1.0
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 }
60
61 /**
62 Get category of selected node
63
64 @return The category of selected node
65
66 **/
67 public int getSelectCategory() {
68 int intCategory = 0;
69 TreePath path = this.getSelectionPath();
70 IDefaultMutableTreeNode node = (IDefaultMutableTreeNode) path.getLastPathComponent();
71 intCategory = node.getCategory();
72 return intCategory;
73 }
74
75 /**
76 Get operation of selected node
77
78 @return The operation of selected node
79
80 **/
81 public int getSelectOperation() {
82 int intOperation = 0;
83 TreePath path = this.getSelectionPath();
84 IDefaultMutableTreeNode node = (IDefaultMutableTreeNode) path.getLastPathComponent();
85 intOperation = node.getOperation();
86 return intOperation;
87 }
88
89 /**
90 Get selectLoaction of selected node
91
92 @return The selectLoaction of selected node
93
94 **/
95 public int getSelectLoaction() {
96 int intLocation = 0;
97 TreePath path = this.getSelectionPath();
98 IDefaultMutableTreeNode node = (IDefaultMutableTreeNode) path.getLastPathComponent();
99 intLocation = node.getLocation();
100 return intLocation;
101 }
102
103 /**
104 Main class, reserved for test
105
106 @param args
107
108 **/
109 public static void main(String[] args) {
110 // TODO Auto-generated method stub
111 }
112
113 /**
114 Add input node as child node for current selected node
115
116 @param strNewNode The name of the node which need be added
117
118 **/
119 public void addNode(String strNewNode) {
120 DefaultMutableTreeNode parentNode = null;
121 DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(strNewNode);
122 newNode.setAllowsChildren(true);
123 TreePath parentPath = this.getSelectionPath();
124
125 /**
126 * Get parent node of new node
127 */
128 parentNode = (DefaultMutableTreeNode) (parentPath.getLastPathComponent());
129
130 /**
131 * Insert new node
132 */
133 treeModel.insertNodeInto(newNode, parentNode, parentNode.getChildCount());
134 this.scrollPathToVisible(new TreePath(newNode.getPath()));
135 }
136
137 /**
138 Add input node as child node for current selected node
139
140 @param newNode The node need be added
141
142 **/
143 public void addNode(IDefaultMutableTreeNode newNode) {
144 IDefaultMutableTreeNode parentNode = null;
145 newNode.setAllowsChildren(true);
146 TreePath parentPath = this.getSelectionPath();
147 parentNode = (IDefaultMutableTreeNode) (parentPath.getLastPathComponent());
148 treeModel.insertNodeInto(newNode, parentNode, parentNode.getChildCount());
149 this.scrollPathToVisible(new TreePath(newNode.getPath()));
150 }
151
152 /**
153 Remove current selectd node
154
155 **/
156 public void removeNode() {
157 TreePath treepath = this.getSelectionPath();
158 if (treepath != null) {
159 DefaultMutableTreeNode selectionNode = (DefaultMutableTreeNode) treepath.getLastPathComponent();
160 TreeNode parent = (TreeNode) selectionNode.getParent();
161 if (parent != null) {
162 treeModel.removeNodeFromParent(selectionNode);
163 }
164 }
165 }
166
167 /**
168 Remove all node on a same level
169
170 **/
171 public void removeNodeOnSameLevel() {
172 TreePath treepath = this.getSelectionPath();
173 IDefaultMutableTreeNode parentNode = (IDefaultMutableTreeNode) treepath.getLastPathComponent();
174 parentNode.removeAllChildren();
175 treeModel.reload();
176 }
177
178 /**
179 Remove the input node by name
180
181 @param strRemovedNode
182
183 **/
184 public void removeNode(String strRemovedNode) {
185 TreePath treepath = this.getSelectionPath();
186 if (treepath != null) {
187 DefaultMutableTreeNode selectionNode = (DefaultMutableTreeNode) treepath.getLastPathComponent();
188 TreeNode parent = (TreeNode) selectionNode.getParent();
189 if (parent != null) {
190 treeModel.removeNodeFromParent(selectionNode);
191 }
192 }
193 }
194
195 /**
196 Remove all nodes of the tree
197
198 **/
199 public void removeAllNode() {
200 DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) treeModel.getRoot();
201 rootNode.removeAllChildren();
202 treeModel.reload();
203 }
204 }