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