|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 package com.nokia.testfw.stf.configeditor.editors; |
|
20 |
|
21 import java.util.ArrayList; |
|
22 import java.util.List; |
|
23 |
|
24 import com.nokia.testfw.stf.configmanager.SectionElementType; |
|
25 |
|
26 /** |
|
27 * Modules tree node |
|
28 * |
|
29 */ |
|
30 public class ModulesTreeNode { |
|
31 /** |
|
32 * Node type |
|
33 */ |
|
34 private SectionElementType type; |
|
35 /** |
|
36 * Node value |
|
37 */ |
|
38 private String value; |
|
39 /** |
|
40 * Index in config source. |
|
41 * |
|
42 * Depens on node <code>type</code> it represents module index in config |
|
43 * file or testcase file entry index in <code>[New_Module]...[End_Module]</code> |
|
44 * section of config file. |
|
45 */ |
|
46 private int index; |
|
47 /** |
|
48 * Parent node |
|
49 */ |
|
50 ModulesTreeNode parent = null; |
|
51 /** |
|
52 * List of node childrens |
|
53 */ |
|
54 private List<ModulesTreeNode> childrens = null; |
|
55 /** |
|
56 * Creates node |
|
57 */ |
|
58 public ModulesTreeNode() { |
|
59 childrens = new ArrayList<ModulesTreeNode>(); |
|
60 } |
|
61 |
|
62 /** |
|
63 * Creates node |
|
64 * @param parent parent node |
|
65 */ |
|
66 public ModulesTreeNode(ModulesTreeNode parent) { |
|
67 childrens = new ArrayList<ModulesTreeNode>(); |
|
68 if ( parent != null ) { |
|
69 this.parent = parent; |
|
70 parent.childrens.add(this); |
|
71 } |
|
72 } |
|
73 |
|
74 /** |
|
75 * Gets node childrens |
|
76 * @return list of node childrens |
|
77 */ |
|
78 public List<ModulesTreeNode> getChildrens() { |
|
79 return childrens; |
|
80 } |
|
81 |
|
82 /** |
|
83 * Adds child node |
|
84 * @param node child node to add |
|
85 */ |
|
86 public void addChildren( ModulesTreeNode node ) { |
|
87 if ( node != null ) { |
|
88 node.parent = this; |
|
89 childrens.add( node ); |
|
90 } |
|
91 } |
|
92 |
|
93 /** |
|
94 * Removes child node |
|
95 * @param node node to remove |
|
96 */ |
|
97 public void removeChildrean( ModulesTreeNode node ) { |
|
98 childrens.remove( node ); |
|
99 node.parent = null; |
|
100 } |
|
101 |
|
102 /** |
|
103 * Disposes node |
|
104 */ |
|
105 public void dispose() { |
|
106 if ( parent != null ) { |
|
107 parent.childrens.remove(this); |
|
108 this.parent = null; |
|
109 } |
|
110 } |
|
111 |
|
112 /** |
|
113 * Gets index value |
|
114 * @return index value |
|
115 */ |
|
116 public int getIndex() { |
|
117 return index; |
|
118 } |
|
119 |
|
120 /** |
|
121 * Sets new index value |
|
122 * @param index new index value |
|
123 */ |
|
124 public void setIndex(int index) { |
|
125 this.index = index; |
|
126 } |
|
127 |
|
128 /** |
|
129 * Gets parent node |
|
130 * @return parent node |
|
131 */ |
|
132 public ModulesTreeNode getParent() { |
|
133 return parent; |
|
134 } |
|
135 |
|
136 /** |
|
137 * Sets new parent node |
|
138 * @param parent parent node |
|
139 */ |
|
140 public void setParent( ModulesTreeNode parent ) { |
|
141 if ( parent != null ) { |
|
142 this.parent = parent; |
|
143 parent.childrens.add( this ); |
|
144 } |
|
145 } |
|
146 |
|
147 /** |
|
148 * Gets node type |
|
149 * @return node type |
|
150 */ |
|
151 public SectionElementType getType() { |
|
152 return type; |
|
153 } |
|
154 |
|
155 /** |
|
156 * Sets new node type value |
|
157 * @param type new node type value |
|
158 */ |
|
159 public void setType(SectionElementType type) { |
|
160 this.type = type; |
|
161 } |
|
162 |
|
163 /** |
|
164 * Gets node value |
|
165 * @return node value |
|
166 */ |
|
167 public String getValue() { |
|
168 return value; |
|
169 } |
|
170 |
|
171 /** |
|
172 * Sets new node value |
|
173 * @param value new node value |
|
174 */ |
|
175 public void setValue(String value) { |
|
176 this.value = value; |
|
177 } |
|
178 |
|
179 /** |
|
180 * Checks if node has childreans |
|
181 * @return <b><code>true</code></b> if node has childrens, <b><code>false</code></b> |
|
182 * if node does not have childrens |
|
183 */ |
|
184 public boolean hasChildren() { |
|
185 if ( ( childrens != null ) && ( childrens.size() != 0 ) ) { |
|
186 return true; |
|
187 } |
|
188 return false; |
|
189 } |
|
190 |
|
191 /** |
|
192 * Removes all children nodes |
|
193 */ |
|
194 public void removeAllChildreans() { |
|
195 childrens = new ArrayList<ModulesTreeNode>(); |
|
196 } |
|
197 } |