]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/common/Identifications/OpeningPackageList.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 / OpeningPackageList.java
1 /** @file
2
3 The file is used to define opening package 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.PackageSurfaceAreaDocument;
23 import org.tianocore.frameworkwizard.packaging.PackageIdentification;
24
25 public class OpeningPackageList {
26 private Vector<OpeningPackageType> vOpeningPackageList = new Vector<OpeningPackageType>();
27
28 public OpeningPackageList() {
29
30 }
31
32 public Vector<OpeningPackageType> getVOpeningPackageList() {
33 return vOpeningPackageList;
34 }
35
36 public void setVOpeningPackageList(Vector<OpeningPackageType> openingPackageList) {
37 vOpeningPackageList = openingPackageList;
38 }
39
40 public void insertToOpeningPackageList(PackageIdentification id, PackageSurfaceAreaDocument.PackageSurfaceArea xmlMsa) {
41 vOpeningPackageList.addElement(new OpeningPackageType(id, xmlMsa));
42 }
43
44 public OpeningPackageType getOpeningPackageByIndex(int index) {
45 if (index > -1 && index < vOpeningPackageList.size()) {
46 return vOpeningPackageList.elementAt(index);
47 }
48 return null;
49 }
50
51 public OpeningPackageType getOpeningPackageById(PackageIdentification id) {
52 int index = findIndexOfListById(id);
53 if (index > -1) {
54 return vOpeningPackageList.elementAt(index);
55 }
56 return null;
57 }
58
59 public int findIndexOfListById(PackageIdentification id) {
60 for (int index = 0; index < vOpeningPackageList.size(); index++) {
61 if (vOpeningPackageList.elementAt(index).getId().equals(id)) {
62 return index;
63 }
64 }
65 return -1;
66 }
67
68 public void removeFromOpeningPackageListByIndex(int index) {
69 if (index > -1 && index < vOpeningPackageList.size()) {
70 vOpeningPackageList.removeElementAt(index);
71 }
72 }
73
74 public void removeFromOpeningPackageListById(PackageIdentification id) {
75 int index = findIndexOfListById(id);
76 if (index > -1) {
77 vOpeningPackageList.removeElementAt(findIndexOfListById(id));
78 }
79 }
80
81 public void removeAllFromOpeningPackageList() {
82 vOpeningPackageList.removeAllElements();
83 }
84
85 public PackageSurfaceAreaDocument.PackageSurfaceArea getPackageSurfaceAreaFromId(PackageIdentification id) {
86 int index = findIndexOfListById(id);
87 if (index > -1) {
88 return vOpeningPackageList.elementAt(index).getXmlSpd();
89 }
90 return null;
91 }
92
93 public boolean existsPackage(PackageIdentification id) {
94 int index = findIndexOfListById(id);
95 if (index > -1) {
96 return true;
97 }
98 return false;
99 }
100
101 public void setPackageSaved(PackageIdentification id, boolean isSaved) {
102 setPackageSaved(findIndexOfListById(id), isSaved);
103 }
104
105 public void setPackageSaved(int index, boolean isSaved) {
106 if (index > -1) {
107 vOpeningPackageList.elementAt(index).setSaved(isSaved);
108 }
109 }
110
111 public boolean getPackageSaved(PackageIdentification id) {
112 return getPackageSaved(findIndexOfListById(id));
113 }
114
115 public boolean getPackageSaved(int index) {
116 if (index > -1) {
117 return vOpeningPackageList.elementAt(index).isSaved();
118 }
119 return true;
120 }
121
122 public void setPackageOpen(PackageIdentification id, boolean isOpem) {
123 setPackageOpen(findIndexOfListById(id), isOpem);
124 }
125
126 public void setPackageOpen(int index, boolean isOpem) {
127 if (index > -1) {
128 vOpeningPackageList.elementAt(index).setOpen(isOpem);
129 }
130 }
131
132 public boolean getPackageOpen(PackageIdentification id) {
133 return getPackageOpen(findIndexOfListById(id));
134 }
135
136 public boolean getPackageOpen(int index) {
137 if (index > -1) {
138 return vOpeningPackageList.elementAt(index).isOpen();
139 }
140 return false;
141 }
142
143 public void setTreePathById(PackageIdentification id, Set<TreePath> treePath) {
144 int index = findIndexOfListById(id);
145 if (index > -1) {
146 vOpeningPackageList.elementAt(index).setTreePath(treePath);
147 }
148 }
149
150 public Set<TreePath> getTreePathById(PackageIdentification id) {
151 int index = findIndexOfListById(id);
152 if (index > -1) {
153 return vOpeningPackageList.elementAt(index).getTreePath();
154 }
155 return null;
156 }
157
158 public Set<TreePath> getTreePathByIndex(int index) {
159 if (index > -1) {
160 return vOpeningPackageList.elementAt(index).getTreePath();
161 }
162 return null;
163 }
164
165 public PackageIdentification getIdByPath(String path) {
166 PackageIdentification id = new PackageIdentification(null, null, null, path);
167 int index = findIndexOfListById(id);
168 if (index > -1) {
169 return vOpeningPackageList.elementAt(index).getId();
170 }
171 return null;
172 }
173
174 public PackageIdentification getIdByGuidVersion(String guid, String version) {
175 for (int index = 0; index < vOpeningPackageList.size(); index++) {
176 PackageIdentification id = vOpeningPackageList.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(PackageIdentification id, boolean isNew) {
191 int index = findIndexOfListById(id);
192 if (index > -1) {
193 vOpeningPackageList.elementAt(index).setNew(isNew);
194 }
195 }
196
197 public void closeAll() {
198 for (int index = 0; index < this.size(); index++) {
199 this.setPackageOpen(index, false);
200 this.setPackageSaved(index, true);
201 }
202 }
203
204 public int size() {
205 return vOpeningPackageList.size();
206 }
207
208 public boolean isSaved() {
209 for (int index = 0; index < this.size(); index++) {
210 if (!this.getPackageSaved(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.getPackageOpen(index)) {
220 return true;
221 }
222 }
223 return false;
224 }
225
226 public void reload(int index) {
227 if (index > -1) {
228 vOpeningPackageList.elementAt(index).reload();
229 }
230 }
231 }