]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/module/ui/dialog/LibraryClassDefsDlg.java
1. Fix EDKT321 A module's all top level elements' arch should be in range of the...
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / module / ui / dialog / LibraryClassDefsDlg.java
1 /** @file
2
3 The file is used to create, update Library Class Definition section of the MSA 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.Dimension;
18 import java.awt.event.ActionEvent;
19 import java.util.Vector;
20
21 import javax.swing.JButton;
22 import javax.swing.JComboBox;
23 import javax.swing.JLabel;
24 import javax.swing.JPanel;
25 import javax.swing.JScrollPane;
26 import javax.swing.JTextField;
27
28 import org.tianocore.frameworkwizard.common.DataType;
29 import org.tianocore.frameworkwizard.common.DataValidation;
30 import org.tianocore.frameworkwizard.common.EnumerationData;
31 import org.tianocore.frameworkwizard.common.Log;
32 import org.tianocore.frameworkwizard.common.Tools;
33 import org.tianocore.frameworkwizard.common.ui.ArchCheckBox;
34 import org.tianocore.frameworkwizard.common.ui.IDialog;
35 import org.tianocore.frameworkwizard.common.ui.IFrame;
36 import org.tianocore.frameworkwizard.common.ui.StarLabel;
37 import org.tianocore.frameworkwizard.common.ui.iCheckBoxList.ICheckBoxList;
38 import org.tianocore.frameworkwizard.module.Identifications.ModuleIdentification;
39 import org.tianocore.frameworkwizard.module.Identifications.LibraryClass.LibraryClassIdentification;
40 import org.tianocore.frameworkwizard.packaging.PackageIdentification;
41 import org.tianocore.frameworkwizard.workspace.WorkspaceTools;
42
43 /**
44 * The class is used to create, update Library Class Definition section of the MSA file
45 *
46 * It extends IDialog
47 *
48 */
49 public class LibraryClassDefsDlg extends IDialog {
50
51 ///
52 /// Define class Serial Version UID
53 ///
54 private static final long serialVersionUID = -1743248695411382857L;
55
56 //
57 //Define class members
58 //
59 private JPanel jContentPane = null;
60
61 private JComboBox jComboBoxLibraryClassName = null;
62
63 private JLabel jLabelUsage = null;
64
65 private JComboBox jComboBoxUsage = null;
66
67 private JLabel jLabelLibraryClassName = null;
68
69 private JScrollPane jScrollPane = null;
70
71 private StarLabel jStarLabel1 = null;
72
73 private StarLabel jStarLabel2 = null;
74
75 private JLabel jLabelRecommendedInstanceVersion = null;
76
77 private JTextField jTextFieldRecommendedInstanceVersion = null;
78
79 private JLabel jLabelRecommendedInstanceGuid = null;
80
81 private JTextField jTextFieldRecommendedInstanceGuid = null;
82
83 private JButton jButtonGenerateGuid = null;
84
85 private JLabel jLabelFeatureFlag = null;
86
87 private JTextField jTextFieldFeatureFlag = null;
88
89 private JLabel jLabelArch = null;
90
91 private JLabel jLabelModuleList = null;
92
93 private JScrollPane jScrollPaneModuleList = null;
94
95 private ICheckBoxList iCheckBoxListModule = null;
96
97 private JLabel jLabelHelpText = null;
98
99 private JTextField jTextFieldHelpText = null;
100
101 private ArchCheckBox jArchCheckBox = null;
102
103 private JButton jButtonOk = null;
104
105 private JButton jButtonCancel = null;
106
107 //
108 // Not for UI
109 //
110 private EnumerationData ed = new EnumerationData();
111
112 private WorkspaceTools wt = new WorkspaceTools();
113
114 private LibraryClassIdentification lcid = null;
115
116 /**
117 This method initializes jComboBoxSelect
118
119 @return javax.swing.JComboBox jComboBoxSelect
120
121 **/
122 private JComboBox getJComboBoxLibraryClassName() {
123 if (jComboBoxLibraryClassName == null) {
124 jComboBoxLibraryClassName = new JComboBox();
125 jComboBoxLibraryClassName.setBounds(new java.awt.Rectangle(168, 12, 320, 20));
126 jComboBoxLibraryClassName.setPreferredSize(new Dimension(320, 20));
127 jComboBoxLibraryClassName.setEnabled(true);
128 }
129 return jComboBoxLibraryClassName;
130 }
131
132 /**
133 This method initializes jComboBoxUsage
134
135 @return javax.swing.JComboBox jComboBoxUsage
136
137 **/
138 private JComboBox getJComboBoxUsage() {
139 if (jComboBoxUsage == null) {
140 jComboBoxUsage = new JComboBox();
141 jComboBoxUsage.setBounds(new java.awt.Rectangle(168, 37, 320, 20));
142 jComboBoxUsage.setPreferredSize(new Dimension(320, 20));
143 }
144 return jComboBoxUsage;
145 }
146
147 /**
148 This method initializes jScrollPane
149
150 @return javax.swing.JScrollPane
151 */
152 private JScrollPane getJScrollPane() {
153 if (jScrollPane == null) {
154 jScrollPane = new JScrollPane();
155 jScrollPane.setViewportView(getJContentPane());
156 }
157 return jScrollPane;
158 }
159
160 /**
161 * This method initializes jTextFieldRecommendedInstanceVersion
162 *
163 * @return javax.swing.JTextField
164 */
165 private JTextField getJTextFieldRecommendedInstanceVersion() {
166 if (jTextFieldRecommendedInstanceVersion == null) {
167 jTextFieldRecommendedInstanceVersion = new JTextField();
168 jTextFieldRecommendedInstanceVersion.setPreferredSize(new java.awt.Dimension(260, 20));
169 jTextFieldRecommendedInstanceVersion.setSize(new java.awt.Dimension(260, 20));
170 jTextFieldRecommendedInstanceVersion.setLocation(new java.awt.Point(220, 85));
171 jTextFieldRecommendedInstanceVersion.setVisible(false);
172 }
173 return jTextFieldRecommendedInstanceVersion;
174 }
175
176 /**
177 * This method initializes jTextFieldRecommendedInstanceGuid
178 *
179 * @return javax.swing.JTextField
180 */
181 private JTextField getJTextFieldRecommendedInstanceGuid() {
182 if (jTextFieldRecommendedInstanceGuid == null) {
183 jTextFieldRecommendedInstanceGuid = new JTextField();
184 jTextFieldRecommendedInstanceGuid.setBounds(new java.awt.Rectangle(220, 110, 190, 20));
185 jTextFieldRecommendedInstanceGuid.setPreferredSize(new java.awt.Dimension(190, 20));
186 jTextFieldRecommendedInstanceGuid.setVisible(false);
187 }
188 return jTextFieldRecommendedInstanceGuid;
189 }
190
191 /**
192 * This method initializes jButtonGenerateGuid
193 *
194 * @return javax.swing.JButton
195 */
196 private JButton getJButtonGenerateGuid() {
197 if (jButtonGenerateGuid == null) {
198 jButtonGenerateGuid = new JButton();
199 jButtonGenerateGuid.setBounds(new java.awt.Rectangle(415, 112, 65, 20));
200 jButtonGenerateGuid.setPreferredSize(new java.awt.Dimension(65, 20));
201 jButtonGenerateGuid.setText("GEN");
202 jButtonGenerateGuid.setVisible(false);
203 jButtonGenerateGuid.addActionListener(this);
204 }
205 return jButtonGenerateGuid;
206 }
207
208 /**
209 * This method initializes jTextFieldFeatureFlag
210 *
211 * @return javax.swing.JTextField
212 */
213 private JTextField getJTextFieldFeatureFlag() {
214 if (jTextFieldFeatureFlag == null) {
215 jTextFieldFeatureFlag = new JTextField();
216 jTextFieldFeatureFlag.setBounds(new java.awt.Rectangle(168,197,320,20));
217 jTextFieldFeatureFlag.setPreferredSize(new java.awt.Dimension(320, 20));
218 jTextFieldFeatureFlag.setToolTipText("Postfix expression that must evaluate to TRUE or FALSE");
219 jTextFieldFeatureFlag.setEnabled(false);
220 }
221 return jTextFieldFeatureFlag;
222 }
223
224 /**
225 This method initializes iCheckBoxListArch
226
227 @return ICheckBoxList
228 **/
229 private ICheckBoxList getICheckBoxListSupModuleList() {
230 if (iCheckBoxListModule == null) {
231 iCheckBoxListModule = new ICheckBoxList();
232 }
233 return iCheckBoxListModule;
234 }
235
236 /**
237 This method initializes jScrollPaneModuleList
238
239 @return javax.swing.JScrollPane
240
241 **/
242 private JScrollPane getJScrollPaneModuleList() {
243 if (jScrollPaneModuleList == null) {
244 jScrollPaneModuleList = new JScrollPane();
245 jScrollPaneModuleList.setBounds(new java.awt.Rectangle(168, 112, 320, 80));
246 jScrollPaneModuleList.setPreferredSize(new java.awt.Dimension(320, 80));
247 jScrollPaneModuleList.setViewportView(getICheckBoxListSupModuleList());
248 }
249 return jScrollPaneModuleList;
250 }
251
252 /**
253 This method initializes jTextFieldHelpText
254
255 @return javax.swing.JTextField
256
257 **/
258 private JTextField getJTextFieldHelpText() {
259 if (jTextFieldHelpText == null) {
260 jTextFieldHelpText = new JTextField();
261 jTextFieldHelpText.setBounds(new java.awt.Rectangle(168, 62, 320, 20));
262 jTextFieldHelpText.setPreferredSize(new java.awt.Dimension(320, 20));
263 }
264 return jTextFieldHelpText;
265 }
266
267 /**
268 This method initializes jButtonOk
269
270 @return javax.swing.JButton
271
272 **/
273 private JButton getJButtonOk() {
274 if (jButtonOk == null) {
275 jButtonOk = new JButton();
276 jButtonOk.setBounds(new java.awt.Rectangle(300, 232, 90, 20));
277 jButtonOk.setText("Ok");
278 jButtonOk.addActionListener(this);
279 }
280 return jButtonOk;
281 }
282
283 /**
284 This method initializes jButtonCancel
285
286 @return javax.swing.JButton
287
288 **/
289 private JButton getJButtonCancel() {
290 if (jButtonCancel == null) {
291 jButtonCancel = new JButton();
292 jButtonCancel.setBounds(new java.awt.Rectangle(400, 232, 90, 20));
293 jButtonCancel.setText("Cancel");
294 jButtonCancel.addActionListener(this);
295 }
296 return jButtonCancel;
297 }
298
299 public static void main(String[] args) {
300
301 }
302
303 /**
304 This is the default constructor
305
306 **/
307 public LibraryClassDefsDlg(LibraryClassIdentification inLibraryClassIdentification, IFrame iFrame, ModuleIdentification mid) {
308 super(iFrame, true);
309 init(inLibraryClassIdentification, mid);
310 }
311
312 /**
313 This method initializes this
314
315 **/
316 private void init() {
317 this.setContentPane(getJScrollPane());
318 this.setTitle("Library Class Definitions");
319 this.setBounds(new java.awt.Rectangle(0, 0, 505, 305));
320 initFrame();
321 this.setViewMode(false);
322 this.centerWindow();
323 }
324
325 /**
326 This method initializes this
327
328 **/
329 private void init(LibraryClassIdentification inLibraryClassIdentification, ModuleIdentification mid) {
330 init();
331 this.lcid = inLibraryClassIdentification;
332
333 //
334 // Init arch with module's arch
335 //
336 this.jArchCheckBox.setEnabledItems(wt.getModuleArch(mid));
337
338 //
339 // Get defined library classes from dependent packages
340 //
341 Vector<PackageIdentification> vpid = wt.getPackageDependenciesOfModule(mid);
342 if (vpid.size() <= 0) {
343 Log.wrn("Init Library Class", "This module hasn't defined any package dependency, so there is no library class can be added");
344 }
345
346 Tools.generateComboBoxByVector(this.jComboBoxLibraryClassName,
347 wt.getAllLibraryClassDefinitionsFromPackages(wt.getPackageDependenciesOfModule(mid)));
348
349 if (lcid != null) {
350 this.jComboBoxLibraryClassName.setSelectedItem(lcid.getLibraryClassName());
351 this.jComboBoxUsage.setSelectedItem(lcid.getUsage());
352 this.jTextFieldRecommendedInstanceVersion.setText(lcid.getRecommendedInstanceVersion());
353 this.jTextFieldRecommendedInstanceGuid.setText(lcid.getRecommendedInstanceGuid());
354 this.jTextFieldFeatureFlag.setText(lcid.getFeatureFlag());
355 this.jArchCheckBox.setSelectedItems(lcid.getSupArchList());
356 this.iCheckBoxListModule.setAllItemsUnchecked();
357 this.iCheckBoxListModule.initCheckedItem(true, lcid.getSupModuleList());
358 this.jTextFieldHelpText.setText(lcid.getHelp());
359 }
360 }
361
362 /**
363 Disable all components when the mode is view
364
365 @param isView true - The view mode; false - The non-view mode
366
367 **/
368 public void setViewMode(boolean isView) {
369 if (isView) {
370 this.jComboBoxLibraryClassName.setEnabled(!isView);
371 this.jComboBoxUsage.setEnabled(!isView);
372 }
373 }
374
375 /**
376 This method initializes jContentPane
377
378 @return javax.swing.JPanel jContentPane
379
380 **/
381 private JPanel getJContentPane() {
382 if (jContentPane == null) {
383 jArchCheckBox = new ArchCheckBox();
384 jArchCheckBox.setBounds(new java.awt.Rectangle(168, 87, 320, 20));
385 jArchCheckBox.setPreferredSize(new java.awt.Dimension(320, 20));
386 jLabelHelpText = new JLabel();
387 jLabelHelpText.setBounds(new java.awt.Rectangle(12, 62, 168, 20));
388 jLabelHelpText.setText("Help Text");
389 jLabelModuleList = new JLabel();
390 jLabelModuleList.setBounds(new java.awt.Rectangle(12, 112, 168, 20));
391 jLabelModuleList.setText("Supported Module Types");
392 jLabelArch = new JLabel();
393 jLabelArch.setBounds(new java.awt.Rectangle(12, 87, 168, 20));
394 jLabelArch.setText("Supported Architectures");
395 jLabelFeatureFlag = new JLabel();
396 jLabelFeatureFlag.setBounds(new java.awt.Rectangle(12,197,168,20));
397 jLabelFeatureFlag.setText("Feature Flag Expression");
398 jLabelFeatureFlag.setEnabled(false);
399 jLabelRecommendedInstanceGuid = new JLabel();
400 jLabelRecommendedInstanceGuid.setBounds(new java.awt.Rectangle(12, 87, 200, 20));
401 jLabelRecommendedInstanceGuid.setText("Recommended Instance Guid");
402 jLabelRecommendedInstanceGuid.setVisible(false);
403 jLabelRecommendedInstanceVersion = new JLabel();
404 jLabelRecommendedInstanceVersion.setBounds(new java.awt.Rectangle(12, 87, 200, 20));
405 jLabelRecommendedInstanceVersion.setText("Recommended Instance Version");
406 jLabelRecommendedInstanceVersion.setVisible(false);
407 jLabelLibraryClassName = new JLabel();
408 jLabelLibraryClassName.setBounds(new java.awt.Rectangle(12, 12, 168, 20));
409 jLabelLibraryClassName.setText("Library Class Name");
410 jLabelUsage = new JLabel();
411 jLabelUsage.setBounds(new java.awt.Rectangle(12, 37, 168, 20));
412 jLabelUsage.setText("Usage");
413 jContentPane = new JPanel();
414 jContentPane.setLayout(null);
415 jContentPane.setPreferredSize(new java.awt.Dimension(495, 255));
416
417 jContentPane.add(getJComboBoxLibraryClassName(), null);
418 jContentPane.add(jLabelUsage, null);
419 jContentPane.add(getJComboBoxUsage(), null);
420 jContentPane.add(jLabelLibraryClassName, null);
421 jContentPane.add(jLabelRecommendedInstanceVersion, null);
422 jContentPane.add(getJTextFieldRecommendedInstanceVersion(), null);
423 jContentPane.add(jLabelRecommendedInstanceGuid, null);
424 jContentPane.add(getJTextFieldRecommendedInstanceGuid(), null);
425 jContentPane.add(getJButtonGenerateGuid(), null);
426 jContentPane.add(jLabelFeatureFlag, null);
427 jContentPane.add(getJTextFieldFeatureFlag(), null);
428 jContentPane.add(jLabelArch, null);
429 jStarLabel1 = new StarLabel();
430 jStarLabel1.setLocation(new java.awt.Point(2, 10));
431 jStarLabel2 = new StarLabel();
432 jStarLabel2.setLocation(new java.awt.Point(2, 35));
433
434 jContentPane.add(jStarLabel1, null);
435 jContentPane.add(jStarLabel2, null);
436 jContentPane.add(jLabelModuleList, null);
437 jContentPane.add(getJScrollPaneModuleList(), null);
438 jContentPane.add(jLabelHelpText, null);
439 jContentPane.add(getJTextFieldHelpText(), null);
440 jContentPane.add(jArchCheckBox, null);
441 jContentPane.add(getJButtonOk(), null);
442 jContentPane.add(getJButtonCancel(), null);
443 }
444 return jContentPane;
445 }
446
447 /**
448 This method initializes all existing libraries and usage types
449
450 **/
451 private void initFrame() {
452 Tools.generateComboBoxByVector(jComboBoxUsage, ed.getVLibraryUsage());
453 this.iCheckBoxListModule.setAllItems(ed.getVFrameworkModuleTypes());
454 }
455
456 /* (non-Javadoc)
457 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
458 *
459 * Override actionPerformed to listen all actions
460 *
461 */
462 public void actionPerformed(ActionEvent arg0) {
463 if (arg0.getSource() == jButtonGenerateGuid) {
464 this.jTextFieldRecommendedInstanceGuid.setText(Tools.generateUuidString());
465 }
466
467 if (arg0.getSource() == jButtonOk) {
468 if (checkAdd()) {
469 getCurrentLibraryClass();
470 this.returnType = DataType.RETURN_TYPE_OK;
471 this.setVisible(false);
472 }
473 }
474
475 if (arg0.getSource() == jButtonCancel) {
476 this.returnType = DataType.RETURN_TYPE_CANCEL;
477 this.setVisible(false);
478 }
479 }
480
481 /**
482 Data validation for all fields
483
484 @retval true - All datas are valid
485 @retval false - At least one data is invalid
486
487 **/
488 public boolean checkAdd() {
489 //
490 // Check LibraryClass
491 //
492 if (this.jComboBoxLibraryClassName.getSelectedItem() == null) {
493 Log.wrn("Update Library Class Definitions", "Please select one Library Class");
494 return false;
495 }
496 if (!DataValidation.isLibraryClass(this.jComboBoxLibraryClassName.getSelectedItem().toString())) {
497 Log.wrn("Update Library Class Definitions", "Incorrect data type for Library Class");
498 return false;
499 }
500
501 //
502 // Check RecommendedInstanceVersion
503 //
504 // if (!isEmpty(this.jTextFieldRecommendedInstanceVersion.getText())) {
505 // if (!DataValidation.isRecommendedInstanceVersion(this.jTextFieldRecommendedInstanceVersion.getText())) {
506 // Log.err("Incorrect data type for Recommended Instance Version");
507 // return false;
508 // }
509 // }
510
511 //
512 // Check RecommendedInstanceGuid
513 //
514 // if (!isEmpty(this.jTextFieldRecommendedInstanceGuid.getText())) {
515 // if (!DataValidation.isGuid(this.jTextFieldRecommendedInstanceGuid.getText())) {
516 // Log.err("Incorrect data type for Recommended Instance Guid");
517 // return false;
518 // }
519 // }
520
521 //
522 // Check FeatureFlag
523 //
524 if (!isEmpty(this.jTextFieldFeatureFlag.getText())) {
525 if (!DataValidation.isFeatureFlag(this.jTextFieldFeatureFlag.getText())) {
526 Log.wrn("Update Library Class Definitions", "Incorrect data type for Feature Flag");
527 return false;
528 }
529 }
530
531 return true;
532 }
533
534 private LibraryClassIdentification getCurrentLibraryClass() {
535 String name = this.jComboBoxLibraryClassName.getSelectedItem().toString();
536 String usage = this.jComboBoxUsage.getSelectedItem().toString();
537 String version = this.jTextFieldRecommendedInstanceVersion.getText();
538 String guid = this.jTextFieldRecommendedInstanceGuid.getText();
539 String featureFlag = this.jTextFieldFeatureFlag.getText();
540 Vector<String> arch = this.jArchCheckBox.getSelectedItemsVector();
541 Vector<String> module = this.iCheckBoxListModule.getAllCheckedItemsString();
542 String help = this.jTextFieldHelpText.getText();
543 lcid = new LibraryClassIdentification(name, usage, version, guid, arch, featureFlag, module, help);
544 return lcid;
545 }
546
547 public LibraryClassIdentification getLcid() {
548 return lcid;
549 }
550
551 public void setLcid(LibraryClassIdentification lcid) {
552 this.lcid = lcid;
553 }
554 }