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
;
316 Vector
<PackageIdentification
> vpid
= wt
.getPackageDependenciesOfModule(mid
);
317 if (vpid
.size() <= 0) {
318 Log
.wrn("Init Pcd", "This module hasn't defined any package dependency, so there is no pcd can be added");
321 pcd
= wt
.getAllPcdDeclarationsFromPackages(wt
.getPackageDependenciesOfModule(mid
));
322 for (int index
= 0; index
< pcd
.size(); index
++) {
323 jComboBoxCName
.addItem(pcd
.getPcd(index
));
326 if (this.id
!= null) {
327 for (int index
= 0; index
< this.jComboBoxCName
.getItemCount(); index
++) {
328 if (this.jComboBoxCName
.getItemAt(index
).toString().equals(id
.getName())) {
329 this.jComboBoxCName
.setSelectedIndex(index
);
333 this.jTextFieldTokenSpaceGuid
.setText(id
.getGuid());
334 this.jTextFieldDefaultValue
.setText(id
.getValue());
335 this.jComboBoxUsage
.setSelectedItem(id
.getUsage());
336 this.jTextAreaHelpText
.setText(id
.getHelp());
337 this.jComboBoxItemType
.setSelectedItem(id
.getType());
338 this.jTextFieldFeatureFlag
.setText(id
.getFeatureFlag());
339 this.jArchCheckBox
.setSelectedItems(id
.getSupArchList());
344 * This is the override edit constructor
346 * @param inPcdCodedId
350 public PCDsDlg(PcdCodedIdentification inPcdCodedId
, IFrame iFrame
, ModuleIdentification mid
) {
352 init(inPcdCodedId
, mid
);
356 * Disable all components when the mode is view
359 * true - The view mode; false - The non-view mode
362 public void setViewMode(boolean isView
) {
364 this.jTextFieldDefaultValue
.setEnabled(!isView
);
365 this.jComboBoxItemType
.setEnabled(!isView
);
370 * This method initializes jContentPane
372 * @return javax.swing.JPanel jContentPane
375 private JPanel
getJContentPane() {
376 if (jContentPane
== null) {
377 jLabelUsage
= new JLabel();
378 jLabelUsage
.setBounds(new java
.awt
.Rectangle(12, 87, 168, 20));
379 jLabelUsage
.setText("Usge");
380 jStarLabel1
= new StarLabel();
381 jStarLabel1
.setLocation(new java
.awt
.Point(2, 12));
382 jLabelC_Name
= new JLabel();
383 jLabelC_Name
.setText("PCD C Name");
384 jLabelC_Name
.setBounds(new java
.awt
.Rectangle(12, 12, 168, 20));
386 jStarLabel2
= new StarLabel();
387 jStarLabel2
.setLocation(new java
.awt
.Point(2, 37));
388 jLabelItemType
= new JLabel();
389 jLabelItemType
.setText("PCD Item Type");
390 jLabelItemType
.setBounds(new java
.awt
.Rectangle(12, 37, 168, 20));
392 jLabelDefaultValue
= new JLabel();
393 jLabelDefaultValue
.setText("Default Value");
394 jLabelDefaultValue
.setBounds(new java
.awt
.Rectangle(12, 62, 168, 20));
396 jStarLabel3
= new StarLabel();
397 jStarLabel3
.setLocation(new java
.awt
.Point(2, 112));
398 jLabelHelpText
= new JLabel();
399 jLabelHelpText
.setText("Help Text");
400 jLabelHelpText
.setBounds(new java
.awt
.Rectangle(12, 112, 168, 20));
402 jLabelFeatureFlag
= new JLabel();
403 jLabelFeatureFlag
.setText("Feature Flag Expression");
404 jLabelFeatureFlag
.setBounds(new java
.awt
.Rectangle(12, 182, 168, 20));
405 jLabelFeatureFlag
.setEnabled(false);
407 jLabelTokenSpaceGuid
= new JLabel();
408 jLabelTokenSpaceGuid
.setText("Token Space C Name");
409 jLabelTokenSpaceGuid
.setVisible(false);
411 jLabelArch
= new JLabel();
412 jLabelArch
.setText("Supported Architectures");
413 jLabelArch
.setBounds(new java
.awt
.Rectangle(12, 157, 168, 20));
414 jArchCheckBox
= new ArchCheckBox();
415 jArchCheckBox
.setPreferredSize(new java
.awt
.Dimension(320, 20));
416 jArchCheckBox
.setBounds(new java
.awt
.Rectangle(168, 157, 320, 20));
419 jLabelTokenSpaceGuid
.setBounds(new java
.awt
.Rectangle(12, 62, 140, 20));
421 jContentPane
= new JPanel();
422 jContentPane
.setLayout(null);
423 jContentPane
.setPreferredSize(new java
.awt
.Dimension(485, 235));
425 jContentPane
.add(jStarLabel1
, null);
426 jContentPane
.add(jLabelC_Name
, null);
427 jContentPane
.add(getJComboBoxCName(), null);
428 jContentPane
.add(jStarLabel2
, null);
429 jContentPane
.add(jLabelItemType
, null);
430 jContentPane
.add(getJComboBoxItemType(), null);
431 jContentPane
.add(jLabelDefaultValue
, null);
432 jContentPane
.add(getJTextFieldDefaultValue(), null);
433 jContentPane
.add(jStarLabel3
, null);
434 jContentPane
.add(jLabelHelpText
, null);
435 jContentPane
.add(getJScrollPaneHelpText(), null);
436 jContentPane
.add(jLabelFeatureFlag
, null);
437 jContentPane
.add(getJTextFieldFeatureFlag(), null);
438 jContentPane
.add(jLabelArch
, null);
439 jContentPane
.add(jArchCheckBox
, null);
441 jContentPane
.add(getJTextFieldTokenSpaceGuid(), null);
442 jContentPane
.add(jLabelTokenSpaceGuid
, null);
443 jContentPane
.add(getJButtonOk(), null);
444 jContentPane
.add(getJButtonCancel(), null);
445 jContentPane
.add(jLabelUsage
, null);
446 jContentPane
.add(getJComboBoxUsage(), null);
452 * This method initializes Usage type, Item type and Datum type
455 private void initFrame() {
456 Tools
.generateComboBoxByVector(jComboBoxUsage
, ed
.getVPcdUsage());
462 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
464 * Override actionPerformed to listen all actions
467 public void actionPerformed(ActionEvent arg0
) {
468 if (arg0
.getSource() == jButtonOk
) {
470 getCurrentPcdCoded();
471 this.returnType
= DataType
.RETURN_TYPE_OK
;
472 this.setVisible(false);
476 if (arg0
.getSource() == jButtonCancel
) {
477 this.returnType
= DataType
.RETURN_TYPE_CANCEL
;
478 this.setVisible(false);
483 * Data validation for all fields
485 * @retval true - All datas are valid
486 * @retval false - At least one data is invalid
489 public boolean checkAdd() {
491 // Check if all fields have correct data types
497 if (this.jComboBoxCName
.getSelectedItem() == null) {
498 Log
.wrn("Update Pcd", "Please select one Pcd Name");
502 if (!isEmpty(this.jComboBoxCName
.getSelectedItem().toString())) {
503 if (!DataValidation
.isC_NameType(this.jComboBoxCName
.getSelectedItem().toString())) {
504 Log
.wrn("Update PcdCoded", "Incorrect data type for C Name");
510 // Check TokenSpaceGuid
512 if (!isEmpty(this.jTextFieldTokenSpaceGuid
.getText())) {
513 if (!DataValidation
.isC_NameType(this.jTextFieldTokenSpaceGuid
.getText())) {
514 Log
.wrn("Update PcdCoded",
515 "Incorrect data type for the selected pcd entry, please check the datatype specified in the spd file");
521 // Check DefaultValue
523 if (!isEmpty(this.jTextFieldDefaultValue
.getText())) {
524 if (!DataValidation
.isDefaultValueType(this.jTextFieldDefaultValue
.getText())) {
525 Log
.wrn("Update PcdCoded", "Incorrect data type for Default Value");
533 if (isEmpty(this.jTextAreaHelpText
.getText())) {
534 Log
.wrn("Update PcdCoded", "Help Text should not be empty");
541 if (!isEmpty(this.jTextFieldFeatureFlag
.getText())) {
542 if (!DataValidation
.isFeatureFlag(this.jTextFieldFeatureFlag
.getText())) {
543 Log
.wrn("Update PcdCoded", "Incorrect data type for Feature Flag");
551 private PcdCodedIdentification
getCurrentPcdCoded() {
552 String arg0
= this.jComboBoxCName
.getSelectedItem().toString();
553 String arg1
= this.jTextFieldTokenSpaceGuid
.getText();
555 String arg2
= this.jTextFieldFeatureFlag
.getText();
556 Vector
<String
> arg3
= this.jArchCheckBox
.getSelectedItemsVector();
558 String arg4
= this.jTextFieldDefaultValue
.getText();
559 String arg5
= this.jTextAreaHelpText
.getText();
560 String arg6
= this.jComboBoxItemType
.getSelectedItem().toString();
561 String arg7
= this.jComboBoxUsage
.getSelectedItem().toString();
562 if (arg7
.equals(DataType
.EMPTY_SELECT_ITEM
)) {
566 id
= new PcdCodedIdentification(arg0
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
, arg7
);
570 public PcdCodedIdentification
getId() {
574 public void setId(PcdCodedIdentification id
) {
581 * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
583 * Reflesh the frame when selected item changed
586 public void itemStateChanged(ItemEvent arg0
) {
587 int index
= this.jComboBoxCName
.getSelectedIndex();
588 if (arg0
.getSource() == this.jComboBoxCName
&& arg0
.getStateChange() == ItemEvent
.SELECTED
) {
589 if (pcd
.getPcd(index
).getGuidCName() == null || isEmpty(pcd
.getPcd(index
).getGuidCName())
590 || pcd
.getPcd(index
).getType() == null || pcd
.getPcd(index
).getHelp() == null
591 || isEmpty(pcd
.getPcd(index
).getHelp())) {
592 Log
.wrn("select pcd entry when editing msa",
593 "The selected value is defined incorrectly.\r\nPlease check it in the spd file");
595 this.jTextFieldTokenSpaceGuid
.setText(pcd
.getPcd(index
).getGuidCName());
596 Tools
.generateComboBoxByVector(this.jComboBoxItemType
, pcd
.getPcd(index
).getType());
597 this.jTextAreaHelpText
.setText(pcd
.getPcd(index
).getHelp());
598 this.jTextAreaHelpText
.setSelectionStart(0);
599 this.jTextAreaHelpText
.setSelectionEnd(0);