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
.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
.JTextField
;
25 import org
.tianocore
.PCDsDocument
;
26 import org
.tianocore
.PcdDataTypes
;
27 import org
.tianocore
.PcdItemTypes
;
28 import org
.tianocore
.PcdUsage
;
29 import org
.tianocore
.common
.DataValidation
;
30 import org
.tianocore
.common
.Log
;
31 import org
.tianocore
.packaging
.common
.ui
.IInternalFrame
;
32 import org
.tianocore
.packaging
.common
.ui
.StarLabel
;
35 The class is used to create, update PCD of MSA/MBD file
36 It extends IInternalFrame
38 @since ModuleEditor 1.0
41 public class ModulePCDs
extends IInternalFrame
{
44 /// Define class Serial Version UID
46 private static final long serialVersionUID
= 2227717658188438696L;
49 //Define class members
51 private PCDsDocument
.PCDs pcds
= null;
53 private int location
= -1;
55 private JPanel jContentPane
= null;
57 private JLabel jLabelItemType
= null;
59 private JLabel jLabelC_Name
= null;
61 private JComboBox jComboBoxItemType
= null;
63 private JTextField jTextFieldC_Name
= null;
65 private JLabel jLabelToken
= null;
67 private JTextField jTextFieldToken
= null;
69 private JLabel jLabelDefaultValue
= null;
71 private JTextField jTextFieldDefaultValue
= null;
73 private JLabel jLabelUsage
= null;
75 private JComboBox jComboBoxUsage
= null;
77 private JButton jButtonOk
= null;
79 private JButton jButtonCancel
= null;
81 private JLabel jLabelDatumType
= null;
83 private JComboBox jComboBoxDatumType
= null;
85 private StarLabel jStarLabel1
= null;
87 private StarLabel jStarLabel2
= null;
89 private StarLabel jStarLabel3
= null;
91 private StarLabel jStarLabel4
= null;
94 This method initializes jComboBoxItemType
96 @return javax.swing.JComboBox jComboBoxItemType
99 private JComboBox
getJComboBoxItemType() {
100 if (jComboBoxItemType
== null) {
101 jComboBoxItemType
= new JComboBox();
102 jComboBoxItemType
.setBounds(new java
.awt
.Rectangle(160, 110, 320, 20));
104 return jComboBoxItemType
;
108 This method initializes jTextFieldC_Name
110 @return javax.swing.JTextField jTextFieldC_Name
113 private JTextField
getJTextFieldC_Name() {
114 if (jTextFieldC_Name
== null) {
115 jTextFieldC_Name
= new JTextField();
116 jTextFieldC_Name
.setBounds(new java
.awt
.Rectangle(160, 10, 320, 20));
118 return jTextFieldC_Name
;
122 This method initializes jTextFieldToken
124 @return javax.swing.JTextField jTextFieldToken
127 private JTextField
getJTextFieldToken() {
128 if (jTextFieldToken
== null) {
129 jTextFieldToken
= new JTextField();
130 jTextFieldToken
.setBounds(new java
.awt
.Rectangle(160, 35, 320, 20));
132 return jTextFieldToken
;
136 This method initializes jTextFieldDefaultValue
138 @return javax.swing.JTextField jTextFieldDefaultValue
141 private JTextField
getJTextFieldDefaultValue() {
142 if (jTextFieldDefaultValue
== null) {
143 jTextFieldDefaultValue
= new JTextField();
144 jTextFieldDefaultValue
.setBounds(new java
.awt
.Rectangle(160, 85, 320, 20));
146 return jTextFieldDefaultValue
;
150 This method initializes jComboBoxUsage
152 @return javax.swing.JComboBox jComboBoxUsage
155 private JComboBox
getJComboBoxUsage() {
156 if (jComboBoxUsage
== null) {
157 jComboBoxUsage
= new JComboBox();
158 jComboBoxUsage
.setBounds(new java
.awt
.Rectangle(160, 135, 320, 20));
160 return jComboBoxUsage
;
164 This method initializes jButtonOk
166 @return javax.swing.JButton jButtonOk
169 private JButton
getJButtonOk() {
170 if (jButtonOk
== null) {
171 jButtonOk
= new JButton();
172 jButtonOk
.setText("OK");
173 jButtonOk
.setBounds(new java
.awt
.Rectangle(280, 290, 90, 20));
174 jButtonOk
.addActionListener(this);
180 This method initializes jButtonCancel
182 @return javax.swing.JButton jButtonCancel
185 private JButton
getJButtonCancel() {
186 if (jButtonCancel
== null) {
187 jButtonCancel
= new JButton();
188 jButtonCancel
.setText("Cancel");
189 jButtonCancel
.setBounds(new java
.awt
.Rectangle(390, 290, 90, 20));
190 jButtonCancel
.addActionListener(this);
192 return jButtonCancel
;
196 This method initializes jTextFieldDatumType
198 @return javax.swing.JTextField jComboBoxDatumType
201 private JComboBox
getJComboBoxDatumType() {
202 if (jComboBoxDatumType
== null) {
203 jComboBoxDatumType
= new JComboBox();
204 jComboBoxDatumType
.setBounds(new java
.awt
.Rectangle(160, 60, 320, 20));
206 return jComboBoxDatumType
;
209 public static void main(String
[] args
) {
214 This is the default constructor
217 public ModulePCDs() {
220 this.setVisible(true);
224 This is the override edit constructor
226 @param inPcds The input data of PCDsDocument.PCDs
229 public ModulePCDs(PCDsDocument
.PCDs inPcds
) {
232 this.setVisible(true);
236 This is the override edit constructor
238 @param inPcds The input data of PCDsDocument.PCDs
239 @param type The input data of node type
240 @param index The input data of node index
243 public ModulePCDs(PCDsDocument
.PCDs inPcds
, int type
, int index
) {
245 init(inPcds
, type
, index
);
246 this.setVisible(true);
250 This method initializes this
252 @param inPcds The input data of PCDsDocument.PCDs
255 private void init(PCDsDocument
.PCDs inPcds
) {
257 this.setPcds(inPcds
);
261 This method initializes this
262 Fill values to all fields if these values are not empty
264 @param inPcds The input data of PCDsDocument.PCDs
265 @param type The input data of node type
266 @param index The input data of node index
269 private void init(PCDsDocument
.PCDs inPcds
, int type
, int index
) {
271 this.location
= index
;
272 if (this.pcds
.getPcdDataList().size() > 0) {
273 if (this.pcds
.getPcdDataArray(index
).getCName() != null) {
274 this.jTextFieldC_Name
.setText(this.pcds
.getPcdDataArray(index
).getCName());
276 if (this.pcds
.getPcdDataArray(index
).getToken() != null) {
277 this.jTextFieldToken
.setText(this.pcds
.getPcdDataArray(index
).getToken());
279 if (this.pcds
.getPcdDataArray(index
).getDatumType() != null) {
280 this.jComboBoxDatumType
.setSelectedItem(this.pcds
.getPcdDataArray(index
).getDatumType().toString());
282 if (this.pcds
.getPcdDataArray(index
).getDefaultValue() != null) {
283 this.jTextFieldDefaultValue
.setText(this.pcds
.getPcdDataArray(index
).getDefaultValue());
285 if (this.pcds
.getPcdDataArray(index
).getPcdUsage() != null) {
286 this.jComboBoxUsage
.setSelectedItem(this.pcds
.getPcdDataArray(index
).getPcdUsage().toString());
288 if (this.pcds
.getPcdDataArray(index
).getItemType() != null) {
289 this.jComboBoxItemType
.setSelectedItem(this.pcds
.getPcdDataArray(index
).getItemType().toString());
295 This method initializes this
298 private void init() {
299 this.setSize(500, 515);
300 this.setContentPane(getJContentPane());
301 this.setTitle("PCDs");
303 this.setViewMode(false);
307 Disable all components when the mode is view
309 @param isView true - The view mode; false - The non-view mode
312 public void setViewMode(boolean isView
) {
313 this.jButtonOk
.setVisible(false);
314 this.jButtonCancel
.setVisible(false);
316 this.jTextFieldC_Name
.setEnabled(!isView
);
317 this.jTextFieldToken
.setEnabled(!isView
);
318 this.jComboBoxDatumType
.setEnabled(!isView
);
319 this.jTextFieldDefaultValue
.setEnabled(!isView
);
320 this.jComboBoxUsage
.setEnabled(!isView
);
321 this.jComboBoxItemType
.setEnabled(!isView
);
326 This method initializes jContentPane
328 @return javax.swing.JPanel jContentPane
331 private JPanel
getJContentPane() {
332 if (jContentPane
== null) {
333 jLabelDatumType
= new JLabel();
334 jLabelDatumType
.setBounds(new java
.awt
.Rectangle(15, 60, 140, 20));
335 jLabelDatumType
.setText("Datum Type");
336 jLabelC_Name
= new JLabel();
337 jLabelC_Name
.setText("C_Name");
338 jLabelC_Name
.setBounds(new java
.awt
.Rectangle(15, 10, 140, 20));
339 jLabelUsage
= new JLabel();
340 jLabelUsage
.setText("Usage");
341 jLabelUsage
.setBounds(new java
.awt
.Rectangle(15, 135, 140, 20));
342 jLabelDefaultValue
= new JLabel();
343 jLabelDefaultValue
.setText("Default Value");
344 jLabelDefaultValue
.setBounds(new java
.awt
.Rectangle(15, 85, 140, 20));
345 jLabelToken
= new JLabel();
346 jLabelToken
.setText("Token");
347 jLabelToken
.setBounds(new java
.awt
.Rectangle(15, 35, 140, 20));
348 jLabelItemType
= new JLabel();
349 jLabelItemType
.setText("Item Type");
350 jLabelItemType
.setBounds(new java
.awt
.Rectangle(15, 110, 140, 20));
351 jContentPane
= new JPanel();
352 jContentPane
.setLayout(null);
353 jContentPane
.setSize(new java
.awt
.Dimension(480,336));
354 jContentPane
.add(jLabelItemType
, null);
355 jContentPane
.add(jLabelC_Name
, null);
356 jContentPane
.add(getJTextFieldC_Name(), null);
357 jContentPane
.add(jLabelToken
, null);
358 jContentPane
.add(getJTextFieldToken(), null);
359 jContentPane
.add(jLabelDefaultValue
, null);
360 jContentPane
.add(getJTextFieldDefaultValue(), null);
361 jContentPane
.add(jLabelUsage
, null);
362 jContentPane
.add(getJComboBoxUsage(), null);
363 jContentPane
.add(getJButtonOk(), null);
364 jContentPane
.add(getJButtonCancel(), null);
365 jContentPane
.add(getJComboBoxItemType(), null);
366 jContentPane
.add(jLabelDatumType
, null);
367 jContentPane
.add(getJComboBoxDatumType(), null);
369 jStarLabel1
= new StarLabel();
370 jStarLabel1
.setLocation(new java
.awt
.Point(0, 10));
371 jStarLabel2
= new StarLabel();
372 jStarLabel2
.setLocation(new java
.awt
.Point(0, 35));
373 jStarLabel3
= new StarLabel();
374 jStarLabel3
.setLocation(new java
.awt
.Point(0, 60));
375 jStarLabel4
= new StarLabel();
376 jStarLabel4
.setLocation(new java
.awt
.Point(0, 110));
378 jContentPane
.add(jStarLabel1
, null);
379 jContentPane
.add(jStarLabel2
, null);
380 jContentPane
.add(jStarLabel3
, null);
381 jContentPane
.add(jStarLabel4
, null);
387 This method initializes Usage type, Item type and Datum type
390 private void initFrame() {
391 jComboBoxUsage
.addItem("ALWAYS_CONSUMED");
392 jComboBoxUsage
.addItem("SOMETIMES_CONSUMED");
393 jComboBoxUsage
.addItem("ALWAYS_PRODUCED");
394 jComboBoxUsage
.addItem("SOMETIMES_PRODUCED");
395 jComboBoxUsage
.addItem("DEFAULT");
397 jComboBoxItemType
.addItem("FEATURE_FLAG");
398 jComboBoxItemType
.addItem("FIXED_AT_BUILD");
399 jComboBoxItemType
.addItem("PATCHABLE_IN_MODULE");
400 jComboBoxItemType
.addItem("DYNAMIC");
401 jComboBoxItemType
.addItem("DYNAMIC_EX");
403 jComboBoxDatumType
.addItem("UINT8");
404 jComboBoxDatumType
.addItem("UINT16");
405 jComboBoxDatumType
.addItem("UINT32");
406 jComboBoxDatumType
.addItem("UINT64");
407 jComboBoxDatumType
.addItem("VOID*");
408 jComboBoxDatumType
.addItem("BOOLEAN");
412 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
414 * Override actionPerformed to listen all actions
417 public void actionPerformed(ActionEvent arg0
) {
418 if (arg0
.getSource() == jButtonOk
) {
419 this.setEdited(true);
423 if (arg0
.getSource() == jButtonCancel
) {
429 Get PCDsDocument.PCDs
431 @return PCDsDocument.PCDs
434 public PCDsDocument
.PCDs
getPcds() {
439 Set PCDsDocument.PCDs
441 @param pcds The input data of PCDsDocument.PCDs
444 public void setPcds(PCDsDocument
.PCDs pcds
) {
449 Data validation for all fields
451 @retval true - All datas are valid
452 @retval false - At least one data is invalid
455 public boolean check() {
457 // Check if all required fields are not empty
459 if (isEmpty(this.jTextFieldC_Name
.getText())) {
460 Log
.err("C_Name couldn't be empty");
463 if (isEmpty(this.jTextFieldToken
.getText())) {
464 Log
.err("Token couldn't be empty");
469 // Check if all fields have correct data types
471 if (!isEmpty(this.jTextFieldC_Name
.getText()) && !DataValidation
.isCName(this.jTextFieldC_Name
.getText())) {
472 Log
.err("Incorrect data type for C_Name");
475 if (!isEmpty(this.jTextFieldToken
.getText()) && !DataValidation
.isToken(this.jTextFieldToken
.getText())) {
476 Log
.err("Incorrect data type for Token");
484 Save all components of PCDs
485 if exists pcds, set the value directly
486 if not exists pcds, new an instance first
491 if (this.pcds
== null) {
492 pcds
= PCDsDocument
.PCDs
.Factory
.newInstance();
494 PCDsDocument
.PCDs
.PcdData pcdData
= PCDsDocument
.PCDs
.PcdData
.Factory
.newInstance();
495 if (!isEmpty(this.jTextFieldC_Name
.getText())) {
496 pcdData
.setCName(this.jTextFieldC_Name
.getText());
498 if (!isEmpty(this.jTextFieldToken
.getText())) {
499 pcdData
.setToken(this.jTextFieldToken
.getText());
501 pcdData
.setDatumType(PcdDataTypes
.Enum
.forString(this.jComboBoxDatumType
.getSelectedItem().toString()));
502 if (!isEmpty(this.jTextFieldDefaultValue
.getText())) {
503 pcdData
.setDefaultValue(this.jTextFieldDefaultValue
.getText());
505 pcdData
.setItemType(PcdItemTypes
.Enum
.forString(this.jComboBoxItemType
.getSelectedItem().toString()));
506 pcdData
.setPcdUsage(PcdUsage
.Enum
.forString(this.jComboBoxUsage
.getSelectedItem().toString()));
510 pcds
.setPcdDataArray(location
, pcdData
);
512 pcds
.addNewPcdData();
513 pcds
.setPcdDataArray(pcds
.getPcdDataList().size() - 1, pcdData
);
515 } catch (Exception e
) {
516 Log
.err("Update Hobs", e
.getMessage());