]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/module/ui/dialog/HobsDlg.java
1. Fix EDKT528: Framework wizard should not force user to specify a GuidCName for...
[mirror_edk2.git] / Tools / Java / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / module / ui / dialog / HobsDlg.java
1 /** @file
2
3 The file is used to create, update Hob section of the MSA 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.frameworkwizard.module.ui.dialog;
16
17 import java.awt.event.ActionEvent;
18 import java.util.Vector;
19
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;
27
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;
42
43 /**
44 * The class is used to create, update Hob of the MSA file
45 *
46 * It extends IDialog
47 *
48 */
49 public class HobsDlg extends IDialog {
50
51 // /
52 // / Define class Serial Version UID
53 // /
54 private static final long serialVersionUID = -553473437579358325L;
55
56 //
57 // Define class members
58 //
59 private JPanel jContentPane = null;
60
61 private JLabel jLabelC_Name = null;
62
63 private IComboBox iComboBoxGuidC_Name = null;
64
65 private JLabel jLabelUsage = null;
66
67 private JLabel jLabelHobType = null;
68
69 private JComboBox jComboBoxUsage = null;
70
71 private JComboBox jComboBoxHobType = null;
72
73 private StarLabel jStarLabel1 = null;
74
75 private StarLabel jStarLabel2 = null;
76
77 private StarLabel jStarLabel3 = null;
78
79 private JLabel jLabelArch = null;
80
81 private JScrollPane jScrollPane = null;
82
83 private JLabel jLabelFeatureFlag = null;
84
85 private JTextField jTextFieldFeatureFlag = null;
86
87 private JLabel jLabelHelpText = null;
88
89 private JTextArea jTextAreaHelpText = null;
90
91 private JScrollPane jScrollPaneHelpText = null;
92
93 private ArchCheckBox jArchCheckBox = null;
94
95 private JButton jButtonOk = null;
96
97 private JButton jButtonCancel = null;
98
99 //
100 // Not used by UI
101 //
102 private HobsIdentification id = null;
103
104 private EnumerationData ed = new EnumerationData();
105
106 private WorkspaceTools wt = new WorkspaceTools();
107
108 /**
109 * This method initializes jTextField
110 *
111 * @return javax.swing.JTextField jTextFieldC_Name
112 *
113 */
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");
120 }
121 return iComboBoxGuidC_Name;
122 }
123
124 /**
125 * This method initializes jComboBoxHobType
126 *
127 * @return javax.swing.JComboBox jComboBoxHobType
128 *
129 */
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));
135 jComboBoxHobType
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>");
146 }
147 return jComboBoxHobType;
148 }
149
150 /**
151 * This method initializes jComboBoxUsage
152 *
153 * @return javax.swing.JComboBox jComboBoxUsage
154 *
155 */
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));
161 jComboBoxUsage
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>");
168 }
169 return jComboBoxUsage;
170 }
171
172 /**
173 * This method initializes jScrollPane
174 *
175 * @return javax.swing.JScrollPane
176 */
177 private JScrollPane getJScrollPane() {
178 if (jScrollPane == null) {
179 jScrollPane = new JScrollPane();
180 jScrollPane.setViewportView(getJContentPane());
181 }
182 return jScrollPane;
183 }
184
185 /**
186 * This method initializes jTextFieldFeatureFlag
187 *
188 * @return javax.swing.JTextField
189 */
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);
197 }
198 return jTextFieldFeatureFlag;
199 }
200
201 /**
202 * This method initializes jTextFieldHelpText
203 *
204 * @return javax.swing.JTextField
205 *
206 */
207 private JTextArea getJTextAreaHelpText() {
208 if (jTextAreaHelpText == null) {
209 jTextAreaHelpText = new JTextArea();
210 jTextAreaHelpText.setLineWrap(true);
211 jTextAreaHelpText.setWrapStyleWord(true);
212 }
213 return jTextAreaHelpText;
214 }
215
216 /**
217 * This method initializes jScrollPaneHelpText
218 *
219 * @return javax.swing.JScrollPane
220 */
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());
229 }
230 return jScrollPaneHelpText;
231 }
232
233 /**
234 * This method initializes jButtonOk
235 *
236 * @return javax.swing.JButton
237 *
238 */
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);
245 }
246 return jButtonOk;
247 }
248
249 /**
250 * This method initializes jButtonCancel
251 *
252 * @return javax.swing.JButton
253 *
254 */
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);
261 }
262 return jButtonCancel;
263 }
264
265 public static void main(String[] args) {
266
267 }
268
269 /**
270 * This method initializes this
271 *
272 */
273 private void init() {
274 this.setSize(505, 260);
275 this.setContentPane(getJScrollPane());
276 this.setTitle("Hobs");
277 initFrame();
278 this.setViewMode(false);
279 this.centerWindow();
280 }
281
282 /**
283 * This method initializes this Fill values to all fields if these values are
284 * not empty
285 *
286 * @param inHobsId
287 *
288 */
289 private void init(HobsIdentification inHobsId, ModuleIdentification mid) {
290 init();
291 this.id = inHobsId;
292
293 //
294 // Init arch with module's arch
295 //
296 this.jArchCheckBox.setEnabledItems(wt.getModuleArch(mid));
297
298 //
299 // Get defined guids from dependent packages
300 //
301 Vector<PackageIdentification> vpid = wt.getPackageDependenciesOfModule(mid);
302 if (vpid.size() <= 0) {
303 Log
304 .wrn("Init Guid",
305 "This module hasn't defined any package dependency, so there is no guid value can be added for hob");
306 }
307 //
308 // Init guids drop down list
309 //
310 Tools
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);
315
316
317 if (this.id != null) {
318 String tmpName = id.getName();
319 if (isEmpty(tmpName)) {
320 tmpName = DataType.EMPTY_SELECT_ITEM;
321 }
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());
328 }
329 }
330
331 /**
332 * This is the override edit constructor
333 *
334 * @param inHobsIdentification
335 * @param iFrame
336 *
337 */
338 public HobsDlg(HobsIdentification inHobsIdentification, IFrame iFrame, ModuleIdentification mid) {
339 super(iFrame, true);
340 init(inHobsIdentification, mid);
341 }
342
343 /**
344 * Disable all components when the mode is view
345 *
346 * @param isView
347 * true - The view mode; false - The non-view mode
348 *
349 */
350 public void setViewMode(boolean isView) {
351 if (isView) {
352 this.iComboBoxGuidC_Name.setEnabled(!isView);
353 this.jComboBoxUsage.setEnabled(!isView);
354 this.jComboBoxHobType.setEnabled(!isView);
355 }
356 }
357
358 /**
359 * This method initializes jContentPane
360 *
361 * @return javax.swing.JPanel jContentPane
362 *
363 */
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));
371
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));
377
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));
383
384 jLabelHelpText = new JLabel();
385 jLabelHelpText.setBounds(new java.awt.Rectangle(12, 87, 155, 20));
386 jLabelHelpText.setText("Help Text");
387
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);
392
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));
399
400 jContentPane = new JPanel();
401 jContentPane.setLayout(null);
402 jContentPane.setPreferredSize(new java.awt.Dimension(485, 215));
403
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);
420 }
421 return jContentPane;
422 }
423
424 /**
425 * This method initializes Usage type and Hob type
426 *
427 */
428 private void initFrame() {
429 Tools.generateComboBoxByVector(jComboBoxUsage, ed.getVHobUsage());
430 Tools.generateComboBoxByVector(jComboBoxHobType, ed.getVHobType());
431 }
432
433 /*
434 * (non-Javadoc)
435 *
436 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
437 *
438 * Override actionPerformed to listen all actions
439 *
440 */
441 public void actionPerformed(ActionEvent arg0) {
442 if (arg0.getSource() == jButtonOk) {
443 if (checkAdd()) {
444 getCurrentHobs();
445 this.returnType = DataType.RETURN_TYPE_OK;
446 this.setVisible(false);
447 }
448 }
449
450 if (arg0.getSource() == jButtonCancel) {
451 this.returnType = DataType.RETURN_TYPE_CANCEL;
452 this.setVisible(false);
453 }
454 }
455
456 /**
457 * Data validation for all fields
458 *
459 * @retval true - All datas are valid
460 * @retval false - At least one data is invalid
461 *
462 */
463 public boolean checkAdd() {
464 //
465 // Check if all fields have correct data types
466 //
467
468 //
469 // Check Name
470 //
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");
475 return false;
476 }
477 }
478
479 //
480 // Check FeatureFlag
481 //
482 if (!isEmpty(this.jTextFieldFeatureFlag.getText())) {
483 if (!DataValidation.isFeatureFlag(this.jTextFieldFeatureFlag.getText())) {
484 Log.wrn("Update Hobs", "Incorrect data type for Feature Flag");
485 return false;
486 }
487 }
488
489 return true;
490 }
491
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();
496
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);
501 return id;
502 }
503
504 public HobsIdentification getId() {
505 return id;
506 }
507
508 public void setId(HobsIdentification id) {
509 this.id = id;
510 }
511 }