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
.IComboBox
;
35 import org
.tianocore
.frameworkwizard
.common
.ui
.IDialog
;
36 import org
.tianocore
.frameworkwizard
.common
.ui
.IFrame
;
37 import org
.tianocore
.frameworkwizard
.common
.ui
.StarLabel
;
38 import org
.tianocore
.frameworkwizard
.module
.Identifications
.ModuleIdentification
;
39 import org
.tianocore
.frameworkwizard
.module
.Identifications
.Hobs
.HobsIdentification
;
40 import org
.tianocore
.frameworkwizard
.packaging
.PackageIdentification
;
41 import org
.tianocore
.frameworkwizard
.workspace
.WorkspaceTools
;
44 * The class is used to create, update Hob of the MSA file
49 public class HobsDlg
extends IDialog
{
52 // / Define class Serial Version UID
54 private static final long serialVersionUID
= -553473437579358325L;
57 // Define class members
59 private JPanel jContentPane
= null;
61 private JLabel jLabelC_Name
= null;
63 private IComboBox iComboBoxGuidC_Name
= null;
65 private JLabel jLabelUsage
= null;
67 private JLabel jLabelHobType
= null;
69 private JComboBox jComboBoxUsage
= null;
71 private JComboBox jComboBoxHobType
= null;
73 private StarLabel jStarLabel1
= null;
75 private StarLabel jStarLabel2
= null;
77 private StarLabel jStarLabel3
= null;
79 private JLabel jLabelArch
= null;
81 private JScrollPane jScrollPane
= null;
83 private JLabel jLabelFeatureFlag
= null;
85 private JTextField jTextFieldFeatureFlag
= null;
87 private JLabel jLabelHelpText
= null;
89 private JTextArea jTextAreaHelpText
= null;
91 private JScrollPane jScrollPaneHelpText
= null;
93 private ArchCheckBox jArchCheckBox
= null;
95 private JButton jButtonOk
= null;
97 private JButton jButtonCancel
= null;
102 private HobsIdentification id
= null;
104 private EnumerationData ed
= new EnumerationData();
106 private WorkspaceTools wt
= new WorkspaceTools();
109 * This method initializes jTextField
111 * @return javax.swing.JTextField jTextFieldC_Name
114 private IComboBox
getIComboBoxGuidC_Name() {
115 if (iComboBoxGuidC_Name
== null) {
116 iComboBoxGuidC_Name
= new IComboBox();
117 iComboBoxGuidC_Name
.setBounds(new java
.awt
.Rectangle(168, 12, 320, 20));
118 iComboBoxGuidC_Name
.setPreferredSize(new java
.awt
.Dimension(320, 20));
119 iComboBoxGuidC_Name
.setToolTipText("Select the GUID C Name of the Hob");
121 return iComboBoxGuidC_Name
;
125 * This method initializes jComboBoxHobType
127 * @return javax.swing.JComboBox jComboBoxHobType
130 private JComboBox
getJComboBoxHobType() {
131 if (jComboBoxHobType
== null) {
132 jComboBoxHobType
= new JComboBox();
133 jComboBoxHobType
.setBounds(new java
.awt
.Rectangle(168, 37, 320, 20));
134 jComboBoxHobType
.setPreferredSize(new java
.awt
.Dimension(320, 20));
136 .setToolTipText("<html><table>"
137 + "<tr><td>PHIT</td><td>EFI_HOB_TYPE_HANDOFF</td></tr>"
138 + "<tr><td>MEMORY_ALLOCATION</td><td>EFI_HOB_TYPE_MEMORY_ALLOCATION and $BaseName</td></tr>"
139 + "<tr><td>RESOURCE_DESCRIPTOR</td><td>EFI_HOB_TYPE_RESOURCE_DESCRIPTOR</td></tr>"
140 + "<tr><td>GUID_EXTENTION</td><td>EFI_HOB_TYPE_GUID_EXTENSION and BaseName of GUID</td></tr>"
141 + "<tr><td>FIRMWARE_VOLUME</td><td>EFI_HOB_TYPE_FV</td></tr>"
142 + "<tr><td>CPU</td><td>EFI_HOB_TYPE_CPU</td></tr>"
143 + "<tr><td>POOL</td><td>EFI_HOB_TYPE_PEI_MEMORY_POOL</td></tr>"
144 + "<tr><td>CAPSULE_VOLUME</td><td>EFI_HOB_TYPE_CV</td></tr>"
145 + "</table></html>");
147 return jComboBoxHobType
;
151 * This method initializes jComboBoxUsage
153 * @return javax.swing.JComboBox jComboBoxUsage
156 private JComboBox
getJComboBoxUsage() {
157 if (jComboBoxUsage
== null) {
158 jComboBoxUsage
= new JComboBox();
159 jComboBoxUsage
.setBounds(new java
.awt
.Rectangle(168, 62, 320, 20));
160 jComboBoxUsage
.setPreferredSize(new java
.awt
.Dimension(320, 20));
162 .setToolTipText("<html><table>"
163 + "<tr><td>ALWAYS_CONSUMED</td><td>HOB must be present in the system</td></tr>"
164 + "<tr><td>SOMETIMES_CONSUMED</td><td>HOB will be used if it's present</td></tr>"
165 + "<tr><td>ALWAYS_PRODUCED</td><td>HOB is always produced</td></tr>"
166 + "<tr><td>SOMETIMES_PRODUCED</td><td>HOB will sometimes be produced by the module</td></tr>"
167 + "</table></html>");
169 return jComboBoxUsage
;
173 * This method initializes jScrollPane
175 * @return javax.swing.JScrollPane
177 private JScrollPane
getJScrollPane() {
178 if (jScrollPane
== null) {
179 jScrollPane
= new JScrollPane();
180 jScrollPane
.setViewportView(getJContentPane());
186 * This method initializes jTextFieldFeatureFlag
188 * @return javax.swing.JTextField
190 private JTextField
getJTextFieldFeatureFlag() {
191 if (jTextFieldFeatureFlag
== null) {
192 jTextFieldFeatureFlag
= new JTextField();
193 jTextFieldFeatureFlag
.setBounds(new java
.awt
.Rectangle(168, 157, 320, 20));
194 jTextFieldFeatureFlag
.setPreferredSize(new java
.awt
.Dimension(320, 20));
195 jTextFieldFeatureFlag
.setToolTipText("Postfix expression that must evaluate to TRUE or FALSE");
196 jTextFieldFeatureFlag
.setEnabled(false);
198 return jTextFieldFeatureFlag
;
202 * This method initializes jTextFieldHelpText
204 * @return javax.swing.JTextField
207 private JTextArea
getJTextAreaHelpText() {
208 if (jTextAreaHelpText
== null) {
209 jTextAreaHelpText
= new JTextArea();
210 jTextAreaHelpText
.setLineWrap(true);
211 jTextAreaHelpText
.setWrapStyleWord(true);
213 return jTextAreaHelpText
;
217 * This method initializes jScrollPaneHelpText
219 * @return javax.swing.JScrollPane
221 private JScrollPane
getJScrollPaneHelpText() {
222 if (jScrollPaneHelpText
== null) {
223 jScrollPaneHelpText
= new JScrollPane();
224 jScrollPaneHelpText
.setHorizontalScrollBarPolicy(javax
.swing
.JScrollPane
.HORIZONTAL_SCROLLBAR_NEVER
);
225 jScrollPaneHelpText
.setSize(new java
.awt
.Dimension(320, 40));
226 jScrollPaneHelpText
.setPreferredSize(new java
.awt
.Dimension(320, 40));
227 jScrollPaneHelpText
.setLocation(new java
.awt
.Point(168, 87));
228 jScrollPaneHelpText
.setViewportView(getJTextAreaHelpText());
230 return jScrollPaneHelpText
;
234 * This method initializes jButtonOk
236 * @return javax.swing.JButton
239 private JButton
getJButtonOk() {
240 if (jButtonOk
== null) {
241 jButtonOk
= new JButton();
242 jButtonOk
.setBounds(new java
.awt
.Rectangle(290, 187, 90, 20));
243 jButtonOk
.setText("Ok");
244 jButtonOk
.addActionListener(this);
250 * This method initializes jButtonCancel
252 * @return javax.swing.JButton
255 private JButton
getJButtonCancel() {
256 if (jButtonCancel
== null) {
257 jButtonCancel
= new JButton();
258 jButtonCancel
.setBounds(new java
.awt
.Rectangle(390, 187, 90, 20));
259 jButtonCancel
.setText("Cancel");
260 jButtonCancel
.addActionListener(this);
262 return jButtonCancel
;
265 public static void main(String
[] args
) {
270 * This method initializes this
273 private void init() {
274 this.setSize(505, 260);
275 this.setContentPane(getJScrollPane());
276 this.setTitle("Hobs");
278 this.setViewMode(false);
283 * This method initializes this Fill values to all fields if these values are
289 private void init(HobsIdentification inHobsId
, ModuleIdentification mid
) {
294 // Init arch with module's arch
296 this.jArchCheckBox
.setEnabledItems(wt
.getModuleArch(mid
));
299 // Get defined guids from dependent packages
301 Vector
<PackageIdentification
> vpid
= wt
.getPackageDependenciesOfModule(mid
);
302 if (vpid
.size() <= 0) {
305 "This module hasn't defined any package dependency, so there is no guid value can be added for hob");
308 // Init guids drop down list
311 .generateComboBoxByVector(iComboBoxGuidC_Name
,
312 wt
.getAllGuidDeclarationsFromPackages(vpid
, EnumerationData
.GUID_TYPE_HOB
));
313 this.iComboBoxGuidC_Name
.insertItemAt(DataType
.EMPTY_SELECT_ITEM
, 0);
314 this.iComboBoxGuidC_Name
.setSelectedIndex(0);
317 if (this.id
!= null) {
318 String tmpName
= id
.getName();
319 if (isEmpty(tmpName
)) {
320 tmpName
= DataType
.EMPTY_SELECT_ITEM
;
322 this.iComboBoxGuidC_Name
.setSelectedItem(tmpName
);
323 this.jComboBoxHobType
.setSelectedItem(id
.getType());
324 this.jComboBoxUsage
.setSelectedItem(id
.getUsage());
325 this.jTextAreaHelpText
.setText(id
.getHelp());
326 this.jTextFieldFeatureFlag
.setText(id
.getFeatureFlag());
327 this.jArchCheckBox
.setSelectedItems(id
.getSupArchList());
332 * This is the override edit constructor
334 * @param inHobsIdentification
338 public HobsDlg(HobsIdentification inHobsIdentification
, IFrame iFrame
, ModuleIdentification mid
) {
340 init(inHobsIdentification
, mid
);
344 * Disable all components when the mode is view
347 * true - The view mode; false - The non-view mode
350 public void setViewMode(boolean isView
) {
352 this.iComboBoxGuidC_Name
.setEnabled(!isView
);
353 this.jComboBoxUsage
.setEnabled(!isView
);
354 this.jComboBoxHobType
.setEnabled(!isView
);
359 * This method initializes jContentPane
361 * @return javax.swing.JPanel jContentPane
364 public JPanel
getJContentPane() {
365 if (jContentPane
== null) {
366 jStarLabel1
= new StarLabel();
367 jStarLabel1
.setLocation(new java
.awt
.Point(2, 12));
368 jLabelC_Name
= new JLabel();
369 jLabelC_Name
.setText("Hob's Guid C Name");
370 jLabelC_Name
.setBounds(new java
.awt
.Rectangle(12, 12, 155, 20));
372 jStarLabel2
= new StarLabel();
373 jStarLabel2
.setLocation(new java
.awt
.Point(2, 37));
374 jLabelHobType
= new JLabel();
375 jLabelHobType
.setText("Hob Type");
376 jLabelHobType
.setBounds(new java
.awt
.Rectangle(12, 37, 155, 20));
378 jStarLabel3
= new StarLabel();
379 jStarLabel3
.setLocation(new java
.awt
.Point(2, 62));
380 jLabelUsage
= new JLabel();
381 jLabelUsage
.setText("Usage");
382 jLabelUsage
.setBounds(new java
.awt
.Rectangle(12, 62, 155, 20));
384 jLabelHelpText
= new JLabel();
385 jLabelHelpText
.setBounds(new java
.awt
.Rectangle(12, 87, 155, 20));
386 jLabelHelpText
.setText("Help Text");
388 jLabelFeatureFlag
= new JLabel();
389 jLabelFeatureFlag
.setBounds(new java
.awt
.Rectangle(12, 157, 155, 20));
390 jLabelFeatureFlag
.setText("Feature Flag Expression");
391 jLabelFeatureFlag
.setEnabled(false);
393 jLabelArch
= new JLabel();
394 jLabelArch
.setBounds(new java
.awt
.Rectangle(12, 132, 155, 20));
395 jLabelArch
.setText("Supported Architectures");
396 jArchCheckBox
= new ArchCheckBox();
397 jArchCheckBox
.setBounds(new java
.awt
.Rectangle(168, 132, 320, 20));
398 jArchCheckBox
.setPreferredSize(new java
.awt
.Dimension(320, 20));
400 jContentPane
= new JPanel();
401 jContentPane
.setLayout(null);
402 jContentPane
.setPreferredSize(new java
.awt
.Dimension(485, 215));
404 jContentPane
.add(jLabelC_Name
, null);
405 jContentPane
.add(getIComboBoxGuidC_Name(), null);
406 jContentPane
.add(jStarLabel2
, null);
407 jContentPane
.add(jLabelHobType
, null);
408 jContentPane
.add(getJComboBoxHobType(), null);
409 jContentPane
.add(jStarLabel3
, null);
410 jContentPane
.add(jLabelUsage
, null);
411 jContentPane
.add(getJComboBoxUsage(), null);
412 jContentPane
.add(jLabelHelpText
, null);
413 jContentPane
.add(getJScrollPaneHelpText(), null);
414 jContentPane
.add(jLabelFeatureFlag
, null);
415 jContentPane
.add(getJTextFieldFeatureFlag(), null);
416 jContentPane
.add(jLabelArch
, null);
417 jContentPane
.add(jArchCheckBox
, null);
418 jContentPane
.add(getJButtonOk(), null);
419 jContentPane
.add(getJButtonCancel(), null);
425 * This method initializes Usage type and Hob type
428 private void initFrame() {
429 Tools
.generateComboBoxByVector(jComboBoxUsage
, ed
.getVHobUsage());
430 Tools
.generateComboBoxByVector(jComboBoxHobType
, ed
.getVHobType());
436 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
438 * Override actionPerformed to listen all actions
441 public void actionPerformed(ActionEvent arg0
) {
442 if (arg0
.getSource() == jButtonOk
) {
445 this.returnType
= DataType
.RETURN_TYPE_OK
;
446 this.setVisible(false);
450 if (arg0
.getSource() == jButtonCancel
) {
451 this.returnType
= DataType
.RETURN_TYPE_CANCEL
;
452 this.setVisible(false);
457 * Data validation for all fields
459 * @retval true - All datas are valid
460 * @retval false - At least one data is invalid
463 public boolean checkAdd() {
465 // Check if all fields have correct data types
471 String tmpName
= this.iComboBoxGuidC_Name
.getSelectedItem().toString();
472 if (!tmpName
.equals(DataType
.EMPTY_SELECT_ITEM
) && isEmpty(tmpName
)) {
473 if (!DataValidation
.isC_NameType(this.iComboBoxGuidC_Name
.getSelectedItem().toString())) {
474 Log
.wrn("Update Hobs", "Incorrect data type for Hob Name");
482 if (!isEmpty(this.jTextFieldFeatureFlag
.getText())) {
483 if (!DataValidation
.isFeatureFlag(this.jTextFieldFeatureFlag
.getText())) {
484 Log
.wrn("Update Hobs", "Incorrect data type for Feature Flag");
492 private HobsIdentification
getCurrentHobs() {
493 String arg0
= this.iComboBoxGuidC_Name
.getSelectedItem().toString();
494 String arg1
= this.jComboBoxHobType
.getSelectedItem().toString();
495 String arg2
= this.jComboBoxUsage
.getSelectedItem().toString();
497 String arg3
= this.jTextFieldFeatureFlag
.getText();
498 Vector
<String
> arg4
= this.jArchCheckBox
.getSelectedItemsVector();
499 String arg5
= this.jTextAreaHelpText
.getText();
500 id
= new HobsIdentification(arg0
, arg1
, arg2
, arg3
, arg4
, arg5
);
504 public HobsIdentification
getId() {
508 public void setId(HobsIdentification id
) {