]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/ModuleEditor/src/org/tianocore/packaging/module/ui/ModuleHobs.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 / ModuleHobs.java
1 /** @file
2
3 The file is used to create, update Hob 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 package org.tianocore.packaging.module.ui;
16
17 import java.awt.event.ActionEvent;
18
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;
25
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;
35
36 /**
37 The class is used to create, update Hob of MSA/MBD file
38 It extends IInternalFrame
39
40 @since ModuleEditor 1.0
41
42 **/
43 public class ModuleHobs extends IInternalFrame {
44
45 ///
46 /// Define class Serial Version UID
47 ///
48 private static final long serialVersionUID = -553473437579358325L;
49
50 //
51 //Define class members
52 //
53 private HobsDocument.Hobs hobs = null;
54
55 private int location = -1;
56
57 private JPanel jContentPane = null;
58
59 private JLabel jLabel = null;
60
61 private JTextField jTextFieldC_Name = null;
62
63 private JLabel jLabelGuid = null;
64
65 private JTextField jTextFieldGuid = null;
66
67 private JLabel jLabelName = null;
68
69 private JTextField jTextFieldName = null;
70
71 private JLabel jLabelUsage = null;
72
73 private JLabel jLabelHobType = null;
74
75 private JComboBox jComboBoxUsage = null;
76
77 private JComboBox jComboBoxHobType = null;
78
79 private JLabel jLabelHobEnabled = null;
80
81 private JRadioButton jRadioButtonHobEnable = null;
82
83 private JRadioButton jRadioButtonHobDisable = null;
84
85 private JButton jButtonOk = null;
86
87 private JButton jButtonCancel = null;
88
89 private JButton jButtonGenerateGuid = null;
90
91 private JLabel jLabelOverrideID = null;
92
93 private JTextField jTextFieldOverrideID = null;
94
95 private StarLabel jStarLabel1 = null;
96
97 /**
98 This method initializes jTextField
99
100 @return javax.swing.JTextField jTextFieldC_Name
101
102 **/
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));
107 }
108 return jTextFieldC_Name;
109 }
110
111 /**
112 This method initializes jTextField
113
114 @return javax.swing.JTextField jTextFieldGuid
115
116 **/
117 private JTextField getJTextFieldGuid() {
118 if (jTextFieldGuid == null) {
119 jTextFieldGuid = new JTextField();
120 jTextFieldGuid.setBounds(new java.awt.Rectangle(160, 60, 250, 20));
121 }
122 return jTextFieldGuid;
123 }
124
125 /**
126 This method initializes jTextFieldName
127
128 @return javax.swing.JTextField jTextFieldName
129
130 **/
131 private JTextField getJTextFieldName() {
132 if (jTextFieldName == null) {
133 jTextFieldName = new JTextField();
134 jTextFieldName.setBounds(new java.awt.Rectangle(160, 10, 320, 20));
135 }
136 return jTextFieldName;
137 }
138
139 /**
140 This method initializes jComboBoxUsage
141
142 @return javax.swing.JComboBox jComboBoxUsage
143
144 **/
145 private JComboBox getJComboBoxUsage() {
146 if (jComboBoxUsage == null) {
147 jComboBoxUsage = new JComboBox();
148 jComboBoxUsage.setBounds(new java.awt.Rectangle(160, 85, 320, 20));
149 }
150 return jComboBoxUsage;
151 }
152
153 /**
154 This method initializes jComboBoxHobType
155
156 @return javax.swing.JComboBox jComboBoxHobType
157
158 **/
159 private JComboBox getJComboBoxHobType() {
160 if (jComboBoxHobType == null) {
161 jComboBoxHobType = new JComboBox();
162 jComboBoxHobType.setBounds(new java.awt.Rectangle(160, 110, 320, 20));
163 }
164 return jComboBoxHobType;
165 }
166
167 /**
168 This method initializes jRadioButtonEnable
169
170 @return javax.swing.JRadioButton jRadioButtonHobEnable
171
172 **/
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);
180 }
181 return jRadioButtonHobEnable;
182 }
183
184 /**
185 This method initializes jRadioButtonDisable
186
187 @return javax.swing.JRadioButton jRadioButtonHobDisable
188
189 **/
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);
196 }
197 return jRadioButtonHobDisable;
198 }
199
200 /**
201 This method initializes jButtonOk
202
203 @return javax.swing.JButton jButtonOk
204
205 **/
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);
212 }
213 return jButtonOk;
214 }
215
216 /**
217 This method initializes jButtonCancel
218
219 @return javax.swing.JButton jButtonCancel
220
221 **/
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);
228 }
229 return jButtonCancel;
230 }
231
232 /**
233 This method initializes jButtonGenerateGuid
234
235 @return javax.swing.JButton jButtonGenerateGuid
236
237 **/
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);
244 }
245 return jButtonGenerateGuid;
246 }
247
248 /**
249 This method initializes jTextFieldOverrideID
250
251 @return javax.swing.JTextField jTextFieldOverrideID
252
253 **/
254 private JTextField getJTextFieldOverrideID() {
255 if (jTextFieldOverrideID == null) {
256 jTextFieldOverrideID = new JTextField();
257 jTextFieldOverrideID.setBounds(new java.awt.Rectangle(160, 160, 50, 20));
258 }
259 return jTextFieldOverrideID;
260 }
261
262 public static void main(String[] args) {
263
264 }
265
266 /**
267 This is the default constructor
268
269 **/
270 public ModuleHobs() {
271 super();
272 init();
273 this.setVisible(true);
274 }
275
276 /**
277 This is the override edit constructor
278
279 @param inHobs The input data of HobsDocument.Hobs
280
281 **/
282 public ModuleHobs(HobsDocument.Hobs inHobs) {
283 super();
284 init(inHobs);
285 this.setVisible(true);
286 }
287
288 /**
289 This is the override edit constructor
290
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
294
295 **/
296 public ModuleHobs(HobsDocument.Hobs inHobs, int type, int index) {
297 super();
298 init(inHobs, type, index);
299 this.setVisible(true);
300 }
301
302 /**
303 This method initializes this
304
305 @param inHobs The input data of HobsDocument.Hobs
306
307 **/
308 private void init(HobsDocument.Hobs inHobs) {
309 init();
310 this.setHobs(inHobs);
311 }
312
313 /**
314 This method initializes this
315 Fill values to all fields if these values are not empty
316
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
320
321 **/
322 private void init(HobsDocument.Hobs inHobs, int type, int index) {
323 init(inHobs);
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());
328 }
329 if (this.hobs.getHobArray(index).getCName() != null) {
330 this.jTextFieldC_Name.setText(this.hobs.getHobArray(index).getCName());
331 }
332 if (this.hobs.getHobArray(index).getGuid() != null) {
333 this.jTextFieldGuid.setText(this.hobs.getHobArray(index).getGuid().getStringValue());
334 }
335 if (this.hobs.getHobArray(index).getUsage() != null) {
336 this.jComboBoxUsage.setSelectedItem(this.hobs.getHobArray(index).getUsage().toString());
337 }
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()));
341 }
342 }
343
344 /**
345 This method initializes this
346
347 **/
348 private void init() {
349 this.setSize(500, 515);
350 this.setContentPane(getJContentPane());
351 this.setTitle("Hobs");
352 initFrame();
353 this.setViewMode(false);
354 }
355
356 /**
357 Disable all components when the mode is view
358
359 @param isView true - The view mode; false - The non-view mode
360
361 **/
362 public void setViewMode(boolean isView) {
363 this.jButtonOk.setVisible(false);
364 this.jButtonCancel.setVisible(false);
365 if (isView) {
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);
377 }
378 }
379
380 /**
381 This method initializes jContentPane
382
383 @return javax.swing.JPanel jContentPane
384
385 **/
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);
429
430 jStarLabel1 = new StarLabel();
431 jStarLabel1.setLocation(new java.awt.Point(0, 10));
432 jContentPane.add(jStarLabel1, null);
433 }
434 return jContentPane;
435 }
436
437 /**
438 This method initializes Usage type and Hob type
439
440 **/
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");
450
451 jComboBoxUsage.addItem("ALWAYS_CONSUMED");
452 jComboBoxUsage.addItem("SOMETIMES_CONSUMED");
453 jComboBoxUsage.addItem("ALWAYS_PRODUCED");
454 jComboBoxUsage.addItem("SOMETIMES_PRODUCED");
455 jComboBoxUsage.addItem("PRIVATE");
456 }
457
458 /* (non-Javadoc)
459 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
460 *
461 * Override actionPerformed to listen all actions
462 *
463 */
464 public void actionPerformed(ActionEvent arg0) {
465 if (arg0.getSource() == jButtonOk) {
466 this.setEdited(true);
467 this.save();
468 this.dispose();
469 }
470 if (arg0.getSource() == jButtonCancel) {
471 this.dispose();
472 }
473
474 //
475 // Contorl the selected status when click RadionButton
476 // Do not use Radio Button Group
477 //
478 if (arg0.getSource() == jRadioButtonHobEnable) {
479 if (jRadioButtonHobEnable.isSelected()) {
480 jRadioButtonHobDisable.setSelected(false);
481 }
482 if (!jRadioButtonHobDisable.isSelected() && !jRadioButtonHobEnable.isSelected()) {
483 jRadioButtonHobEnable.setSelected(true);
484 }
485 }
486
487 if (arg0.getSource() == jRadioButtonHobDisable) {
488 if (jRadioButtonHobDisable.isSelected()) {
489 jRadioButtonHobEnable.setSelected(false);
490 }
491 if (!jRadioButtonHobDisable.isSelected() && !jRadioButtonHobEnable.isSelected()) {
492 jRadioButtonHobDisable.setSelected(true);
493 }
494 }
495
496 if (arg0.getSource() == jButtonGenerateGuid) {
497 jTextFieldGuid.setText(Tools.generateUuidString());
498 }
499 }
500
501 /**
502 Get HobsDocument.Hobs
503
504 @return HobsDocument.Hobs
505
506 **/
507 public HobsDocument.Hobs getHobs() {
508 return hobs;
509 }
510
511 /**
512 Set HobsDocument.Hobs
513
514 @param hobs The input data of HobsDocument.Hobs
515
516 **/
517 public void setHobs(HobsDocument.Hobs hobs) {
518 this.hobs = hobs;
519 }
520
521 /**
522 Data validation for all fields
523
524 @retval true - All datas are valid
525 @retval false - At least one data is invalid
526
527 **/
528 public boolean check() {
529 //
530 // Check if all required fields are not empty
531 //
532 if (isEmpty(this.jTextFieldName.getText())) {
533 Log.err("Name couldn't be empty");
534 return false;
535 }
536
537 //
538 // Check if all fields have correct data types
539 //
540 if (!DataValidation.isCName(this.jTextFieldC_Name.getText())) {
541 Log.err("Incorrect data type for C_Name");
542 return false;
543 }
544 if (!isEmpty(this.jTextFieldGuid.getText()) && !DataValidation.isGuid(this.jTextFieldGuid.getText())) {
545 Log.err("Incorrect data type for Guid");
546 return false;
547 }
548 if (!isEmpty(this.jTextFieldOverrideID.getText())
549 && !DataValidation.isOverrideID(this.jTextFieldOverrideID.getText())) {
550 Log.err("Incorrect data type for Override ID");
551 return false;
552 }
553
554 return true;
555 }
556
557 /**
558 Save all components of Hobs
559 if exists hobs, set the value directly
560 if not exists hobs, new an instance first
561
562 **/
563 public void save() {
564 try {
565 if (this.hobs == null) {
566 hobs = HobsDocument.Hobs.Factory.newInstance();
567 }
568 HobsDocument.Hobs.Hob hob = HobsDocument.Hobs.Hob.Factory.newInstance();
569 if (!isEmpty(this.jTextFieldName.getText())) {
570 hob.setName(this.jTextFieldName.getText());
571 }
572 if (!isEmpty(this.jTextFieldC_Name.getText())) {
573 hob.setCName(this.jTextFieldC_Name.getText());
574 }
575 if (!isEmpty(this.jTextFieldGuid.getText())) {
576 GuidDocument.Guid guid = GuidDocument.Guid.Factory.newInstance();
577 guid.setStringValue(this.jTextFieldGuid.getText());
578 hob.setGuid(guid);
579 }
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()));
585 }
586 if (location > -1) {
587 hobs.setHobArray(location, hob);
588 } else {
589 hobs.addNewHob();
590 hobs.setHobArray(hobs.getHobList().size() - 1, hob);
591 }
592 } catch (Exception e) {
593 Log.err("Update Hobs", e.getMessage());
594 }
595 }
596 }