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
));
315 if (this.id
!= null) {
316 this.iComboBoxGuidC_Name
.setSelectedItem(id
.getName());
317 this.jComboBoxHobType
.setSelectedItem(id
.getType());
318 this.jComboBoxUsage
.setSelectedItem(id
.getUsage());
319 this.jTextAreaHelpText
.setText(id
.getHelp());
320 this.jTextFieldFeatureFlag
.setText(id
.getFeatureFlag());
321 this.jArchCheckBox
.setSelectedItems(id
.getSupArchList());
326 * This is the override edit constructor
328 * @param inHobsIdentification
332 public HobsDlg(HobsIdentification inHobsIdentification
, IFrame iFrame
, ModuleIdentification mid
) {
334 init(inHobsIdentification
, mid
);
338 * Disable all components when the mode is view
341 * true - The view mode; false - The non-view mode
344 public void setViewMode(boolean isView
) {
346 this.iComboBoxGuidC_Name
.setEnabled(!isView
);
347 this.jComboBoxUsage
.setEnabled(!isView
);
348 this.jComboBoxHobType
.setEnabled(!isView
);
353 * This method initializes jContentPane
355 * @return javax.swing.JPanel jContentPane
358 public JPanel
getJContentPane() {
359 if (jContentPane
== null) {
360 jStarLabel1
= new StarLabel();
361 jStarLabel1
.setLocation(new java
.awt
.Point(2, 12));
362 jLabelC_Name
= new JLabel();
363 jLabelC_Name
.setText("Hob's Guid C Name");
364 jLabelC_Name
.setBounds(new java
.awt
.Rectangle(12, 12, 155, 20));
366 jStarLabel2
= new StarLabel();
367 jStarLabel2
.setLocation(new java
.awt
.Point(2, 37));
368 jLabelHobType
= new JLabel();
369 jLabelHobType
.setText("Hob Type");
370 jLabelHobType
.setBounds(new java
.awt
.Rectangle(12, 37, 155, 20));
372 jStarLabel3
= new StarLabel();
373 jStarLabel3
.setLocation(new java
.awt
.Point(2, 62));
374 jLabelUsage
= new JLabel();
375 jLabelUsage
.setText("Usage");
376 jLabelUsage
.setBounds(new java
.awt
.Rectangle(12, 62, 155, 20));
378 jLabelHelpText
= new JLabel();
379 jLabelHelpText
.setBounds(new java
.awt
.Rectangle(12, 87, 155, 20));
380 jLabelHelpText
.setText("Help Text");
382 jLabelFeatureFlag
= new JLabel();
383 jLabelFeatureFlag
.setBounds(new java
.awt
.Rectangle(12, 157, 155, 20));
384 jLabelFeatureFlag
.setText("Feature Flag Expression");
385 jLabelFeatureFlag
.setEnabled(false);
387 jLabelArch
= new JLabel();
388 jLabelArch
.setBounds(new java
.awt
.Rectangle(12, 132, 155, 20));
389 jLabelArch
.setText("Supported Architectures");
390 jArchCheckBox
= new ArchCheckBox();
391 jArchCheckBox
.setBounds(new java
.awt
.Rectangle(168, 132, 320, 20));
392 jArchCheckBox
.setPreferredSize(new java
.awt
.Dimension(320, 20));
394 jContentPane
= new JPanel();
395 jContentPane
.setLayout(null);
396 jContentPane
.setPreferredSize(new java
.awt
.Dimension(485, 215));
398 jContentPane
.add(jStarLabel1
, null);
399 jContentPane
.add(jLabelC_Name
, null);
400 jContentPane
.add(getIComboBoxGuidC_Name(), null);
401 jContentPane
.add(jStarLabel2
, null);
402 jContentPane
.add(jLabelHobType
, null);
403 jContentPane
.add(getJComboBoxHobType(), null);
404 jContentPane
.add(jStarLabel3
, null);
405 jContentPane
.add(jLabelUsage
, null);
406 jContentPane
.add(getJComboBoxUsage(), null);
407 jContentPane
.add(jLabelHelpText
, null);
408 jContentPane
.add(getJScrollPaneHelpText(), null);
409 jContentPane
.add(jLabelFeatureFlag
, null);
410 jContentPane
.add(getJTextFieldFeatureFlag(), null);
411 jContentPane
.add(jLabelArch
, null);
412 jContentPane
.add(jArchCheckBox
, null);
413 jContentPane
.add(getJButtonOk(), null);
414 jContentPane
.add(getJButtonCancel(), null);
420 * This method initializes Usage type and Hob type
423 private void initFrame() {
424 Tools
.generateComboBoxByVector(jComboBoxUsage
, ed
.getVHobUsage());
425 Tools
.generateComboBoxByVector(jComboBoxHobType
, ed
.getVHobType());
431 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
433 * Override actionPerformed to listen all actions
436 public void actionPerformed(ActionEvent arg0
) {
437 if (arg0
.getSource() == jButtonOk
) {
440 this.returnType
= DataType
.RETURN_TYPE_OK
;
441 this.setVisible(false);
445 if (arg0
.getSource() == jButtonCancel
) {
446 this.returnType
= DataType
.RETURN_TYPE_CANCEL
;
447 this.setVisible(false);
452 * Data validation for all fields
454 * @retval true - All datas are valid
455 * @retval false - At least one data is invalid
458 public boolean checkAdd() {
460 // Check if all fields have correct data types
466 if (this.iComboBoxGuidC_Name
.getSelectedItem() == null) {
467 Log
.wrn("Update Guids", "Please select one Hob Name");
473 if (isEmpty(this.iComboBoxGuidC_Name
.getSelectedItem().toString())) {
474 Log
.wrn("Update Hobs", "Hob Guid C Name must be entered!");
478 if (!isEmpty(this.iComboBoxGuidC_Name
.getSelectedItem().toString())) {
479 if (!DataValidation
.isC_NameType(this.iComboBoxGuidC_Name
.getSelectedItem().toString())) {
480 Log
.wrn("Update Hobs", "Incorrect data type for Hob Name");
488 if (!isEmpty(this.jTextFieldFeatureFlag
.getText())) {
489 if (!DataValidation
.isFeatureFlag(this.jTextFieldFeatureFlag
.getText())) {
490 Log
.wrn("Update Hobs", "Incorrect data type for Feature Flag");
498 private HobsIdentification
getCurrentHobs() {
499 String arg0
= this.iComboBoxGuidC_Name
.getSelectedItem().toString();
500 String arg1
= this.jComboBoxHobType
.getSelectedItem().toString();
501 String arg2
= this.jComboBoxUsage
.getSelectedItem().toString();
503 String arg3
= this.jTextFieldFeatureFlag
.getText();
504 Vector
<String
> arg4
= this.jArchCheckBox
.getSelectedItemsVector();
505 String arg5
= this.jTextAreaHelpText
.getText();
506 id
= new HobsIdentification(arg0
, arg1
, arg2
, arg3
, arg4
, arg5
);
510 public HobsIdentification
getId() {
514 public void setId(HobsIdentification id
) {