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
.createui
;
16 import java
.awt
.event
.MouseEvent
;
17 import java
.awt
.event
.MouseListener
;
18 import java
.util
.ArrayList
;
19 import java
.util
.Iterator
;
20 import java
.util
.List
;
21 import java
.util
.Vector
;
23 import javax
.swing
.JButton
;
24 import javax
.swing
.JLabel
;
25 import javax
.swing
.JOptionPane
;
26 import javax
.swing
.JPanel
;
27 import javax
.swing
.JScrollPane
;
28 import javax
.swing
.JTextArea
;
30 import org
.tianocore
.frameworkwizard
.common
.Log
;
31 import org
.tianocore
.frameworkwizard
.common
.ui
.IDialog
;
32 import org
.tianocore
.frameworkwizard
.common
.ui
.iCheckBoxList
.ICheckBoxList
;
33 import org
.tianocore
.frameworkwizard
.far
.FarStringDefinition
;
34 import org
.tianocore
.frameworkwizard
.packaging
.PackageIdentification
;
35 import org
.tianocore
.frameworkwizard
.platform
.PlatformIdentification
;
36 import org
.tianocore
.frameworkwizard
.workspace
.WorkspaceTools
;
38 public class CreateStepTwo
extends IDialog
implements MouseListener
{
43 private static final long serialVersionUID
= 3003841865197005528L;
45 private JPanel jContentPane
= null;
47 private JTextArea jTextArea
= null;
49 private JLabel jLabel
= null;
51 private JLabel jLabel1
= null;
53 private ICheckBoxList jComboBoxPackage
= null;
55 private ICheckBoxList jComboBoxPlatform
= null;
57 private JButton jButtonNext
= null;
59 private JButton jButtonCancel
= null;
61 private JScrollPane jScrollPanePackage
= null;
63 private JScrollPane jScrollPanePlatform
= null;
65 private CreateStepThree stepThree
= null;
67 private Vector
<PlatformIdentification
> platformVector
= null;
69 private Vector
<PackageIdentification
> packageVector
= null;
71 private CreateStepOne stepOne
= null;
73 private JButton jButtonPrevious
= null;
75 public CreateStepTwo(IDialog iDialog
, boolean modal
, CreateStepOne stepOne
) {
77 this.stepOne
= stepOne
;
81 * This method initializes jTextArea
83 * @return javax.swing.JTextArea
85 private JTextArea
getJTextArea() {
86 if (jTextArea
== null) {
87 jTextArea
= new JTextArea();
88 jTextArea
.setBounds(new java
.awt
.Rectangle(30, 7, 642, 50));
89 jTextArea
.setText("Choose at least one package or platform. ");
90 jTextArea
.setEditable(false);
96 * This method initializes jComboBox
98 * @return javax.swing.JComboBox
100 private ICheckBoxList
getJComboBoxPackage() {
101 if (jComboBoxPackage
== null) {
102 jComboBoxPackage
= new ICheckBoxList();
103 WorkspaceTools wt
= new WorkspaceTools();
104 Vector
<String
> v
= new Vector
<String
>();
105 packageVector
= wt
.getAllPackages();
106 Iterator
<PackageIdentification
> iter
= packageVector
.iterator();
107 while (iter
.hasNext()) {
108 PackageIdentification item
= iter
.next();
109 String str
= item
.getName() + " " + item
.getVersion() + " [" + item
.getPath() + "]";
112 jComboBoxPackage
.setAllItems(v
);
114 return jComboBoxPackage
;
118 * This method initializes jComboBox1
120 * @return javax.swing.JComboBox
122 private ICheckBoxList
getJComboBoxPlatform() {
123 if (jComboBoxPlatform
== null) {
124 jComboBoxPlatform
= new ICheckBoxList();
125 WorkspaceTools wt
= new WorkspaceTools();
126 Vector
<String
> v
= new Vector
<String
>();
127 platformVector
= wt
.getAllPlatforms();
128 Iterator
<PlatformIdentification
> iter
= platformVector
.iterator();
129 while (iter
.hasNext()) {
130 PlatformIdentification item
= iter
.next();
131 String str
= item
.getName() + " " + item
.getVersion() + " [" + item
.getPath() + "]";
134 jComboBoxPlatform
.setAllItems(v
);
136 return jComboBoxPlatform
;
140 * This method initializes jButtonNext
142 * @return javax.swing.JButton
144 private JButton
getJButtonNext() {
145 if (jButtonNext
== null) {
146 jButtonNext
= new JButton();
147 jButtonNext
.setBounds(new java
.awt
.Rectangle(470, 330, 90, 20));
148 jButtonNext
.setText("Next");
149 jButtonNext
.addMouseListener(this);
155 * This method initializes jButtonCancel
157 * @return javax.swing.JButton
159 private JButton
getJButtonCancel() {
160 if (jButtonCancel
== null) {
161 jButtonCancel
= new JButton();
162 jButtonCancel
.setBounds(new java
.awt
.Rectangle(570, 330, 90, 20));
163 jButtonCancel
.setText("Cancel");
164 jButtonCancel
.addMouseListener(this);
166 return jButtonCancel
;
170 * This method initializes jScrollPane
172 * @return javax.swing.JScrollPane
174 private JScrollPane
getJScrollPanePackage() {
175 if (jScrollPanePackage
== null) {
176 jScrollPanePackage
= new JScrollPane();
177 jScrollPanePackage
.setBounds(new java
.awt
.Rectangle(140,65,535,130));
178 jScrollPanePackage
.setViewportView(getJComboBoxPackage());
180 return jScrollPanePackage
;
184 * This method initializes jScrollPane1
186 * @return javax.swing.JScrollPane
188 private JScrollPane
getJScrollPanePlatform() {
189 if (jScrollPanePlatform
== null) {
190 jScrollPanePlatform
= new JScrollPane();
191 jScrollPanePlatform
.setBounds(new java
.awt
.Rectangle(140,200,535,110));
192 jScrollPanePlatform
.setViewportView(getJComboBoxPlatform());
194 return jScrollPanePlatform
;
198 * This is the default constructor
200 public CreateStepTwo(IDialog iDialog
, boolean modal
) {
201 super(iDialog
, modal
);
206 * This method initializes this
210 private void initialize() {
211 this.setSize(700, 400);
212 this.setContentPane(getJContentPane());
213 this.setTitle(FarStringDefinition
.CREATE_STEP_TWO_TITLE
);
218 * This method initializes jContentPane
220 * @return javax.swing.JPanel
222 private JPanel
getJContentPane() {
223 if (jContentPane
== null) {
224 jLabel1
= new JLabel();
225 jLabel1
.setBounds(new java
.awt
.Rectangle(30, 200, 100, 20));
226 jLabel1
.setText("Platforms: ");
227 jLabel
= new JLabel();
228 jLabel
.setBounds(new java
.awt
.Rectangle(30, 64, 100, 20));
229 jLabel
.setText("Packages:");
230 jContentPane
= new JPanel();
231 jContentPane
.setLayout(null);
232 jContentPane
.add(getJTextArea(), null);
233 jContentPane
.add(jLabel
, null);
234 jContentPane
.add(jLabel1
, null);
235 jContentPane
.add(getJButtonNext(), null);
236 jContentPane
.add(getJButtonCancel(), null);
237 jContentPane
.add(getJScrollPanePackage(), null);
238 jContentPane
.add(getJScrollPanePlatform(), null);
239 jContentPane
.add(getJButtonPrevious(), null);
244 public void mouseClicked(MouseEvent e
) {
245 if (e
.getSource() == jButtonCancel
) {
246 this.setVisible(false);
247 } else if (e
.getSource() == jButtonPrevious
) {
248 this.setVisible(false);
249 stepOne
.setVisible(true);
250 } else if (e
.getSource() == jButtonNext
) {
252 // Add some logic process here
254 if (jComboBoxPlatform
.getAllCheckedItemsIndex().size() == 0
255 && jComboBoxPackage
.getAllCheckedItemsIndex().size() == 0) {
256 Log
.wrn("Create far", "Choose at least one package and/or platform.");
261 // If some packages a Repackage=false, give a warning message
263 List
<PackageIdentification
> selectedPackages
= getSelectedPackages();
264 WorkspaceTools wt
= new WorkspaceTools();
265 List
<PackageIdentification
> allRepackablePackages
= wt
.getAllRepackagablePackages();
267 List
<PackageIdentification
> unRepackablePackages
= new Vector
<PackageIdentification
>();
268 String msg
= "Following selected packages: \n";
269 Iterator
<PackageIdentification
> iter
= selectedPackages
.iterator();
270 while (iter
.hasNext()) {
271 PackageIdentification item
= iter
.next();
272 if (!allRepackablePackages
.contains(item
)) {
273 unRepackablePackages
.add(item
);
274 msg
+= item
.getName() + "\n";
277 msg
+= "is un-Repackagable. Do you want to continue? ";
279 if (unRepackablePackages
.size() > 0) {
280 if(JOptionPane
.showConfirmDialog(null, msg
, "Warning", JOptionPane
.YES_NO_OPTION
) == JOptionPane
.NO_OPTION
) {
285 if (stepThree
== null) {
286 stepThree
= new CreateStepThree(this, true, this);
288 this.setVisible(false);
289 stepThree
.setVisible(true);
293 public void mousePressed(MouseEvent e
) {
294 // TODO Auto-generated method stub
298 public void mouseReleased(MouseEvent e
) {
299 // TODO Auto-generated method stub
303 public void mouseEntered(MouseEvent e
) {
304 // TODO Auto-generated method stub
308 public void mouseExited(MouseEvent e
) {
309 // TODO Auto-generated method stub
314 * This method initializes jButtonPrevious
316 * @return javax.swing.JButton
318 private JButton
getJButtonPrevious() {
319 if (jButtonPrevious
== null) {
320 jButtonPrevious
= new JButton();
321 jButtonPrevious
.setBounds(new java
.awt
.Rectangle(370, 330, 90, 20));
322 jButtonPrevious
.setText("Previous");
323 jButtonPrevious
.addMouseListener(this);
325 return jButtonPrevious
;
328 public List
<PackageIdentification
> getSelectedPackages() {
329 Vector
<Integer
> v
= jComboBoxPackage
.getAllCheckedItemsIndex();
330 List
<PackageIdentification
> result
= new ArrayList
<PackageIdentification
>();
331 for (int i
= 0; i
< v
.size(); i
++) {
332 result
.add(packageVector
.get(v
.get(i
).intValue()));
337 public List
<PlatformIdentification
> getSelectedPlatforms() {
338 Vector
<Integer
> v
= jComboBoxPlatform
.getAllCheckedItemsIndex();
339 List
<PlatformIdentification
> result
= new ArrayList
<PlatformIdentification
>();
340 for (int i
= 0; i
< v
.size(); i
++) {
341 result
.add(platformVector
.get(v
.get(i
).intValue()));
346 public CreateStepOne
getPreviousStep() {