]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/ModuleEditor/src/org/tianocore/packaging/module/ui/ModuleBootModes.java
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@671 6f19259b...
[mirror_edk2.git] / Tools / Source / ModuleEditor / src / org / tianocore / packaging / module / ui / ModuleBootModes.java
1 /** @file
2
3 The file is used to create, update BootModes of MSA/MBD file
4
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
10
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.
13
14 **/
15
16 package org.tianocore.packaging.module.ui;
17
18 import java.awt.event.ActionEvent;
19
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;
25
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;
34
35 /**
36 The class is used to create, update BootModes of MSA/MBD file
37 It extends IInternalFrame
38
39 @since ModuleEditor 1.0
40
41 **/
42 public class ModuleBootModes extends IInternalFrame {
43
44 ///
45 /// Define class Serial Version UID
46 ///
47 private static final long serialVersionUID = -3888558623432442561L;
48
49 //
50 //Define class members
51 //
52 private BootModesDocument.BootModes bootModes = null;
53
54 private int location = -1;
55
56 private JPanel jContentPane = null;
57
58 private JLabel jLabelGuid = null;
59
60 private JTextField jTextFieldGuid = null;
61
62 private JLabel jLabelBootModeName = null;
63
64 private JComboBox jComboBoxBootModeName = null;
65
66 private JLabel jLabelUsage = null;
67
68 private JComboBox jComboBoxUsage = null;
69
70 private JButton jButtonOk = null;
71
72 private JButton jButtonCancel = null;
73
74 private JLabel jLabelOverrideID = null;
75
76 private JTextField jTextFieldOverrideID = null;
77
78 private JButton jButtonGenerateGuid = null;
79
80 private StarLabel jStarLabel1 = null;
81
82 /**
83 This method initializes jTextFieldGuid
84
85 @return javax.swing.JTextField jTextFieldGuid
86
87 **/
88 private JTextField getJTextFieldGuid() {
89 if (jTextFieldGuid == null) {
90 jTextFieldGuid = new JTextField();
91 jTextFieldGuid.setBounds(new java.awt.Rectangle(160, 35, 250, 20));
92 }
93 return jTextFieldGuid;
94 }
95
96 /**
97 This method initializes jComboBoxBootModeName
98
99 @return javax.swing.JComboBox jComboBoxBootModeName
100
101 **/
102 private JComboBox getJComboBoxBootModeName() {
103 if (jComboBoxBootModeName == null) {
104 jComboBoxBootModeName = new JComboBox();
105 jComboBoxBootModeName.setBounds(new java.awt.Rectangle(160, 10, 320, 20));
106 }
107 return jComboBoxBootModeName;
108 }
109
110 /**
111 This method initializes jComboBoxUsage
112
113 @return javax.swing.JComboBox jComboBoxUsage
114
115 **/
116 private JComboBox getJComboBoxUsage() {
117 if (jComboBoxUsage == null) {
118 jComboBoxUsage = new JComboBox();
119 jComboBoxUsage.setBounds(new java.awt.Rectangle(160, 60, 320, 20));
120 }
121 return jComboBoxUsage;
122 }
123
124 /**
125 This method initializes jButtonOk
126
127 @return javax.swing.JButton jButtonOk
128
129 **/
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);
136 }
137 return jButtonOk;
138 }
139
140 /**
141 This method initializes jButtonCancel
142
143 @return javax.swing.JButton jButtonCancel
144
145 **/
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);
152 }
153 return jButtonCancel;
154 }
155
156 /**
157 This method initializes jTextFieldOverrideID
158
159 @return javax.swing.JTextField jTextFieldOverrideID
160
161 **/
162 private JTextField getJTextFieldOverrideID() {
163 if (jTextFieldOverrideID == null) {
164 jTextFieldOverrideID = new JTextField();
165 jTextFieldOverrideID.setBounds(new java.awt.Rectangle(160, 85, 50, 20));
166 }
167 return jTextFieldOverrideID;
168 }
169
170 /**
171 This method initializes jButtonGenerateGuid
172
173 @return javax.swing.JButton jButtonGenerateGuid
174
175 **/
176 private JButton getJButtonGenerateGuid() {
177 if (jButtonGenerateGuid == null) {
178 jButtonGenerateGuid = new JButton();
179 jButtonGenerateGuid.setBounds(new java.awt.Rectangle(415, 35, 65, 20));
180 jButtonGenerateGuid.setText("GEN");
181 jButtonGenerateGuid.addActionListener(this);
182 }
183 return jButtonGenerateGuid;
184 }
185
186 public static void main(String[] args) {
187 }
188
189 /**
190 This is the default constructor
191
192 **/
193 public ModuleBootModes() {
194 super();
195 init();
196 this.setVisible(true);
197 }
198
199 /**
200 This is the override edit constructor
201
202 @param inBootModes The input BootModesDocument.BootModes
203
204 **/
205 public ModuleBootModes(BootModesDocument.BootModes inBootModes) {
206 super();
207 init(inBootModes);
208 this.setVisible(true);
209 }
210
211 /**
212 This is the override edit constructor
213
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
217
218 **/
219 public ModuleBootModes(BootModesDocument.BootModes inBootModes, int type, int index) {
220 super();
221 init(inBootModes, type, index);
222 this.setVisible(true);
223 }
224
225 /**
226 This method initializes this
227
228 @param inBootModes BootModesDocument.BootModes
229
230 **/
231 private void init(BootModesDocument.BootModes inBootModes) {
232 init();
233 this.setBootModes(inBootModes);
234 }
235
236 /**
237 This method initializes this
238 Fill values to all fields if these values are not empty
239
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
243
244 **/
245 private void init(BootModesDocument.BootModes inBootModes, int type, int index) {
246 init(inBootModes);
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()
251 .toString());
252 }
253 if (this.bootModes.getBootModeArray(index).getGuid() != null) {
254 this.jTextFieldGuid.setText(this.bootModes.getBootModeArray(index).getGuid());
255 }
256 if (this.bootModes.getBootModeArray(index).getUsage() != null) {
257 this.jComboBoxUsage.setSelectedItem(this.bootModes.getBootModeArray(index).getUsage().toString());
258 }
259 this.jTextFieldOverrideID.setText(String.valueOf(this.bootModes.getBootModeArray(index).getOverrideID()));
260 }
261 }
262
263 /**
264 * This method initializes this
265 *
266 * @return void
267 */
268 private void init() {
269 this.setContentPane(getJContentPane());
270 this.setTitle("Boot Mode");
271 this.setBounds(new java.awt.Rectangle(0, 0, 500, 515));
272 initFrame();
273 this.setViewMode(false);
274 }
275
276 /**
277 Disable all components when the mode is view
278
279 @param isView true - The view mode; false - The non-view mode
280
281 **/
282 public void setViewMode(boolean isView) {
283 this.jButtonOk.setVisible(false);
284 this.jButtonCancel.setVisible(false);
285 if (isView) {
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);
293 }
294 }
295
296 /**
297 This method initializes jContentPane
298
299 @return javax.swing.JPanel jContentPane
300
301 **/
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);
329
330 jStarLabel1 = new StarLabel();
331 jStarLabel1.setLocation(new java.awt.Point(0, 10));
332
333 jContentPane.add(jStarLabel1, null);
334 }
335 return jContentPane;
336 }
337
338 /**
339 This method initializes BootModeName groups and Usage type
340
341 **/
342 private void initFrame() {
343 jComboBoxUsage.addItem("ALWAYS_CONSUMED");
344 jComboBoxUsage.addItem("SOMETIMES_CONSUMED");
345 jComboBoxUsage.addItem("ALWAYS_PRODUCED");
346 jComboBoxUsage.addItem("SOMETIMES_PRODUCED");
347
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");
359 }
360
361 /* (non-Javadoc)
362 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
363 *
364 * Override actionPerformed to listen all actions
365 *
366 */
367 public void actionPerformed(ActionEvent arg0) {
368 if (arg0.getSource() == jButtonOk) {
369 this.setEdited(true);
370 this.save();
371 this.dispose();
372 }
373 if (arg0.getSource() == jButtonCancel) {
374 this.dispose();
375 }
376
377 if (arg0.getSource() == jButtonGenerateGuid) {
378 jTextFieldGuid.setText(Tools.generateUuidString());
379 }
380 }
381
382 /**
383 Get BootModesDocument.BootModes
384
385 @return BootModesDocument.BootModes
386
387 **/
388 public BootModesDocument.BootModes getBootModes() {
389 return bootModes;
390 }
391
392 /**
393 Set BootModesDocument.BootModes
394
395 @param bootModes BootModesDocument.BootModes
396
397 **/
398 public void setBootModes(BootModesDocument.BootModes bootModes) {
399 this.bootModes = bootModes;
400 }
401
402 /**
403 Data validation for all fields
404
405 @retval true - All datas are valid
406 @retval false - At least one data is invalid
407
408 **/
409 public boolean check() {
410 //
411 // Check if all fields have correct data types
412 //
413 if (!isEmpty(this.jTextFieldGuid.getText()) && !DataValidation.isGuid(this.jTextFieldGuid.getText())) {
414 Log.err("Incorrect data type for Guid");
415 return false;
416 }
417 if (!isEmpty(this.jTextFieldOverrideID.getText())
418 && !DataValidation.isOverrideID(this.jTextFieldOverrideID.getText())) {
419 Log.err("Incorrect data type for Override ID");
420 return false;
421 }
422
423 return true;
424 }
425
426 /**
427 Save all components of Mbd Header
428 if exists bootModes, set the value directly
429 if not exists bootModes, new an instance first
430
431 **/
432 public void save() {
433 try {
434 if (this.bootModes == null) {
435 bootModes = BootModesDocument.BootModes.Factory.newInstance();
436 }
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());
441 }
442 bootMode.setUsage(BootModeUsage.Enum.forString(jComboBoxUsage.getSelectedItem().toString()));
443 if (!isEmpty(this.jTextFieldOverrideID.getText())) {
444 bootMode.setOverrideID(Integer.parseInt(this.jTextFieldOverrideID.getText()));
445 }
446 if (location > -1) {
447 bootModes.setBootModeArray(location, bootMode);
448 } else {
449 bootModes.addNewBootMode();
450 bootModes.setBootModeArray(bootModes.getBootModeList().size() - 1, bootMode);
451 }
452 } catch (Exception e) {
453 Log.err("Update Boot Modes", e.getMessage());
454 }
455 }
456 }