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
.LibraryClass
.LibraryClassIdentification
;
39 import org
.tianocore
.frameworkwizard
.workspace
.WorkspaceTools
;
42 * The class is used to create, update Library Class Definition of MSA/MBD file
47 public class LibraryClassDefsDlg
extends IDialog
{
50 /// Define class Serial Version UID
52 private static final long serialVersionUID
= -1743248695411382857L;
55 //Define class members
57 private JPanel jContentPane
= null;
59 private JComboBox jComboBoxLibraryClassName
= null;
61 private JLabel jLabelUsage
= null;
63 private JComboBox jComboBoxUsage
= null;
65 private JLabel jLabelLibraryClassName
= null;
67 private JScrollPane jScrollPane
= null;
69 private StarLabel jStarLabel1
= null;
71 private StarLabel jStarLabel2
= null;
73 private JLabel jLabelRecommendedInstanceVersion
= null;
75 private JTextField jTextFieldRecommendedInstanceVersion
= null;
77 private JLabel jLabelRecommendedInstanceGuid
= null;
79 private JTextField jTextFieldRecommendedInstanceGuid
= null;
81 private JButton jButtonGenerateGuid
= null;
83 private JLabel jLabelFeatureFlag
= null;
85 private JTextField jTextFieldFeatureFlag
= null;
87 private JLabel jLabelArch
= null;
89 private JLabel jLabelModuleList
= null;
91 private JScrollPane jScrollPaneModuleList
= null;
93 private ICheckBoxList iCheckBoxListModule
= null;
95 private JLabel jLabelHelpText
= null;
97 private JTextField jTextFieldHelpText
= null;
99 private ArchCheckBox jArchCheckBox
= null;
101 private JButton jButtonOk
= null;
103 private JButton jButtonCancel
= null;
108 private EnumerationData ed
= new EnumerationData();
110 private WorkspaceTools wt
= new WorkspaceTools();
112 private LibraryClassIdentification lcid
= null;
115 This method initializes jComboBoxSelect
117 @return javax.swing.JComboBox jComboBoxSelect
120 private JComboBox
getJComboBoxLibraryClassName() {
121 if (jComboBoxLibraryClassName
== null) {
122 jComboBoxLibraryClassName
= new JComboBox();
123 jComboBoxLibraryClassName
.setBounds(new java
.awt
.Rectangle(168, 12, 320, 20));
124 jComboBoxLibraryClassName
.setPreferredSize(new Dimension(320, 20));
125 jComboBoxLibraryClassName
.setEnabled(true);
127 return jComboBoxLibraryClassName
;
131 This method initializes jComboBoxUsage
133 @return javax.swing.JComboBox jComboBoxUsage
136 private JComboBox
getJComboBoxUsage() {
137 if (jComboBoxUsage
== null) {
138 jComboBoxUsage
= new JComboBox();
139 jComboBoxUsage
.setBounds(new java
.awt
.Rectangle(168, 37, 320, 20));
140 jComboBoxUsage
.setPreferredSize(new Dimension(320, 20));
142 return jComboBoxUsage
;
146 This method initializes jScrollPane
148 @return javax.swing.JScrollPane
150 private JScrollPane
getJScrollPane() {
151 if (jScrollPane
== null) {
152 jScrollPane
= new JScrollPane();
153 jScrollPane
.setViewportView(getJContentPane());
159 * This method initializes jTextFieldRecommendedInstanceVersion
161 * @return javax.swing.JTextField
163 private JTextField
getJTextFieldRecommendedInstanceVersion() {
164 if (jTextFieldRecommendedInstanceVersion
== null) {
165 jTextFieldRecommendedInstanceVersion
= new JTextField();
166 jTextFieldRecommendedInstanceVersion
.setPreferredSize(new java
.awt
.Dimension(260, 20));
167 jTextFieldRecommendedInstanceVersion
.setSize(new java
.awt
.Dimension(260, 20));
168 jTextFieldRecommendedInstanceVersion
.setLocation(new java
.awt
.Point(220, 85));
169 jTextFieldRecommendedInstanceVersion
.setVisible(false);
171 return jTextFieldRecommendedInstanceVersion
;
175 * This method initializes jTextFieldRecommendedInstanceGuid
177 * @return javax.swing.JTextField
179 private JTextField
getJTextFieldRecommendedInstanceGuid() {
180 if (jTextFieldRecommendedInstanceGuid
== null) {
181 jTextFieldRecommendedInstanceGuid
= new JTextField();
182 jTextFieldRecommendedInstanceGuid
.setBounds(new java
.awt
.Rectangle(220, 110, 190, 20));
183 jTextFieldRecommendedInstanceGuid
.setPreferredSize(new java
.awt
.Dimension(190, 20));
184 jTextFieldRecommendedInstanceGuid
.setVisible(false);
186 return jTextFieldRecommendedInstanceGuid
;
190 * This method initializes jButtonGenerateGuid
192 * @return javax.swing.JButton
194 private JButton
getJButtonGenerateGuid() {
195 if (jButtonGenerateGuid
== null) {
196 jButtonGenerateGuid
= new JButton();
197 jButtonGenerateGuid
.setBounds(new java
.awt
.Rectangle(415, 112, 65, 20));
198 jButtonGenerateGuid
.setPreferredSize(new java
.awt
.Dimension(65, 20));
199 jButtonGenerateGuid
.setText("GEN");
200 jButtonGenerateGuid
.setVisible(false);
201 jButtonGenerateGuid
.addActionListener(this);
203 return jButtonGenerateGuid
;
207 * This method initializes jTextFieldFeatureFlag
209 * @return javax.swing.JTextField
211 private JTextField
getJTextFieldFeatureFlag() {
212 if (jTextFieldFeatureFlag
== null) {
213 jTextFieldFeatureFlag
= new JTextField();
214 jTextFieldFeatureFlag
.setBounds(new java
.awt
.Rectangle(168, 87, 320, 20));
215 jTextFieldFeatureFlag
.setPreferredSize(new java
.awt
.Dimension(320, 20));
216 jTextFieldFeatureFlag
.setToolTipText("Postfix expression that must evaluate to TRUE or FALSE");
218 return jTextFieldFeatureFlag
;
222 This method initializes iCheckBoxListArch
224 @return ICheckBoxList
226 private ICheckBoxList
getICheckBoxListSupModuleList() {
227 if (iCheckBoxListModule
== null) {
228 iCheckBoxListModule
= new ICheckBoxList();
230 return iCheckBoxListModule
;
234 This method initializes jScrollPaneModuleList
236 @return javax.swing.JScrollPane
239 private JScrollPane
getJScrollPaneModuleList() {
240 if (jScrollPaneModuleList
== null) {
241 jScrollPaneModuleList
= new JScrollPane();
242 jScrollPaneModuleList
.setBounds(new java
.awt
.Rectangle(168, 137, 320, 80));
243 jScrollPaneModuleList
.setPreferredSize(new java
.awt
.Dimension(320, 80));
244 jScrollPaneModuleList
.setViewportView(getICheckBoxListSupModuleList());
246 return jScrollPaneModuleList
;
250 This method initializes jTextFieldHelpText
252 @return javax.swing.JTextField
255 private JTextField
getJTextFieldHelpText() {
256 if (jTextFieldHelpText
== null) {
257 jTextFieldHelpText
= new JTextField();
258 jTextFieldHelpText
.setBounds(new java
.awt
.Rectangle(168, 62, 320, 20));
259 jTextFieldHelpText
.setPreferredSize(new java
.awt
.Dimension(320, 20));
261 return jTextFieldHelpText
;
265 This method initializes jButtonOk
267 @return javax.swing.JButton
270 private JButton
getJButtonOk() {
271 if (jButtonOk
== null) {
272 jButtonOk
= new JButton();
273 jButtonOk
.setBounds(new java
.awt
.Rectangle(300, 232, 90, 20));
274 jButtonOk
.setText("Ok");
275 jButtonOk
.addActionListener(this);
281 This method initializes jButtonCancel
283 @return javax.swing.JButton
286 private JButton
getJButtonCancel() {
287 if (jButtonCancel
== null) {
288 jButtonCancel
= new JButton();
289 jButtonCancel
.setBounds(new java
.awt
.Rectangle(400, 232, 90, 20));
290 jButtonCancel
.setText("Cancel");
291 jButtonCancel
.addActionListener(this);
293 return jButtonCancel
;
296 public static void main(String
[] args
) {
301 This is the default constructor
304 public LibraryClassDefsDlg(LibraryClassIdentification inLibraryClassIdentification
, IFrame iFrame
) {
306 init(inLibraryClassIdentification
);
310 This method initializes this
313 private void init() {
314 this.setContentPane(getJScrollPane());
315 this.setTitle("Library Class Definitions");
316 this.setBounds(new java
.awt
.Rectangle(0, 0, 505, 305));
318 this.setViewMode(false);
323 This method initializes this
326 private void init(LibraryClassIdentification inLibraryClassIdentification
) {
328 this.lcid
= inLibraryClassIdentification
;
330 this.jComboBoxLibraryClassName
.setSelectedItem(lcid
.getLibraryClassName());
331 this.jComboBoxUsage
.setSelectedItem(lcid
.getUsage());
332 this.jTextFieldRecommendedInstanceVersion
.setText(lcid
.getRecommendedInstanceVersion());
333 this.jTextFieldRecommendedInstanceGuid
.setText(lcid
.getRecommendedInstanceGuid());
334 this.jTextFieldFeatureFlag
.setText(lcid
.getFeatureFlag());
335 this.jArchCheckBox
.setSelectedItems(lcid
.getSupArchList());
336 this.iCheckBoxListModule
.setAllItemsUnchecked();
337 this.iCheckBoxListModule
.initCheckedItem(true, lcid
.getSupModuleList());
338 this.jTextFieldHelpText
.setText(lcid
.getHelp());
343 Disable all components when the mode is view
345 @param isView true - The view mode; false - The non-view mode
348 public void setViewMode(boolean isView
) {
350 this.jComboBoxLibraryClassName
.setEnabled(!isView
);
351 this.jComboBoxUsage
.setEnabled(!isView
);
356 This method initializes jContentPane
358 @return javax.swing.JPanel jContentPane
361 private JPanel
getJContentPane() {
362 if (jContentPane
== null) {
363 jArchCheckBox
= new ArchCheckBox();
364 jArchCheckBox
.setBounds(new java
.awt
.Rectangle(168, 112, 320, 20));
365 jArchCheckBox
.setPreferredSize(new java
.awt
.Dimension(320, 20));
366 jLabelHelpText
= new JLabel();
367 jLabelHelpText
.setBounds(new java
.awt
.Rectangle(12, 62, 168, 20));
368 jLabelHelpText
.setText("Help Text");
369 jLabelModuleList
= new JLabel();
370 jLabelModuleList
.setBounds(new java
.awt
.Rectangle(12, 137, 168, 20));
371 jLabelModuleList
.setText("Supported Module Types");
372 jLabelArch
= new JLabel();
373 jLabelArch
.setBounds(new java
.awt
.Rectangle(12, 112, 168, 20));
374 jLabelArch
.setText("Supported Architectures");
375 jLabelFeatureFlag
= new JLabel();
376 jLabelFeatureFlag
.setBounds(new java
.awt
.Rectangle(12, 87, 168, 20));
377 jLabelFeatureFlag
.setText("Feature Flag Expression");
378 jLabelRecommendedInstanceGuid
= new JLabel();
379 jLabelRecommendedInstanceGuid
.setBounds(new java
.awt
.Rectangle(12, 112, 200, 20));
380 jLabelRecommendedInstanceGuid
.setText("Recommended Instance Guid");
381 jLabelRecommendedInstanceGuid
.setVisible(false);
382 jLabelRecommendedInstanceVersion
= new JLabel();
383 jLabelRecommendedInstanceVersion
.setBounds(new java
.awt
.Rectangle(12, 87, 200, 20));
384 jLabelRecommendedInstanceVersion
.setText("Recommended Instance Version");
385 jLabelRecommendedInstanceVersion
.setVisible(false);
386 jLabelLibraryClassName
= new JLabel();
387 jLabelLibraryClassName
.setBounds(new java
.awt
.Rectangle(12, 12, 168, 20));
388 jLabelLibraryClassName
.setText("Library Class Name");
389 jLabelUsage
= new JLabel();
390 jLabelUsage
.setBounds(new java
.awt
.Rectangle(12, 37, 168, 20));
391 jLabelUsage
.setText("Usage");
392 jContentPane
= new JPanel();
393 jContentPane
.setLayout(null);
394 jContentPane
.setPreferredSize(new java
.awt
.Dimension(495, 255));
396 jContentPane
.add(getJComboBoxLibraryClassName(), null);
397 jContentPane
.add(jLabelUsage
, null);
398 jContentPane
.add(getJComboBoxUsage(), null);
399 jContentPane
.add(jLabelLibraryClassName
, null);
400 jContentPane
.add(jLabelRecommendedInstanceVersion
, null);
401 jContentPane
.add(getJTextFieldRecommendedInstanceVersion(), null);
402 jContentPane
.add(jLabelRecommendedInstanceGuid
, null);
403 jContentPane
.add(getJTextFieldRecommendedInstanceGuid(), null);
404 jContentPane
.add(getJButtonGenerateGuid(), null);
405 jContentPane
.add(jLabelFeatureFlag
, null);
406 jContentPane
.add(getJTextFieldFeatureFlag(), null);
407 jContentPane
.add(jLabelArch
, null);
408 jStarLabel1
= new StarLabel();
409 jStarLabel1
.setLocation(new java
.awt
.Point(2, 10));
410 jStarLabel2
= new StarLabel();
411 jStarLabel2
.setLocation(new java
.awt
.Point(2, 35));
413 jContentPane
.add(jStarLabel1
, null);
414 jContentPane
.add(jStarLabel2
, null);
415 jContentPane
.add(jLabelModuleList
, null);
416 jContentPane
.add(getJScrollPaneModuleList(), null);
417 jContentPane
.add(jLabelHelpText
, null);
418 jContentPane
.add(getJTextFieldHelpText(), null);
419 jContentPane
.add(jArchCheckBox
, null);
420 jContentPane
.add(getJButtonOk(), null);
421 jContentPane
.add(getJButtonCancel(), null);
427 This method initializes all existing libraries and usage types
430 private void initFrame() {
431 Tools
.generateComboBoxByVector(jComboBoxLibraryClassName
, wt
.getAllLibraryClassDefinitionsFromWorkspace());
432 Tools
.generateComboBoxByVector(jComboBoxUsage
, ed
.getVLibraryUsage());
433 this.iCheckBoxListModule
.setAllItems(ed
.getVFrameworkModuleTypes());
437 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
439 * Override actionPerformed to listen all actions
442 public void actionPerformed(ActionEvent arg0
) {
443 if (arg0
.getSource() == jButtonGenerateGuid
) {
444 this.jTextFieldRecommendedInstanceGuid
.setText(Tools
.generateUuidString());
447 if (arg0
.getSource() == jButtonOk
) {
449 getCurrentLibraryClass();
450 this.returnType
= DataType
.RETURN_TYPE_OK
;
451 this.setVisible(false);
455 if (arg0
.getSource() == jButtonCancel
) {
456 this.returnType
= DataType
.RETURN_TYPE_CANCEL
;
457 this.setVisible(false);
462 Data validation for all fields
464 @retval true - All datas are valid
465 @retval false - At least one data is invalid
468 public boolean checkAdd() {
470 // Check LibraryClass
472 if (this.jComboBoxLibraryClassName
.getSelectedItem() == null) {
473 Log
.wrn("Update Library Class Definitions", "No Library Class can be added");
476 if (!DataValidation
.isLibraryClass(this.jComboBoxLibraryClassName
.getSelectedItem().toString())) {
477 Log
.wrn("Update Library Class Definitions", "Incorrect data type for Library Class");
482 // Check RecommendedInstanceVersion
484 // if (!isEmpty(this.jTextFieldRecommendedInstanceVersion.getText())) {
485 // if (!DataValidation.isRecommendedInstanceVersion(this.jTextFieldRecommendedInstanceVersion.getText())) {
486 // Log.err("Incorrect data type for Recommended Instance Version");
492 // Check RecommendedInstanceGuid
494 // if (!isEmpty(this.jTextFieldRecommendedInstanceGuid.getText())) {
495 // if (!DataValidation.isGuid(this.jTextFieldRecommendedInstanceGuid.getText())) {
496 // Log.err("Incorrect data type for Recommended Instance Guid");
504 if (!isEmpty(this.jTextFieldFeatureFlag
.getText())) {
505 if (!DataValidation
.isFeatureFlag(this.jTextFieldFeatureFlag
.getText())) {
506 Log
.wrn("Update Library Class Definitions", "Incorrect data type for Feature Flag");
514 private LibraryClassIdentification
getCurrentLibraryClass() {
515 String name
= this.jComboBoxLibraryClassName
.getSelectedItem().toString();
516 String usage
= this.jComboBoxUsage
.getSelectedItem().toString();
517 String version
= this.jTextFieldRecommendedInstanceVersion
.getText();
518 String guid
= this.jTextFieldRecommendedInstanceGuid
.getText();
519 String featureFlag
= this.jTextFieldFeatureFlag
.getText();
520 Vector
<String
> arch
= this.jArchCheckBox
.getSelectedItemsVector();
521 Vector
<String
> module
= this.iCheckBoxListModule
.getAllCheckedItemsString();
522 String help
= this.jTextFieldHelpText
.getText();
523 lcid
= new LibraryClassIdentification(name
, usage
, version
, guid
, arch
, featureFlag
, module
, help
);
527 public LibraryClassIdentification
getLcid() {
531 public void setLcid(LibraryClassIdentification lcid
) {