3 The file is used to create, update Hob section of the MSA 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
46 public class HobsDlg
extends IDialog
{
49 // / Define class Serial Version UID
51 private static final long serialVersionUID
= -553473437579358325L;
54 // Define class members
56 private JPanel jContentPane
= null;
58 private JLabel jLabelC_Name
= null;
60 private JComboBox jComboBoxGuidC_Name
= null;
62 private JLabel jLabelUsage
= null;
64 private JLabel jLabelHobType
= null;
66 private JComboBox jComboBoxUsage
= null;
68 private JComboBox jComboBoxHobType
= null;
70 private StarLabel jStarLabel1
= null;
72 private StarLabel jStarLabel2
= null;
74 private StarLabel jStarLabel3
= null;
76 private JLabel jLabelArch
= null;
78 private JScrollPane jScrollPane
= null;
80 private JLabel jLabelFeatureFlag
= null;
82 private JTextField jTextFieldFeatureFlag
= null;
84 private JLabel jLabelHelpText
= null;
86 private JTextArea jTextAreaHelpText
= null;
88 private JScrollPane jScrollPaneHelpText
= null;
90 private ArchCheckBox jArchCheckBox
= null;
92 private JButton jButtonOk
= null;
94 private JButton jButtonCancel
= null;
99 private HobsIdentification id
= null;
101 private EnumerationData ed
= new EnumerationData();
103 private WorkspaceTools wt
= new WorkspaceTools();
106 * This method initializes jTextField
108 * @return javax.swing.JTextField jTextFieldC_Name
111 private JComboBox
getJComboBoxGuidC_Name() {
112 if (jComboBoxGuidC_Name
== null) {
113 jComboBoxGuidC_Name
= new JComboBox();
114 jComboBoxGuidC_Name
.setBounds(new java
.awt
.Rectangle(168, 12, 320, 20));
115 jComboBoxGuidC_Name
.setPreferredSize(new java
.awt
.Dimension(320, 20));
116 jComboBoxGuidC_Name
.setToolTipText("Select the GUID C Name of the Hob");
118 return jComboBoxGuidC_Name
;
122 * This method initializes jComboBoxHobType
124 * @return javax.swing.JComboBox jComboBoxHobType
127 private JComboBox
getJComboBoxHobType() {
128 if (jComboBoxHobType
== null) {
129 jComboBoxHobType
= new JComboBox();
130 jComboBoxHobType
.setBounds(new java
.awt
.Rectangle(168, 37, 320, 20));
131 jComboBoxHobType
.setPreferredSize(new java
.awt
.Dimension(320, 20));
133 .setToolTipText("<html><table>"
134 + "<tr><td>PHIT</td><td>EFI_HOB_TYPE_HANDOFF</td></tr>"
135 + "<tr><td>MEMORY_ALLOCATION</td><td>EFI_HOB_TYPE_MEMORY_ALLOCATION and $BaseName</td></tr>"
136 + "<tr><td>RESOURCE_DESCRIPTOR</td><td>EFI_HOB_TYPE_RESOURCE_DESCRIPTOR</td></tr>"
137 + "<tr><td>GUID_EXTENTION</td><td>EFI_HOB_TYPE_GUID_EXTENSION and BaseName of GUID</td></tr>"
138 + "<tr><td>FIRMWARE_VOLUME</td><td>EFI_HOB_TYPE_FV</td></tr>"
139 + "<tr><td>CPU</td><td>EFI_HOB_TYPE_CPU</td></tr>"
140 + "<tr><td>POOL</td><td>EFI_HOB_TYPE_PEI_MEMORY_POOL</td></tr>"
141 + "<tr><td>CAPSULE_VOLUME</td><td>EFI_HOB_TYPE_CV</td></tr>"
142 + "</table></html>");
144 return jComboBoxHobType
;
148 * This method initializes jComboBoxUsage
150 * @return javax.swing.JComboBox jComboBoxUsage
153 private JComboBox
getJComboBoxUsage() {
154 if (jComboBoxUsage
== null) {
155 jComboBoxUsage
= new JComboBox();
156 jComboBoxUsage
.setBounds(new java
.awt
.Rectangle(168, 62, 320, 20));
157 jComboBoxUsage
.setPreferredSize(new java
.awt
.Dimension(320, 20));
159 .setToolTipText("<html><table>"
160 + "<tr><td>ALWAYS_CONSUMED</td><td>HOB must be present in the system</td></tr>"
161 + "<tr><td>SOMETIMES_CONSUMED</td><td>HOB will be used if it's present</td></tr>"
162 + "<tr><td>ALWAYS_PRODUCED</td><td>HOB is always produced</td></tr>"
163 + "<tr><td>SOMETIMES_PRODUCED</td><td>HOB will sometimes be produced by the module</td></tr>"
164 + "</table></html>");
166 return jComboBoxUsage
;
170 * This method initializes jScrollPane
172 * @return javax.swing.JScrollPane
174 private JScrollPane
getJScrollPane() {
175 if (jScrollPane
== null) {
176 jScrollPane
= new JScrollPane();
177 jScrollPane
.setViewportView(getJContentPane());
183 * This method initializes jTextFieldFeatureFlag
185 * @return javax.swing.JTextField
187 private JTextField
getJTextFieldFeatureFlag() {
188 if (jTextFieldFeatureFlag
== null) {
189 jTextFieldFeatureFlag
= new JTextField();
190 jTextFieldFeatureFlag
.setBounds(new java
.awt
.Rectangle(168, 132, 320, 20));
191 jTextFieldFeatureFlag
.setPreferredSize(new java
.awt
.Dimension(320, 20));
192 jTextFieldFeatureFlag
.setToolTipText("Postfix expression that must evaluate to TRUE or FALSE");
194 return jTextFieldFeatureFlag
;
198 * This method initializes jTextFieldHelpText
200 * @return javax.swing.JTextField
203 private JTextArea
getJTextAreaHelpText() {
204 if (jTextAreaHelpText
== null) {
205 jTextAreaHelpText
= new JTextArea();
206 jTextAreaHelpText
.setLineWrap(true);
207 jTextAreaHelpText
.setWrapStyleWord(true);
209 return jTextAreaHelpText
;
213 * This method initializes jScrollPaneHelpText
215 * @return javax.swing.JScrollPane
217 private JScrollPane
getJScrollPaneHelpText() {
218 if (jScrollPaneHelpText
== null) {
219 jScrollPaneHelpText
= new JScrollPane();
220 jScrollPaneHelpText
.setHorizontalScrollBarPolicy(javax
.swing
.JScrollPane
.HORIZONTAL_SCROLLBAR_NEVER
);
221 jScrollPaneHelpText
.setSize(new java
.awt
.Dimension(320, 40));
222 jScrollPaneHelpText
.setPreferredSize(new java
.awt
.Dimension(320, 40));
223 jScrollPaneHelpText
.setLocation(new java
.awt
.Point(168, 87));
224 jScrollPaneHelpText
.setViewportView(getJTextAreaHelpText());
226 return jScrollPaneHelpText
;
230 * This method initializes jButtonOk
232 * @return javax.swing.JButton
235 private JButton
getJButtonOk() {
236 if (jButtonOk
== null) {
237 jButtonOk
= new JButton();
238 jButtonOk
.setBounds(new java
.awt
.Rectangle(290, 187, 90, 20));
239 jButtonOk
.setText("Ok");
240 jButtonOk
.addActionListener(this);
246 * This method initializes jButtonCancel
248 * @return javax.swing.JButton
251 private JButton
getJButtonCancel() {
252 if (jButtonCancel
== null) {
253 jButtonCancel
= new JButton();
254 jButtonCancel
.setBounds(new java
.awt
.Rectangle(390, 187, 90, 20));
255 jButtonCancel
.setText("Cancel");
256 jButtonCancel
.addActionListener(this);
258 return jButtonCancel
;
261 public static void main(String
[] args
) {
266 * This method initializes this
269 private void init() {
270 this.setSize(505, 260);
271 this.setContentPane(getJScrollPane());
272 this.setTitle("Hobs");
274 this.setViewMode(false);
279 * This method initializes this Fill values to all fields if these values are
285 private void init(HobsIdentification inHobsId
) {
289 if (this.id
!= null) {
290 this.jComboBoxGuidC_Name
.setSelectedItem(id
.getName());
291 this.jComboBoxHobType
.setSelectedItem(id
.getType());
292 this.jComboBoxUsage
.setSelectedItem(id
.getUsage());
293 this.jTextAreaHelpText
.setText(id
.getHelp());
294 this.jTextFieldFeatureFlag
.setText(id
.getFeatureFlag());
295 this.jArchCheckBox
.setSelectedItems(id
.getSupArchList());
300 * This is the override edit constructor
302 * @param inHobsIdentification
306 public HobsDlg(HobsIdentification inHobsIdentification
, IFrame iFrame
) {
308 init(inHobsIdentification
);
312 * Disable all components when the mode is view
315 * true - The view mode; false - The non-view mode
318 public void setViewMode(boolean isView
) {
320 this.jComboBoxGuidC_Name
.setEnabled(!isView
);
321 this.jComboBoxUsage
.setEnabled(!isView
);
322 this.jComboBoxHobType
.setEnabled(!isView
);
327 * This method initializes jContentPane
329 * @return javax.swing.JPanel jContentPane
332 public JPanel
getJContentPane() {
333 if (jContentPane
== null) {
334 jStarLabel1
= new StarLabel();
335 jStarLabel1
.setLocation(new java
.awt
.Point(2, 12));
336 jLabelC_Name
= new JLabel();
337 jLabelC_Name
.setText("Hob's Guid C Name");
338 jLabelC_Name
.setBounds(new java
.awt
.Rectangle(12, 12, 155, 20));
340 jStarLabel2
= new StarLabel();
341 jStarLabel2
.setLocation(new java
.awt
.Point(2, 37));
342 jLabelHobType
= new JLabel();
343 jLabelHobType
.setText("Hob Type");
344 jLabelHobType
.setBounds(new java
.awt
.Rectangle(12, 37, 155, 20));
346 jStarLabel3
= new StarLabel();
347 jStarLabel3
.setLocation(new java
.awt
.Point(2, 62));
348 jLabelUsage
= new JLabel();
349 jLabelUsage
.setText("Usage");
350 jLabelUsage
.setBounds(new java
.awt
.Rectangle(12, 62, 155, 20));
352 jLabelHelpText
= new JLabel();
353 jLabelHelpText
.setBounds(new java
.awt
.Rectangle(12, 87, 155, 20));
354 jLabelHelpText
.setText("Help Text");
356 jLabelFeatureFlag
= new JLabel();
357 jLabelFeatureFlag
.setBounds(new java
.awt
.Rectangle(12, 132, 155, 20));
358 jLabelFeatureFlag
.setText("Feature Flag Expression");
360 jLabelArch
= new JLabel();
361 jLabelArch
.setBounds(new java
.awt
.Rectangle(12, 157, 155, 20));
362 jLabelArch
.setText("Supported Architectures");
363 jArchCheckBox
= new ArchCheckBox();
364 jArchCheckBox
.setBounds(new java
.awt
.Rectangle(168, 157, 320, 20));
365 jArchCheckBox
.setPreferredSize(new java
.awt
.Dimension(320, 20));
367 jContentPane
= new JPanel();
368 jContentPane
.setLayout(null);
369 jContentPane
.setPreferredSize(new java
.awt
.Dimension(485, 215));
371 jContentPane
.add(jStarLabel1
, null);
372 jContentPane
.add(jLabelC_Name
, null);
373 jContentPane
.add(getJComboBoxGuidC_Name(), null);
374 jContentPane
.add(jStarLabel2
, null);
375 jContentPane
.add(jLabelHobType
, null);
376 jContentPane
.add(getJComboBoxHobType(), null);
377 jContentPane
.add(jStarLabel3
, null);
378 jContentPane
.add(jLabelUsage
, null);
379 jContentPane
.add(getJComboBoxUsage(), null);
380 jContentPane
.add(jLabelHelpText
, null);
381 jContentPane
.add(getJScrollPaneHelpText(), null);
382 jContentPane
.add(jLabelFeatureFlag
, null);
383 jContentPane
.add(getJTextFieldFeatureFlag(), null);
384 jContentPane
.add(jLabelArch
, null);
385 jContentPane
.add(jArchCheckBox
, null);
386 jContentPane
.add(getJButtonOk(), null);
387 jContentPane
.add(getJButtonCancel(), null);
393 * This method initializes Usage type and Hob type
396 private void initFrame() {
397 Tools
.generateComboBoxByVector(jComboBoxUsage
, ed
.getVHobUsage());
398 Tools
.generateComboBoxByVector(jComboBoxHobType
, ed
.getVHobType());
399 Tools
.generateComboBoxByVector(jComboBoxGuidC_Name
, wt
.getAllGuidDeclarationsFromWorkspace());
405 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
407 * Override actionPerformed to listen all actions
410 public void actionPerformed(ActionEvent arg0
) {
411 if (arg0
.getSource() == jButtonOk
) {
414 this.returnType
= DataType
.RETURN_TYPE_OK
;
415 this.setVisible(false);
419 if (arg0
.getSource() == jButtonCancel
) {
420 this.returnType
= DataType
.RETURN_TYPE_CANCEL
;
421 this.setVisible(false);
426 * Data validation for all fields
428 * @retval true - All datas are valid
429 * @retval false - At least one data is invalid
432 public boolean checkAdd() {
434 // Check if all fields have correct data types
440 if (isEmpty(this.jComboBoxGuidC_Name
.getSelectedItem().toString())) {
441 Log
.wrn("Update Hobs", "Hob Guid C Name must not be empty");
445 if (!isEmpty(this.jComboBoxGuidC_Name
.getSelectedItem().toString())) {
446 if (!DataValidation
.isC_NameType(this.jComboBoxGuidC_Name
.getSelectedItem().toString())) {
447 Log
.wrn("Update Hobs", "Incorrect data type for Hob Name");
455 if (!isEmpty(this.jTextFieldFeatureFlag
.getText())) {
456 if (!DataValidation
.isFeatureFlag(this.jTextFieldFeatureFlag
.getText())) {
457 Log
.wrn("Update Hobs", "Incorrect data type for Feature Flag");
465 private HobsIdentification
getCurrentHobs() {
466 String arg0
= this.jComboBoxGuidC_Name
.getSelectedItem().toString();
467 String arg1
= this.jComboBoxHobType
.getSelectedItem().toString();
468 String arg2
= this.jComboBoxUsage
.getSelectedItem().toString();
470 String arg3
= this.jTextFieldFeatureFlag
.getText();
471 Vector
<String
> arg4
= this.jArchCheckBox
.getSelectedItemsVector();
472 String arg5
= this.jTextAreaHelpText
.getText();
473 id
= new HobsIdentification(arg0
, arg1
, arg2
, arg3
, arg4
, arg5
);
477 public HobsIdentification
getId() {
481 public void setId(HobsIdentification id
) {