3 The file is used to create, update Guids 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
.packaging
.module
.ui
;
17 import java
.awt
.event
.ActionEvent
;
19 import javax
.swing
.JButton
;
20 import javax
.swing
.JComboBox
;
21 import javax
.swing
.JLabel
;
22 import javax
.swing
.JPanel
;
23 import javax
.swing
.JRadioButton
;
24 import javax
.swing
.JTextField
;
26 import org
.tianocore
.ConditionalExpressionDocument
;
27 import org
.tianocore
.DefaultValueDocument
;
28 import org
.tianocore
.GuidUsage
;
29 import org
.tianocore
.GuidsDocument
;
30 import org
.tianocore
.common
.DataValidation
;
31 import org
.tianocore
.common
.Log
;
32 import org
.tianocore
.common
.Tools
;
33 import org
.tianocore
.packaging
.common
.ui
.IComboBox
;
34 import org
.tianocore
.packaging
.common
.ui
.IInternalFrame
;
35 import org
.tianocore
.packaging
.common
.ui
.StarLabel
;
38 The class is used to create, update Guids of MSA/MBD file
39 It extends IInternalFrame
41 @since ModuleEditor 1.0
44 public class ModuleGuids
extends IInternalFrame
{
47 /// Define class Serial Version UID
49 private static final long serialVersionUID
= 6710858997766979803L;
52 //Define class members
54 private GuidsDocument
.Guids guids
= null;
56 private int location
= -1;
58 private JPanel jContentPane
= null;
60 private JLabel jLabelC_Name
= null;
62 private JTextField jTextFieldC_Name
= null;
64 private JLabel jLabelGuidValue
= null;
66 private JTextField jTextFieldGuidValue
= null;
68 private JLabel jLabelFeatureFlag
= null;
70 private IComboBox iComboBoxFeatureFlag
= null;
72 private JLabel jLabelConditionalExpression
= null;
74 private IComboBox iComboBoxConditionalExpression
= null;
76 private JLabel jLabelDefault
= null;
78 private JTextField jTextFieldDefaultValue
= null;
80 private JLabel jLabelHelpText
= null;
82 private JTextField jTextFieldHelpText
= null;
84 private JLabel jLabelEnableFeature
= null;
86 private JRadioButton jRadioButtonEnableFeature
= null;
88 private JRadioButton jRadioButtonDisableFeature
= null;
90 private JLabel jLabelUsage
= null;
92 private JComboBox jComboBoxUsage
= null;
94 private JButton jButtonOk
= null;
96 private JButton jButtonCancel
= null;
98 private JButton jButtonGenerateGuid
= null;
100 private JLabel jLabelOverrideID
= null;
102 private JTextField jTextFieldOverrideID
= null;
105 This method initializes jTextFieldC_Name
107 @return javax.swing.JTextField jTextFieldC_Name
110 private JTextField
getJTextFieldC_Name() {
111 if (jTextFieldC_Name
== null) {
112 jTextFieldC_Name
= new JTextField();
113 jTextFieldC_Name
.setBounds(new java
.awt
.Rectangle(160, 10, 320, 20));
115 return jTextFieldC_Name
;
119 This method initializes jTextFieldGuidValsue
121 @return javax.swing.JTextField jTextFieldGuidValue
124 private JTextField
getJTextFieldGuidValsue() {
125 if (jTextFieldGuidValue
== null) {
126 jTextFieldGuidValue
= new JTextField();
127 jTextFieldGuidValue
.setBounds(new java
.awt
.Rectangle(160, 35, 250, 20));
129 return jTextFieldGuidValue
;
133 This method initializes jTextFieldFeatureFlag
135 @return javax.swing.JTextField iComboBoxFeatureFlag
138 private IComboBox
getIComboBoxFeatureFlag() {
139 if (iComboBoxFeatureFlag
== null) {
140 iComboBoxFeatureFlag
= new IComboBox();
141 iComboBoxFeatureFlag
.setBounds(new java
.awt
.Rectangle(160, 60, 320, 20));
143 return iComboBoxFeatureFlag
;
147 This method initializes jTextFieldConditionalExpression
149 @return javax.swing.JTextField iComboBoxConditionalExpression
152 private IComboBox
getIComboBoxConditionalExpression() {
153 if (iComboBoxConditionalExpression
== null) {
154 iComboBoxConditionalExpression
= new IComboBox();
155 iComboBoxConditionalExpression
.setBounds(new java
.awt
.Rectangle(160, 85, 320, 20));
157 return iComboBoxConditionalExpression
;
161 This method initializes jTextFieldDefault
163 @return javax.swing.JTextField jTextFieldDefaultValue
166 private JTextField
getJTextFieldDefaultValue() {
167 if (jTextFieldDefaultValue
== null) {
168 jTextFieldDefaultValue
= new JTextField();
169 jTextFieldDefaultValue
.setBounds(new java
.awt
.Rectangle(160, 110, 320, 20));
171 return jTextFieldDefaultValue
;
175 This method initializes jTextFieldHelpText
177 @return javax.swing.JTextField jTextFieldHelpText
180 private JTextField
getJTextFieldHelpText() {
181 if (jTextFieldHelpText
== null) {
182 jTextFieldHelpText
= new JTextField();
183 jTextFieldHelpText
.setBounds(new java
.awt
.Rectangle(160, 135, 320, 20));
185 return jTextFieldHelpText
;
189 This method initializes jRadioButtonEnableFeature
191 @return javax.swing.JRadioButton jRadioButtonEnableFeature
194 private JRadioButton
getJRadioButtonEnableFeature() {
195 if (jRadioButtonEnableFeature
== null) {
196 jRadioButtonEnableFeature
= new JRadioButton();
197 jRadioButtonEnableFeature
.setText("Enable");
198 jRadioButtonEnableFeature
.setBounds(new java
.awt
.Rectangle(160, 160, 90, 20));
199 jRadioButtonEnableFeature
.setSelected(true);
200 jRadioButtonEnableFeature
.addActionListener(this);
202 return jRadioButtonEnableFeature
;
206 This method initializes jRadioButtonDisableFeature
208 @return javax.swing.JRadioButton jRadioButtonDisableFeature
211 private JRadioButton
getJRadioButtonDisableFeature() {
212 if (jRadioButtonDisableFeature
== null) {
213 jRadioButtonDisableFeature
= new JRadioButton();
214 jRadioButtonDisableFeature
.setText("Disable");
215 jRadioButtonDisableFeature
.setBounds(new java
.awt
.Rectangle(320, 160, 90, 20));
216 jRadioButtonDisableFeature
.addActionListener(this);
218 return jRadioButtonDisableFeature
;
222 This method initializes jComboBoxUsage
224 @return javax.swing.JComboBox jComboBoxUsage
227 private JComboBox
getJComboBoxUsage() {
228 if (jComboBoxUsage
== null) {
229 jComboBoxUsage
= new JComboBox();
230 jComboBoxUsage
.setBounds(new java
.awt
.Rectangle(160, 185, 320, 20));
232 return jComboBoxUsage
;
236 This method initializes jButtonOk
238 @return javax.swing.JButton jButtonOk
241 private JButton
getJButtonOk() {
242 if (jButtonOk
== null) {
243 jButtonOk
= new JButton();
244 jButtonOk
.setText("OK");
245 jButtonOk
.setBounds(new java
.awt
.Rectangle(290, 240, 90, 20));
246 jButtonOk
.addActionListener(this);
252 This method initializes jButtonCancel
254 @return javax.swing.JButton jButtonCancel
257 private JButton
getJButtonCancel() {
258 if (jButtonCancel
== null) {
259 jButtonCancel
= new JButton();
260 jButtonCancel
.setText("Cancel");
261 jButtonCancel
.setBounds(new java
.awt
.Rectangle(390, 240, 90, 20));
262 jButtonCancel
.addActionListener(this);
264 return jButtonCancel
;
268 This method initializes jButtonGenerateGuid
270 @return javax.swing.JButton jButtonGenerateGuid
273 private JButton
getJButtonGenerateGuid() {
274 if (jButtonGenerateGuid
== null) {
275 jButtonGenerateGuid
= new JButton();
276 jButtonGenerateGuid
.setBounds(new java
.awt
.Rectangle(415, 35, 65, 20));
277 jButtonGenerateGuid
.setText("GEN");
278 jButtonGenerateGuid
.addActionListener(this);
280 return jButtonGenerateGuid
;
284 This method initializes jTextFieldOverrideID
286 @return javax.swing.JTextField jTextFieldOverrideID
289 private JTextField
getJTextFieldOverrideID() {
290 if (jTextFieldOverrideID
== null) {
291 jTextFieldOverrideID
= new JTextField();
292 jTextFieldOverrideID
.setBounds(new java
.awt
.Rectangle(160, 210, 50, 20));
294 return jTextFieldOverrideID
;
297 public static void main(String
[] args
) {
302 This is the default constructor
305 public ModuleGuids() {
308 this.setVisible(true);
312 This is the override edit constructor
314 @param inGuids The input data of GuidsDocument.Guids
317 public ModuleGuids(GuidsDocument
.Guids inGuids
) {
320 this.setVisible(true);
324 This is the override edit constructor
326 @param inGuids The input data of GuidsDocument.Guids
327 @param type The input data of node type
328 @param index The input data of node index
331 public ModuleGuids(GuidsDocument
.Guids inGuids
, int type
, int index
) {
333 init(inGuids
, type
, index
);
334 this.setVisible(true);
338 This method initializes this
340 @param inGuids The input data of GuidsDocument.Guids
343 private void init(GuidsDocument
.Guids inGuids
) {
345 this.setGuids(inGuids
);
349 This method initializes this
350 Fill values to all fields if these values are not empty
352 @param inGuids The input data of GuidsDocument.Guids
353 @param type The input data of node type
354 @param index The input data of node index
357 private void init(GuidsDocument
.Guids inGuids
, int type
, int index
) {
359 this.location
= index
;
360 if (this.guids
.getGuidEntryList().size() > 0) {
361 if (this.guids
.getGuidEntryArray(index
).getCName() != null) {
362 this.jTextFieldC_Name
.setText(this.guids
.getGuidEntryArray(index
).getCName());
364 if (this.guids
.getGuidEntryArray(index
).getGuidValue() != null) {
365 this.jTextFieldGuidValue
.setText(this.guids
.getGuidEntryArray(index
).getGuidValue());
367 if (this.guids
.getGuidEntryArray(index
).getFeatureFlagList().size() > 0) {
368 for (int indexI
= 0; indexI
< this.guids
.getGuidEntryArray(index
).getFeatureFlagList().size(); indexI
++) {
369 this.iComboBoxFeatureFlag
.addItem(this.guids
.getGuidEntryArray(index
).getFeatureFlagArray(indexI
));
372 if (this.guids
.getGuidEntryArray(index
).getConditionalExpressionList().size() > 0) {
373 for (int indexI
= 0; indexI
< this.guids
.getGuidEntryArray(index
).getConditionalExpressionArray(0)
374 .getConditionList().size(); indexI
++) {
375 this.iComboBoxConditionalExpression
.addItem(this.guids
.getGuidEntryArray(index
)
376 .getConditionalExpressionArray(0)
377 .getConditionArray(indexI
));
380 if (this.guids
.getGuidEntryArray(index
).getDefaultValue() != null) {
381 this.jTextFieldDefaultValue
.setText(this.guids
.getGuidEntryArray(index
).getDefaultValue()
384 if (this.guids
.getGuidEntryArray(index
).getHelpText() != null) {
385 this.jTextFieldHelpText
.setText(this.guids
.getGuidEntryArray(index
).getHelpText());
387 if (this.guids
.getGuidEntryArray(index
).getUsage() != null) {
388 this.jComboBoxUsage
.setSelectedItem(this.guids
.getGuidEntryArray(index
).getUsage().toString());
390 this.jRadioButtonEnableFeature
.setSelected(this.guids
.getGuidEntryArray(index
).getEnableFeature());
391 this.jRadioButtonDisableFeature
.setSelected(!this.guids
.getGuidEntryArray(index
).getEnableFeature());
392 this.jTextFieldOverrideID
.setText(String
.valueOf(this.guids
.getGuidEntryArray(index
).getOverrideID()));
397 This method initializes this
400 private void init() {
401 this.setSize(500, 515);
402 this.setContentPane(getJContentPane());
403 this.setTitle("Guids");
405 this.setViewMode(false);
409 Disable all components when the mode is view
411 @param isView true - The view mode; false - The non-view mode
414 public void setViewMode(boolean isView
) {
415 this.jButtonOk
.setVisible(false);
416 this.jButtonCancel
.setVisible(false);
418 this.jTextFieldC_Name
.setEnabled(!isView
);
419 this.jTextFieldGuidValue
.setEnabled(!isView
);
420 this.iComboBoxFeatureFlag
.setEnabled(!isView
);
421 this.iComboBoxConditionalExpression
.setEnabled(!isView
);
422 this.jTextFieldDefaultValue
.setEnabled(!isView
);
423 this.jTextFieldHelpText
.setEnabled(!isView
);
424 this.jComboBoxUsage
.setEnabled(!isView
);
425 this.jRadioButtonEnableFeature
.setEnabled(!isView
);
426 this.jRadioButtonDisableFeature
.setEnabled(!isView
);
427 this.jTextFieldOverrideID
.setEnabled(!isView
);
428 this.jButtonCancel
.setEnabled(!isView
);
429 this.jButtonGenerateGuid
.setEnabled(!isView
);
430 this.jButtonOk
.setEnabled(!isView
);
435 This method initializes jContentPane
437 @return javax.swing.JPanel jContentPane
440 private JPanel
getJContentPane() {
441 if (jContentPane
== null) {
442 jLabelOverrideID
= new JLabel();
443 jLabelOverrideID
.setBounds(new java
.awt
.Rectangle(15, 210, 140, 20));
444 jLabelOverrideID
.setText("Override ID");
445 jLabelUsage
= new JLabel();
446 jLabelUsage
.setText("Usage");
447 jLabelUsage
.setBounds(new java
.awt
.Rectangle(15, 185, 140, 20));
448 jLabelEnableFeature
= new JLabel();
449 jLabelEnableFeature
.setText("Enable Feature");
450 jLabelEnableFeature
.setBounds(new java
.awt
.Rectangle(15, 160, 140, 20));
451 jLabelHelpText
= new JLabel();
452 jLabelHelpText
.setText("Help Text");
453 jLabelHelpText
.setBounds(new java
.awt
.Rectangle(15, 135, 140, 20));
454 jLabelDefault
= new JLabel();
455 jLabelDefault
.setText("Default Value");
456 jLabelDefault
.setBounds(new java
.awt
.Rectangle(15, 110, 140, 20));
457 jLabelConditionalExpression
= new JLabel();
458 jLabelConditionalExpression
.setText("Conditional Expression");
459 jLabelConditionalExpression
.setBounds(new java
.awt
.Rectangle(15, 85, 140, 20));
460 jLabelFeatureFlag
= new JLabel();
461 jLabelFeatureFlag
.setText("Feature Flag");
462 jLabelFeatureFlag
.setBounds(new java
.awt
.Rectangle(15, 60, 140, 20));
463 jLabelGuidValue
= new JLabel();
464 jLabelGuidValue
.setText("Guid Value");
465 jLabelGuidValue
.setBounds(new java
.awt
.Rectangle(15, 35, 140, 20));
466 jLabelC_Name
= new JLabel();
467 jLabelC_Name
.setText("C_Name");
468 jLabelC_Name
.setBounds(new java
.awt
.Rectangle(15, 10, 140, 20));
469 jContentPane
= new JPanel();
470 jContentPane
.setLayout(null);
471 jContentPane
.add(jLabelC_Name
, null);
472 jContentPane
.add(getJTextFieldC_Name(), null);
473 jContentPane
.add(jLabelGuidValue
, null);
474 jContentPane
.add(getJTextFieldGuidValsue(), null);
475 jContentPane
.add(jLabelFeatureFlag
, null);
476 jContentPane
.add(getIComboBoxFeatureFlag(), null);
477 jContentPane
.add(jLabelConditionalExpression
, null);
478 jContentPane
.add(getIComboBoxConditionalExpression(), null);
479 jContentPane
.add(jLabelDefault
, null);
480 jContentPane
.add(getJTextFieldDefaultValue(), null);
481 jContentPane
.add(jLabelHelpText
, null);
482 jContentPane
.add(getJTextFieldHelpText(), null);
483 jContentPane
.add(jLabelEnableFeature
, null);
484 jContentPane
.add(getJRadioButtonEnableFeature(), null);
485 jContentPane
.add(getJRadioButtonDisableFeature(), null);
486 jContentPane
.add(jLabelUsage
, null);
487 jContentPane
.add(getJComboBoxUsage(), null);
488 jContentPane
.add(getJButtonOk(), null);
489 jContentPane
.add(getJButtonCancel(), null);
490 jContentPane
.add(getJButtonGenerateGuid(), null);
491 jContentPane
.add(jLabelOverrideID
, null);
492 jContentPane
.add(getJTextFieldOverrideID(), null);
494 StarLabel jStarLabel1
= new StarLabel();
495 jStarLabel1
.setLocation(new java
.awt
.Point(0, 10));
497 jContentPane
.add(jStarLabel1
, null);
506 This method initializes Usage type
509 private void initFrame() {
510 jComboBoxUsage
.addItem("ALWAYS_CONSUMED");
511 jComboBoxUsage
.addItem("SOMETIMES_CONSUMED");
512 jComboBoxUsage
.addItem("ALWAYS_PRODUCED");
513 jComboBoxUsage
.addItem("SOMETIMES_PRODUCED");
514 jComboBoxUsage
.addItem("DEFAULT");
518 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
520 * Override actionPerformed to listen all actions
523 public void actionPerformed(ActionEvent arg0
) {
524 if (arg0
.getSource() == jButtonOk
) {
525 this.setEdited(true);
529 if (arg0
.getSource() == jButtonCancel
) {
533 if (arg0
.getSource() == jButtonGenerateGuid
) {
534 jTextFieldGuidValue
.setText(Tools
.generateUuidString());
538 //Contorl the selected status when click RadionButton
539 //Do not use Radio Button Group
541 if (arg0
.getSource() == jRadioButtonEnableFeature
) {
542 if (jRadioButtonEnableFeature
.isSelected()) {
543 jRadioButtonDisableFeature
.setSelected(false);
545 if (!jRadioButtonDisableFeature
.isSelected() && !jRadioButtonEnableFeature
.isSelected()) {
546 jRadioButtonEnableFeature
.setSelected(true);
550 if (arg0
.getSource() == jRadioButtonDisableFeature
) {
551 if (jRadioButtonDisableFeature
.isSelected()) {
552 jRadioButtonEnableFeature
.setSelected(false);
554 if (!jRadioButtonDisableFeature
.isSelected() && !jRadioButtonEnableFeature
.isSelected()) {
555 jRadioButtonDisableFeature
.setSelected(true);
561 Get GuidsDocument.Guids
563 @return GuidsDocument.Guids
566 public GuidsDocument
.Guids
getGuids() {
571 Set GuidsDocument.Guids
573 @param guids The input GuidsDocument.Guids
576 public void setGuids(GuidsDocument
.Guids guids
) {
581 Data validation for all fields
583 @retval true - All datas are valid
584 @retval false - At least one data is invalid
587 public boolean check() {
589 // Check if all required fields are not empty
591 if (isEmpty(this.jTextFieldC_Name
.getText())) {
592 Log
.err("C_Name couldn't be empty");
597 // Check if all fields have correct data types
599 if (!DataValidation
.isCName(this.jTextFieldC_Name
.getText())) {
600 Log
.err("Incorrect data type for C_Name");
603 if (!isEmpty(this.jTextFieldGuidValue
.getText()) && !DataValidation
.isGuid(this.jTextFieldGuidValue
.getText())) {
604 Log
.err("Incorrect data type for Guid Value");
607 if (!isEmpty(this.jTextFieldOverrideID
.getText())
608 && !DataValidation
.isOverrideID(this.jTextFieldOverrideID
.getText())) {
609 Log
.err("Incorrect data type for Override ID");
617 Save all components of Guids
618 if exists guids, set the value directly
619 if not exists guids, new an instance first
624 if (this.guids
== null) {
625 guids
= GuidsDocument
.Guids
.Factory
.newInstance();
627 GuidsDocument
.Guids
.GuidEntry guid
= GuidsDocument
.Guids
.GuidEntry
.Factory
.newInstance();
628 if (!isEmpty(this.jTextFieldC_Name
.getText())) {
629 guid
.setCName(this.jTextFieldC_Name
.getText());
631 if (!isEmpty(this.jTextFieldGuidValue
.getText())) {
632 guid
.setGuidValue(this.jTextFieldGuidValue
.getText());
634 if (this.iComboBoxFeatureFlag
.getItemCount() > 0) {
635 for (int index
= 0; index
< this.iComboBoxFeatureFlag
.getItemCount(); index
++) {
636 guid
.addNewFeatureFlag();
637 guid
.setFeatureFlagArray(index
, this.iComboBoxFeatureFlag
.getItemAt(index
).toString());
640 if (this.iComboBoxConditionalExpression
.getItemCount() > 0) {
641 ConditionalExpressionDocument
.ConditionalExpression ce
= ConditionalExpressionDocument
.ConditionalExpression
.Factory
643 for (int index
= 0; index
< this.iComboBoxConditionalExpression
.getItemCount(); index
++) {
644 ce
.addCondition(this.iComboBoxConditionalExpression
.getItemAt(index
).toString());
646 if (guid
.getConditionalExpressionList().size() < 1) {
647 guid
.addNewConditionalExpression();
649 guid
.setConditionalExpressionArray(0, ce
);
651 if (!isEmpty(this.jTextFieldDefaultValue
.getText())) {
652 DefaultValueDocument
.DefaultValue dv
= DefaultValueDocument
.DefaultValue
.Factory
.newInstance();
653 dv
.setStringValue(this.jTextFieldDefaultValue
.getText());
654 guid
.setDefaultValue(dv
);
656 if (!isEmpty(this.jTextFieldHelpText
.getText())) {
657 guid
.setHelpText(this.jTextFieldHelpText
.getText());
659 guid
.setUsage(GuidUsage
.Enum
.forString(jComboBoxUsage
.getSelectedItem().toString()));
660 guid
.setEnableFeature(this.jRadioButtonEnableFeature
.isSelected());
661 if (!isEmpty(this.jTextFieldOverrideID
.getText())) {
662 guid
.setOverrideID(Integer
.parseInt(this.jTextFieldOverrideID
.getText()));
666 guids
.setGuidEntryArray(location
, guid
);
668 guids
.addNewGuidEntry();
669 guids
.setGuidEntryArray(guids
.getGuidEntryList().size() - 1, guid
);
671 } catch (Exception e
) {
672 Log
.err("Update Guids", e
.getMessage());