3 The file is used to create, update PcdCode 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
.event
.ActionEvent
;
18 import java
.awt
.event
.ItemEvent
;
19 import java
.awt
.event
.ItemListener
;
20 import java
.util
.Vector
;
22 import javax
.swing
.JButton
;
23 import javax
.swing
.JComboBox
;
24 import javax
.swing
.JLabel
;
25 import javax
.swing
.JPanel
;
26 import javax
.swing
.JScrollPane
;
27 import javax
.swing
.JTextField
;
28 import javax
.swing
.JTextArea
;
30 import org
.tianocore
.frameworkwizard
.common
.DataType
;
31 import org
.tianocore
.frameworkwizard
.common
.DataValidation
;
32 import org
.tianocore
.frameworkwizard
.common
.EnumerationData
;
33 import org
.tianocore
.frameworkwizard
.common
.Log
;
34 import org
.tianocore
.frameworkwizard
.common
.Tools
;
35 import org
.tianocore
.frameworkwizard
.common
.ui
.ArchCheckBox
;
36 import org
.tianocore
.frameworkwizard
.common
.ui
.IDialog
;
37 import org
.tianocore
.frameworkwizard
.common
.ui
.IFrame
;
38 import org
.tianocore
.frameworkwizard
.common
.ui
.StarLabel
;
39 import org
.tianocore
.frameworkwizard
.module
.Identifications
.ModuleIdentification
;
40 import org
.tianocore
.frameworkwizard
.module
.Identifications
.PcdCoded
.PcdCodedIdentification
;
41 import org
.tianocore
.frameworkwizard
.module
.Identifications
.PcdCoded
.PcdVector
;
42 import org
.tianocore
.frameworkwizard
.packaging
.PackageIdentification
;
43 import org
.tianocore
.frameworkwizard
.workspace
.WorkspaceTools
;
46 * The class is used to create, update PcdCoded section of the MSA file
51 public class PCDsDlg
extends IDialog
implements ItemListener
{
54 // / Define class Serial Version UID
56 private static final long serialVersionUID
= 2227717658188438696L;
59 // Define class members
61 private JPanel jContentPane
= null;
63 private JLabel jLabelItemType
= null;
65 private JLabel jLabelC_Name
= null;
67 private JComboBox jComboBoxItemType
= null;
69 private JComboBox jComboBoxCName
= null;
71 private JLabel jLabelDefaultValue
= null;
73 private JTextField jTextFieldDefaultValue
= null;
75 private StarLabel jStarLabel1
= null;
77 private StarLabel jStarLabel2
= null;
79 private StarLabel jStarLabel3
= null;
81 private JLabel jLabelHelpText
= null;
83 private JTextArea jTextAreaHelpText
= null;
85 private JScrollPane jScrollPane
= null;
87 private JLabel jLabelTokenSpaceGuid
= null;
89 private JTextField jTextFieldTokenSpaceGuid
= null;
91 private JLabel jLabelFeatureFlag
= null;
93 private JTextField jTextFieldFeatureFlag
= null;
95 private JLabel jLabelArch
= null;
97 private ArchCheckBox jArchCheckBox
= null;
99 private JButton jButtonOk
= null;
101 private JButton jButtonCancel
= null;
103 private JScrollPane jScrollPaneHelpText
= null;
105 private JLabel jLabelUsage
= null;
107 private JComboBox jComboBoxUsage
= null;
112 private PcdCodedIdentification id
= null;
114 private EnumerationData ed
= new EnumerationData();
116 private WorkspaceTools wt
= new WorkspaceTools();
118 private PcdVector pcd
= wt
.getAllPcdDeclarationsFromWorkspace();
121 * This method initializes jComboBoxItemType
123 * @return javax.swing.JComboBox jComboBoxItemType
126 private JComboBox
getJComboBoxItemType() {
127 if (jComboBoxItemType
== null) {
128 jComboBoxItemType
= new JComboBox();
129 jComboBoxItemType
.setBounds(new java
.awt
.Rectangle(168, 37, 320, 20));
130 jComboBoxItemType
.setPreferredSize(new java
.awt
.Dimension(320, 20));
132 return jComboBoxItemType
;
136 * This method initializes jTextFieldC_Name
138 * @return javax.swing.JTextField jTextFieldC_Name
141 private JComboBox
getJComboBoxCName() {
142 if (jComboBoxCName
== null) {
143 jComboBoxCName
= new JComboBox();
144 jComboBoxCName
.setBounds(new java
.awt
.Rectangle(168, 12, 320, 20));
145 jComboBoxCName
.setPreferredSize(new java
.awt
.Dimension(320, 20));
146 jComboBoxCName
.addItemListener(this);
148 return jComboBoxCName
;
152 * This method initializes jTextFieldDefaultValue
154 * @return javax.swing.JTextField jTextFieldDefaultValue
157 private JTextField
getJTextFieldDefaultValue() {
158 if (jTextFieldDefaultValue
== null) {
159 jTextFieldDefaultValue
= new JTextField();
160 jTextFieldDefaultValue
.setBounds(new java
.awt
.Rectangle(168, 62, 320, 20));
161 jTextFieldDefaultValue
.setPreferredSize(new java
.awt
.Dimension(320, 20));
163 return jTextFieldDefaultValue
;
167 * This method initializes jTextAreaHelpText
169 * @return javax.swing.JTextArea
171 private JTextArea
getJTextAreaHelpText() {
172 if (jTextAreaHelpText
== null) {
173 jTextAreaHelpText
= new JTextArea();
174 jTextAreaHelpText
.setLineWrap(true);
175 jTextAreaHelpText
.setWrapStyleWord(true);
177 return jTextAreaHelpText
;
181 * This method initializes jScrollPaneHelpText
183 * @return javax.swing.JScrollPane
186 private JScrollPane
getJScrollPaneHelpText() {
187 if (jScrollPaneHelpText
== null) {
188 jScrollPaneHelpText
= new JScrollPane();
189 jScrollPaneHelpText
.setHorizontalScrollBarPolicy(javax
.swing
.JScrollPane
.HORIZONTAL_SCROLLBAR_NEVER
);
190 jScrollPaneHelpText
.setSize(new java
.awt
.Dimension(320, 40));
191 jScrollPaneHelpText
.setPreferredSize(new java
.awt
.Dimension(320, 40));
192 jScrollPaneHelpText
.setLocation(new java
.awt
.Point(168, 112));
193 jScrollPaneHelpText
.setViewportView(getJTextAreaHelpText());
195 return jScrollPaneHelpText
;
199 * This method initializes jScrollPane
201 * @return javax.swing.JScrollPane
203 private JScrollPane
getJScrollPane() {
204 if (jScrollPane
== null) {
205 jScrollPane
= new JScrollPane();
206 jScrollPane
.setViewportView(getJContentPane());
212 * This method initializes jTextFieldTokenSpaceGuid
214 * @return javax.swing.JTextField
216 private JTextField
getJTextFieldTokenSpaceGuid() {
217 if (jTextFieldTokenSpaceGuid
== null) {
218 jTextFieldTokenSpaceGuid
= new JTextField();
219 jTextFieldTokenSpaceGuid
.setBounds(new java
.awt
.Rectangle(168, 62, 320, 20));
220 jTextFieldTokenSpaceGuid
.setPreferredSize(new java
.awt
.Dimension(320, 20));
221 jTextFieldTokenSpaceGuid
.setVisible(false);
223 return jTextFieldTokenSpaceGuid
;
227 * This method initializes jTextFieldFeatureFlag
229 * @return javax.swing.JTextField
231 private JTextField
getJTextFieldFeatureFlag() {
232 if (jTextFieldFeatureFlag
== null) {
233 jTextFieldFeatureFlag
= new JTextField();
234 jTextFieldFeatureFlag
.setBounds(new java
.awt
.Rectangle(168, 182, 320, 20));
235 jTextFieldFeatureFlag
.setPreferredSize(new java
.awt
.Dimension(320, 20));
236 jTextFieldFeatureFlag
.setToolTipText("Postfix expression that must evaluate to TRUE or FALSE");
237 jTextFieldFeatureFlag
.setEnabled(false);
239 return jTextFieldFeatureFlag
;
243 * This method initializes jButtonOk
245 * @return javax.swing.JButton
248 private JButton
getJButtonOk() {
249 if (jButtonOk
== null) {
250 jButtonOk
= new JButton();
251 jButtonOk
.setBounds(new java
.awt
.Rectangle(290, 212, 90, 20));
252 jButtonOk
.setText("Ok");
253 jButtonOk
.addActionListener(this);
259 * This method initializes jButtonCancel
261 * @return javax.swing.JButton
264 private JButton
getJButtonCancel() {
265 if (jButtonCancel
== null) {
266 jButtonCancel
= new JButton();
267 jButtonCancel
.setBounds(new java
.awt
.Rectangle(390, 212, 90, 20));
268 jButtonCancel
.setText("Cancel");
269 jButtonCancel
.addActionListener(this);
271 return jButtonCancel
;
275 * This method initializes jComboBoxUsage
277 * @return javax.swing.JComboBox
279 private JComboBox
getJComboBoxUsage() {
280 if (jComboBoxUsage
== null) {
281 jComboBoxUsage
= new JComboBox();
282 jComboBoxUsage
.setBounds(new java
.awt
.Rectangle(168, 87, 320, 20));
283 jComboBoxUsage
.setPreferredSize(new java
.awt
.Dimension(320, 20));
285 return jComboBoxUsage
;
288 public static void main(String
[] args
) {
293 * This method initializes this
296 private void init() {
297 this.setSize(505, 280);
298 this.setContentPane(getJScrollPane());
299 this.setTitle("Pcd Coded");
301 this.setViewMode(false);
306 * This method initializes this Fill values to all fields if these values are
309 * @param inPcdCodedId
312 private void init(PcdCodedIdentification inPcdCodedId
, ModuleIdentification mid
) {
314 this.id
= inPcdCodedId
;
317 // Init arch with module's arch
319 this.jArchCheckBox
.setEnabledItems(wt
.getModuleArch(mid
));
322 // Get defined pcds from dependent packages
324 Vector
<PackageIdentification
> vpid
= wt
.getPackageDependenciesOfModule(mid
);
325 if (vpid
.size() <= 0) {
326 Log
.wrn("Init Pcd", "This module hasn't defined any package dependency, so there is no pcd can be added");
329 pcd
= wt
.getAllPcdDeclarationsFromPackages(wt
.getPackageDependenciesOfModule(mid
));
330 for (int index
= 0; index
< pcd
.size(); index
++) {
331 jComboBoxCName
.addItem(pcd
.getPcd(index
));
334 if (this.id
!= null) {
335 for (int index
= 0; index
< this.jComboBoxCName
.getItemCount(); index
++) {
336 if (this.jComboBoxCName
.getItemAt(index
).toString().equals(id
.getName())) {
337 this.jComboBoxCName
.setSelectedIndex(index
);
341 this.jTextFieldTokenSpaceGuid
.setText(id
.getGuid());
342 this.jTextFieldDefaultValue
.setText(id
.getValue());
343 this.jComboBoxUsage
.setSelectedItem(id
.getUsage());
344 this.jTextAreaHelpText
.setText(id
.getHelp());
345 this.jComboBoxItemType
.setSelectedItem(id
.getType());
346 this.jTextFieldFeatureFlag
.setText(id
.getFeatureFlag());
347 this.jArchCheckBox
.setSelectedItems(id
.getSupArchList());
352 * This is the override edit constructor
354 * @param inPcdCodedId
358 public PCDsDlg(PcdCodedIdentification inPcdCodedId
, IFrame iFrame
, ModuleIdentification mid
) {
360 init(inPcdCodedId
, mid
);
364 * Disable all components when the mode is view
367 * true - The view mode; false - The non-view mode
370 public void setViewMode(boolean isView
) {
372 this.jTextFieldDefaultValue
.setEnabled(!isView
);
373 this.jComboBoxItemType
.setEnabled(!isView
);
378 * This method initializes jContentPane
380 * @return javax.swing.JPanel jContentPane
383 private JPanel
getJContentPane() {
384 if (jContentPane
== null) {
385 jLabelUsage
= new JLabel();
386 jLabelUsage
.setBounds(new java
.awt
.Rectangle(12, 87, 168, 20));
387 jLabelUsage
.setText("Usge");
388 jStarLabel1
= new StarLabel();
389 jStarLabel1
.setLocation(new java
.awt
.Point(2, 12));
390 jLabelC_Name
= new JLabel();
391 jLabelC_Name
.setText("PCD C Name");
392 jLabelC_Name
.setBounds(new java
.awt
.Rectangle(12, 12, 168, 20));
394 jStarLabel2
= new StarLabel();
395 jStarLabel2
.setLocation(new java
.awt
.Point(2, 37));
396 jLabelItemType
= new JLabel();
397 jLabelItemType
.setText("PCD Item Type");
398 jLabelItemType
.setBounds(new java
.awt
.Rectangle(12, 37, 168, 20));
400 jLabelDefaultValue
= new JLabel();
401 jLabelDefaultValue
.setText("Default Value");
402 jLabelDefaultValue
.setBounds(new java
.awt
.Rectangle(12, 62, 168, 20));
404 jStarLabel3
= new StarLabel();
405 jStarLabel3
.setLocation(new java
.awt
.Point(2, 112));
406 jLabelHelpText
= new JLabel();
407 jLabelHelpText
.setText("Help Text");
408 jLabelHelpText
.setBounds(new java
.awt
.Rectangle(12, 112, 168, 20));
410 jLabelFeatureFlag
= new JLabel();
411 jLabelFeatureFlag
.setText("Feature Flag Expression");
412 jLabelFeatureFlag
.setBounds(new java
.awt
.Rectangle(12, 182, 168, 20));
413 jLabelFeatureFlag
.setEnabled(false);
415 jLabelTokenSpaceGuid
= new JLabel();
416 jLabelTokenSpaceGuid
.setText("Token Space C Name");
417 jLabelTokenSpaceGuid
.setVisible(false);
419 jLabelArch
= new JLabel();
420 jLabelArch
.setText("Supported Architectures");
421 jLabelArch
.setBounds(new java
.awt
.Rectangle(12, 157, 168, 20));
422 jArchCheckBox
= new ArchCheckBox();
423 jArchCheckBox
.setPreferredSize(new java
.awt
.Dimension(320, 20));
424 jArchCheckBox
.setBounds(new java
.awt
.Rectangle(168, 157, 320, 20));
427 jLabelTokenSpaceGuid
.setBounds(new java
.awt
.Rectangle(12, 62, 140, 20));
429 jContentPane
= new JPanel();
430 jContentPane
.setLayout(null);
431 jContentPane
.setPreferredSize(new java
.awt
.Dimension(485, 235));
433 jContentPane
.add(jStarLabel1
, null);
434 jContentPane
.add(jLabelC_Name
, null);
435 jContentPane
.add(getJComboBoxCName(), null);
436 jContentPane
.add(jStarLabel2
, null);
437 jContentPane
.add(jLabelItemType
, null);
438 jContentPane
.add(getJComboBoxItemType(), null);
439 jContentPane
.add(jLabelDefaultValue
, null);
440 jContentPane
.add(getJTextFieldDefaultValue(), null);
441 jContentPane
.add(jStarLabel3
, null);
442 jContentPane
.add(jLabelHelpText
, null);
443 jContentPane
.add(getJScrollPaneHelpText(), null);
444 jContentPane
.add(jLabelFeatureFlag
, null);
445 jContentPane
.add(getJTextFieldFeatureFlag(), null);
446 jContentPane
.add(jLabelArch
, null);
447 jContentPane
.add(jArchCheckBox
, null);
449 jContentPane
.add(getJTextFieldTokenSpaceGuid(), null);
450 jContentPane
.add(jLabelTokenSpaceGuid
, null);
451 jContentPane
.add(getJButtonOk(), null);
452 jContentPane
.add(getJButtonCancel(), null);
453 jContentPane
.add(jLabelUsage
, null);
454 jContentPane
.add(getJComboBoxUsage(), null);
460 * This method initializes Usage type, Item type and Datum type
463 private void initFrame() {
464 Tools
.generateComboBoxByVector(jComboBoxUsage
, ed
.getVPcdUsage());
470 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
472 * Override actionPerformed to listen all actions
475 public void actionPerformed(ActionEvent arg0
) {
476 if (arg0
.getSource() == jButtonOk
) {
478 getCurrentPcdCoded();
479 this.returnType
= DataType
.RETURN_TYPE_OK
;
480 this.setVisible(false);
484 if (arg0
.getSource() == jButtonCancel
) {
485 this.returnType
= DataType
.RETURN_TYPE_CANCEL
;
486 this.setVisible(false);
491 * Data validation for all fields
493 * @retval true - All datas are valid
494 * @retval false - At least one data is invalid
497 public boolean checkAdd() {
499 // Check if all fields have correct data types
505 if (this.jComboBoxCName
.getSelectedItem() == null) {
506 Log
.wrn("Update Pcd", "Please select one Pcd Name");
510 if (!isEmpty(this.jComboBoxCName
.getSelectedItem().toString())) {
511 if (!DataValidation
.isC_NameType(this.jComboBoxCName
.getSelectedItem().toString())) {
512 Log
.wrn("Update PcdCoded", "Incorrect data type for C Name");
518 // Check TokenSpaceGuid
520 if (!isEmpty(this.jTextFieldTokenSpaceGuid
.getText())) {
521 if (!DataValidation
.isC_NameType(this.jTextFieldTokenSpaceGuid
.getText())) {
522 Log
.wrn("Update PcdCoded",
523 "Incorrect data type for the selected pcd entry, please check the datatype specified in the spd file");
529 // Check DefaultValue
531 if (!isEmpty(this.jTextFieldDefaultValue
.getText())) {
532 if (!DataValidation
.isDefaultValueType(this.jTextFieldDefaultValue
.getText())) {
533 Log
.wrn("Update PcdCoded", "Incorrect data type for Default Value");
541 if (isEmpty(this.jTextAreaHelpText
.getText())) {
542 Log
.wrn("Update PcdCoded", "Help Text should not be empty");
549 if (!isEmpty(this.jTextFieldFeatureFlag
.getText())) {
550 if (!DataValidation
.isFeatureFlag(this.jTextFieldFeatureFlag
.getText())) {
551 Log
.wrn("Update PcdCoded", "Incorrect data type for Feature Flag");
559 private PcdCodedIdentification
getCurrentPcdCoded() {
560 String arg0
= this.jComboBoxCName
.getSelectedItem().toString();
561 String arg1
= this.jTextFieldTokenSpaceGuid
.getText();
563 String arg2
= this.jTextFieldFeatureFlag
.getText();
564 Vector
<String
> arg3
= this.jArchCheckBox
.getSelectedItemsVector();
566 String arg4
= this.jTextFieldDefaultValue
.getText();
567 String arg5
= this.jTextAreaHelpText
.getText();
568 String arg6
= this.jComboBoxItemType
.getSelectedItem().toString();
569 String arg7
= this.jComboBoxUsage
.getSelectedItem().toString();
570 if (arg7
.equals(DataType
.EMPTY_SELECT_ITEM
)) {
574 id
= new PcdCodedIdentification(arg0
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
, arg7
);
578 public PcdCodedIdentification
getId() {
582 public void setId(PcdCodedIdentification id
) {
589 * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
591 * Reflesh the frame when selected item changed
594 public void itemStateChanged(ItemEvent arg0
) {
595 int index
= this.jComboBoxCName
.getSelectedIndex();
596 if (arg0
.getSource() == this.jComboBoxCName
&& arg0
.getStateChange() == ItemEvent
.SELECTED
) {
597 if (pcd
.getPcd(index
).getGuidCName() == null || isEmpty(pcd
.getPcd(index
).getGuidCName())
598 || pcd
.getPcd(index
).getType() == null || pcd
.getPcd(index
).getHelp() == null
599 || isEmpty(pcd
.getPcd(index
).getHelp())) {
600 Log
.wrn("select pcd entry when editing msa",
601 "The selected value is defined incorrectly.\r\nPlease check it in the spd file");
603 this.jTextFieldTokenSpaceGuid
.setText(pcd
.getPcd(index
).getGuidCName());
604 Tools
.generateComboBoxByVector(this.jComboBoxItemType
, pcd
.getPcd(index
).getType());
605 this.jTextAreaHelpText
.setText(pcd
.getPcd(index
).getHelp());
606 this.jTextAreaHelpText
.setSelectionStart(0);
607 this.jTextAreaHelpText
.setSelectionEnd(0);