3 The file is used to create, update BootModes 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.
16 package org
.tianocore
.packaging
.module
.ui
;
18 import java
.awt
.event
.ActionEvent
;
20 import javax
.swing
.JButton
;
21 import javax
.swing
.JComboBox
;
22 import javax
.swing
.JLabel
;
23 import javax
.swing
.JPanel
;
24 import javax
.swing
.JTextField
;
26 import org
.tianocore
.BootModeNames
;
27 import org
.tianocore
.BootModeUsage
;
28 import org
.tianocore
.BootModesDocument
;
29 import org
.tianocore
.common
.DataValidation
;
30 import org
.tianocore
.common
.Log
;
31 import org
.tianocore
.common
.Tools
;
32 import org
.tianocore
.packaging
.common
.ui
.IInternalFrame
;
33 import org
.tianocore
.packaging
.common
.ui
.StarLabel
;
36 The class is used to create, update BootModes of MSA/MBD file
37 It extends IInternalFrame
39 @since ModuleEditor 1.0
42 public class ModuleBootModes
extends IInternalFrame
{
45 /// Define class Serial Version UID
47 private static final long serialVersionUID
= -3888558623432442561L;
50 //Define class members
52 private BootModesDocument
.BootModes bootModes
= null;
54 private int location
= -1;
56 private JPanel jContentPane
= null;
58 private JLabel jLabelGuid
= null;
60 private JTextField jTextFieldGuid
= null;
62 private JLabel jLabelBootModeName
= null;
64 private JComboBox jComboBoxBootModeName
= null;
66 private JLabel jLabelUsage
= null;
68 private JComboBox jComboBoxUsage
= null;
70 private JButton jButtonOk
= null;
72 private JButton jButtonCancel
= null;
74 private JLabel jLabelOverrideID
= null;
76 private JTextField jTextFieldOverrideID
= null;
78 private JButton jButtonGenerateGuid
= null;
80 private StarLabel jStarLabel1
= null;
83 This method initializes jTextFieldGuid
85 @return javax.swing.JTextField jTextFieldGuid
88 private JTextField
getJTextFieldGuid() {
89 if (jTextFieldGuid
== null) {
90 jTextFieldGuid
= new JTextField();
91 jTextFieldGuid
.setBounds(new java
.awt
.Rectangle(160, 35, 240, 20));
93 return jTextFieldGuid
;
97 This method initializes jComboBoxBootModeName
99 @return javax.swing.JComboBox jComboBoxBootModeName
102 private JComboBox
getJComboBoxBootModeName() {
103 if (jComboBoxBootModeName
== null) {
104 jComboBoxBootModeName
= new JComboBox();
105 jComboBoxBootModeName
.setBounds(new java
.awt
.Rectangle(160, 10, 320, 20));
107 return jComboBoxBootModeName
;
111 This method initializes jComboBoxUsage
113 @return javax.swing.JComboBox jComboBoxUsage
116 private JComboBox
getJComboBoxUsage() {
117 if (jComboBoxUsage
== null) {
118 jComboBoxUsage
= new JComboBox();
119 jComboBoxUsage
.setBounds(new java
.awt
.Rectangle(160, 60, 320, 20));
121 return jComboBoxUsage
;
125 This method initializes jButtonOk
127 @return javax.swing.JButton jButtonOk
130 private JButton
getJButtonOk() {
131 if (jButtonOk
== null) {
132 jButtonOk
= new JButton();
133 jButtonOk
.setText("OK");
134 jButtonOk
.setBounds(new java
.awt
.Rectangle(280, 115, 90, 20));
135 jButtonOk
.addActionListener(this);
141 This method initializes jButtonCancel
143 @return javax.swing.JButton jButtonCancel
146 private JButton
getJButtonCancel() {
147 if (jButtonCancel
== null) {
148 jButtonCancel
= new JButton();
149 jButtonCancel
.setText("Cancel");
150 jButtonCancel
.setBounds(new java
.awt
.Rectangle(390, 115, 90, 20));
151 jButtonCancel
.addActionListener(this);
153 return jButtonCancel
;
157 This method initializes jTextFieldOverrideID
159 @return javax.swing.JTextField jTextFieldOverrideID
162 private JTextField
getJTextFieldOverrideID() {
163 if (jTextFieldOverrideID
== null) {
164 jTextFieldOverrideID
= new JTextField();
165 jTextFieldOverrideID
.setBounds(new java
.awt
.Rectangle(160, 85, 320, 20));
167 return jTextFieldOverrideID
;
171 This method initializes jButtonGenerateGuid
173 @return javax.swing.JButton jButtonGenerateGuid
176 private JButton
getJButtonGenerateGuid() {
177 if (jButtonGenerateGuid
== null) {
178 jButtonGenerateGuid
= new JButton();
179 jButtonGenerateGuid
.setBounds(new java
.awt
.Rectangle(405, 35, 75, 20));
180 jButtonGenerateGuid
.setText("GEN");
181 jButtonGenerateGuid
.addActionListener(this);
183 return jButtonGenerateGuid
;
186 public static void main(String
[] args
) {
190 This is the default constructor
193 public ModuleBootModes() {
196 this.setVisible(true);
200 This is the override edit constructor
202 @param inBootModes The input BootModesDocument.BootModes
205 public ModuleBootModes(BootModesDocument
.BootModes inBootModes
) {
208 this.setVisible(true);
212 This is the override edit constructor
214 @param inBootModes The input BootModesDocument.BootModes
215 @param type The input data of node type
216 @param index The input data of node index
219 public ModuleBootModes(BootModesDocument
.BootModes inBootModes
, int type
, int index
) {
221 init(inBootModes
, type
, index
);
222 this.setVisible(true);
226 This method initializes this
228 @param inBootModes BootModesDocument.BootModes
231 private void init(BootModesDocument
.BootModes inBootModes
) {
233 this.setBootModes(inBootModes
);
237 This method initializes this
238 Fill values to all fields if these values are not empty
240 @param inBootModes The input BootModesDocument.BootModes
241 @param type The input data of node type
242 @param index The input data of node index
245 private void init(BootModesDocument
.BootModes inBootModes
, int type
, int index
) {
247 this.location
= index
;
248 if (this.bootModes
.getBootModeList().size() > 0) {
249 if (this.bootModes
.getBootModeArray(index
).getBootModeName() != null) {
250 this.jComboBoxBootModeName
.setSelectedItem(this.bootModes
.getBootModeArray(index
).getBootModeName()
253 if (this.bootModes
.getBootModeArray(index
).getGuid() != null) {
254 this.jTextFieldGuid
.setText(this.bootModes
.getBootModeArray(index
).getGuid());
256 if (this.bootModes
.getBootModeArray(index
).getUsage() != null) {
257 this.jComboBoxUsage
.setSelectedItem(this.bootModes
.getBootModeArray(index
).getUsage().toString());
259 this.jTextFieldOverrideID
.setText(String
.valueOf(this.bootModes
.getBootModeArray(index
).getOverrideID()));
264 * This method initializes this
268 private void init() {
269 this.setContentPane(getJContentPane());
270 this.setTitle("Boot Mode");
271 this.setBounds(new java
.awt
.Rectangle(0, 0, 500, 515));
273 this.setViewMode(false);
277 Disable all components when the mode is view
279 @param isView true - The view mode; false - The non-view mode
282 public void setViewMode(boolean isView
) {
283 this.jButtonOk
.setVisible(false);
284 this.jButtonCancel
.setVisible(false);
286 this.jComboBoxBootModeName
.setEnabled(!isView
);
287 this.jTextFieldGuid
.setEnabled(!isView
);
288 this.jComboBoxUsage
.setEnabled(!isView
);
289 this.jTextFieldOverrideID
.setEnabled(!isView
);
290 this.jButtonCancel
.setEnabled(!isView
);
291 this.jButtonGenerateGuid
.setEnabled(!isView
);
292 this.jButtonOk
.setEnabled(!isView
);
297 This method initializes jContentPane
299 @return javax.swing.JPanel jContentPane
302 private JPanel
getJContentPane() {
303 if (jContentPane
== null) {
304 jLabelOverrideID
= new JLabel();
305 jLabelOverrideID
.setBounds(new java
.awt
.Rectangle(15, 85, 140, 20));
306 jLabelOverrideID
.setText("Override ID");
307 jLabelUsage
= new JLabel();
308 jLabelUsage
.setText("Usage");
309 jLabelUsage
.setBounds(new java
.awt
.Rectangle(15, 60, 140, 20));
310 jLabelBootModeName
= new JLabel();
311 jLabelBootModeName
.setText("Boot Mode Name");
312 jLabelBootModeName
.setBounds(new java
.awt
.Rectangle(15, 10, 140, 20));
313 jLabelGuid
= new JLabel();
314 jLabelGuid
.setText("Guid");
315 jLabelGuid
.setBounds(new java
.awt
.Rectangle(15, 35, 140, 20));
316 jContentPane
= new JPanel();
317 jContentPane
.setLayout(null);
318 jContentPane
.add(jLabelGuid
, null);
319 jContentPane
.add(getJTextFieldGuid(), null);
320 jContentPane
.add(jLabelBootModeName
, null);
321 jContentPane
.add(getJComboBoxBootModeName(), null);
322 jContentPane
.add(jLabelUsage
, null);
323 jContentPane
.add(getJComboBoxUsage(), null);
324 jContentPane
.add(getJButtonOk(), null);
325 jContentPane
.add(getJButtonCancel(), null);
326 jContentPane
.add(jLabelOverrideID
, null);
327 jContentPane
.add(getJTextFieldOverrideID(), null);
328 jContentPane
.add(getJButtonGenerateGuid(), null);
330 jStarLabel1
= new StarLabel();
331 jStarLabel1
.setLocation(new java
.awt
.Point(0, 10));
333 jContentPane
.add(jStarLabel1
, null);
339 This method initializes BootModeName groups and Usage type
342 private void initFrame() {
343 jComboBoxUsage
.addItem("ALWAYS_CONSUMED");
344 jComboBoxUsage
.addItem("SOMETIMES_CONSUMED");
345 jComboBoxUsage
.addItem("ALWAYS_PRODUCED");
346 jComboBoxUsage
.addItem("SOMETIMES_PRODUCED");
348 jComboBoxBootModeName
.addItem("FULL");
349 jComboBoxBootModeName
.addItem("MINIMAL");
350 jComboBoxBootModeName
.addItem("NO_CHANGE");
351 jComboBoxBootModeName
.addItem("DIAGNOSTICS");
352 jComboBoxBootModeName
.addItem("DEFAULT");
353 jComboBoxBootModeName
.addItem("S2_RESUME");
354 jComboBoxBootModeName
.addItem("S3_RESUME");
355 jComboBoxBootModeName
.addItem("S4_RESUME");
356 jComboBoxBootModeName
.addItem("S5_RESUME");
357 jComboBoxBootModeName
.addItem("FLASH_UPDATE");
358 jComboBoxBootModeName
.addItem("RECOVERY");
362 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
364 * Override actionPerformed to listen all actions
367 public void actionPerformed(ActionEvent arg0
) {
368 if (arg0
.getSource() == jButtonOk
) {
369 this.setEdited(true);
373 if (arg0
.getSource() == jButtonCancel
) {
377 if (arg0
.getSource() == jButtonGenerateGuid
) {
378 jTextFieldGuid
.setText(Tools
.generateUuidString());
383 Get BootModesDocument.BootModes
385 @return BootModesDocument.BootModes
388 public BootModesDocument
.BootModes
getBootModes() {
393 Set BootModesDocument.BootModes
395 @param bootModes BootModesDocument.BootModes
398 public void setBootModes(BootModesDocument
.BootModes bootModes
) {
399 this.bootModes
= bootModes
;
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 check() {
411 // Check if all fields have correct data types
413 if (!isEmpty(this.jTextFieldGuid
.getText()) && !DataValidation
.isGuid(this.jTextFieldGuid
.getText())) {
414 Log
.err("Incorrect data type for Guid");
417 if (!isEmpty(this.jTextFieldOverrideID
.getText())
418 && !DataValidation
.isOverrideID(this.jTextFieldOverrideID
.getText())) {
419 Log
.err("Incorrect data type for Override ID");
427 Save all components of Mbd Header
428 if exists bootModes, set the value directly
429 if not exists bootModes, new an instance first
434 if (this.bootModes
== null) {
435 bootModes
= BootModesDocument
.BootModes
.Factory
.newInstance();
437 BootModesDocument
.BootModes
.BootMode bootMode
= BootModesDocument
.BootModes
.BootMode
.Factory
.newInstance();
438 bootMode
.setBootModeName(BootModeNames
.Enum
.forString(jComboBoxBootModeName
.getSelectedItem().toString()));
439 if (!isEmpty(this.jTextFieldGuid
.getText())) {
440 bootMode
.setGuid(this.jTextFieldGuid
.getText());
442 bootMode
.setUsage(BootModeUsage
.Enum
.forString(jComboBoxUsage
.getSelectedItem().toString()));
443 if (!isEmpty(this.jTextFieldOverrideID
.getText())) {
444 bootMode
.setOverrideID(Integer
.parseInt(this.jTextFieldOverrideID
.getText()));
447 bootModes
.setBootModeArray(location
, bootMode
);
449 bootModes
.addNewBootMode();
450 bootModes
.setBootModeArray(bootModes
.getBootModeList().size() - 1, bootMode
);
452 } catch (Exception e
) {
453 Log
.err("Update Boot Modes", e
.getMessage());