3 The file is used to create, update Hob 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
.GuidDocument
;
27 import org
.tianocore
.HobTypes
;
28 import org
.tianocore
.HobUsage
;
29 import org
.tianocore
.HobsDocument
;
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
.IInternalFrame
;
34 import org
.tianocore
.packaging
.common
.ui
.StarLabel
;
37 The class is used to create, update Hob of MSA/MBD file
38 It extends IInternalFrame
40 @since ModuleEditor 1.0
43 public class ModuleHobs
extends IInternalFrame
{
46 /// Define class Serial Version UID
48 private static final long serialVersionUID
= -553473437579358325L;
51 //Define class members
53 private HobsDocument
.Hobs hobs
= null;
55 private int location
= -1;
57 private JPanel jContentPane
= null;
59 private JLabel jLabel
= null;
61 private JTextField jTextFieldC_Name
= null;
63 private JLabel jLabelGuid
= null;
65 private JTextField jTextFieldGuid
= null;
67 private JLabel jLabelName
= null;
69 private JTextField jTextFieldName
= null;
71 private JLabel jLabelUsage
= null;
73 private JLabel jLabelHobType
= null;
75 private JComboBox jComboBoxUsage
= null;
77 private JComboBox jComboBoxHobType
= null;
79 private JLabel jLabelHobEnabled
= null;
81 private JRadioButton jRadioButtonHobEnable
= null;
83 private JRadioButton jRadioButtonHobDisable
= null;
85 private JButton jButtonOk
= null;
87 private JButton jButtonCancel
= null;
89 private JButton jButtonGenerateGuid
= null;
91 private JLabel jLabelOverrideID
= null;
93 private JTextField jTextFieldOverrideID
= null;
95 private StarLabel jStarLabel1
= null;
98 This method initializes jTextField
100 @return javax.swing.JTextField jTextFieldC_Name
103 private JTextField
getJTextFieldC_Name() {
104 if (jTextFieldC_Name
== null) {
105 jTextFieldC_Name
= new JTextField();
106 jTextFieldC_Name
.setBounds(new java
.awt
.Rectangle(160, 35, 320, 20));
108 return jTextFieldC_Name
;
112 This method initializes jTextField
114 @return javax.swing.JTextField jTextFieldGuid
117 private JTextField
getJTextFieldGuid() {
118 if (jTextFieldGuid
== null) {
119 jTextFieldGuid
= new JTextField();
120 jTextFieldGuid
.setBounds(new java
.awt
.Rectangle(160, 60, 250, 20));
122 return jTextFieldGuid
;
126 This method initializes jTextFieldName
128 @return javax.swing.JTextField jTextFieldName
131 private JTextField
getJTextFieldName() {
132 if (jTextFieldName
== null) {
133 jTextFieldName
= new JTextField();
134 jTextFieldName
.setBounds(new java
.awt
.Rectangle(160, 10, 320, 20));
136 return jTextFieldName
;
140 This method initializes jComboBoxUsage
142 @return javax.swing.JComboBox jComboBoxUsage
145 private JComboBox
getJComboBoxUsage() {
146 if (jComboBoxUsage
== null) {
147 jComboBoxUsage
= new JComboBox();
148 jComboBoxUsage
.setBounds(new java
.awt
.Rectangle(160, 85, 320, 20));
150 return jComboBoxUsage
;
154 This method initializes jComboBoxHobType
156 @return javax.swing.JComboBox jComboBoxHobType
159 private JComboBox
getJComboBoxHobType() {
160 if (jComboBoxHobType
== null) {
161 jComboBoxHobType
= new JComboBox();
162 jComboBoxHobType
.setBounds(new java
.awt
.Rectangle(160, 110, 320, 20));
164 return jComboBoxHobType
;
168 This method initializes jRadioButtonEnable
170 @return javax.swing.JRadioButton jRadioButtonHobEnable
173 private JRadioButton
getJRadioButtonHobEnable() {
174 if (jRadioButtonHobEnable
== null) {
175 jRadioButtonHobEnable
= new JRadioButton();
176 jRadioButtonHobEnable
.setText("Enable");
177 jRadioButtonHobEnable
.setBounds(new java
.awt
.Rectangle(160, 135, 90, 20));
178 jRadioButtonHobEnable
.setSelected(true);
179 jRadioButtonHobEnable
.addActionListener(this);
181 return jRadioButtonHobEnable
;
185 This method initializes jRadioButtonDisable
187 @return javax.swing.JRadioButton jRadioButtonHobDisable
190 private JRadioButton
getJRadioButtonHobDisable() {
191 if (jRadioButtonHobDisable
== null) {
192 jRadioButtonHobDisable
= new JRadioButton();
193 jRadioButtonHobDisable
.setText("Disable");
194 jRadioButtonHobDisable
.setBounds(new java
.awt
.Rectangle(320, 135, 90, 20));
195 jRadioButtonHobDisable
.addActionListener(this);
197 return jRadioButtonHobDisable
;
201 This method initializes jButtonOk
203 @return javax.swing.JButton jButtonOk
206 private JButton
getJButtonOk() {
207 if (jButtonOk
== null) {
208 jButtonOk
= new JButton();
209 jButtonOk
.setText("OK");
210 jButtonOk
.setBounds(new java
.awt
.Rectangle(290, 190, 90, 20));
211 jButtonOk
.addActionListener(this);
217 This method initializes jButtonCancel
219 @return javax.swing.JButton jButtonCancel
222 private JButton
getJButtonCancel() {
223 if (jButtonCancel
== null) {
224 jButtonCancel
= new JButton();
225 jButtonCancel
.setText("Cancel");
226 jButtonCancel
.setBounds(new java
.awt
.Rectangle(390, 190, 90, 20));
227 jButtonCancel
.addActionListener(this);
229 return jButtonCancel
;
233 This method initializes jButtonGenerateGuid
235 @return javax.swing.JButton jButtonGenerateGuid
238 private JButton
getJButtonGenerateGuid() {
239 if (jButtonGenerateGuid
== null) {
240 jButtonGenerateGuid
= new JButton();
241 jButtonGenerateGuid
.setBounds(new java
.awt
.Rectangle(415, 60, 65, 20));
242 jButtonGenerateGuid
.setText("GEN");
243 jButtonGenerateGuid
.addActionListener(this);
245 return jButtonGenerateGuid
;
249 This method initializes jTextFieldOverrideID
251 @return javax.swing.JTextField jTextFieldOverrideID
254 private JTextField
getJTextFieldOverrideID() {
255 if (jTextFieldOverrideID
== null) {
256 jTextFieldOverrideID
= new JTextField();
257 jTextFieldOverrideID
.setBounds(new java
.awt
.Rectangle(160, 160, 50, 20));
259 return jTextFieldOverrideID
;
262 public static void main(String
[] args
) {
267 This is the default constructor
270 public ModuleHobs() {
273 this.setVisible(true);
277 This is the override edit constructor
279 @param inHobs The input data of HobsDocument.Hobs
282 public ModuleHobs(HobsDocument
.Hobs inHobs
) {
285 this.setVisible(true);
289 This is the override edit constructor
291 @param inHobs The input data of HobsDocument.Hobs
292 @param type The input data of node type
293 @param index The input data of node index
296 public ModuleHobs(HobsDocument
.Hobs inHobs
, int type
, int index
) {
298 init(inHobs
, type
, index
);
299 this.setVisible(true);
303 This method initializes this
305 @param inHobs The input data of HobsDocument.Hobs
308 private void init(HobsDocument
.Hobs inHobs
) {
310 this.setHobs(inHobs
);
314 This method initializes this
315 Fill values to all fields if these values are not empty
317 @param inHobs The input data of HobsDocument.Hobs
318 @param type The input data of node type
319 @param index The input data of node index
322 private void init(HobsDocument
.Hobs inHobs
, int type
, int index
) {
324 this.location
= index
;
325 if (this.hobs
.getHobList().size() > 0) {
326 if (this.hobs
.getHobArray(index
).getName() != null) {
327 this.jTextFieldName
.setText(this.hobs
.getHobArray(index
).getName());
329 if (this.hobs
.getHobArray(index
).getCName() != null) {
330 this.jTextFieldC_Name
.setText(this.hobs
.getHobArray(index
).getCName());
332 if (this.hobs
.getHobArray(index
).getGuid() != null) {
333 this.jTextFieldGuid
.setText(this.hobs
.getHobArray(index
).getGuid().getStringValue());
335 if (this.hobs
.getHobArray(index
).getUsage() != null) {
336 this.jComboBoxUsage
.setSelectedItem(this.hobs
.getHobArray(index
).getUsage().toString());
338 this.jRadioButtonHobEnable
.setSelected(this.hobs
.getHobArray(index
).getHobEnabled());
339 this.jRadioButtonHobDisable
.setSelected(!this.hobs
.getHobArray(index
).getHobEnabled());
340 this.jTextFieldOverrideID
.setText(String
.valueOf(this.hobs
.getHobArray(index
).getOverrideID()));
345 This method initializes this
348 private void init() {
349 this.setSize(500, 515);
350 this.setContentPane(getJContentPane());
351 this.setTitle("Hobs");
353 this.setViewMode(false);
357 Disable all components when the mode is view
359 @param isView true - The view mode; false - The non-view mode
362 public void setViewMode(boolean isView
) {
363 this.jButtonOk
.setVisible(false);
364 this.jButtonCancel
.setVisible(false);
366 this.jTextFieldName
.setEnabled(!isView
);
367 this.jTextFieldC_Name
.setEnabled(!isView
);
368 this.jTextFieldGuid
.setEnabled(!isView
);
369 this.jComboBoxUsage
.setEnabled(!isView
);
370 this.jComboBoxHobType
.setEnabled(!isView
);
371 this.jRadioButtonHobEnable
.setEnabled(!isView
);
372 this.jRadioButtonHobDisable
.setEnabled(!isView
);
373 this.jTextFieldOverrideID
.setEnabled(!isView
);
374 this.jButtonCancel
.setEnabled(!isView
);
375 this.jButtonGenerateGuid
.setEnabled(!isView
);
376 this.jButtonOk
.setEnabled(!isView
);
381 This method initializes jContentPane
383 @return javax.swing.JPanel jContentPane
386 public JPanel
getJContentPane() {
387 if (jContentPane
== null) {
388 jLabelOverrideID
= new JLabel();
389 jLabelOverrideID
.setBounds(new java
.awt
.Rectangle(15, 160, 140, 20));
390 jLabelOverrideID
.setText("Override ID");
391 jLabelHobEnabled
= new JLabel();
392 jLabelHobEnabled
.setText("Hob Enabled");
393 jLabelHobEnabled
.setBounds(new java
.awt
.Rectangle(15, 135, 140, 20));
394 jLabelHobType
= new JLabel();
395 jLabelHobType
.setText("Hob Type");
396 jLabelHobType
.setBounds(new java
.awt
.Rectangle(15, 110, 140, 20));
397 jLabelUsage
= new JLabel();
398 jLabelUsage
.setText("Usage");
399 jLabelUsage
.setBounds(new java
.awt
.Rectangle(15, 85, 140, 20));
400 jLabelName
= new JLabel();
401 jLabelName
.setText("Name");
402 jLabelName
.setBounds(new java
.awt
.Rectangle(15, 10, 140, 20));
403 jLabelGuid
= new JLabel();
404 jLabelGuid
.setText("Guid");
405 jLabelGuid
.setBounds(new java
.awt
.Rectangle(15, 60, 140, 20));
406 jLabel
= new JLabel();
407 jLabel
.setText("C_Name");
408 jLabel
.setBounds(new java
.awt
.Rectangle(15, 35, 140, 20));
409 jContentPane
= new JPanel();
410 jContentPane
.setLayout(null);
411 jContentPane
.add(jLabel
, null);
412 jContentPane
.add(getJTextFieldC_Name(), null);
413 jContentPane
.add(getJTextFieldGuid(), null);
414 jContentPane
.add(jLabelUsage
, null);
415 jContentPane
.add(jLabelName
, null);
416 jContentPane
.add(getJTextFieldName(), null);
417 jContentPane
.add(jLabelGuid
, null);
418 jContentPane
.add(jLabelHobType
, null);
419 jContentPane
.add(getJComboBoxUsage(), null);
420 jContentPane
.add(getJComboBoxHobType(), null);
421 jContentPane
.add(jLabelHobEnabled
, null);
422 jContentPane
.add(getJRadioButtonHobEnable(), null);
423 jContentPane
.add(getJRadioButtonHobDisable(), null);
424 jContentPane
.add(getJButtonOk(), null);
425 jContentPane
.add(getJButtonCancel(), null);
426 jContentPane
.add(getJButtonGenerateGuid(), null);
427 jContentPane
.add(jLabelOverrideID
, null);
428 jContentPane
.add(getJTextFieldOverrideID(), null);
430 jStarLabel1
= new StarLabel();
431 jStarLabel1
.setLocation(new java
.awt
.Point(0, 10));
432 jContentPane
.add(jStarLabel1
, null);
438 This method initializes Usage type and Hob type
441 private void initFrame() {
442 jComboBoxHobType
.addItem("PHIT");
443 jComboBoxHobType
.addItem("MEMORY_ALLOCATION");
444 jComboBoxHobType
.addItem("RESOURCE_DESCRIPTOR");
445 jComboBoxHobType
.addItem("GUID_EXTENSION");
446 jComboBoxHobType
.addItem("FIRMWARE_VOLUME");
447 jComboBoxHobType
.addItem("CPU");
448 jComboBoxHobType
.addItem("POOL");
449 jComboBoxHobType
.addItem("CAPSULE_VOLUME");
451 jComboBoxUsage
.addItem("ALWAYS_CONSUMED");
452 jComboBoxUsage
.addItem("SOMETIMES_CONSUMED");
453 jComboBoxUsage
.addItem("ALWAYS_PRODUCED");
454 jComboBoxUsage
.addItem("SOMETIMES_PRODUCED");
455 jComboBoxUsage
.addItem("PRIVATE");
459 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
461 * Override actionPerformed to listen all actions
464 public void actionPerformed(ActionEvent arg0
) {
465 if (arg0
.getSource() == jButtonOk
) {
466 this.setEdited(true);
470 if (arg0
.getSource() == jButtonCancel
) {
475 // Contorl the selected status when click RadionButton
476 // Do not use Radio Button Group
478 if (arg0
.getSource() == jRadioButtonHobEnable
) {
479 if (jRadioButtonHobEnable
.isSelected()) {
480 jRadioButtonHobDisable
.setSelected(false);
482 if (!jRadioButtonHobDisable
.isSelected() && !jRadioButtonHobEnable
.isSelected()) {
483 jRadioButtonHobEnable
.setSelected(true);
487 if (arg0
.getSource() == jRadioButtonHobDisable
) {
488 if (jRadioButtonHobDisable
.isSelected()) {
489 jRadioButtonHobEnable
.setSelected(false);
491 if (!jRadioButtonHobDisable
.isSelected() && !jRadioButtonHobEnable
.isSelected()) {
492 jRadioButtonHobDisable
.setSelected(true);
496 if (arg0
.getSource() == jButtonGenerateGuid
) {
497 jTextFieldGuid
.setText(Tools
.generateUuidString());
502 Get HobsDocument.Hobs
504 @return HobsDocument.Hobs
507 public HobsDocument
.Hobs
getHobs() {
512 Set HobsDocument.Hobs
514 @param hobs The input data of HobsDocument.Hobs
517 public void setHobs(HobsDocument
.Hobs hobs
) {
522 Data validation for all fields
524 @retval true - All datas are valid
525 @retval false - At least one data is invalid
528 public boolean check() {
530 // Check if all required fields are not empty
532 if (isEmpty(this.jTextFieldName
.getText())) {
533 Log
.err("Name couldn't be empty");
538 // Check if all fields have correct data types
540 if (!DataValidation
.isCName(this.jTextFieldC_Name
.getText())) {
541 Log
.err("Incorrect data type for C_Name");
544 if (!isEmpty(this.jTextFieldGuid
.getText()) && !DataValidation
.isGuid(this.jTextFieldGuid
.getText())) {
545 Log
.err("Incorrect data type for Guid");
548 if (!isEmpty(this.jTextFieldOverrideID
.getText())
549 && !DataValidation
.isOverrideID(this.jTextFieldOverrideID
.getText())) {
550 Log
.err("Incorrect data type for Override ID");
558 Save all components of Hobs
559 if exists hobs, set the value directly
560 if not exists hobs, new an instance first
565 if (this.hobs
== null) {
566 hobs
= HobsDocument
.Hobs
.Factory
.newInstance();
568 HobsDocument
.Hobs
.Hob hob
= HobsDocument
.Hobs
.Hob
.Factory
.newInstance();
569 if (!isEmpty(this.jTextFieldName
.getText())) {
570 hob
.setName(this.jTextFieldName
.getText());
572 if (!isEmpty(this.jTextFieldC_Name
.getText())) {
573 hob
.setCName(this.jTextFieldC_Name
.getText());
575 if (!isEmpty(this.jTextFieldGuid
.getText())) {
576 GuidDocument
.Guid guid
= GuidDocument
.Guid
.Factory
.newInstance();
577 guid
.setStringValue(this.jTextFieldGuid
.getText());
580 hob
.setUsage(HobUsage
.Enum
.forString(jComboBoxUsage
.getSelectedItem().toString()));
581 hob
.setHobType(HobTypes
.Enum
.forString(jComboBoxHobType
.getSelectedItem().toString()));
582 hob
.setHobEnabled(this.jRadioButtonHobEnable
.isSelected());
583 if (!isEmpty(this.jTextFieldOverrideID
.getText())) {
584 hob
.setOverrideID(Integer
.parseInt(this.jTextFieldOverrideID
.getText()));
587 hobs
.setHobArray(location
, hob
);
590 hobs
.setHobArray(hobs
.getHobList().size() - 1, hob
);
592 } catch (Exception e
) {
593 Log
.err("Update Hobs", e
.getMessage());