3 The file is used to create, update Library Class Definition of MSA/MBD 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
43 It extends IInternalFrame
46 public class LibraryClassDefsDlg
extends IDialog
{
49 /// Define class Serial Version UID
51 private static final long serialVersionUID
= -1743248695411382857L;
54 //Define class members
56 private JPanel jContentPane
= null;
58 private JComboBox jComboBoxLibraryClassName
= null;
60 private JLabel jLabelUsage
= null;
62 private JComboBox jComboBoxUsage
= null;
64 private JLabel jLabelLibraryClassName
= null;
66 private JScrollPane jScrollPane
= null;
68 private StarLabel jStarLabel1
= null;
70 private StarLabel jStarLabel2
= null;
72 private JLabel jLabelRecommendedInstanceVersion
= null;
74 private JTextField jTextFieldRecommendedInstanceVersion
= null;
76 private JLabel jLabelRecommendedInstanceGuid
= null;
78 private JTextField jTextFieldRecommendedInstanceGuid
= null;
80 private JButton jButtonGenerateGuid
= null;
82 private JLabel jLabelFeatureFlag
= null;
84 private JTextField jTextFieldFeatureFlag
= null;
86 private JLabel jLabelArch
= null;
88 private JLabel jLabelModuleList
= null;
90 private JScrollPane jScrollPaneModuleList
= null;
92 private ICheckBoxList iCheckBoxListModule
= null;
94 private JLabel jLabelHelpText
= null;
96 private JTextField jTextFieldHelpText
= null;
98 private ArchCheckBox jArchCheckBox
= null;
100 private JButton jButtonOk
= null;
102 private JButton jButtonCancel
= null;
107 private EnumerationData ed
= new EnumerationData();
109 private WorkspaceTools wt
= new WorkspaceTools();
111 private LibraryClassIdentification lcid
= null;
114 This method initializes jComboBoxSelect
116 @return javax.swing.JComboBox jComboBoxSelect
119 private JComboBox
getJComboBoxLibraryClassName() {
120 if (jComboBoxLibraryClassName
== null) {
121 jComboBoxLibraryClassName
= new JComboBox();
122 jComboBoxLibraryClassName
.setBounds(new java
.awt
.Rectangle(160, 10, 320, 20));
123 jComboBoxLibraryClassName
.setPreferredSize(new Dimension(320, 20));
124 jComboBoxLibraryClassName
.setEnabled(true);
126 return jComboBoxLibraryClassName
;
130 This method initializes jComboBoxUsage
132 @return javax.swing.JComboBox jComboBoxUsage
135 private JComboBox
getJComboBoxUsage() {
136 if (jComboBoxUsage
== null) {
137 jComboBoxUsage
= new JComboBox();
138 jComboBoxUsage
.setBounds(new java
.awt
.Rectangle(160, 35, 320, 20));
139 jComboBoxUsage
.setPreferredSize(new Dimension(320, 20));
141 return jComboBoxUsage
;
145 This method initializes jScrollPane
147 @return javax.swing.JScrollPane
149 private JScrollPane
getJScrollPane() {
150 if (jScrollPane
== null) {
151 jScrollPane
= new JScrollPane();
152 jScrollPane
.setViewportView(getJContentPane());
158 * This method initializes jTextFieldRecommendedInstanceVersion
160 * @return javax.swing.JTextField
162 private JTextField
getJTextFieldRecommendedInstanceVersion() {
163 if (jTextFieldRecommendedInstanceVersion
== null) {
164 jTextFieldRecommendedInstanceVersion
= new JTextField();
165 jTextFieldRecommendedInstanceVersion
.setPreferredSize(new java
.awt
.Dimension(260, 20));
166 jTextFieldRecommendedInstanceVersion
.setSize(new java
.awt
.Dimension(260, 20));
167 jTextFieldRecommendedInstanceVersion
.setLocation(new java
.awt
.Point(220, 85));
168 jTextFieldRecommendedInstanceVersion
.setVisible(false);
170 return jTextFieldRecommendedInstanceVersion
;
174 * This method initializes jTextFieldRecommendedInstanceGuid
176 * @return javax.swing.JTextField
178 private JTextField
getJTextFieldRecommendedInstanceGuid() {
179 if (jTextFieldRecommendedInstanceGuid
== null) {
180 jTextFieldRecommendedInstanceGuid
= new JTextField();
181 jTextFieldRecommendedInstanceGuid
.setBounds(new java
.awt
.Rectangle(220, 110, 190, 20));
182 jTextFieldRecommendedInstanceGuid
.setPreferredSize(new java
.awt
.Dimension(190, 20));
183 jTextFieldRecommendedInstanceGuid
.setVisible(false);
185 return jTextFieldRecommendedInstanceGuid
;
189 * This method initializes jButtonGenerateGuid
191 * @return javax.swing.JButton
193 private JButton
getJButtonGenerateGuid() {
194 if (jButtonGenerateGuid
== null) {
195 jButtonGenerateGuid
= new JButton();
196 jButtonGenerateGuid
.setBounds(new java
.awt
.Rectangle(415, 110, 65, 20));
197 jButtonGenerateGuid
.setPreferredSize(new java
.awt
.Dimension(65, 20));
198 jButtonGenerateGuid
.setText("GEN");
199 jButtonGenerateGuid
.setVisible(false);
200 jButtonGenerateGuid
.addActionListener(this);
202 return jButtonGenerateGuid
;
206 * This method initializes jTextFieldFeatureFlag
208 * @return javax.swing.JTextField
210 private JTextField
getJTextFieldFeatureFlag() {
211 if (jTextFieldFeatureFlag
== null) {
212 jTextFieldFeatureFlag
= new JTextField();
213 jTextFieldFeatureFlag
.setBounds(new java
.awt
.Rectangle(160, 85, 320, 20));
214 jTextFieldFeatureFlag
.setPreferredSize(new java
.awt
.Dimension(320, 20));
215 jTextFieldFeatureFlag
.setToolTipText("Postfix expression that must evaluate to TRUE or FALSE");
217 return jTextFieldFeatureFlag
;
221 This method initializes iCheckBoxListArch
223 @return ICheckBoxList
225 private ICheckBoxList
getICheckBoxListSupModuleList() {
226 if (iCheckBoxListModule
== null) {
227 iCheckBoxListModule
= new ICheckBoxList();
229 return iCheckBoxListModule
;
233 This method initializes jScrollPaneModuleList
235 @return javax.swing.JScrollPane
238 private JScrollPane
getJScrollPaneModuleList() {
239 if (jScrollPaneModuleList
== null) {
240 jScrollPaneModuleList
= new JScrollPane();
241 jScrollPaneModuleList
.setBounds(new java
.awt
.Rectangle(160, 135, 320, 80));
242 jScrollPaneModuleList
.setPreferredSize(new java
.awt
.Dimension(320, 80));
243 jScrollPaneModuleList
.setViewportView(getICheckBoxListSupModuleList());
245 return jScrollPaneModuleList
;
249 This method initializes jTextFieldHelpText
251 @return javax.swing.JTextField
254 private JTextField
getJTextFieldHelpText() {
255 if (jTextFieldHelpText
== null) {
256 jTextFieldHelpText
= new JTextField();
257 jTextFieldHelpText
.setBounds(new java
.awt
.Rectangle(160, 60, 320, 20));
258 jTextFieldHelpText
.setPreferredSize(new java
.awt
.Dimension(320, 20));
260 return jTextFieldHelpText
;
264 This method initializes jButtonOk
266 @return javax.swing.JButton
269 private JButton
getJButtonOk() {
270 if (jButtonOk
== null) {
271 jButtonOk
= new JButton();
272 jButtonOk
.setBounds(new java
.awt
.Rectangle(290, 225, 90, 20));
273 jButtonOk
.setText("Ok");
274 jButtonOk
.addActionListener(this);
280 This method initializes jButtonCancel
282 @return javax.swing.JButton
285 private JButton
getJButtonCancel() {
286 if (jButtonCancel
== null) {
287 jButtonCancel
= new JButton();
288 jButtonCancel
.setBounds(new java
.awt
.Rectangle(390, 225, 90, 20));
289 jButtonCancel
.setText("Cancel");
290 jButtonCancel
.addActionListener(this);
292 return jButtonCancel
;
295 public static void main(String
[] args
) {
300 This is the default constructor
303 public LibraryClassDefsDlg(LibraryClassIdentification inLibraryClassIdentification
, IFrame iFrame
) {
305 init(inLibraryClassIdentification
);
309 This method initializes this
312 private void init() {
313 this.setContentPane(getJScrollPane());
314 this.setTitle("Library Class Definitions");
315 this.setBounds(new java
.awt
.Rectangle(0, 0, 500, 295));
317 this.setViewMode(false);
322 This method initializes this
325 private void init(LibraryClassIdentification inLibraryClassIdentification
) {
327 this.lcid
= inLibraryClassIdentification
;
329 this.jComboBoxLibraryClassName
.setSelectedItem(lcid
.getLibraryClassName());
330 this.jComboBoxUsage
.setSelectedItem(lcid
.getUsage());
331 this.jTextFieldRecommendedInstanceVersion
.setText(lcid
.getRecommendedInstanceVersion());
332 this.jTextFieldRecommendedInstanceGuid
.setText(lcid
.getRecommendedInstanceGuid());
333 this.jTextFieldFeatureFlag
.setText(lcid
.getFeatureFlag());
334 this.jArchCheckBox
.setSelectedItems(lcid
.getSupArchList());
335 this.iCheckBoxListModule
.setAllItemsUnchecked();
336 this.iCheckBoxListModule
.initCheckedItem(true, lcid
.getSupModuleList());
337 this.jTextFieldHelpText
.setText(lcid
.getHelp());
342 Disable all components when the mode is view
344 @param isView true - The view mode; false - The non-view mode
347 public void setViewMode(boolean isView
) {
349 this.jComboBoxLibraryClassName
.setEnabled(!isView
);
350 this.jComboBoxUsage
.setEnabled(!isView
);
355 This method initializes jContentPane
357 @return javax.swing.JPanel jContentPane
360 private JPanel
getJContentPane() {
361 if (jContentPane
== null) {
362 jArchCheckBox
= new ArchCheckBox();
363 jArchCheckBox
.setBounds(new java
.awt
.Rectangle(160, 110, 320, 20));
364 jArchCheckBox
.setPreferredSize(new java
.awt
.Dimension(320, 20));
365 jLabelHelpText
= new JLabel();
366 jLabelHelpText
.setBounds(new java
.awt
.Rectangle(15, 60, 140, 20));
367 jLabelHelpText
.setText("Help Text");
368 jLabelModuleList
= new JLabel();
369 jLabelModuleList
.setBounds(new java
.awt
.Rectangle(15, 135, 140, 20));
370 jLabelModuleList
.setText("Supported Module Types");
371 jLabelArch
= new JLabel();
372 jLabelArch
.setBounds(new java
.awt
.Rectangle(15, 110, 140, 20));
373 jLabelArch
.setText("Supported Architectures");
374 jLabelFeatureFlag
= new JLabel();
375 jLabelFeatureFlag
.setBounds(new java
.awt
.Rectangle(15, 85, 140, 20));
376 jLabelFeatureFlag
.setText("Feature Flag Expression");
377 jLabelRecommendedInstanceGuid
= new JLabel();
378 jLabelRecommendedInstanceGuid
.setBounds(new java
.awt
.Rectangle(15, 110, 200, 20));
379 jLabelRecommendedInstanceGuid
.setText("Recommended Instance Guid");
380 jLabelRecommendedInstanceGuid
.setVisible(false);
381 jLabelRecommendedInstanceVersion
= new JLabel();
382 jLabelRecommendedInstanceVersion
.setBounds(new java
.awt
.Rectangle(15, 85, 200, 20));
383 jLabelRecommendedInstanceVersion
.setText("Recommended Instance Version");
384 jLabelRecommendedInstanceVersion
.setVisible(false);
385 jLabelLibraryClassName
= new JLabel();
386 jLabelLibraryClassName
.setBounds(new java
.awt
.Rectangle(15, 10, 140, 20));
387 jLabelLibraryClassName
.setText("Library Class Name");
388 jLabelUsage
= new JLabel();
389 jLabelUsage
.setBounds(new java
.awt
.Rectangle(15, 35, 140, 20));
390 jLabelUsage
.setText("Usage");
391 jContentPane
= new JPanel();
392 jContentPane
.setLayout(null);
393 jContentPane
.setPreferredSize(new java
.awt
.Dimension(490, 245));
395 jContentPane
.add(getJComboBoxLibraryClassName(), null);
396 jContentPane
.add(jLabelUsage
, null);
397 jContentPane
.add(getJComboBoxUsage(), null);
398 jContentPane
.add(jLabelLibraryClassName
, null);
399 jContentPane
.add(jLabelRecommendedInstanceVersion
, null);
400 jContentPane
.add(getJTextFieldRecommendedInstanceVersion(), null);
401 jContentPane
.add(jLabelRecommendedInstanceGuid
, null);
402 jContentPane
.add(getJTextFieldRecommendedInstanceGuid(), null);
403 jContentPane
.add(getJButtonGenerateGuid(), null);
404 jContentPane
.add(jLabelFeatureFlag
, null);
405 jContentPane
.add(getJTextFieldFeatureFlag(), null);
406 jContentPane
.add(jLabelArch
, null);
407 jStarLabel1
= new StarLabel();
408 jStarLabel1
.setLocation(new java
.awt
.Point(2, 10));
409 jStarLabel2
= new StarLabel();
410 jStarLabel2
.setLocation(new java
.awt
.Point(2, 35));
412 jContentPane
.add(jStarLabel1
, null);
413 jContentPane
.add(jStarLabel2
, null);
414 jContentPane
.add(jLabelModuleList
, null);
415 jContentPane
.add(getJScrollPaneModuleList(), null);
416 jContentPane
.add(jLabelHelpText
, null);
417 jContentPane
.add(getJTextFieldHelpText(), null);
418 jContentPane
.add(jArchCheckBox
, null);
419 jContentPane
.add(getJButtonOk(), null);
420 jContentPane
.add(getJButtonCancel(), null);
426 This method initializes all existing libraries and usage types
429 private void initFrame() {
430 Tools
.generateComboBoxByVector(jComboBoxLibraryClassName
, wt
.getAllLibraryClassDefinitionsFromWorkspace());
431 Tools
.generateComboBoxByVector(jComboBoxUsage
, ed
.getVLibraryUsage());
432 this.iCheckBoxListModule
.setAllItems(ed
.getVFrameworkModuleTypes());
436 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
438 * Override actionPerformed to listen all actions
441 public void actionPerformed(ActionEvent arg0
) {
442 if (arg0
.getSource() == jButtonGenerateGuid
) {
443 this.jTextFieldRecommendedInstanceGuid
.setText(Tools
.generateUuidString());
446 if (arg0
.getSource() == jButtonOk
) {
448 getCurrentLibraryClass();
449 this.returnType
= DataType
.RETURN_TYPE_OK
;
450 this.setVisible(false);
454 if (arg0
.getSource() == jButtonCancel
) {
455 this.returnType
= DataType
.RETURN_TYPE_CANCEL
;
456 this.setVisible(false);
461 Data validation for all fields
463 @retval true - All datas are valid
464 @retval false - At least one data is invalid
467 public boolean checkAdd() {
469 // Check LibraryClass
471 if (this.jComboBoxLibraryClassName
.getSelectedItem() == null) {
472 Log
.wrn("Update Library Class Definitions", "No Library Class can be added");
475 if (!DataValidation
.isLibraryClass(this.jComboBoxLibraryClassName
.getSelectedItem().toString())) {
476 Log
.wrn("Update Library Class Definitions", "Incorrect data type for Library Class");
481 // Check RecommendedInstanceVersion
483 // if (!isEmpty(this.jTextFieldRecommendedInstanceVersion.getText())) {
484 // if (!DataValidation.isRecommendedInstanceVersion(this.jTextFieldRecommendedInstanceVersion.getText())) {
485 // Log.err("Incorrect data type for Recommended Instance Version");
491 // Check RecommendedInstanceGuid
493 // if (!isEmpty(this.jTextFieldRecommendedInstanceGuid.getText())) {
494 // if (!DataValidation.isGuid(this.jTextFieldRecommendedInstanceGuid.getText())) {
495 // Log.err("Incorrect data type for Recommended Instance Guid");
503 if (!isEmpty(this.jTextFieldFeatureFlag
.getText())) {
504 if (!DataValidation
.isFeatureFlag(this.jTextFieldFeatureFlag
.getText())) {
505 Log
.wrn("Update Library Class Definitions", "Incorrect data type for Feature Flag");
513 private LibraryClassIdentification
getCurrentLibraryClass() {
514 String name
= this.jComboBoxLibraryClassName
.getSelectedItem().toString();
515 String usage
= this.jComboBoxUsage
.getSelectedItem().toString();
516 String version
= this.jTextFieldRecommendedInstanceVersion
.getText();
517 String guid
= this.jTextFieldRecommendedInstanceGuid
.getText();
518 String featureFlag
= this.jTextFieldFeatureFlag
.getText();
519 Vector
<String
> arch
= this.jArchCheckBox
.getSelectedItemsVector();
520 Vector
<String
> module
= this.iCheckBoxListModule
.getAllCheckedItemsString();
521 String help
= this.jTextFieldHelpText
.getText();
522 lcid
= new LibraryClassIdentification(name
, usage
, version
, guid
, arch
, featureFlag
, module
, help
);
526 public LibraryClassIdentification
getLcid() {
530 public void setLcid(LibraryClassIdentification lcid
) {