3 The file is used to create, update PCD 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
.event
.ActionEvent
;
18 import java
.util
.Vector
;
20 import javax
.swing
.JButton
;
21 import javax
.swing
.JComboBox
;
22 import javax
.swing
.JLabel
;
23 import javax
.swing
.JPanel
;
24 import javax
.swing
.JScrollPane
;
25 import javax
.swing
.JTextField
;
27 import org
.tianocore
.frameworkwizard
.common
.DataType
;
28 import org
.tianocore
.frameworkwizard
.common
.DataValidation
;
29 import org
.tianocore
.frameworkwizard
.common
.EnumerationData
;
30 import org
.tianocore
.frameworkwizard
.common
.Log
;
31 import org
.tianocore
.frameworkwizard
.common
.Tools
;
32 import org
.tianocore
.frameworkwizard
.common
.ui
.ArchCheckBox
;
33 import org
.tianocore
.frameworkwizard
.common
.ui
.IDialog
;
34 import org
.tianocore
.frameworkwizard
.common
.ui
.IFrame
;
35 import org
.tianocore
.frameworkwizard
.common
.ui
.StarLabel
;
36 import org
.tianocore
.frameworkwizard
.module
.Identifications
.PcdCoded
.PcdCodedIdentification
;
37 import org
.tianocore
.frameworkwizard
.workspace
.WorkspaceTools
;
40 The class is used to create, update PCD of MSA/MBD file
41 It extends IInternalFrame
46 public class PCDsDlg
extends IDialog
{
49 /// Define class Serial Version UID
51 private static final long serialVersionUID
= 2227717658188438696L;
54 //Define class members
56 private JPanel jContentPane
= null;
58 private JLabel jLabelItemType
= null;
60 private JLabel jLabelC_Name
= null;
62 private JComboBox jComboBoxItemType
= null;
64 private JComboBox jComboBoxCName
= null;
66 private JLabel jLabelDefaultValue
= null;
68 private JTextField jTextFieldDefaultValue
= null;
70 private StarLabel jStarLabel1
= null;
72 private StarLabel jStarLabel2
= null;
74 private StarLabel jStarLabel3
= null;
76 private JLabel jLabelHelpText
= null;
78 private JTextField jTextFieldHelpText
= null;
80 private JScrollPane jScrollPane
= null;
82 private JLabel jLabelTokenSpaceGuid
= null;
84 private JTextField jTextFieldTokenSpaceGuid
= null;
86 private JLabel jLabelFeatureFlag
= null;
88 private JTextField jTextFieldFeatureFlag
= null;
90 private JLabel jLabelArch
= null;
92 private ArchCheckBox jArchCheckBox
= null;
94 private JButton jButtonOk
= null;
96 private JButton jButtonCancel
= null;
101 private PcdCodedIdentification id
= null;
103 private EnumerationData ed
= new EnumerationData();
105 private WorkspaceTools wt
= new WorkspaceTools();
108 This method initializes jComboBoxItemType
110 @return javax.swing.JComboBox jComboBoxItemType
113 private JComboBox
getJComboBoxItemType() {
114 if (jComboBoxItemType
== null) {
115 jComboBoxItemType
= new JComboBox();
116 jComboBoxItemType
.setBounds(new java
.awt
.Rectangle(160, 35, 320, 20));
117 jComboBoxItemType
.setPreferredSize(new java
.awt
.Dimension(320, 20));
119 return jComboBoxItemType
;
123 This method initializes jTextFieldC_Name
125 @return javax.swing.JTextField jTextFieldC_Name
128 private JComboBox
getJComboBoxCName() {
129 if (jComboBoxCName
== null) {
130 jComboBoxCName
= new JComboBox();
131 jComboBoxCName
.setBounds(new java
.awt
.Rectangle(160, 10, 320, 20));
132 jComboBoxCName
.setPreferredSize(new java
.awt
.Dimension(320, 20));
134 return jComboBoxCName
;
138 This method initializes jTextFieldDefaultValue
140 @return javax.swing.JTextField jTextFieldDefaultValue
143 private JTextField
getJTextFieldDefaultValue() {
144 if (jTextFieldDefaultValue
== null) {
145 jTextFieldDefaultValue
= new JTextField();
146 jTextFieldDefaultValue
.setBounds(new java
.awt
.Rectangle(160, 60, 320, 20));
147 jTextFieldDefaultValue
.setPreferredSize(new java
.awt
.Dimension(320, 20));
149 return jTextFieldDefaultValue
;
153 * This method initializes jTextFieldHelpText
155 * @return javax.swing.JTextField
157 private JTextField
getJTextFieldHelpText() {
158 if (jTextFieldHelpText
== null) {
159 jTextFieldHelpText
= new JTextField();
160 jTextFieldHelpText
.setBounds(new java
.awt
.Rectangle(160, 85, 320, 20));
161 jTextFieldHelpText
.setPreferredSize(new java
.awt
.Dimension(320, 20));
163 return jTextFieldHelpText
;
167 This method initializes jScrollPane
169 @return javax.swing.JScrollPane
171 private JScrollPane
getJScrollPane() {
172 if (jScrollPane
== null) {
173 jScrollPane
= new JScrollPane();
174 jScrollPane
.setViewportView(getJContentPane());
180 * This method initializes jTextFieldTokenSpaceGuid
182 * @return javax.swing.JTextField
184 private JTextField
getJTextFieldTokenSpaceGuid() {
185 if (jTextFieldTokenSpaceGuid
== null) {
186 jTextFieldTokenSpaceGuid
= new JTextField();
187 jTextFieldTokenSpaceGuid
.setBounds(new java
.awt
.Rectangle(160, 60, 320, 20));
188 jTextFieldTokenSpaceGuid
.setPreferredSize(new java
.awt
.Dimension(320, 20));
189 jTextFieldTokenSpaceGuid
.setVisible(false);
191 return jTextFieldTokenSpaceGuid
;
195 * This method initializes jTextFieldFeatureFlag
197 * @return javax.swing.JTextField
199 private JTextField
getJTextFieldFeatureFlag() {
200 if (jTextFieldFeatureFlag
== null) {
201 jTextFieldFeatureFlag
= new JTextField();
202 jTextFieldFeatureFlag
.setBounds(new java
.awt
.Rectangle(160, 110, 320, 20));
203 jTextFieldFeatureFlag
.setPreferredSize(new java
.awt
.Dimension(320, 20));
205 return jTextFieldFeatureFlag
;
209 This method initializes jButtonOk
211 @return javax.swing.JButton
214 private JButton
getJButtonOk() {
215 if (jButtonOk
== null) {
216 jButtonOk
= new JButton();
217 jButtonOk
.setBounds(new java
.awt
.Rectangle(290, 165, 90, 20));
218 jButtonOk
.setText("Ok");
219 jButtonOk
.addActionListener(this);
225 This method initializes jButtonCancel
227 @return javax.swing.JButton
230 private JButton
getJButtonCancel() {
231 if (jButtonCancel
== null) {
232 jButtonCancel
= new JButton();
233 jButtonCancel
.setBounds(new java
.awt
.Rectangle(390, 165, 90, 20));
234 jButtonCancel
.setText("Cancel");
235 jButtonCancel
.addActionListener(this);
237 return jButtonCancel
;
240 public static void main(String
[] args
) {
245 This method initializes this
248 private void init() {
249 this.setSize(500, 225);
250 this.setContentPane(getJScrollPane());
251 this.setTitle("Pcd Coded");
253 this.setViewMode(false);
258 This method initializes this
259 Fill values to all fields if these values are not empty
264 private void init(PcdCodedIdentification inPcdCodedId
) {
266 this.id
= inPcdCodedId
;
268 if (this.id
!= null) {
269 this.jComboBoxCName
.setSelectedItem(id
.getName());
270 this.jTextFieldTokenSpaceGuid
.setText(id
.getGuid());
271 this.jTextFieldDefaultValue
.setText(id
.getValue());
272 this.jTextFieldHelpText
.setText(id
.getHelp());
273 this.jComboBoxItemType
.setSelectedItem(id
.getType());
274 this.jTextFieldFeatureFlag
.setText(id
.getFeatureFlag());
275 this.jArchCheckBox
.setSelectedItems(id
.getSupArchList());
280 This is the override edit constructor
286 public PCDsDlg(PcdCodedIdentification inPcdCodedId
, IFrame iFrame
) {
292 Disable all components when the mode is view
294 @param isView true - The view mode; false - The non-view mode
297 public void setViewMode(boolean isView
) {
299 this.jTextFieldDefaultValue
.setEnabled(!isView
);
300 this.jComboBoxItemType
.setEnabled(!isView
);
305 This method initializes jContentPane
307 @return javax.swing.JPanel jContentPane
310 private JPanel
getJContentPane() {
311 if (jContentPane
== null) {
312 jArchCheckBox
= new ArchCheckBox();
313 jArchCheckBox
.setBounds(new java
.awt
.Rectangle(160, 135, 320, 20));
314 jArchCheckBox
.setPreferredSize(new java
.awt
.Dimension(320, 20));
315 jLabelArch
= new JLabel();
316 jLabelArch
.setBounds(new java
.awt
.Rectangle(15, 135, 140, 20));
317 jLabelArch
.setText("Sup Arch List");
318 jLabelFeatureFlag
= new JLabel();
319 jLabelFeatureFlag
.setBounds(new java
.awt
.Rectangle(15, 110, 140, 20));
320 jLabelFeatureFlag
.setText("Feature Flag");
321 jLabelTokenSpaceGuid
= new JLabel();
322 jLabelTokenSpaceGuid
.setBounds(new java
.awt
.Rectangle(15, 60, 140, 20));
323 jLabelTokenSpaceGuid
.setText("Token Space C_Name");
324 jLabelTokenSpaceGuid
.setVisible(false);
325 jLabelHelpText
= new JLabel();
326 jLabelHelpText
.setBounds(new java
.awt
.Rectangle(15, 85, 140, 20));
327 jLabelHelpText
.setText("Help Text");
328 jLabelC_Name
= new JLabel();
329 jLabelC_Name
.setText("C_Name");
330 jLabelC_Name
.setBounds(new java
.awt
.Rectangle(15, 10, 140, 20));
331 jLabelDefaultValue
= new JLabel();
332 jLabelDefaultValue
.setText("Default Value");
333 jLabelDefaultValue
.setBounds(new java
.awt
.Rectangle(15, 60, 140, 20));
334 jLabelItemType
= new JLabel();
335 jLabelItemType
.setText("Item Type");
336 jLabelItemType
.setBounds(new java
.awt
.Rectangle(15, 35, 140, 20));
338 jContentPane
= new JPanel();
339 jContentPane
.setLayout(null);
340 jContentPane
.setPreferredSize(new java
.awt
.Dimension(490, 190));
342 jContentPane
.add(jLabelItemType
, null);
343 jContentPane
.add(jLabelC_Name
, null);
344 jContentPane
.add(getJComboBoxCName(), null);
345 jContentPane
.add(jLabelDefaultValue
, null);
346 jContentPane
.add(getJTextFieldDefaultValue(), null);
347 jContentPane
.add(getJComboBoxItemType(), null);
348 jStarLabel1
= new StarLabel();
349 jStarLabel1
.setLocation(new java
.awt
.Point(0, 10));
350 jStarLabel2
= new StarLabel();
351 jStarLabel2
.setLocation(new java
.awt
.Point(0, 35));
352 jStarLabel3
= new StarLabel();
353 jStarLabel3
.setLocation(new java
.awt
.Point(0, 85));
354 jContentPane
.add(jStarLabel1
, null);
355 jContentPane
.add(jStarLabel2
, null);
356 jContentPane
.add(jStarLabel3
, null);
357 jContentPane
.add(jLabelHelpText
, null);
358 jContentPane
.add(getJTextFieldHelpText(), null);
360 jContentPane
.add(jLabelTokenSpaceGuid
, null);
361 jContentPane
.add(getJTextFieldTokenSpaceGuid(), null);
362 jContentPane
.add(jLabelFeatureFlag
, null);
363 jContentPane
.add(getJTextFieldFeatureFlag(), null);
364 jContentPane
.add(jLabelArch
, null);
365 jContentPane
.add(jArchCheckBox
, null);
366 jContentPane
.add(getJButtonOk(), null);
367 jContentPane
.add(getJButtonCancel(), null);
373 This method initializes Usage type, Item type and Datum type
376 private void initFrame() {
377 Tools
.generateComboBoxByVector(jComboBoxCName
, wt
.getAllPcdDeclarationsFromWorkspace());
378 Tools
.generateComboBoxByVector(jComboBoxItemType
, ed
.getVPcdItemTypes());
382 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
384 * Override actionPerformed to listen all actions
387 public void actionPerformed(ActionEvent arg0
) {
388 if (arg0
.getSource() == jButtonOk
) {
390 getCurrentPcdCoded();
391 this.returnType
= DataType
.RETURN_TYPE_OK
;
392 this.setVisible(false);
396 if (arg0
.getSource() == jButtonCancel
) {
397 this.returnType
= DataType
.RETURN_TYPE_CANCEL
;
398 this.setVisible(false);
403 Data validation for all fields
405 @retval true - All datas are valid
406 @retval false - At least one data is invalid
409 public boolean checkAdd() {
411 // Check if all fields have correct data types
417 if (!isEmpty(this.jComboBoxCName
.getSelectedItem().toString())) {
418 if (!DataValidation
.isC_NameType(this.jComboBoxCName
.getSelectedItem().toString())) {
419 Log
.err("Incorrect data type for C_Name");
425 // Check TokenSpaceGuid
427 // if (!isEmpty(this.jTextFieldTokenSpaceGuid.getText())) {
428 // if (!DataValidation.isC_NameType(this.jTextFieldTokenSpaceGuid.getText())) {
429 // Log.err("Incorrect data type for Token Space C_Name");
435 // Check DefaultValue
437 if (!isEmpty(this.jTextFieldDefaultValue
.getText())) {
438 if (!DataValidation
.isDefaultValueType(this.jTextFieldDefaultValue
.getText())) {
439 Log
.err("Incorrect data type for Default Value");
447 if (isEmpty(this.jTextFieldHelpText
.getText())) {
448 Log
.err("Help Text couldn't be empty");
455 if (!isEmpty(this.jTextFieldFeatureFlag
.getText())) {
456 if (!DataValidation
.isFeatureFlag(this.jTextFieldFeatureFlag
.getText())) {
457 Log
.err("Incorrect data type for Feature Flag");
465 private PcdCodedIdentification
getCurrentPcdCoded() {
466 String arg0
= this.jComboBoxCName
.getSelectedItem().toString();
467 String arg1
= this.jTextFieldTokenSpaceGuid
.getText();
469 String arg2
= this.jTextFieldFeatureFlag
.getText();
470 Vector
<String
> arg3
= this.jArchCheckBox
.getSelectedItemsVector();
472 String arg4
= this.jTextFieldDefaultValue
.getText();
473 String arg5
= this.jTextFieldHelpText
.getText();
474 String arg6
= this.jComboBoxItemType
.getSelectedItem().toString();
475 id
= new PcdCodedIdentification(arg0
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
479 public PcdCodedIdentification
getId() {
483 public void setId(PcdCodedIdentification id
) {