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
.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
;
47 * The class is used to create, update Library Class Definition section of the MSA file
52 public class LibraryClassDefsDlg
extends IDialog
{
55 /// Define class Serial Version UID
57 private static final long serialVersionUID
= -1743248695411382857L;
60 //Define class members
62 private JPanel jContentPane
= null;
64 private IComboBox iComboBoxLibraryClassName
= null;
66 private JLabel jLabelUsage
= null;
68 private JComboBox jComboBoxUsage
= null;
70 private JLabel jLabelLibraryClassName
= null;
72 private JScrollPane jScrollPane
= null;
74 private StarLabel jStarLabel1
= null;
76 private StarLabel jStarLabel2
= null;
78 private JLabel jLabelRecommendedInstanceVersion
= null;
80 private JTextField jTextFieldRecommendedInstanceVersion
= null;
82 private JLabel jLabelRecommendedInstanceGuid
= null;
84 private JTextField jTextFieldRecommendedInstanceGuid
= null;
86 private JButton jButtonGenerateGuid
= null;
88 private JLabel jLabelFeatureFlag
= null;
90 private JTextField jTextFieldFeatureFlag
= null;
92 private JLabel jLabelArch
= null;
94 private JLabel jLabelModuleList
= null;
96 private JScrollPane jScrollPaneModuleList
= null;
98 private ICheckBoxList iCheckBoxListModule
= null;
100 private JLabel jLabelHelpText
= null;
102 private JTextField jTextFieldHelpText
= null;
104 private ArchCheckBox jArchCheckBox
= null;
106 private JButton jButtonOk
= null;
108 private JButton jButtonCancel
= null;
113 private EnumerationData ed
= new EnumerationData();
115 private WorkspaceTools wt
= new WorkspaceTools();
117 private LibraryClassIdentification lcid
= null;
120 This method initializes jComboBoxSelect
122 @return javax.swing.JComboBox jComboBoxSelect
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);
132 return iComboBoxLibraryClassName
;
136 This method initializes jComboBoxUsage
138 @return javax.swing.JComboBox jComboBoxUsage
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));
147 return jComboBoxUsage
;
151 This method initializes jScrollPane
153 @return javax.swing.JScrollPane
155 private JScrollPane
getJScrollPane() {
156 if (jScrollPane
== null) {
157 jScrollPane
= new JScrollPane();
158 jScrollPane
.setViewportView(getJContentPane());
164 * This method initializes jTextFieldRecommendedInstanceVersion
166 * @return javax.swing.JTextField
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);
176 return jTextFieldRecommendedInstanceVersion
;
180 * This method initializes jTextFieldRecommendedInstanceGuid
182 * @return javax.swing.JTextField
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);
191 return jTextFieldRecommendedInstanceGuid
;
195 * This method initializes jButtonGenerateGuid
197 * @return javax.swing.JButton
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);
208 return jButtonGenerateGuid
;
212 * This method initializes jTextFieldFeatureFlag
214 * @return javax.swing.JTextField
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);
224 return jTextFieldFeatureFlag
;
228 This method initializes iCheckBoxListArch
230 @return ICheckBoxList
232 private ICheckBoxList
getICheckBoxListSupModuleList() {
233 if (iCheckBoxListModule
== null) {
234 iCheckBoxListModule
= new ICheckBoxList();
236 return iCheckBoxListModule
;
240 This method initializes jScrollPaneModuleList
242 @return javax.swing.JScrollPane
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());
252 return jScrollPaneModuleList
;
256 This method initializes jTextFieldHelpText
258 @return javax.swing.JTextField
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));
267 return jTextFieldHelpText
;
271 This method initializes jButtonOk
273 @return javax.swing.JButton
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);
287 This method initializes jButtonCancel
289 @return javax.swing.JButton
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);
299 return jButtonCancel
;
302 public static void main(String
[] args
) {
307 This is the default constructor
310 public LibraryClassDefsDlg(LibraryClassIdentification inLibraryClassIdentification
, IFrame iFrame
,
311 ModuleIdentification mid
) {
313 init(inLibraryClassIdentification
, mid
);
317 This method initializes this
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));
325 this.setViewMode(false);
330 This method initializes this
333 private void init(LibraryClassIdentification inLibraryClassIdentification
, ModuleIdentification mid
) {
335 this.lcid
= inLibraryClassIdentification
;
338 // Init arch with module's arch
340 this.jArchCheckBox
.setEnabledItems(wt
.getModuleArch(mid
));
343 // Get defined library classes from dependent packages
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");
352 .generateComboBoxByVector(
353 this.iComboBoxLibraryClassName
,
355 .getAllLibraryClassDefinitionsFromPackages(wt
356 .getPackageDependenciesOfModule(mid
)));
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());
372 Disable all components when the mode is view
374 @param isView true - The view mode; false - The non-view mode
377 public void setViewMode(boolean isView
) {
379 this.iComboBoxLibraryClassName
.setEnabled(!isView
);
380 this.jComboBoxUsage
.setEnabled(!isView
);
385 This method initializes jContentPane
387 @return javax.swing.JPanel jContentPane
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));
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));
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);
457 This method initializes all existing libraries and usage types
460 private void initFrame() {
461 Tools
.generateComboBoxByVector(jComboBoxUsage
, ed
.getVLibraryUsage());
462 this.iCheckBoxListModule
.setAllItems(ed
.getVFrameworkModuleTypes());
466 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
468 * Override actionPerformed to listen all actions
471 public void actionPerformed(ActionEvent arg0
) {
472 if (arg0
.getSource() == jButtonGenerateGuid
) {
473 this.jTextFieldRecommendedInstanceGuid
.setText(Tools
.generateUuidString());
476 if (arg0
.getSource() == jButtonOk
) {
478 getCurrentLibraryClass();
479 this.returnType
= DataType
.RETURN_TYPE_OK
;
480 this.setVisible(false);
484 if (arg0
.getSource() == jButtonCancel
) {
485 this.returnType
= DataType
.RETURN_TYPE_CANCEL
;
486 this.setVisible(false);
491 Data validation for all fields
493 @retval true - All datas are valid
494 @retval false - At least one data is invalid
497 public boolean checkAdd() {
499 // Check LibraryClass
501 if (this.iComboBoxLibraryClassName
.getSelectedItem() == null) {
502 Log
.wrn("Update Library Class Definitions", "Please select one Library Class");
505 if (!DataValidation
.isLibraryClass(this.iComboBoxLibraryClassName
.getSelectedItem().toString())) {
506 Log
.wrn("Update Library Class Definitions", "Incorrect data type for Library Class");
511 // Check RecommendedInstanceVersion
513 // if (!isEmpty(this.jTextFieldRecommendedInstanceVersion.getText())) {
514 // if (!DataValidation.isRecommendedInstanceVersion(this.jTextFieldRecommendedInstanceVersion.getText())) {
515 // Log.err("Incorrect data type for Recommended Instance Version");
521 // Check RecommendedInstanceGuid
523 // if (!isEmpty(this.jTextFieldRecommendedInstanceGuid.getText())) {
524 // if (!DataValidation.isGuid(this.jTextFieldRecommendedInstanceGuid.getText())) {
525 // Log.err("Incorrect data type for Recommended Instance Guid");
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");
541 // Check if the library is produced
543 String strUsage
= this.jComboBoxUsage
.getSelectedItem().toString();
545 // Check only when the library class is consumed
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
)) {
561 Log
.wrn("Update Library Class Definitions", "This Library Class has no instance yet. It may have some errors in build time.");
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
);
582 public LibraryClassIdentification
getLcid() {
586 public void setLcid(LibraryClassIdentification lcid
) {