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
.frameworkwizard
.module
.ui
.dialog
;
17 import java
.awt
.event
.ActionEvent
;
18 import java
.util
.Vector
;
20 import javax
.swing
.JButton
;
21 import javax
.swing
.JComboBox
;
22 import javax
.swing
.JLabel
;
23 import javax
.swing
.JPanel
;
24 import javax
.swing
.JScrollPane
;
25 import javax
.swing
.JTextField
;
26 import javax
.swing
.JTextArea
;
28 import org
.tianocore
.frameworkwizard
.common
.DataType
;
29 import org
.tianocore
.frameworkwizard
.common
.DataValidation
;
30 import org
.tianocore
.frameworkwizard
.common
.EnumerationData
;
31 import org
.tianocore
.frameworkwizard
.common
.Log
;
32 import org
.tianocore
.frameworkwizard
.common
.Tools
;
33 import org
.tianocore
.frameworkwizard
.common
.ui
.ArchCheckBox
;
34 import org
.tianocore
.frameworkwizard
.common
.ui
.IDialog
;
35 import org
.tianocore
.frameworkwizard
.common
.ui
.IFrame
;
36 import org
.tianocore
.frameworkwizard
.common
.ui
.StarLabel
;
37 import org
.tianocore
.frameworkwizard
.module
.Identifications
.Hobs
.HobsIdentification
;
38 import org
.tianocore
.frameworkwizard
.workspace
.WorkspaceTools
;
41 * The class is used to create, update Hob of the MSA file It extends JDialog
44 public class HobsDlg
extends IDialog
{
47 // / Define class Serial Version UID
49 private static final long serialVersionUID
= -553473437579358325L;
52 // Define class members
54 private JPanel jContentPane
= null;
56 private JLabel jLabelC_Name
= null;
58 private JComboBox jComboBoxGuidC_Name
= null;
60 private JLabel jLabelUsage
= null;
62 private JLabel jLabelHobType
= null;
64 private JComboBox jComboBoxUsage
= null;
66 private JComboBox jComboBoxHobType
= null;
68 private StarLabel jStarLabel1
= null;
70 private StarLabel jStarLabel2
= null;
72 private StarLabel jStarLabel3
= null;
74 private JLabel jLabelArch
= null;
76 private JScrollPane jScrollPane
= null;
78 private JLabel jLabelFeatureFlag
= null;
80 private JTextField jTextFieldFeatureFlag
= null;
82 private JLabel jLabelHelpText
= null;
84 private JTextArea jTextAreaHelpText
= null;
86 private JScrollPane jScrollPaneHelpText
= null;
88 private ArchCheckBox jArchCheckBox
= null;
90 private JButton jButtonOk
= null;
92 private JButton jButtonCancel
= null;
97 private HobsIdentification id
= null;
99 private EnumerationData ed
= new EnumerationData();
101 private WorkspaceTools wt
= new WorkspaceTools();
104 * This method initializes jTextField
106 * @return javax.swing.JTextField jTextFieldC_Name
109 private JComboBox
getJComboBoxGuidC_Name() {
110 if (jComboBoxGuidC_Name
== null) {
111 jComboBoxGuidC_Name
= new JComboBox();
112 jComboBoxGuidC_Name
.setBounds(new java
.awt
.Rectangle(160, 10, 320, 20));
113 jComboBoxGuidC_Name
.setPreferredSize(new java
.awt
.Dimension(320, 20));
114 jComboBoxGuidC_Name
.setToolTipText("Select the GUID C Name of the Hob");
116 return jComboBoxGuidC_Name
;
120 * This method initializes jComboBoxHobType
122 * @return javax.swing.JComboBox jComboBoxHobType
125 private JComboBox
getJComboBoxHobType() {
126 if (jComboBoxHobType
== null) {
127 jComboBoxHobType
= new JComboBox();
128 jComboBoxHobType
.setBounds(new java
.awt
.Rectangle(160, 35, 320, 20));
129 jComboBoxHobType
.setPreferredSize(new java
.awt
.Dimension(320, 20));
130 jComboBoxHobType
.setToolTipText("<html><table><tr><td>PHIT</td><td>EFI_HOB_TYPE_HANDOFF</td></tr><tr><td>MEMORY_ALLOCATION</td><td>EFI_HOB_TYPE_MEMORY_ALLOCATION and $BaseName</td></tr><tr><td>RESOURCE_DESCRIPTOR</td><td>EFI_HOB_TYPE_RESOURCE_DESCRIPTOR</td></tr><tr><td>GUID_EXTENTION</td><td>EFI_HOB_TYPE_GUID_EXTENSION and BaseName of GUID</td></tr><tr><td>FIRMWARE_VOLUME</td><td>EFI_HOB_TYPE_FV</td></tr><tr><td>CPU</td><td>EFI_HOB_TYPE_CPU</td></tr><tr><td>POOL</td><td>EFI_HOB_TYPE_PEI_MEMORY_POOL</td></tr><tr><td>CAPSULE_VOLUME</td><td>EFI_HOB_TYPE_CV</td></tr></table></html>");
132 return jComboBoxHobType
;
136 * This method initializes jComboBoxUsage
138 * @return javax.swing.JComboBox jComboBoxUsage
141 private JComboBox
getJComboBoxUsage() {
142 if (jComboBoxUsage
== null) {
143 jComboBoxUsage
= new JComboBox();
144 jComboBoxUsage
.setBounds(new java
.awt
.Rectangle(160, 60, 320, 20));
145 jComboBoxUsage
.setPreferredSize(new java
.awt
.Dimension(320, 20));
146 jComboBoxUsage
.setToolTipText("<html><table><tr><td>ALWAYS_CONSUMED</td><td>HOB must be present in the system</td></tr><tr><td>SOMETIMES_CONSUMED</td><td>HOB will be used if it's present</td></tr><tr><td>ALWAYS_PRODUCED</td><td>HOB is always produced</td></tr><tr><td>SOMETIMES_PRODUCED</td><td>HOB will sometimes be produced by the module</td></tr></table></html>");
148 return jComboBoxUsage
;
152 * This method initializes jScrollPane
154 * @return javax.swing.JScrollPane
156 private JScrollPane
getJScrollPane() {
157 if (jScrollPane
== null) {
158 jScrollPane
= new JScrollPane();
159 jScrollPane
.setViewportView(getJContentPane());
165 * This method initializes jTextFieldFeatureFlag
167 * @return javax.swing.JTextField
169 private JTextField
getJTextFieldFeatureFlag() {
170 if (jTextFieldFeatureFlag
== null) {
171 jTextFieldFeatureFlag
= new JTextField();
172 jTextFieldFeatureFlag
173 .setBounds(new java
.awt
.Rectangle(160, 130, 320, 20));
174 jTextFieldFeatureFlag
.setPreferredSize(new java
.awt
.Dimension(320, 20));
175 jTextFieldFeatureFlag
.setToolTipText("Postfix expression that must evaluate to TRUE or FALSE");
177 return jTextFieldFeatureFlag
;
181 * This method initializes jTextFieldHelpText
183 * @return javax.swing.JTextField
186 private JTextArea
getJTextAreaHelpText() {
187 if (jTextAreaHelpText
== null) {
188 jTextAreaHelpText
= new JTextArea();
189 jTextAreaHelpText
.setLineWrap(true);
190 jTextAreaHelpText
.setWrapStyleWord(true);
192 return jTextAreaHelpText
;
196 * This method initializes jScrollPaneHelpText
198 * @return javax.swing.JScrollPane
200 private JScrollPane
getJScrollPaneHelpText() {
201 if (jScrollPaneHelpText
== null) {
202 jScrollPaneHelpText
= new JScrollPane();
204 .setHorizontalScrollBarPolicy(javax
.swing
.JScrollPane
.HORIZONTAL_SCROLLBAR_NEVER
);
205 jScrollPaneHelpText
.setSize(new java
.awt
.Dimension(320, 40));
206 jScrollPaneHelpText
.setPreferredSize(new java
.awt
.Dimension(320, 40));
207 jScrollPaneHelpText
.setLocation(new java
.awt
.Point(160, 85));
208 jScrollPaneHelpText
.setViewportView(getJTextAreaHelpText());
210 return jScrollPaneHelpText
;
214 * This method initializes jButtonOk
216 * @return javax.swing.JButton
219 private JButton
getJButtonOk() {
220 if (jButtonOk
== null) {
221 jButtonOk
= new JButton();
222 jButtonOk
.setBounds(new java
.awt
.Rectangle(290, 182, 90, 20));
223 jButtonOk
.setText("Ok");
224 jButtonOk
.addActionListener(this);
230 * This method initializes jButtonCancel
232 * @return javax.swing.JButton
235 private JButton
getJButtonCancel() {
236 if (jButtonCancel
== null) {
237 jButtonCancel
= new JButton();
238 jButtonCancel
.setBounds(new java
.awt
.Rectangle(390, 182, 90, 20));
239 jButtonCancel
.setText("Cancel");
240 jButtonCancel
.addActionListener(this);
242 return jButtonCancel
;
245 public static void main(String
[] args
) {
250 * This method initializes this
253 private void init() {
254 this.setSize(500, 255);
255 this.setContentPane(getJScrollPane());
256 this.setTitle("Hobs");
258 this.setViewMode(false);
263 * This method initializes this Fill values to all fields if these values are
269 private void init(HobsIdentification inHobsId
) {
273 if (this.id
!= null) {
274 this.jComboBoxGuidC_Name
.setSelectedItem(id
.getName());
275 this.jComboBoxHobType
.setSelectedItem(id
.getType());
276 this.jComboBoxUsage
.setSelectedItem(id
.getUsage());
277 this.jTextAreaHelpText
.setText(id
.getHelp());
278 this.jTextFieldFeatureFlag
.setText(id
.getFeatureFlag());
279 this.jArchCheckBox
.setSelectedItems(id
.getSupArchList());
284 * This is the override edit constructor
286 * @param inHobsIdentification
290 public HobsDlg(HobsIdentification inHobsIdentification
, IFrame iFrame
) {
292 init(inHobsIdentification
);
296 * Disable all components when the mode is view
299 * true - The view mode; false - The non-view mode
302 public void setViewMode(boolean isView
) {
304 this.jComboBoxGuidC_Name
.setEnabled(!isView
);
305 this.jComboBoxUsage
.setEnabled(!isView
);
306 this.jComboBoxHobType
.setEnabled(!isView
);
311 * This method initializes jContentPane
313 * @return javax.swing.JPanel jContentPane
316 public JPanel
getJContentPane() {
317 if (jContentPane
== null) {
318 jStarLabel1
= new StarLabel();
319 jStarLabel1
.setLocation(new java
.awt
.Point(2, 10));
320 jLabelC_Name
= new JLabel();
321 jLabelC_Name
.setText("Hob's Guid C Name");
322 jLabelC_Name
.setBounds(new java
.awt
.Rectangle(15, 10, 145, 20));
324 jStarLabel2
= new StarLabel();
325 jStarLabel2
.setLocation(new java
.awt
.Point(2, 35));
326 jLabelHobType
= new JLabel();
327 jLabelHobType
.setText("Hob Type");
328 jLabelHobType
.setBounds(new java
.awt
.Rectangle(15, 35, 145, 20));
330 jStarLabel3
= new StarLabel();
331 jStarLabel3
.setLocation(new java
.awt
.Point(2, 60));
332 jLabelUsage
= new JLabel();
333 jLabelUsage
.setText("Usage");
334 jLabelUsage
.setBounds(new java
.awt
.Rectangle(15, 60, 145, 20));
336 jLabelHelpText
= new JLabel();
337 jLabelHelpText
.setBounds(new java
.awt
.Rectangle(15, 85, 145, 20));
338 jLabelHelpText
.setText("Help Text");
340 jLabelFeatureFlag
= new JLabel();
341 jLabelFeatureFlag
.setBounds(new java
.awt
.Rectangle(15, 130, 145, 20));
342 jLabelFeatureFlag
.setText("Feature Flag Expression");
344 jLabelArch
= new JLabel();
345 jLabelArch
.setBounds(new java
.awt
.Rectangle(15, 155, 145, 20));
346 jLabelArch
.setText("Supported Architectures");
347 jArchCheckBox
= new ArchCheckBox();
348 jArchCheckBox
.setBounds(new java
.awt
.Rectangle(160, 155, 320, 20));
349 jArchCheckBox
.setPreferredSize(new java
.awt
.Dimension(320, 20));
351 jContentPane
= new JPanel();
352 jContentPane
.setLayout(null);
353 jContentPane
.setPreferredSize(new java
.awt
.Dimension(485, 210));
355 jContentPane
.add(jStarLabel1
, null);
356 jContentPane
.add(jLabelC_Name
, null);
357 jContentPane
.add(getJComboBoxGuidC_Name(), null);
358 jContentPane
.add(jStarLabel2
, null);
359 jContentPane
.add(jLabelHobType
, null);
360 jContentPane
.add(getJComboBoxHobType(), null);
361 jContentPane
.add(jStarLabel3
, null);
362 jContentPane
.add(jLabelUsage
, null);
363 jContentPane
.add(getJComboBoxUsage(), null);
364 jContentPane
.add(jLabelHelpText
, null);
365 jContentPane
.add(getJScrollPaneHelpText(), null);
366 jContentPane
.add(jLabelFeatureFlag
, null);
367 jContentPane
.add(getJTextFieldFeatureFlag(), null);
368 jContentPane
.add(jLabelArch
, null);
369 jContentPane
.add(jArchCheckBox
, null);
370 jContentPane
.add(getJButtonOk(), null);
371 jContentPane
.add(getJButtonCancel(), null);
377 * This method initializes Usage type and Hob type
380 private void initFrame() {
381 Tools
.generateComboBoxByVector(jComboBoxUsage
, ed
.getVHobUsage());
382 Tools
.generateComboBoxByVector(jComboBoxHobType
, ed
.getVHobType());
383 Tools
.generateComboBoxByVector(jComboBoxGuidC_Name
, wt
384 .getAllGuidDeclarationsFromWorkspace());
390 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
392 * Override actionPerformed to listen all actions
395 public void actionPerformed(ActionEvent arg0
) {
396 if (arg0
.getSource() == jButtonOk
) {
399 this.returnType
= DataType
.RETURN_TYPE_OK
;
400 this.setVisible(false);
404 if (arg0
.getSource() == jButtonCancel
) {
405 this.returnType
= DataType
.RETURN_TYPE_CANCEL
;
406 this.setVisible(false);
411 * Data validation for all fields
413 * @retval true - All datas are valid
414 * @retval false - At least one data is invalid
417 public boolean checkAdd() {
419 // Check if all fields have correct data types
425 if (isEmpty(this.jComboBoxGuidC_Name
.getSelectedItem().toString())) {
426 Log
.wrn("Update Hobs", "Hob Guid C Name must not be empty");
430 if (!isEmpty(this.jComboBoxGuidC_Name
.getSelectedItem().toString())) {
431 if (!DataValidation
.isC_NameType(this.jComboBoxGuidC_Name
432 .getSelectedItem().toString())) {
433 Log
.wrn("Update Hobs", "Incorrect data type for Hob Name");
441 if (!isEmpty(this.jTextFieldFeatureFlag
.getText())) {
442 if (!DataValidation
.isFeatureFlag(this.jTextFieldFeatureFlag
.getText())) {
443 Log
.wrn("Update Hobs", "Incorrect data type for Feature Flag");
451 private HobsIdentification
getCurrentHobs() {
452 String arg0
= this.jComboBoxGuidC_Name
.getSelectedItem().toString();
453 String arg1
= this.jComboBoxHobType
.getSelectedItem().toString();
454 String arg2
= this.jComboBoxUsage
.getSelectedItem().toString();
456 String arg3
= this.jTextFieldFeatureFlag
.getText();
457 Vector
<String
> arg4
= this.jArchCheckBox
.getSelectedItemsVector();
458 String arg5
= this.jTextAreaHelpText
.getText();
459 id
= new HobsIdentification(arg0
, arg1
, arg2
, arg3
, arg4
, arg5
);
463 public HobsIdentification
getId() {
467 public void setId(HobsIdentification id
) {