]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/module/ui/dialog/HobsDlg.java
- Fixed PVCS tracker 484 by merging the GenDll and GenEfi macro in BuildMacro.xml...
[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
314
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());
322 }
323 }
324
325 /**
326 * This is the override edit constructor
327 *
328 * @param inHobsIdentification
329 * @param iFrame
330 *
331 */
332 public HobsDlg(HobsIdentification inHobsIdentification, IFrame iFrame, ModuleIdentification mid) {
333 super(iFrame, true);
334 init(inHobsIdentification, mid);
335 }
336
337 /**
338 * Disable all components when the mode is view
339 *
340 * @param isView
341 * true - The view mode; false - The non-view mode
342 *
343 */
344 public void setViewMode(boolean isView) {
345 if (isView) {
346 this.iComboBoxGuidC_Name.setEnabled(!isView);
347 this.jComboBoxUsage.setEnabled(!isView);
348 this.jComboBoxHobType.setEnabled(!isView);
349 }
350 }
351
352 /**
353 * This method initializes jContentPane
354 *
355 * @return javax.swing.JPanel jContentPane
356 *
357 */
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));
365
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));
371
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));
377
378 jLabelHelpText = new JLabel();
379 jLabelHelpText.setBounds(new java.awt.Rectangle(12, 87, 155, 20));
380 jLabelHelpText.setText("Help Text");
381
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);
386
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));
393
394 jContentPane = new JPanel();
395 jContentPane.setLayout(null);
396 jContentPane.setPreferredSize(new java.awt.Dimension(485, 215));
397
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);
415 }
416 return jContentPane;
417 }
418
419 /**
420 * This method initializes Usage type and Hob type
421 *
422 */
423 private void initFrame() {
424 Tools.generateComboBoxByVector(jComboBoxUsage, ed.getVHobUsage());
425 Tools.generateComboBoxByVector(jComboBoxHobType, ed.getVHobType());
426 }
427
428 /*
429 * (non-Javadoc)
430 *
431 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
432 *
433 * Override actionPerformed to listen all actions
434 *
435 */
436 public void actionPerformed(ActionEvent arg0) {
437 if (arg0.getSource() == jButtonOk) {
438 if (checkAdd()) {
439 getCurrentHobs();
440 this.returnType = DataType.RETURN_TYPE_OK;
441 this.setVisible(false);
442 }
443 }
444
445 if (arg0.getSource() == jButtonCancel) {
446 this.returnType = DataType.RETURN_TYPE_CANCEL;
447 this.setVisible(false);
448 }
449 }
450
451 /**
452 * Data validation for all fields
453 *
454 * @retval true - All datas are valid
455 * @retval false - At least one data is invalid
456 *
457 */
458 public boolean checkAdd() {
459 //
460 // Check if all fields have correct data types
461 //
462
463 //
464 // Check Name
465 //
466 if (this.iComboBoxGuidC_Name.getSelectedItem() == null) {
467 Log.wrn("Update Guids", "Please select one Hob Name");
468 return false;
469 }
470 //
471 // Check Name
472 //
473 if (isEmpty(this.iComboBoxGuidC_Name.getSelectedItem().toString())) {
474 Log.wrn("Update Hobs", "Hob Guid C Name must be entered!");
475 return false;
476 }
477
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");
481 return false;
482 }
483 }
484
485 //
486 // Check FeatureFlag
487 //
488 if (!isEmpty(this.jTextFieldFeatureFlag.getText())) {
489 if (!DataValidation.isFeatureFlag(this.jTextFieldFeatureFlag.getText())) {
490 Log.wrn("Update Hobs", "Incorrect data type for Feature Flag");
491 return false;
492 }
493 }
494
495 return true;
496 }
497
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();
502
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);
507 return id;
508 }
509
510 public HobsIdentification getId() {
511 return id;
512 }
513
514 public void setId(HobsIdentification id) {
515 this.id = id;
516 }
517 }