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
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.
14 package org
.tianocore
.frameworkwizard
.far
.deleteui
;
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
;
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
;
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
;
45 public class DeleteStepOne
extends IDialog
implements ListSelectionListener
{
50 private static final long serialVersionUID
= 636773964435618476L;
52 private JPanel jContentPane
= null;
54 private JButton jButtonCancel
= null;
56 private JButton jButtonNext
= null;
58 private JTextArea jTextAreaInstruction
= null;
60 private JLabel jLabel
= null;
62 private JScrollPane jScrollPane
= null;
64 private JLabel jLabel2
= null;
66 private JLabel jLabel3
= null;
68 private JScrollPane jScrollPane1
= null;
70 private JScrollPane jScrollPane2
= null;
72 private JList jListPlatform
= null;
74 private JList jListPackage
= null;
76 private JLabel jLabel4
= null;
78 private JButton jButtonDetail
= null;
80 private JList jListFar
= null;
82 private JLabel jLabelImage
= null;
84 private Vector
<FarIdentification
> farVector
= null;
86 Vector
<PackageIdentification
> removePackages
= null;
88 Vector
<PlatformIdentification
> removePlatforms
= null;
90 private DeleteStepTwo stepTwo
= null;
93 * This method initializes jButtonCancel
95 * @return javax.swing.JButton
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);
104 return jButtonCancel
;
108 * This method initializes jButtonFinish
110 * @return javax.swing.JButton
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);
124 * This method initializes jTextArea1
126 * @return javax.swing.JTextArea
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
);
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);
139 return jTextAreaInstruction
;
143 * This method initializes jScrollPane
145 * @return javax.swing.JScrollPane
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());
157 * This method initializes jScrollPane1
159 * @return javax.swing.JScrollPane
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());
171 * This method initializes jScrollPane2
173 * @return javax.swing.JScrollPane
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());
185 * This method initializes jList
187 * @return javax.swing.JList
189 private JList
getJListPlatform() {
190 if (jListPlatform
== null) {
191 jListPlatform
= new JList();
192 jListPlatform
.setEnabled(false);
194 return jListPlatform
;
198 * This method initializes jList1
200 * @return javax.swing.JList
202 private JList
getJListPackage() {
203 if (jListPackage
== null) {
204 jListPackage
= new JList();
205 jListPackage
.setEnabled(false);
211 * This method initializes jButtonDetail
213 * @return javax.swing.JButton
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);
222 return jButtonDetail
;
226 * This method initializes jListFar
228 * @return javax.swing.JList
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);
242 * This is the default constructor
244 public DeleteStepOne(IFrame iFrame
, boolean modal
) {
245 super(iFrame
, modal
);
250 * This method initializes this
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);
263 * This method initializes jContentPane
265 * @return javax.swing.JPanel
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);
300 public void valueChanged(ListSelectionEvent e
) {
302 // Add logic for FAR list value changed
304 if (e
.getSource() == jListFar
) {
306 FarIdentification far
= (FarIdentification
) jListFar
.getSelectedValue();
307 WorkspaceTools wt
= new WorkspaceTools();
309 removePackages
= wt
.getPackagesByFar(far
);
310 jListPackage
.setListData(removePackages
);
311 removePlatforms
= wt
.getPlatformsByFar(far
);
312 jListPlatform
.setListData(removePlatforms
);
315 // Get Dependencies Info for current FAR
317 List
<PackageIdentification
> allPackages
= wt
.getAllPackages();
322 allPackages
.removeAll(removePackages
);
324 Iterator
<PackageIdentification
> iter
= allPackages
.iterator();
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) {
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);
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);
353 public void actionPerformed(ActionEvent e
) {
354 if (e
.getSource() == jButtonCancel
) {
355 this.setVisible(false);
356 } else if (e
.getSource() == jButtonNext
) {
358 // Add some logic process here
361 if (stepTwo
== null) {
362 stepTwo
= new DeleteStepTwo(this, true, this);
364 this.setVisible(false);
365 stepTwo
.setVisible(true);
370 public FarIdentification
getSelecedFar() {
371 return (FarIdentification
) jListFar
.getSelectedValue();