]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/common/Identifications/OpeningModuleList.java
1. Fix EDKT463: When wizard new or clone a msa/spd/fpd, should follow these rules
[mirror_edk2.git] / Tools / Java / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / common / Identifications / OpeningModuleList.java
1 /** @file
2
3 The file is used to define opening module list
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 package org.tianocore.frameworkwizard.common.Identifications;
16
17 import java.util.Set;
18 import java.util.Vector;
19
20 import javax.swing.tree.TreePath;
21
22 import org.tianocore.ModuleSurfaceAreaDocument;
23 import org.tianocore.frameworkwizard.module.Identifications.ModuleIdentification;
24
25 public class OpeningModuleList {
26 private Vector<OpeningModuleType> vOpeningModuleList = new Vector<OpeningModuleType>();
27
28 public OpeningModuleList() {
29
30 }
31
32 public Vector<OpeningModuleType> getVOpeningModuleList() {
33 return vOpeningModuleList;
34 }
35
36 public void setVOpeningModuleList(Vector<OpeningModuleType> openingModuleList) {
37 vOpeningModuleList = openingModuleList;
38 }
39
40 public void insertToOpeningModuleList(ModuleIdentification id, ModuleSurfaceAreaDocument.ModuleSurfaceArea xmlMsa) {
41 vOpeningModuleList.addElement(new OpeningModuleType(id, xmlMsa));
42 }
43
44 public OpeningModuleType getOpeningModuleByIndex(int index) {
45 if (index > -1 && index < vOpeningModuleList.size()) {
46 return vOpeningModuleList.elementAt(index);
47 }
48 return null;
49 }
50
51 public OpeningModuleType getOpeningModuleById(ModuleIdentification id) {
52 int index = findIndexOfListById(id);
53 if (index > -1) {
54 return vOpeningModuleList.elementAt(index);
55 }
56 return null;
57 }
58
59 public int findIndexOfListById(ModuleIdentification id) {
60 for (int index = 0; index < vOpeningModuleList.size(); index++) {
61 if (vOpeningModuleList.elementAt(index).getId().equals(id)) {
62 return index;
63 }
64 }
65 return -1;
66 }
67
68 public void removeFromOpeningModuleListByIndex(int index) {
69 if (index > -1 && index < vOpeningModuleList.size()) {
70 vOpeningModuleList.removeElementAt(index);
71 }
72 }
73
74 public void removeFromOpeningModuleListById(ModuleIdentification id) {
75 int index = findIndexOfListById(id);
76 if (index > -1) {
77 vOpeningModuleList.removeElementAt(findIndexOfListById(id));
78 }
79 }
80
81 public void removeAllFromOpeningModuleList() {
82 vOpeningModuleList.removeAllElements();
83 }
84
85 public ModuleSurfaceAreaDocument.ModuleSurfaceArea getModuleSurfaceAreaFromId(ModuleIdentification id) {
86 int index = findIndexOfListById(id);
87 if (index > -1) {
88 return vOpeningModuleList.elementAt(index).getXmlMsa();
89 }
90 return null;
91 }
92
93 public boolean existsModule(ModuleIdentification id) {
94 int index = findIndexOfListById(id);
95 if (index > -1) {
96 return true;
97 }
98 return false;
99 }
100
101 public void setModuleSaved(ModuleIdentification id, boolean isSaved) {
102 setModuleSaved(findIndexOfListById(id), isSaved);
103 }
104
105 public void setModuleSaved(int index, boolean isSaved) {
106 if (index > -1) {
107 vOpeningModuleList.elementAt(index).setSaved(isSaved);
108 }
109 }
110
111 public boolean getModuleSaved(ModuleIdentification id) {
112 return getModuleSaved(findIndexOfListById(id));
113 }
114
115 public boolean getModuleSaved(int index) {
116 if (index > -1) {
117 return vOpeningModuleList.elementAt(index).isSaved();
118 }
119 return true;
120 }
121
122 public void setModuleOpen(ModuleIdentification id, boolean isOpen) {
123 setModuleOpen(findIndexOfListById(id), isOpen);
124 }
125
126 public void setModuleOpen(int index, boolean isOpen) {
127 if (index > -1) {
128 vOpeningModuleList.elementAt(index).setOpen(isOpen);
129 }
130 }
131
132 public boolean getModuleOpen(ModuleIdentification id) {
133 return getModuleOpen(findIndexOfListById(id));
134 }
135
136 public boolean getModuleOpen(int index) {
137 if (index > -1) {
138 return vOpeningModuleList.elementAt(index).isOpen();
139 }
140 return false;
141 }
142
143 public void setTreePathById(ModuleIdentification id, Set<TreePath> treePath) {
144 int index = findIndexOfListById(id);
145 if (index > -1) {
146 vOpeningModuleList.elementAt(index).setTreePath(treePath);
147 }
148 }
149
150 public Set<TreePath> getTreePathById(ModuleIdentification id) {
151 int index = findIndexOfListById(id);
152 if (index > -1) {
153 return vOpeningModuleList.elementAt(index).getTreePath();
154 }
155 return null;
156 }
157
158 public Set<TreePath> getTreePathByIndex(int index) {
159 if (index > -1) {
160 return vOpeningModuleList.elementAt(index).getTreePath();
161 }
162 return null;
163 }
164
165 public ModuleIdentification getIdByPath(String path) {
166 ModuleIdentification id = new ModuleIdentification(null, null, null, path);
167 int index = findIndexOfListById(id);
168 if (index > -1) {
169 return vOpeningModuleList.elementAt(index).getId();
170 }
171 return null;
172 }
173
174 public ModuleIdentification getIdByGuidVersion(String guid, String version) {
175 for (int index = 0; index < vOpeningModuleList.size(); index++) {
176 ModuleIdentification id = vOpeningModuleList.elementAt(index).getId();
177 if (version != null) {
178 if (id.getGuid().equals(guid) && id.getVersion().equals(version)) {
179 return id;
180 }
181 } else {
182 if (id.getGuid().equals(guid)) {
183 return id;
184 }
185 }
186 }
187 return null;
188 }
189
190 public void setNew(ModuleIdentification id, boolean isNew) {
191 int index = findIndexOfListById(id);
192 if (index > -1) {
193 vOpeningModuleList.elementAt(index).setNew(isNew);
194 }
195 }
196
197 public void closeAll() {
198 for (int index = 0; index < this.size(); index++) {
199 this.setModuleOpen(index, false);
200 this.setModuleSaved(index, true);
201 }
202 }
203
204 public int size() {
205 return vOpeningModuleList.size();
206 }
207
208 public boolean isSaved() {
209 for (int index = 0; index < this.size(); index++) {
210 if (!this.getModuleSaved(index)) {
211 return false;
212 }
213 }
214 return true;
215 }
216
217 public boolean isOpen() {
218 for (int index = 0; index < this.size(); index++) {
219 if (this.getModuleOpen(index)) {
220 return true;
221 }
222 }
223 return false;
224 }
225
226 public void reload(int index) {
227 if (index > -1) {
228 vOpeningModuleList.elementAt(index).reload();
229 }
230 }
231 }