3 The file is used to create, update Library Class Definition section of the MSA file
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
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.
15 package org
.tianocore
.frameworkwizard
.module
.ui
.dialog
;
17 import java
.awt
.Dimension
;
18 import java
.awt
.event
.ActionEvent
;
19 import java
.util
.Vector
;
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
;
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
.IDialog
;
36 import org
.tianocore
.frameworkwizard
.common
.ui
.IFrame
;
37 import org
.tianocore
.frameworkwizard
.common
.ui
.StarLabel
;
38 import org
.tianocore
.frameworkwizard
.common
.ui
.iCheckBoxList
.ICheckBoxList
;
39 import org
.tianocore
.frameworkwizard
.module
.Identifications
.ModuleIdentification
;
40 import org
.tianocore
.frameworkwizard
.module
.Identifications
.LibraryClass
.LibraryClassIdentification
;
41 import org
.tianocore
.frameworkwizard
.module
.Identifications
.LibraryClass
.LibraryClassVector
;
42 import org
.tianocore
.frameworkwizard
.packaging
.PackageIdentification
;
43 import org
.tianocore
.frameworkwizard
.workspace
.WorkspaceTools
;
46 * The class is used to create, update Library Class Definition section of the MSA file
51 public class LibraryClassDefsDlg
extends IDialog
{
54 /// Define class Serial Version UID
56 private static final long serialVersionUID
= -1743248695411382857L;
59 //Define class members
61 private JPanel jContentPane
= null;
63 private JComboBox jComboBoxLibraryClassName
= null;
65 private JLabel jLabelUsage
= null;
67 private JComboBox jComboBoxUsage
= null;
69 private JLabel jLabelLibraryClassName
= null;
71 private JScrollPane jScrollPane
= null;
73 private StarLabel jStarLabel1
= null;
75 private StarLabel jStarLabel2
= null;
77 private JLabel jLabelRecommendedInstanceVersion
= null;
79 private JTextField jTextFieldRecommendedInstanceVersion
= null;
81 private JLabel jLabelRecommendedInstanceGuid
= null;
83 private JTextField jTextFieldRecommendedInstanceGuid
= null;
85 private JButton jButtonGenerateGuid
= null;
87 private JLabel jLabelFeatureFlag
= null;
89 private JTextField jTextFieldFeatureFlag
= null;
91 private JLabel jLabelArch
= null;
93 private JLabel jLabelModuleList
= null;
95 private JScrollPane jScrollPaneModuleList
= null;
97 private ICheckBoxList iCheckBoxListModule
= null;
99 private JLabel jLabelHelpText
= null;
101 private JTextField jTextFieldHelpText
= null;
103 private ArchCheckBox jArchCheckBox
= null;
105 private JButton jButtonOk
= null;
107 private JButton jButtonCancel
= null;
112 private EnumerationData ed
= new EnumerationData();
114 private WorkspaceTools wt
= new WorkspaceTools();
116 private LibraryClassIdentification lcid
= null;
119 This method initializes jComboBoxSelect
121 @return javax.swing.JComboBox jComboBoxSelect
124 private JComboBox
getJComboBoxLibraryClassName() {
125 if (jComboBoxLibraryClassName
== null) {
126 jComboBoxLibraryClassName
= new JComboBox();
127 jComboBoxLibraryClassName
.setBounds(new java
.awt
.Rectangle(168, 12, 320, 20));
128 jComboBoxLibraryClassName
.setPreferredSize(new Dimension(320, 20));
129 jComboBoxLibraryClassName
.setEnabled(true);
131 return jComboBoxLibraryClassName
;
135 This method initializes jComboBoxUsage
137 @return javax.swing.JComboBox jComboBoxUsage
140 private JComboBox
getJComboBoxUsage() {
141 if (jComboBoxUsage
== null) {
142 jComboBoxUsage
= new JComboBox();
143 jComboBoxUsage
.setBounds(new java
.awt
.Rectangle(168, 37, 320, 20));
144 jComboBoxUsage
.setPreferredSize(new Dimension(320, 20));
146 return jComboBoxUsage
;
150 This method initializes jScrollPane
152 @return javax.swing.JScrollPane
154 private JScrollPane
getJScrollPane() {
155 if (jScrollPane
== null) {
156 jScrollPane
= new JScrollPane();
157 jScrollPane
.setViewportView(getJContentPane());
163 * This method initializes jTextFieldRecommendedInstanceVersion
165 * @return javax.swing.JTextField
167 private JTextField
getJTextFieldRecommendedInstanceVersion() {
168 if (jTextFieldRecommendedInstanceVersion
== null) {
169 jTextFieldRecommendedInstanceVersion
= new JTextField();
170 jTextFieldRecommendedInstanceVersion
.setPreferredSize(new java
.awt
.Dimension(260, 20));
171 jTextFieldRecommendedInstanceVersion
.setSize(new java
.awt
.Dimension(260, 20));
172 jTextFieldRecommendedInstanceVersion
.setLocation(new java
.awt
.Point(220, 85));
173 jTextFieldRecommendedInstanceVersion
.setVisible(false);
175 return jTextFieldRecommendedInstanceVersion
;
179 * This method initializes jTextFieldRecommendedInstanceGuid
181 * @return javax.swing.JTextField
183 private JTextField
getJTextFieldRecommendedInstanceGuid() {
184 if (jTextFieldRecommendedInstanceGuid
== null) {
185 jTextFieldRecommendedInstanceGuid
= new JTextField();
186 jTextFieldRecommendedInstanceGuid
.setBounds(new java
.awt
.Rectangle(220, 110, 190, 20));
187 jTextFieldRecommendedInstanceGuid
.setPreferredSize(new java
.awt
.Dimension(190, 20));
188 jTextFieldRecommendedInstanceGuid
.setVisible(false);
190 return jTextFieldRecommendedInstanceGuid
;
194 * This method initializes jButtonGenerateGuid
196 * @return javax.swing.JButton
198 private JButton
getJButtonGenerateGuid() {
199 if (jButtonGenerateGuid
== null) {
200 jButtonGenerateGuid
= new JButton();
201 jButtonGenerateGuid
.setBounds(new java
.awt
.Rectangle(415, 112, 65, 20));
202 jButtonGenerateGuid
.setPreferredSize(new java
.awt
.Dimension(65, 20));
203 jButtonGenerateGuid
.setText("GEN");
204 jButtonGenerateGuid
.setVisible(false);
205 jButtonGenerateGuid
.addActionListener(this);
207 return jButtonGenerateGuid
;
211 * This method initializes jTextFieldFeatureFlag
213 * @return javax.swing.JTextField
215 private JTextField
getJTextFieldFeatureFlag() {
216 if (jTextFieldFeatureFlag
== null) {
217 jTextFieldFeatureFlag
= new JTextField();
218 jTextFieldFeatureFlag
.setBounds(new java
.awt
.Rectangle(168, 197, 320, 20));
219 jTextFieldFeatureFlag
.setPreferredSize(new java
.awt
.Dimension(320, 20));
220 jTextFieldFeatureFlag
.setToolTipText("Postfix expression that must evaluate to TRUE or FALSE");
221 jTextFieldFeatureFlag
.setEnabled(false);
223 return jTextFieldFeatureFlag
;
227 This method initializes iCheckBoxListArch
229 @return ICheckBoxList
231 private ICheckBoxList
getICheckBoxListSupModuleList() {
232 if (iCheckBoxListModule
== null) {
233 iCheckBoxListModule
= new ICheckBoxList();
235 return iCheckBoxListModule
;
239 This method initializes jScrollPaneModuleList
241 @return javax.swing.JScrollPane
244 private JScrollPane
getJScrollPaneModuleList() {
245 if (jScrollPaneModuleList
== null) {
246 jScrollPaneModuleList
= new JScrollPane();
247 jScrollPaneModuleList
.setBounds(new java
.awt
.Rectangle(168, 112, 320, 80));
248 jScrollPaneModuleList
.setPreferredSize(new java
.awt
.Dimension(320, 80));
249 jScrollPaneModuleList
.setViewportView(getICheckBoxListSupModuleList());
251 return jScrollPaneModuleList
;
255 This method initializes jTextFieldHelpText
257 @return javax.swing.JTextField
260 private JTextField
getJTextFieldHelpText() {
261 if (jTextFieldHelpText
== null) {
262 jTextFieldHelpText
= new JTextField();
263 jTextFieldHelpText
.setBounds(new java
.awt
.Rectangle(168, 62, 320, 20));
264 jTextFieldHelpText
.setPreferredSize(new java
.awt
.Dimension(320, 20));
266 return jTextFieldHelpText
;
270 This method initializes jButtonOk
272 @return javax.swing.JButton
275 private JButton
getJButtonOk() {
276 if (jButtonOk
== null) {
277 jButtonOk
= new JButton();
278 jButtonOk
.setBounds(new java
.awt
.Rectangle(300, 232, 90, 20));
279 jButtonOk
.setText("Ok");
280 jButtonOk
.addActionListener(this);
286 This method initializes jButtonCancel
288 @return javax.swing.JButton
291 private JButton
getJButtonCancel() {
292 if (jButtonCancel
== null) {
293 jButtonCancel
= new JButton();
294 jButtonCancel
.setBounds(new java
.awt
.Rectangle(400, 232, 90, 20));
295 jButtonCancel
.setText("Cancel");
296 jButtonCancel
.addActionListener(this);
298 return jButtonCancel
;
301 public static void main(String
[] args
) {
306 This is the default constructor
309 public LibraryClassDefsDlg(LibraryClassIdentification inLibraryClassIdentification
, IFrame iFrame
,
310 ModuleIdentification mid
) {
312 init(inLibraryClassIdentification
, mid
);
316 This method initializes this
319 private void init() {
320 this.setContentPane(getJScrollPane());
321 this.setTitle("Library Class Definitions");
322 this.setBounds(new java
.awt
.Rectangle(0, 0, 505, 305));
324 this.setViewMode(false);
329 This method initializes this
332 private void init(LibraryClassIdentification inLibraryClassIdentification
, ModuleIdentification mid
) {
334 this.lcid
= inLibraryClassIdentification
;
337 // Init arch with module's arch
339 this.jArchCheckBox
.setEnabledItems(wt
.getModuleArch(mid
));
342 // Get defined library classes from dependent packages
344 Vector
<PackageIdentification
> vpid
= wt
.getPackageDependenciesOfModule(mid
);
345 if (vpid
.size() <= 0) {
346 Log
.wrn("Init Library Class",
347 "This module hasn't defined any package dependency, so there is no library class can be added");
351 .generateComboBoxByVector(
352 this.jComboBoxLibraryClassName
,
354 .getAllLibraryClassDefinitionsFromPackages(wt
355 .getPackageDependenciesOfModule(mid
)));
358 this.jComboBoxLibraryClassName
.setSelectedItem(lcid
.getLibraryClassName());
359 this.jComboBoxUsage
.setSelectedItem(lcid
.getUsage());
360 this.jTextFieldRecommendedInstanceVersion
.setText(lcid
.getRecommendedInstanceVersion());
361 this.jTextFieldRecommendedInstanceGuid
.setText(lcid
.getRecommendedInstanceGuid());
362 this.jTextFieldFeatureFlag
.setText(lcid
.getFeatureFlag());
363 this.jArchCheckBox
.setSelectedItems(lcid
.getSupArchList());
364 this.iCheckBoxListModule
.setAllItemsUnchecked();
365 this.iCheckBoxListModule
.initCheckedItem(true, lcid
.getSupModuleList());
366 this.jTextFieldHelpText
.setText(lcid
.getHelp());
371 Disable all components when the mode is view
373 @param isView true - The view mode; false - The non-view mode
376 public void setViewMode(boolean isView
) {
378 this.jComboBoxLibraryClassName
.setEnabled(!isView
);
379 this.jComboBoxUsage
.setEnabled(!isView
);
384 This method initializes jContentPane
386 @return javax.swing.JPanel jContentPane
389 private JPanel
getJContentPane() {
390 if (jContentPane
== null) {
391 jArchCheckBox
= new ArchCheckBox();
392 jArchCheckBox
.setBounds(new java
.awt
.Rectangle(168, 87, 320, 20));
393 jArchCheckBox
.setPreferredSize(new java
.awt
.Dimension(320, 20));
394 jLabelHelpText
= new JLabel();
395 jLabelHelpText
.setBounds(new java
.awt
.Rectangle(12, 62, 168, 20));
396 jLabelHelpText
.setText("Help Text");
397 jLabelModuleList
= new JLabel();
398 jLabelModuleList
.setBounds(new java
.awt
.Rectangle(12, 112, 168, 20));
399 jLabelModuleList
.setText("Supported Module Types");
400 jLabelArch
= new JLabel();
401 jLabelArch
.setBounds(new java
.awt
.Rectangle(12, 87, 168, 20));
402 jLabelArch
.setText("Supported Architectures");
403 jLabelFeatureFlag
= new JLabel();
404 jLabelFeatureFlag
.setBounds(new java
.awt
.Rectangle(12, 197, 168, 20));
405 jLabelFeatureFlag
.setText("Feature Flag Expression");
406 jLabelFeatureFlag
.setEnabled(false);
407 jLabelRecommendedInstanceGuid
= new JLabel();
408 jLabelRecommendedInstanceGuid
.setBounds(new java
.awt
.Rectangle(12, 87, 200, 20));
409 jLabelRecommendedInstanceGuid
.setText("Recommended Instance Guid");
410 jLabelRecommendedInstanceGuid
.setVisible(false);
411 jLabelRecommendedInstanceVersion
= new JLabel();
412 jLabelRecommendedInstanceVersion
.setBounds(new java
.awt
.Rectangle(12, 87, 200, 20));
413 jLabelRecommendedInstanceVersion
.setText("Recommended Instance Version");
414 jLabelRecommendedInstanceVersion
.setVisible(false);
415 jLabelLibraryClassName
= new JLabel();
416 jLabelLibraryClassName
.setBounds(new java
.awt
.Rectangle(12, 12, 168, 20));
417 jLabelLibraryClassName
.setText("Library Class Name");
418 jLabelUsage
= new JLabel();
419 jLabelUsage
.setBounds(new java
.awt
.Rectangle(12, 37, 168, 20));
420 jLabelUsage
.setText("Usage");
421 jContentPane
= new JPanel();
422 jContentPane
.setLayout(null);
423 jContentPane
.setPreferredSize(new java
.awt
.Dimension(495, 255));
425 jContentPane
.add(getJComboBoxLibraryClassName(), null);
426 jContentPane
.add(jLabelUsage
, null);
427 jContentPane
.add(getJComboBoxUsage(), null);
428 jContentPane
.add(jLabelLibraryClassName
, null);
429 jContentPane
.add(jLabelRecommendedInstanceVersion
, null);
430 jContentPane
.add(getJTextFieldRecommendedInstanceVersion(), null);
431 jContentPane
.add(jLabelRecommendedInstanceGuid
, null);
432 jContentPane
.add(getJTextFieldRecommendedInstanceGuid(), null);
433 jContentPane
.add(getJButtonGenerateGuid(), null);
434 jContentPane
.add(jLabelFeatureFlag
, null);
435 jContentPane
.add(getJTextFieldFeatureFlag(), null);
436 jContentPane
.add(jLabelArch
, null);
437 jStarLabel1
= new StarLabel();
438 jStarLabel1
.setLocation(new java
.awt
.Point(2, 10));
439 jStarLabel2
= new StarLabel();
440 jStarLabel2
.setLocation(new java
.awt
.Point(2, 35));
442 jContentPane
.add(jStarLabel1
, null);
443 jContentPane
.add(jStarLabel2
, null);
444 jContentPane
.add(jLabelModuleList
, null);
445 jContentPane
.add(getJScrollPaneModuleList(), null);
446 jContentPane
.add(jLabelHelpText
, null);
447 jContentPane
.add(getJTextFieldHelpText(), null);
448 jContentPane
.add(jArchCheckBox
, null);
449 jContentPane
.add(getJButtonOk(), null);
450 jContentPane
.add(getJButtonCancel(), null);
456 This method initializes all existing libraries and usage types
459 private void initFrame() {
460 Tools
.generateComboBoxByVector(jComboBoxUsage
, ed
.getVLibraryUsage());
461 this.iCheckBoxListModule
.setAllItems(ed
.getVFrameworkModuleTypes());
465 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
467 * Override actionPerformed to listen all actions
470 public void actionPerformed(ActionEvent arg0
) {
471 if (arg0
.getSource() == jButtonGenerateGuid
) {
472 this.jTextFieldRecommendedInstanceGuid
.setText(Tools
.generateUuidString());
475 if (arg0
.getSource() == jButtonOk
) {
477 getCurrentLibraryClass();
478 this.returnType
= DataType
.RETURN_TYPE_OK
;
479 this.setVisible(false);
483 if (arg0
.getSource() == jButtonCancel
) {
484 this.returnType
= DataType
.RETURN_TYPE_CANCEL
;
485 this.setVisible(false);
490 Data validation for all fields
492 @retval true - All datas are valid
493 @retval false - At least one data is invalid
496 public boolean checkAdd() {
498 // Check LibraryClass
500 if (this.jComboBoxLibraryClassName
.getSelectedItem() == null) {
501 Log
.wrn("Update Library Class Definitions", "Please select one Library Class");
504 if (!DataValidation
.isLibraryClass(this.jComboBoxLibraryClassName
.getSelectedItem().toString())) {
505 Log
.wrn("Update Library Class Definitions", "Incorrect data type for Library Class");
510 // Check RecommendedInstanceVersion
512 // if (!isEmpty(this.jTextFieldRecommendedInstanceVersion.getText())) {
513 // if (!DataValidation.isRecommendedInstanceVersion(this.jTextFieldRecommendedInstanceVersion.getText())) {
514 // Log.err("Incorrect data type for Recommended Instance Version");
520 // Check RecommendedInstanceGuid
522 // if (!isEmpty(this.jTextFieldRecommendedInstanceGuid.getText())) {
523 // if (!DataValidation.isGuid(this.jTextFieldRecommendedInstanceGuid.getText())) {
524 // Log.err("Incorrect data type for Recommended Instance Guid");
532 if (!isEmpty(this.jTextFieldFeatureFlag
.getText())) {
533 if (!DataValidation
.isFeatureFlag(this.jTextFieldFeatureFlag
.getText())) {
534 Log
.wrn("Update Library Class Definitions", "Incorrect data type for Feature Flag");
540 // Check if the library is produced
542 String strUsage
= this.jComboBoxUsage
.getSelectedItem().toString();
544 // Check only when the library class is consumed
546 if (strUsage
.equals(DataType
.USAGE_TYPE_ALWAYS_CONSUMED
) || strUsage
.equals(DataType
.USAGE_TYPE_SOMETIMES_CONSUMED
)) {
547 LibraryClassVector v
= Find
.getAllLibraryClassVector();
548 boolean isFind
= false;
549 for (int index
= 0; index
< v
.size(); index
++) {
550 LibraryClassIdentification lid
= v
.getLibraryClass(index
);
551 if (lid
.getLibraryClassName().equals(this.jComboBoxLibraryClassName
.getSelectedItem().toString())) {
552 if (lid
.getUsage().equals(DataType
.USAGE_TYPE_ALWAYS_PRODUCED
)
553 || lid
.getUsage().equals(DataType
.USAGE_TYPE_SOMETIMES_PRODUCED
)) {
560 Log
.wrn("Update Library Class Definitions", "This Library Class has no instance yet. It may have some errors in build time.");
568 private LibraryClassIdentification
getCurrentLibraryClass() {
569 String name
= this.jComboBoxLibraryClassName
.getSelectedItem().toString();
570 String usage
= this.jComboBoxUsage
.getSelectedItem().toString();
571 String version
= this.jTextFieldRecommendedInstanceVersion
.getText();
572 String guid
= this.jTextFieldRecommendedInstanceGuid
.getText();
573 String featureFlag
= this.jTextFieldFeatureFlag
.getText();
574 Vector
<String
> arch
= this.jArchCheckBox
.getSelectedItemsVector();
575 Vector
<String
> module
= this.iCheckBoxListModule
.getAllCheckedItemsString();
576 String help
= this.jTextFieldHelpText
.getText();
577 lcid
= new LibraryClassIdentification(name
, usage
, version
, guid
, arch
, featureFlag
, module
, help
);
581 public LibraryClassIdentification
getLcid() {
585 public void setLcid(LibraryClassIdentification lcid
) {