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