]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/far/createui/CreateStepTwo.java
Make opening dialogs re-gain focus when user switch back to main UI from other window...
[mirror_edk2.git] / Tools / Java / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / far / createui / CreateStepTwo.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.createui;
15
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;
22
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;
29
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;
37
38 public class CreateStepTwo extends IDialog implements MouseListener {
39
40 /**
41 *
42 */
43 private static final long serialVersionUID = 3003841865197005528L;
44
45 private JPanel jContentPane = null;
46
47 private JTextArea jTextArea = null;
48
49 private JLabel jLabel = null;
50
51 private JLabel jLabel1 = null;
52
53 private ICheckBoxList jComboBoxPackage = null;
54
55 private ICheckBoxList jComboBoxPlatform = null;
56
57 private JButton jButtonNext = null;
58
59 private JButton jButtonCancel = null;
60
61 private JScrollPane jScrollPanePackage = null;
62
63 private JScrollPane jScrollPanePlatform = null;
64
65 private CreateStepThree stepThree = null;
66
67 private Vector<PlatformIdentification> platformVector = null;
68
69 private Vector<PackageIdentification> packageVector = null;
70
71 private CreateStepOne stepOne = null;
72
73 private JButton jButtonPrevious = null;
74
75 public CreateStepTwo(IDialog iDialog, boolean modal, CreateStepOne stepOne) {
76 this(iDialog, modal);
77 this.stepOne = stepOne;
78 }
79
80 /**
81 * This method initializes jTextArea
82 *
83 * @return javax.swing.JTextArea
84 */
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);
91 }
92 return jTextArea;
93 }
94
95 /**
96 * This method initializes jComboBox
97 *
98 * @return javax.swing.JComboBox
99 */
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() + "]";
110 v.addElement(str);
111 }
112 jComboBoxPackage.setAllItems(v);
113 }
114 return jComboBoxPackage;
115 }
116
117 /**
118 * This method initializes jComboBox1
119 *
120 * @return javax.swing.JComboBox
121 */
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() + "]";
132 v.addElement(str);
133 }
134 jComboBoxPlatform.setAllItems(v);
135 }
136 return jComboBoxPlatform;
137 }
138
139 /**
140 * This method initializes jButtonNext
141 *
142 * @return javax.swing.JButton
143 */
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);
150 }
151 return jButtonNext;
152 }
153
154 /**
155 * This method initializes jButtonCancel
156 *
157 * @return javax.swing.JButton
158 */
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);
165 }
166 return jButtonCancel;
167 }
168
169 /**
170 * This method initializes jScrollPane
171 *
172 * @return javax.swing.JScrollPane
173 */
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());
179 }
180 return jScrollPanePackage;
181 }
182
183 /**
184 * This method initializes jScrollPane1
185 *
186 * @return javax.swing.JScrollPane
187 */
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());
193 }
194 return jScrollPanePlatform;
195 }
196
197 /**
198 * This is the default constructor
199 */
200 public CreateStepTwo(IDialog iDialog, boolean modal) {
201 super(iDialog, modal);
202 initialize();
203 }
204
205 /**
206 * This method initializes this
207 *
208 * @return void
209 */
210 private void initialize() {
211 this.setSize(700, 400);
212 this.setContentPane(getJContentPane());
213 this.setTitle(FarStringDefinition.CREATE_STEP_TWO_TITLE);
214 this.centerWindow();
215 }
216
217 /**
218 * This method initializes jContentPane
219 *
220 * @return javax.swing.JPanel
221 */
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);
240 }
241 return jContentPane;
242 }
243
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) {
251 //
252 // Add some logic process here
253 //
254 if (jComboBoxPlatform.getAllCheckedItemsIndex().size() == 0
255 && jComboBoxPackage.getAllCheckedItemsIndex().size() == 0) {
256 Log.wrn("Create far", "Choose at least one package and/or platform.");
257 return;
258 }
259
260 //
261 // If some packages a Repackage=false, give a warning message
262 //
263 List<PackageIdentification> selectedPackages = getSelectedPackages();
264 WorkspaceTools wt = new WorkspaceTools();
265 List<PackageIdentification> allRepackablePackages = wt.getAllRepackagablePackages();
266
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";
275 }
276 }
277 msg += "is un-Repackagable. Do you want to continue? ";
278
279 if (unRepackablePackages.size() > 0) {
280 if(JOptionPane.showConfirmDialog(this, msg, "Warning", JOptionPane.YES_NO_OPTION) == JOptionPane.NO_OPTION) {
281 return ;
282 }
283 }
284
285 if (stepThree == null) {
286 stepThree = new CreateStepThree(this, true, this);
287 }
288 this.setVisible(false);
289 stepThree.setVisible(true);
290 }
291 }
292
293 public void mousePressed(MouseEvent e) {
294 // TODO Auto-generated method stub
295
296 }
297
298 public void mouseReleased(MouseEvent e) {
299 // TODO Auto-generated method stub
300
301 }
302
303 public void mouseEntered(MouseEvent e) {
304 // TODO Auto-generated method stub
305
306 }
307
308 public void mouseExited(MouseEvent e) {
309 // TODO Auto-generated method stub
310
311 }
312
313 /**
314 * This method initializes jButtonPrevious
315 *
316 * @return javax.swing.JButton
317 */
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);
324 }
325 return jButtonPrevious;
326 }
327
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()));
333 }
334 return result;
335 }
336
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()));
342 }
343 return result;
344 }
345
346 public CreateStepOne getPreviousStep() {
347 return stepOne;
348 }
349 }