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
.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
;
44 * The class is used to create, update Library Class Definition section of the MSA file
49 public class LibraryClassDefsDlg
extends IDialog
{
52 /// Define class Serial Version UID
54 private static final long serialVersionUID
= -1743248695411382857L;
57 //Define class members
59 private JPanel jContentPane
= null;
61 private JComboBox jComboBoxLibraryClassName
= null;
63 private JLabel jLabelUsage
= null;
65 private JComboBox jComboBoxUsage
= null;
67 private JLabel jLabelLibraryClassName
= null;
69 private JScrollPane jScrollPane
= null;
71 private StarLabel jStarLabel1
= null;
73 private StarLabel jStarLabel2
= null;
75 private JLabel jLabelRecommendedInstanceVersion
= null;
77 private JTextField jTextFieldRecommendedInstanceVersion
= null;
79 private JLabel jLabelRecommendedInstanceGuid
= null;
81 private JTextField jTextFieldRecommendedInstanceGuid
= null;
83 private JButton jButtonGenerateGuid
= null;
85 private JLabel jLabelFeatureFlag
= null;
87 private JTextField jTextFieldFeatureFlag
= null;
89 private JLabel jLabelArch
= null;
91 private JLabel jLabelModuleList
= null;
93 private JScrollPane jScrollPaneModuleList
= null;
95 private ICheckBoxList iCheckBoxListModule
= null;
97 private JLabel jLabelHelpText
= null;
99 private JTextField jTextFieldHelpText
= null;
101 private ArchCheckBox jArchCheckBox
= null;
103 private JButton jButtonOk
= null;
105 private JButton jButtonCancel
= null;
110 private EnumerationData ed
= new EnumerationData();
112 private WorkspaceTools wt
= new WorkspaceTools();
114 private LibraryClassIdentification lcid
= null;
117 This method initializes jComboBoxSelect
119 @return javax.swing.JComboBox jComboBoxSelect
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);
129 return jComboBoxLibraryClassName
;
133 This method initializes jComboBoxUsage
135 @return javax.swing.JComboBox jComboBoxUsage
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));
144 return jComboBoxUsage
;
148 This method initializes jScrollPane
150 @return javax.swing.JScrollPane
152 private JScrollPane
getJScrollPane() {
153 if (jScrollPane
== null) {
154 jScrollPane
= new JScrollPane();
155 jScrollPane
.setViewportView(getJContentPane());
161 * This method initializes jTextFieldRecommendedInstanceVersion
163 * @return javax.swing.JTextField
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);
173 return jTextFieldRecommendedInstanceVersion
;
177 * This method initializes jTextFieldRecommendedInstanceGuid
179 * @return javax.swing.JTextField
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);
188 return jTextFieldRecommendedInstanceGuid
;
192 * This method initializes jButtonGenerateGuid
194 * @return javax.swing.JButton
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);
205 return jButtonGenerateGuid
;
209 * This method initializes jTextFieldFeatureFlag
211 * @return javax.swing.JTextField
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);
221 return jTextFieldFeatureFlag
;
225 This method initializes iCheckBoxListArch
227 @return ICheckBoxList
229 private ICheckBoxList
getICheckBoxListSupModuleList() {
230 if (iCheckBoxListModule
== null) {
231 iCheckBoxListModule
= new ICheckBoxList();
233 return iCheckBoxListModule
;
237 This method initializes jScrollPaneModuleList
239 @return javax.swing.JScrollPane
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());
249 return jScrollPaneModuleList
;
253 This method initializes jTextFieldHelpText
255 @return javax.swing.JTextField
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));
264 return jTextFieldHelpText
;
268 This method initializes jButtonOk
270 @return javax.swing.JButton
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);
284 This method initializes jButtonCancel
286 @return javax.swing.JButton
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);
296 return jButtonCancel
;
299 public static void main(String
[] args
) {
304 This is the default constructor
307 public LibraryClassDefsDlg(LibraryClassIdentification inLibraryClassIdentification
, IFrame iFrame
, ModuleIdentification mid
) {
309 init(inLibraryClassIdentification
, mid
);
313 This method initializes this
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));
321 this.setViewMode(false);
326 This method initializes this
329 private void init(LibraryClassIdentification inLibraryClassIdentification
, ModuleIdentification mid
) {
331 this.lcid
= inLibraryClassIdentification
;
334 // Init arch with module's arch
336 this.jArchCheckBox
.setEnabledItems(wt
.getModuleArch(mid
));
339 // Get defined library classes from dependent packages
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");
346 Tools
.generateComboBoxByVector(this.jComboBoxLibraryClassName
,
347 wt
.getAllLibraryClassDefinitionsFromPackages(wt
.getPackageDependenciesOfModule(mid
)));
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());
363 Disable all components when the mode is view
365 @param isView true - The view mode; false - The non-view mode
368 public void setViewMode(boolean isView
) {
370 this.jComboBoxLibraryClassName
.setEnabled(!isView
);
371 this.jComboBoxUsage
.setEnabled(!isView
);
376 This method initializes jContentPane
378 @return javax.swing.JPanel jContentPane
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));
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));
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);
448 This method initializes all existing libraries and usage types
451 private void initFrame() {
452 Tools
.generateComboBoxByVector(jComboBoxUsage
, ed
.getVLibraryUsage());
453 this.iCheckBoxListModule
.setAllItems(ed
.getVFrameworkModuleTypes());
457 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
459 * Override actionPerformed to listen all actions
462 public void actionPerformed(ActionEvent arg0
) {
463 if (arg0
.getSource() == jButtonGenerateGuid
) {
464 this.jTextFieldRecommendedInstanceGuid
.setText(Tools
.generateUuidString());
467 if (arg0
.getSource() == jButtonOk
) {
469 getCurrentLibraryClass();
470 this.returnType
= DataType
.RETURN_TYPE_OK
;
471 this.setVisible(false);
475 if (arg0
.getSource() == jButtonCancel
) {
476 this.returnType
= DataType
.RETURN_TYPE_CANCEL
;
477 this.setVisible(false);
482 Data validation for all fields
484 @retval true - All datas are valid
485 @retval false - At least one data is invalid
488 public boolean checkAdd() {
490 // Check LibraryClass
492 if (this.jComboBoxLibraryClassName
.getSelectedItem() == null) {
493 Log
.wrn("Update Library Class Definitions", "Please select one Library Class");
496 if (!DataValidation
.isLibraryClass(this.jComboBoxLibraryClassName
.getSelectedItem().toString())) {
497 Log
.wrn("Update Library Class Definitions", "Incorrect data type for Library Class");
502 // Check RecommendedInstanceVersion
504 // if (!isEmpty(this.jTextFieldRecommendedInstanceVersion.getText())) {
505 // if (!DataValidation.isRecommendedInstanceVersion(this.jTextFieldRecommendedInstanceVersion.getText())) {
506 // Log.err("Incorrect data type for Recommended Instance Version");
512 // Check RecommendedInstanceGuid
514 // if (!isEmpty(this.jTextFieldRecommendedInstanceGuid.getText())) {
515 // if (!DataValidation.isGuid(this.jTextFieldRecommendedInstanceGuid.getText())) {
516 // Log.err("Incorrect data type for Recommended Instance Guid");
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");
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
);
547 public LibraryClassIdentification
getLcid() {
551 public void setLcid(LibraryClassIdentification lcid
) {