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
;
333 Vector
<PackageIdentification
> vpid
= wt
.getPackageDependenciesOfModule(mid
);
334 if (vpid
.size() <= 0) {
335 Log
.wrn("Init Library Class", "This module hasn't defined any package dependency, so there is no library class can be added");
338 Tools
.generateComboBoxByVector(this.jComboBoxLibraryClassName
,
339 wt
.getAllLibraryClassDefinitionsFromPackages(wt
.getPackageDependenciesOfModule(mid
)));
342 this.jComboBoxLibraryClassName
.setSelectedItem(lcid
.getLibraryClassName());
343 this.jComboBoxUsage
.setSelectedItem(lcid
.getUsage());
344 this.jTextFieldRecommendedInstanceVersion
.setText(lcid
.getRecommendedInstanceVersion());
345 this.jTextFieldRecommendedInstanceGuid
.setText(lcid
.getRecommendedInstanceGuid());
346 this.jTextFieldFeatureFlag
.setText(lcid
.getFeatureFlag());
347 this.jArchCheckBox
.setSelectedItems(lcid
.getSupArchList());
348 this.iCheckBoxListModule
.setAllItemsUnchecked();
349 this.iCheckBoxListModule
.initCheckedItem(true, lcid
.getSupModuleList());
350 this.jTextFieldHelpText
.setText(lcid
.getHelp());
355 Disable all components when the mode is view
357 @param isView true - The view mode; false - The non-view mode
360 public void setViewMode(boolean isView
) {
362 this.jComboBoxLibraryClassName
.setEnabled(!isView
);
363 this.jComboBoxUsage
.setEnabled(!isView
);
368 This method initializes jContentPane
370 @return javax.swing.JPanel jContentPane
373 private JPanel
getJContentPane() {
374 if (jContentPane
== null) {
375 jArchCheckBox
= new ArchCheckBox();
376 jArchCheckBox
.setBounds(new java
.awt
.Rectangle(168, 87, 320, 20));
377 jArchCheckBox
.setPreferredSize(new java
.awt
.Dimension(320, 20));
378 jLabelHelpText
= new JLabel();
379 jLabelHelpText
.setBounds(new java
.awt
.Rectangle(12, 62, 168, 20));
380 jLabelHelpText
.setText("Help Text");
381 jLabelModuleList
= new JLabel();
382 jLabelModuleList
.setBounds(new java
.awt
.Rectangle(12, 112, 168, 20));
383 jLabelModuleList
.setText("Supported Module Types");
384 jLabelArch
= new JLabel();
385 jLabelArch
.setBounds(new java
.awt
.Rectangle(12, 87, 168, 20));
386 jLabelArch
.setText("Supported Architectures");
387 jLabelFeatureFlag
= new JLabel();
388 jLabelFeatureFlag
.setBounds(new java
.awt
.Rectangle(12,197,168,20));
389 jLabelFeatureFlag
.setText("Feature Flag Expression");
390 jLabelFeatureFlag
.setEnabled(false);
391 jLabelRecommendedInstanceGuid
= new JLabel();
392 jLabelRecommendedInstanceGuid
.setBounds(new java
.awt
.Rectangle(12, 87, 200, 20));
393 jLabelRecommendedInstanceGuid
.setText("Recommended Instance Guid");
394 jLabelRecommendedInstanceGuid
.setVisible(false);
395 jLabelRecommendedInstanceVersion
= new JLabel();
396 jLabelRecommendedInstanceVersion
.setBounds(new java
.awt
.Rectangle(12, 87, 200, 20));
397 jLabelRecommendedInstanceVersion
.setText("Recommended Instance Version");
398 jLabelRecommendedInstanceVersion
.setVisible(false);
399 jLabelLibraryClassName
= new JLabel();
400 jLabelLibraryClassName
.setBounds(new java
.awt
.Rectangle(12, 12, 168, 20));
401 jLabelLibraryClassName
.setText("Library Class Name");
402 jLabelUsage
= new JLabel();
403 jLabelUsage
.setBounds(new java
.awt
.Rectangle(12, 37, 168, 20));
404 jLabelUsage
.setText("Usage");
405 jContentPane
= new JPanel();
406 jContentPane
.setLayout(null);
407 jContentPane
.setPreferredSize(new java
.awt
.Dimension(495, 255));
409 jContentPane
.add(getJComboBoxLibraryClassName(), null);
410 jContentPane
.add(jLabelUsage
, null);
411 jContentPane
.add(getJComboBoxUsage(), null);
412 jContentPane
.add(jLabelLibraryClassName
, null);
413 jContentPane
.add(jLabelRecommendedInstanceVersion
, null);
414 jContentPane
.add(getJTextFieldRecommendedInstanceVersion(), null);
415 jContentPane
.add(jLabelRecommendedInstanceGuid
, null);
416 jContentPane
.add(getJTextFieldRecommendedInstanceGuid(), null);
417 jContentPane
.add(getJButtonGenerateGuid(), null);
418 jContentPane
.add(jLabelFeatureFlag
, null);
419 jContentPane
.add(getJTextFieldFeatureFlag(), null);
420 jContentPane
.add(jLabelArch
, null);
421 jStarLabel1
= new StarLabel();
422 jStarLabel1
.setLocation(new java
.awt
.Point(2, 10));
423 jStarLabel2
= new StarLabel();
424 jStarLabel2
.setLocation(new java
.awt
.Point(2, 35));
426 jContentPane
.add(jStarLabel1
, null);
427 jContentPane
.add(jStarLabel2
, null);
428 jContentPane
.add(jLabelModuleList
, null);
429 jContentPane
.add(getJScrollPaneModuleList(), null);
430 jContentPane
.add(jLabelHelpText
, null);
431 jContentPane
.add(getJTextFieldHelpText(), null);
432 jContentPane
.add(jArchCheckBox
, null);
433 jContentPane
.add(getJButtonOk(), null);
434 jContentPane
.add(getJButtonCancel(), null);
440 This method initializes all existing libraries and usage types
443 private void initFrame() {
444 Tools
.generateComboBoxByVector(jComboBoxUsage
, ed
.getVLibraryUsage());
445 this.iCheckBoxListModule
.setAllItems(ed
.getVFrameworkModuleTypes());
449 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
451 * Override actionPerformed to listen all actions
454 public void actionPerformed(ActionEvent arg0
) {
455 if (arg0
.getSource() == jButtonGenerateGuid
) {
456 this.jTextFieldRecommendedInstanceGuid
.setText(Tools
.generateUuidString());
459 if (arg0
.getSource() == jButtonOk
) {
461 getCurrentLibraryClass();
462 this.returnType
= DataType
.RETURN_TYPE_OK
;
463 this.setVisible(false);
467 if (arg0
.getSource() == jButtonCancel
) {
468 this.returnType
= DataType
.RETURN_TYPE_CANCEL
;
469 this.setVisible(false);
474 Data validation for all fields
476 @retval true - All datas are valid
477 @retval false - At least one data is invalid
480 public boolean checkAdd() {
482 // Check LibraryClass
484 if (this.jComboBoxLibraryClassName
.getSelectedItem() == null) {
485 Log
.wrn("Update Library Class Definitions", "Please select one Library Class");
488 if (!DataValidation
.isLibraryClass(this.jComboBoxLibraryClassName
.getSelectedItem().toString())) {
489 Log
.wrn("Update Library Class Definitions", "Incorrect data type for Library Class");
494 // Check RecommendedInstanceVersion
496 // if (!isEmpty(this.jTextFieldRecommendedInstanceVersion.getText())) {
497 // if (!DataValidation.isRecommendedInstanceVersion(this.jTextFieldRecommendedInstanceVersion.getText())) {
498 // Log.err("Incorrect data type for Recommended Instance Version");
504 // Check RecommendedInstanceGuid
506 // if (!isEmpty(this.jTextFieldRecommendedInstanceGuid.getText())) {
507 // if (!DataValidation.isGuid(this.jTextFieldRecommendedInstanceGuid.getText())) {
508 // Log.err("Incorrect data type for Recommended Instance Guid");
516 if (!isEmpty(this.jTextFieldFeatureFlag
.getText())) {
517 if (!DataValidation
.isFeatureFlag(this.jTextFieldFeatureFlag
.getText())) {
518 Log
.wrn("Update Library Class Definitions", "Incorrect data type for Feature Flag");
526 private LibraryClassIdentification
getCurrentLibraryClass() {
527 String name
= this.jComboBoxLibraryClassName
.getSelectedItem().toString();
528 String usage
= this.jComboBoxUsage
.getSelectedItem().toString();
529 String version
= this.jTextFieldRecommendedInstanceVersion
.getText();
530 String guid
= this.jTextFieldRecommendedInstanceGuid
.getText();
531 String featureFlag
= this.jTextFieldFeatureFlag
.getText();
532 Vector
<String
> arch
= this.jArchCheckBox
.getSelectedItemsVector();
533 Vector
<String
> module
= this.iCheckBoxListModule
.getAllCheckedItemsString();
534 String help
= this.jTextFieldHelpText
.getText();
535 lcid
= new LibraryClassIdentification(name
, usage
, version
, guid
, arch
, featureFlag
, module
, help
);
539 public LibraryClassIdentification
getLcid() {
543 public void setLcid(LibraryClassIdentification lcid
) {