Fixed grammar in text messages.
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / far / deleteui / DeleteStepOne.java
1 /** @file
2
3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 **/
13
14 package org.tianocore.frameworkwizard.far.deleteui;
15
16 import java.awt.Color;
17 import java.awt.Dimension;
18 import java.awt.Toolkit;
19 import java.awt.event.ActionEvent;
20 import java.util.Iterator;
21 import java.util.List;
22 import java.util.Vector;
23
24 import javax.swing.ImageIcon;
25 import javax.swing.JButton;
26 import javax.swing.JLabel;
27 import javax.swing.JList;
28 import javax.swing.JPanel;
29 import javax.swing.JScrollPane;
30 import javax.swing.JTextArea;
31 import javax.swing.event.ListSelectionEvent;
32 import javax.swing.event.ListSelectionListener;
33
34 import org.tianocore.frameworkwizard.common.ui.IDialog;
35 import org.tianocore.frameworkwizard.common.ui.IFrame;
36 import org.tianocore.frameworkwizard.far.AggregationOperation;
37 import org.tianocore.frameworkwizard.far.FarIdentification;
38 import org.tianocore.frameworkwizard.far.FarStringDefinition;
39 import org.tianocore.frameworkwizard.far.PackageQuery;
40 import org.tianocore.frameworkwizard.far.PackageQueryInterface;
41 import org.tianocore.frameworkwizard.packaging.PackageIdentification;
42 import org.tianocore.frameworkwizard.platform.PlatformIdentification;
43 import org.tianocore.frameworkwizard.workspace.WorkspaceTools;
44
45 public class DeleteStepOne extends IDialog implements ListSelectionListener {
46
47 /**
48 *
49 */
50 private static final long serialVersionUID = 636773964435618476L;
51
52 private JPanel jContentPane = null;
53
54 private JButton jButtonCancel = null;
55
56 private JButton jButtonNext = null;
57
58 private JTextArea jTextAreaInstruction = null;
59
60 private JLabel jLabel = null;
61
62 private JScrollPane jScrollPane = null;
63
64 private JLabel jLabel2 = null;
65
66 private JLabel jLabel3 = null;
67
68 private JScrollPane jScrollPane1 = null;
69
70 private JScrollPane jScrollPane2 = null;
71
72 private JList jListPlatform = null;
73
74 private JList jListPackage = null;
75
76 private JLabel jLabel4 = null;
77
78 private JButton jButtonDetail = null;
79
80 private JList jListFar = null;
81
82 private JLabel jLabelImage = null;
83
84 private Vector<FarIdentification> farVector = null;
85
86 Vector<PackageIdentification> removePackages = null;
87
88 Vector<PlatformIdentification> removePlatforms = null;
89
90 private DeleteStepTwo stepTwo = null;
91
92 /**
93 * This method initializes jButtonCancel
94 *
95 * @return javax.swing.JButton
96 */
97 private JButton getJButtonCancel() {
98 if (jButtonCancel == null) {
99 jButtonCancel = new JButton();
100 jButtonCancel.setBounds(new java.awt.Rectangle(570, 330, 90, 20));
101 jButtonCancel.setText("Cancel");
102 jButtonCancel.addActionListener(this);
103 }
104 return jButtonCancel;
105 }
106
107 /**
108 * This method initializes jButtonFinish
109 *
110 * @return javax.swing.JButton
111 */
112 private JButton getJButtonNext() {
113 if (jButtonNext == null) {
114 jButtonNext = new JButton();
115 jButtonNext.setBounds(new java.awt.Rectangle(470, 330, 90, 20));
116 jButtonNext.setText("Next");
117 jButtonNext.setEnabled(false);
118 jButtonNext.addActionListener(this);
119 }
120 return jButtonNext;
121 }
122
123 /**
124 * This method initializes jTextArea1
125 *
126 * @return javax.swing.JTextArea
127 */
128 private JTextArea getJTextArea1() {
129 if (jTextAreaInstruction == null) {
130 jTextAreaInstruction = new JTextArea();
131 jTextAreaInstruction.setBounds(new java.awt.Rectangle(30, 7, 662, 50));
132 jTextAreaInstruction.setText("Step 1: Select FAR to remove.\n");
133 jTextAreaInstruction.setCaretColor(Color.RED);
134 jTextAreaInstruction
135 .append("After choosing the FAR, the packages and/or platforms that belong to the FAR will displayed.\n");
136 jTextAreaInstruction.append("Icon \"OK\" or \"NO\" indicates whether the FAR can be safely removed.");
137 jTextAreaInstruction.setEditable(false);
138 }
139 return jTextAreaInstruction;
140 }
141
142 /**
143 * This method initializes jScrollPane
144 *
145 * @return javax.swing.JScrollPane
146 */
147 private JScrollPane getJScrollPane() {
148 if (jScrollPane == null) {
149 jScrollPane = new JScrollPane();
150 jScrollPane.setBounds(new java.awt.Rectangle(140, 65, 530, 100));
151 jScrollPane.setViewportView(getJListFar());
152 }
153 return jScrollPane;
154 }
155
156 /**
157 * This method initializes jScrollPane1
158 *
159 * @return javax.swing.JScrollPane
160 */
161 private JScrollPane getJScrollPane1() {
162 if (jScrollPane1 == null) {
163 jScrollPane1 = new JScrollPane();
164 jScrollPane1.setBounds(new java.awt.Rectangle(30, 195, 300, 115));
165 jScrollPane1.setViewportView(getJListPackage());
166 }
167 return jScrollPane1;
168 }
169
170 /**
171 * This method initializes jScrollPane2
172 *
173 * @return javax.swing.JScrollPane
174 */
175 private JScrollPane getJScrollPane2() {
176 if (jScrollPane2 == null) {
177 jScrollPane2 = new JScrollPane();
178 jScrollPane2.setBounds(new java.awt.Rectangle(360, 195, 310, 115));
179 jScrollPane2.setViewportView(getJListPlatform());
180 }
181 return jScrollPane2;
182 }
183
184 /**
185 * This method initializes jList
186 *
187 * @return javax.swing.JList
188 */
189 private JList getJListPlatform() {
190 if (jListPlatform == null) {
191 jListPlatform = new JList();
192 jListPlatform.setEnabled(false);
193 }
194 return jListPlatform;
195 }
196
197 /**
198 * This method initializes jList1
199 *
200 * @return javax.swing.JList
201 */
202 private JList getJListPackage() {
203 if (jListPackage == null) {
204 jListPackage = new JList();
205 jListPackage.setEnabled(false);
206 }
207 return jListPackage;
208 }
209
210 /**
211 * This method initializes jButtonDetail
212 *
213 * @return javax.swing.JButton
214 */
215 private JButton getJButtonDetail() {
216 if (jButtonDetail == null) {
217 jButtonDetail = new JButton();
218 jButtonDetail.setBounds(new java.awt.Rectangle(367, 325, 69, 20));
219 jButtonDetail.setText("Detail");
220 jButtonDetail.setVisible(false);
221 }
222 return jButtonDetail;
223 }
224
225 /**
226 * This method initializes jListFar
227 *
228 * @return javax.swing.JList
229 */
230 private JList getJListFar() {
231 if (jListFar == null) {
232 jListFar = new JList();
233 WorkspaceTools wt = new WorkspaceTools();
234 farVector = wt.getAllFars();
235 jListFar.setListData(farVector);
236 jListFar.addListSelectionListener(this);
237 }
238 return jListFar;
239 }
240
241 /**
242 * This is the default constructor
243 */
244 public DeleteStepOne(IFrame iFrame, boolean modal) {
245 super(iFrame, modal);
246 initialize();
247 }
248
249 /**
250 * This method initializes this
251 *
252 * @return void
253 */
254 private void initialize() {
255 this.setSize(700, 400);
256 this.setContentPane(getJContentPane());
257 this.setTitle(FarStringDefinition.DELETE_STEP_ONE_TITLE);
258 Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
259 this.setLocation((d.width - this.getSize().width) / 2, (d.height - this.getSize().height) / 2);
260 }
261
262 /**
263 * This method initializes jContentPane
264 *
265 * @return javax.swing.JPanel
266 */
267 private JPanel getJContentPane() {
268 if (jContentPane == null) {
269 jLabelImage = new JLabel();
270 jLabelImage.setBounds(new java.awt.Rectangle(30, 319, 36, 36));
271 jLabel4 = new JLabel();
272 jLabel4.setBounds(new java.awt.Rectangle(71, 325, 320, 20));
273 jLabel3 = new JLabel();
274 jLabel3.setBounds(new java.awt.Rectangle(360, 170, 113, 20));
275 jLabel3.setText("FAR's Platforms");
276 jLabel2 = new JLabel();
277 jLabel2.setBounds(new java.awt.Rectangle(30, 170, 113, 20));
278 jLabel2.setText("FAR's Packages");
279 jLabel = new JLabel();
280 jLabel.setBounds(new java.awt.Rectangle(30, 65, 100, 20));
281 jLabel.setText("Select one FAR: ");
282 jContentPane = new JPanel();
283 jContentPane.setLayout(null);
284 jContentPane.add(getJButtonCancel(), null);
285 jContentPane.add(getJButtonNext(), null);
286 jContentPane.add(getJTextArea1(), null);
287 jContentPane.add(jLabel, null);
288 jContentPane.add(getJScrollPane(), null);
289 jContentPane.add(jLabel2, null);
290 jContentPane.add(jLabel3, null);
291 jContentPane.add(getJScrollPane1(), null);
292 jContentPane.add(getJScrollPane2(), null);
293 jContentPane.add(jLabel4, null);
294 jContentPane.add(getJButtonDetail(), null);
295 jContentPane.add(jLabelImage, null);
296 }
297 return jContentPane;
298 }
299
300 public void valueChanged(ListSelectionEvent e) {
301 //
302 // Add logic for FAR list value changed
303 //
304 if (e.getSource() == jListFar) {
305 boolean flag = true;
306 FarIdentification far = (FarIdentification) jListFar.getSelectedValue();
307 WorkspaceTools wt = new WorkspaceTools();
308
309 removePackages = wt.getPackagesByFar(far);
310 jListPackage.setListData(removePackages);
311 removePlatforms = wt.getPlatformsByFar(far);
312 jListPlatform.setListData(removePlatforms);
313
314 //
315 // Get Dependencies Info for current FAR
316 //
317 List<PackageIdentification> allPackages = wt.getAllPackages();
318
319 //
320 // Remain packages
321 //
322 allPackages.removeAll(removePackages);
323
324 Iterator<PackageIdentification> iter = allPackages.iterator();
325
326 PackageQueryInterface pq = new PackageQuery();
327 while (iter.hasNext()) {
328 PackageIdentification item = iter.next();
329 List<PackageIdentification> list = pq.getPackageDependencies(item.getSpdFile());
330 List<PackageIdentification> result = AggregationOperation.minus(list, allPackages);
331 if (result.size() > 0) {
332 if (AggregationOperation.intersection(result, removePackages).size() > 0) {
333 flag = false;
334 break;
335 }
336 }
337 }
338
339 if (flag) {
340 jLabelImage.setIcon(new ImageIcon(getClass().getResource("/resources/images/Yes.JPG")));
341 jLabel4.setText("None of the remaining packages depend on this FAR. ");
342 jButtonDetail.setVisible(false);
343 jButtonNext.setEnabled(true);
344 } else {
345 jLabelImage.setIcon(new ImageIcon(getClass().getResource("/resources/images/No.JPG")));
346 jLabel4.setText("Some of the remaining packages still depend on this FAR. ");
347 // jButtonDetail.setVisible(true);
348 jButtonNext.setEnabled(false);
349 }
350 }
351 }
352
353 public void actionPerformed(ActionEvent e) {
354 if (e.getSource() == jButtonCancel) {
355 this.setVisible(false);
356 } else if (e.getSource() == jButtonNext) {
357 //
358 // Add some logic process here
359 //
360
361 if (stepTwo == null) {
362 stepTwo = new DeleteStepTwo(this, true, this);
363 }
364 this.setVisible(false);
365 stepTwo.setVisible(true);
366 }
367
368 }
369
370 public FarIdentification getSelecedFar() {
371 return (FarIdentification) jListFar.getSelectedValue();
372 }
373
374 }