15acd94f8c264e51503de6eef68e22a543ced22a
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / module / ui / dialog / PackageDepDlg.java
1 /** @file
2
3 The file is used to create, update Include of MSA/MBD file
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.module.ui.dialog;
16
17 import java.awt.event.ActionEvent;
18 import java.awt.event.ItemEvent;
19 import java.awt.event.ItemListener;
20 import java.util.Vector;
21
22 import javax.swing.JButton;
23 import javax.swing.JComboBox;
24 import javax.swing.JLabel;
25 import javax.swing.JPanel;
26 import javax.swing.JScrollPane;
27 import javax.swing.JTextField;
28
29 import org.tianocore.frameworkwizard.common.DataType;
30 import org.tianocore.frameworkwizard.common.DataValidation;
31 import org.tianocore.frameworkwizard.common.Log;
32 import org.tianocore.frameworkwizard.common.ui.ArchCheckBox;
33 import org.tianocore.frameworkwizard.common.ui.IDialog;
34 import org.tianocore.frameworkwizard.common.ui.IFrame;
35 import org.tianocore.frameworkwizard.common.ui.StarLabel;
36 import org.tianocore.frameworkwizard.module.Identifications.PackageDependencies.PackageDependenciesIdentification;
37 import org.tianocore.frameworkwizard.packaging.PackageIdentification;
38 import org.tianocore.frameworkwizard.workspace.WorkspaceTools;
39
40 /**
41 * The class is used to create, update Include of MSA/MBD file It extends
42 * IInternalFrame
43 *
44 *
45 *
46 */
47 public class PackageDepDlg extends IDialog implements ItemListener {
48 // /
49 // / Define class Serial Version UID
50 // /
51 private static final long serialVersionUID = 3465193035145152131L;
52
53 //
54 // Define class members
55 //
56 private JPanel jContentPane = null;
57
58 private JLabel jLabelPackageName = null;
59
60 private StarLabel jStarLabel1 = null;
61
62 private JComboBox jComboBoxPackageName = null;
63
64 private JLabel jLabelPackageGuid = null;
65
66 private JTextField jTextFieldPackageGuid = null;
67
68 private JButton jButtonGenerateGuid = null;
69
70 private JLabel jLabelPackageVersion = null;
71
72 private JTextField jTextFieldPackageVersion = null;
73
74 private JLabel jLabelFeatureFlag = null;
75
76 private JTextField jTextFieldFeatureFlag = null;
77
78 private JScrollPane jScrollPane = null;
79
80 private JLabel jLabelArch = null;
81
82 private ArchCheckBox jArchCheckBox = null;
83
84 private JButton jButtonOk = null;
85
86 private JButton jButtonCancel = null;
87
88 //
89 // Not used by UI
90 //
91 private PackageDependenciesIdentification pdid = null;
92
93 private WorkspaceTools wt = new WorkspaceTools();
94
95 private Vector<PackageIdentification> vPackage = wt.getAllPackages();
96
97 /**
98 * This method initializes jComboBoxPackageName
99 *
100 * @return javax.swing.JComboBox
101 */
102 private JComboBox getJComboBoxPackageName() {
103 if (jComboBoxPackageName == null) {
104 jComboBoxPackageName = new JComboBox();
105 jComboBoxPackageName.setBounds(new java.awt.Rectangle(160, 10, 320, 20));
106 jComboBoxPackageName.setPreferredSize(new java.awt.Dimension(320, 20));
107 jComboBoxPackageName.setToolTipText("If your Module requires a package list that here.");
108 jComboBoxPackageName.addItemListener(this);
109 }
110 return jComboBoxPackageName;
111 }
112
113 /**
114 * This method initializes jTextFieldPackageGuid
115 *
116 * @return javax.swing.JTextField
117 */
118 private JTextField getJTextFieldPackageGuid() {
119 if (jTextFieldPackageGuid == null) {
120 jTextFieldPackageGuid = new JTextField();
121 jTextFieldPackageGuid.setBounds(new java.awt.Rectangle(160, 35, 320, 20));
122 jTextFieldPackageGuid.setPreferredSize(new java.awt.Dimension(320, 20));
123 jTextFieldPackageGuid.setEditable(false);
124 jTextFieldPackageGuid.setVisible(false);
125 }
126 return jTextFieldPackageGuid;
127 }
128
129 /**
130 * This method initializes jButtonGenerateGuid
131 *
132 * @return javax.swing.JButton
133 */
134 private JButton getJButtonGenerateGuid() {
135 if (jButtonGenerateGuid == null) {
136 jButtonGenerateGuid = new JButton();
137 jButtonGenerateGuid.setBounds(new java.awt.Rectangle(415, 35, 65, 20));
138 jButtonGenerateGuid.setPreferredSize(new java.awt.Dimension(65, 20));
139 jButtonGenerateGuid.setText("GEN");
140 jButtonGenerateGuid.addActionListener(this);
141 jButtonGenerateGuid.setVisible(false);
142 }
143 return jButtonGenerateGuid;
144 }
145
146 /**
147 * This method initializes jTextFieldPackageVersion
148 *
149 * @return javax.swing.JTextField
150 */
151 private JTextField getJTextFieldPackageVersion() {
152 if (jTextFieldPackageVersion == null) {
153 jTextFieldPackageVersion = new JTextField();
154 jTextFieldPackageVersion.setBounds(new java.awt.Rectangle(160, 35, 320, 20));
155 jTextFieldPackageVersion.setPreferredSize(new java.awt.Dimension(320, 20));
156 jTextFieldPackageVersion
157 .setToolTipText("If this module depends on a specific version of a package, enter the package version here. If the module can use the latest version that does not break backward compatibility, leave this field blank");
158 }
159 return jTextFieldPackageVersion;
160 }
161
162 /**
163 * This method initializes jTextFieldFeatureFlag
164 *
165 * @return javax.swing.JTextField
166 */
167 private JTextField getJTextFieldFeatureFlag() {
168 if (jTextFieldFeatureFlag == null) {
169 jTextFieldFeatureFlag = new JTextField();
170 jTextFieldFeatureFlag.setBounds(new java.awt.Rectangle(160, 60, 320, 20));
171 jTextFieldFeatureFlag.setPreferredSize(new java.awt.Dimension(320, 20));
172 }
173 return jTextFieldFeatureFlag;
174 }
175
176 /**
177 * This method initializes jScrollPane
178 *
179 * @return javax.swing.JScrollPane
180 */
181 private JScrollPane getJScrollPane() {
182 if (jScrollPane == null) {
183 jScrollPane = new JScrollPane();
184 jScrollPane.setViewportView(getJContentPane());
185 }
186 return jScrollPane;
187 }
188
189 /**
190 * This method initializes jButtonOk
191 *
192 * @return javax.swing.JButton
193 *
194 */
195 private JButton getJButtonOk() {
196 if (jButtonOk == null) {
197 jButtonOk = new JButton();
198 jButtonOk.setBounds(new java.awt.Rectangle(290, 115, 90, 20));
199 jButtonOk.setText("Ok");
200 jButtonOk.addActionListener(this);
201 }
202 return jButtonOk;
203 }
204
205 /**
206 * This method initializes jButtonCancel
207 *
208 * @return javax.swing.JButton
209 *
210 */
211 private JButton getJButtonCancel() {
212 if (jButtonCancel == null) {
213 jButtonCancel = new JButton();
214 jButtonCancel.setBounds(new java.awt.Rectangle(390, 115, 90, 20));
215 jButtonCancel.setText("Cancel");
216 jButtonCancel.addActionListener(this);
217 }
218 return jButtonCancel;
219 }
220
221 public static void main(String[] args) {
222
223 }
224
225 /**
226 * This method initializes this
227 *
228 */
229 private void init() {
230 this.setSize(508, 188);
231 this.setContentPane(getJScrollPane());
232 this.setTitle("Package Dependencies");
233 initFrame();
234 this.setViewMode(false);
235 this.centerWindow();
236 }
237
238 /**
239 * This method initializes this
240 *
241 */
242 private void init(PackageDependenciesIdentification inPackageDependenciesIdentification) {
243 init();
244 this.pdid = inPackageDependenciesIdentification;
245 if (pdid != null) {
246 this.jComboBoxPackageName.setSelectedItem(pdid.getName());
247 this.jTextFieldPackageVersion.setText(pdid.getVersion());
248 this.jTextFieldPackageGuid.setText(pdid.getGuid());
249 jTextFieldFeatureFlag.setText(pdid.getFeatureFlag());
250 this.jArchCheckBox.setSelectedItems(pdid.getSupArchList());
251 }
252 }
253
254 /**
255 * This is the default constructor
256 *
257 */
258 public PackageDepDlg(PackageDependenciesIdentification inPackageDependenciesIdentification, IFrame iFrame) {
259 super(iFrame, true);
260 init(inPackageDependenciesIdentification);
261 }
262
263 /**
264 * Disable all components when the mode is view
265 *
266 * @param isView
267 * true - The view mode; false - The non-view mode
268 *
269 */
270 public void setViewMode(boolean isView) {
271 if (isView) {
272 this.jComboBoxPackageName.setEnabled(!isView);
273 }
274 }
275
276 /**
277 * This method initializes jContentPane
278 *
279 * @return javax.swing.JPanel jContentPane
280 *
281 */
282 private JPanel getJContentPane() {
283 if (jContentPane == null) {
284 jStarLabel1 = new StarLabel();
285 jStarLabel1.setLocation(new java.awt.Point(2, 10));
286 jLabelPackageName = new JLabel();
287 jLabelPackageName.setBounds(new java.awt.Rectangle(15, 10, 145, 20));
288 jLabelPackageName.setText("Package Name");
289
290 jLabelPackageVersion = new JLabel();
291 jLabelPackageVersion.setBounds(new java.awt.Rectangle(15, 35, 145, 20));
292 jLabelPackageVersion.setText("Package Version");
293
294 jLabelPackageGuid = new JLabel();
295 jLabelPackageGuid.setBounds(new java.awt.Rectangle(15, 35, 145, 20));
296 jLabelPackageGuid.setText("Package Guid");
297 jLabelPackageGuid.setVisible(false);
298
299 jLabelFeatureFlag = new JLabel();
300 jLabelFeatureFlag.setBounds(new java.awt.Rectangle(15, 60, 145, 20));
301 jLabelFeatureFlag.setText("Feature Flag Expression");
302
303 jLabelArch = new JLabel();
304 jLabelArch.setBounds(new java.awt.Rectangle(15, 85, 145, 20));
305 jLabelArch.setText("Supported Architectures");
306 jArchCheckBox = new ArchCheckBox();
307 jArchCheckBox.setBounds(new java.awt.Rectangle(160, 85, 320, 20));
308 jArchCheckBox.setPreferredSize(new java.awt.Dimension(320, 20));
309
310 jContentPane = new JPanel();
311 jContentPane.setLayout(null);
312 jContentPane.setPreferredSize(new java.awt.Dimension(485, 145));
313
314 jContentPane.add(jStarLabel1, null);
315 jContentPane.add(jLabelPackageName, null);
316 jContentPane.add(getJComboBoxPackageName(), null);
317 jContentPane.add(jLabelPackageGuid, null);
318 jContentPane.add(getJTextFieldPackageGuid(), null);
319 jContentPane.add(jLabelPackageVersion, null);
320 jContentPane.add(getJTextFieldPackageVersion(), null);
321 // LAH Not Used here
322 // jContentPane.add(getJButtonGenerateGuid(), null);
323 jContentPane.add(jLabelFeatureFlag, null);
324 jContentPane.add(getJTextFieldFeatureFlag(), null);
325 jContentPane.add(jLabelArch, null);
326 jContentPane.add(jArchCheckBox, null);
327 jContentPane.add(getJButtonOk(), null);
328 jContentPane.add(getJButtonCancel(), null);
329 }
330 return jContentPane;
331 }
332
333 /*
334 * (non-Javadoc)
335 *
336 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
337 *
338 * Override actionPerformed to listen all actions
339 *
340 */
341 public void actionPerformed(ActionEvent arg0) {
342 if (arg0.getSource() == jButtonOk) {
343 if (checkAdd()) {
344 getCurrentPackageDependencies();
345 this.returnType = DataType.RETURN_TYPE_OK;
346 this.setVisible(false);
347 }
348 }
349
350 if (arg0.getSource() == jButtonCancel) {
351 this.returnType = DataType.RETURN_TYPE_CANCEL;
352 this.setVisible(false);
353 }
354 }
355
356 /**
357 * This method initializes Usage type, Package type and Arch type
358 *
359 */
360 private void initFrame() {
361 for (int index = 0; index < vPackage.size(); index++) {
362 jComboBoxPackageName.addItem(vPackage.elementAt(index).getName());
363 }
364 }
365
366 /**
367 * Data validation for all fields before add current item to Vector
368 *
369 * @retval true - All datas are valid
370 * @retval false - At least one data is invalid
371 *
372 */
373 public boolean checkAdd() {
374 //
375 // Check if all fields have correct data types
376 //
377
378 //
379 // Check PackageGuid
380 //
381 // if (!isEmpty(this.jTextFieldPackageGuid.getText())) {
382 // if (!DataValidation.isGuid(this.jTextFieldPackageGuid.getText())) {
383 // Log.err("Incorrect data type for Package Guid");
384 // return false;
385 // }
386 // }
387
388 //
389 // Check PackageVersion
390 //
391 if (!isEmpty(this.jTextFieldPackageVersion.getText())) {
392 if (!DataValidation.isVersion(this.jTextFieldPackageVersion.getText())) {
393 Log.wrn("Update Package Dependencies", "Incorrect data type for Package Version");
394 return false;
395 }
396 }
397
398 //
399 // Check FeatureFlag
400 //
401 if (!isEmpty(this.jTextFieldFeatureFlag.getText())) {
402 if (!DataValidation.isFeatureFlag(this.jTextFieldFeatureFlag.getText())) {
403 Log.wrn("Update Package Dependencies", "Incorrect data type for Feature Flag");
404 return false;
405 }
406 }
407
408 return true;
409 }
410
411
412 private PackageDependenciesIdentification getCurrentPackageDependencies() {
413 String arg0 = this.jComboBoxPackageName.getSelectedItem().toString();
414 String arg1 = this.jTextFieldPackageVersion.getText();
415 String arg2 = this.jTextFieldPackageGuid.getText();
416
417 String arg3 = this.jTextFieldFeatureFlag.getText();
418 Vector<String> arg4 = this.jArchCheckBox.getSelectedItemsVector();
419 pdid = new PackageDependenciesIdentification(arg0, arg1, arg2, arg3, arg4);
420 return pdid;
421 }
422
423 /*
424 * (non-Javadoc)
425 *
426 * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
427 *
428 * Reflesh the frame when selected item changed
429 *
430 */
431 public void itemStateChanged(ItemEvent arg0) {
432 if (arg0.getSource() == this.jComboBoxPackageName && arg0.getStateChange() == ItemEvent.SELECTED) {
433 for (int index = 0; index < vPackage.size(); index++) {
434 if (this.jComboBoxPackageName.getSelectedItem().toString().equals(vPackage.get(index).getName())) {
435 this.jTextFieldPackageGuid.setText(vPackage.get(index).getGuid());
436 }
437 }
438 }
439 }
440
441 public PackageDependenciesIdentification getPdid() {
442 return pdid;
443 }
444
445 public void setPdid(PackageDependenciesIdentification pdid) {
446 this.pdid = pdid;
447 }
448
449 }