]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/module/ui/dialog/HobsDlg.java
3b76c3c3b948de1f7251d4636c4062027b8cd04b
[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.IDialog;
35 import org.tianocore.frameworkwizard.common.ui.IFrame;
36 import org.tianocore.frameworkwizard.common.ui.StarLabel;
37 import org.tianocore.frameworkwizard.module.Identifications.ModuleIdentification;
38 import org.tianocore.frameworkwizard.module.Identifications.Hobs.HobsIdentification;
39 import org.tianocore.frameworkwizard.packaging.PackageIdentification;
40 import org.tianocore.frameworkwizard.workspace.WorkspaceTools;
41
42 /**
43 * The class is used to create, update Hob of the MSA file
44 *
45 * It extends IDialog
46 *
47 */
48 public class HobsDlg extends IDialog {
49
50 // /
51 // / Define class Serial Version UID
52 // /
53 private static final long serialVersionUID = -553473437579358325L;
54
55 //
56 // Define class members
57 //
58 private JPanel jContentPane = null;
59
60 private JLabel jLabelC_Name = null;
61
62 private JComboBox jComboBoxGuidC_Name = null;
63
64 private JLabel jLabelUsage = null;
65
66 private JLabel jLabelHobType = null;
67
68 private JComboBox jComboBoxUsage = null;
69
70 private JComboBox jComboBoxHobType = null;
71
72 private StarLabel jStarLabel1 = null;
73
74 private StarLabel jStarLabel2 = null;
75
76 private StarLabel jStarLabel3 = null;
77
78 private JLabel jLabelArch = null;
79
80 private JScrollPane jScrollPane = null;
81
82 private JLabel jLabelFeatureFlag = null;
83
84 private JTextField jTextFieldFeatureFlag = null;
85
86 private JLabel jLabelHelpText = null;
87
88 private JTextArea jTextAreaHelpText = null;
89
90 private JScrollPane jScrollPaneHelpText = null;
91
92 private ArchCheckBox jArchCheckBox = null;
93
94 private JButton jButtonOk = null;
95
96 private JButton jButtonCancel = null;
97
98 //
99 // Not used by UI
100 //
101 private HobsIdentification id = null;
102
103 private EnumerationData ed = new EnumerationData();
104
105 private WorkspaceTools wt = new WorkspaceTools();
106
107 /**
108 * This method initializes jTextField
109 *
110 * @return javax.swing.JTextField jTextFieldC_Name
111 *
112 */
113 private JComboBox getJComboBoxGuidC_Name() {
114 if (jComboBoxGuidC_Name == null) {
115 jComboBoxGuidC_Name = new JComboBox();
116 jComboBoxGuidC_Name.setBounds(new java.awt.Rectangle(168, 12, 320, 20));
117 jComboBoxGuidC_Name.setPreferredSize(new java.awt.Dimension(320, 20));
118 jComboBoxGuidC_Name.setToolTipText("Select the GUID C Name of the Hob");
119 }
120 return jComboBoxGuidC_Name;
121 }
122
123 /**
124 * This method initializes jComboBoxHobType
125 *
126 * @return javax.swing.JComboBox jComboBoxHobType
127 *
128 */
129 private JComboBox getJComboBoxHobType() {
130 if (jComboBoxHobType == null) {
131 jComboBoxHobType = new JComboBox();
132 jComboBoxHobType.setBounds(new java.awt.Rectangle(168, 37, 320, 20));
133 jComboBoxHobType.setPreferredSize(new java.awt.Dimension(320, 20));
134 jComboBoxHobType
135 .setToolTipText("<html><table>"
136 + "<tr><td>PHIT</td><td>EFI_HOB_TYPE_HANDOFF</td></tr>"
137 + "<tr><td>MEMORY_ALLOCATION</td><td>EFI_HOB_TYPE_MEMORY_ALLOCATION and $BaseName</td></tr>"
138 + "<tr><td>RESOURCE_DESCRIPTOR</td><td>EFI_HOB_TYPE_RESOURCE_DESCRIPTOR</td></tr>"
139 + "<tr><td>GUID_EXTENTION</td><td>EFI_HOB_TYPE_GUID_EXTENSION and BaseName of GUID</td></tr>"
140 + "<tr><td>FIRMWARE_VOLUME</td><td>EFI_HOB_TYPE_FV</td></tr>"
141 + "<tr><td>CPU</td><td>EFI_HOB_TYPE_CPU</td></tr>"
142 + "<tr><td>POOL</td><td>EFI_HOB_TYPE_PEI_MEMORY_POOL</td></tr>"
143 + "<tr><td>CAPSULE_VOLUME</td><td>EFI_HOB_TYPE_CV</td></tr>"
144 + "</table></html>");
145 }
146 return jComboBoxHobType;
147 }
148
149 /**
150 * This method initializes jComboBoxUsage
151 *
152 * @return javax.swing.JComboBox jComboBoxUsage
153 *
154 */
155 private JComboBox getJComboBoxUsage() {
156 if (jComboBoxUsage == null) {
157 jComboBoxUsage = new JComboBox();
158 jComboBoxUsage.setBounds(new java.awt.Rectangle(168, 62, 320, 20));
159 jComboBoxUsage.setPreferredSize(new java.awt.Dimension(320, 20));
160 jComboBoxUsage
161 .setToolTipText("<html><table>"
162 + "<tr><td>ALWAYS_CONSUMED</td><td>HOB must be present in the system</td></tr>"
163 + "<tr><td>SOMETIMES_CONSUMED</td><td>HOB will be used if it's present</td></tr>"
164 + "<tr><td>ALWAYS_PRODUCED</td><td>HOB is always produced</td></tr>"
165 + "<tr><td>SOMETIMES_PRODUCED</td><td>HOB will sometimes be produced by the module</td></tr>"
166 + "</table></html>");
167 }
168 return jComboBoxUsage;
169 }
170
171 /**
172 * This method initializes jScrollPane
173 *
174 * @return javax.swing.JScrollPane
175 */
176 private JScrollPane getJScrollPane() {
177 if (jScrollPane == null) {
178 jScrollPane = new JScrollPane();
179 jScrollPane.setViewportView(getJContentPane());
180 }
181 return jScrollPane;
182 }
183
184 /**
185 * This method initializes jTextFieldFeatureFlag
186 *
187 * @return javax.swing.JTextField
188 */
189 private JTextField getJTextFieldFeatureFlag() {
190 if (jTextFieldFeatureFlag == null) {
191 jTextFieldFeatureFlag = new JTextField();
192 jTextFieldFeatureFlag.setBounds(new java.awt.Rectangle(168, 157, 320, 20));
193 jTextFieldFeatureFlag.setPreferredSize(new java.awt.Dimension(320, 20));
194 jTextFieldFeatureFlag.setToolTipText("Postfix expression that must evaluate to TRUE or FALSE");
195 jTextFieldFeatureFlag.setEnabled(false);
196 }
197 return jTextFieldFeatureFlag;
198 }
199
200 /**
201 * This method initializes jTextFieldHelpText
202 *
203 * @return javax.swing.JTextField
204 *
205 */
206 private JTextArea getJTextAreaHelpText() {
207 if (jTextAreaHelpText == null) {
208 jTextAreaHelpText = new JTextArea();
209 jTextAreaHelpText.setLineWrap(true);
210 jTextAreaHelpText.setWrapStyleWord(true);
211 }
212 return jTextAreaHelpText;
213 }
214
215 /**
216 * This method initializes jScrollPaneHelpText
217 *
218 * @return javax.swing.JScrollPane
219 */
220 private JScrollPane getJScrollPaneHelpText() {
221 if (jScrollPaneHelpText == null) {
222 jScrollPaneHelpText = new JScrollPane();
223 jScrollPaneHelpText.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
224 jScrollPaneHelpText.setSize(new java.awt.Dimension(320, 40));
225 jScrollPaneHelpText.setPreferredSize(new java.awt.Dimension(320, 40));
226 jScrollPaneHelpText.setLocation(new java.awt.Point(168, 87));
227 jScrollPaneHelpText.setViewportView(getJTextAreaHelpText());
228 }
229 return jScrollPaneHelpText;
230 }
231
232 /**
233 * This method initializes jButtonOk
234 *
235 * @return javax.swing.JButton
236 *
237 */
238 private JButton getJButtonOk() {
239 if (jButtonOk == null) {
240 jButtonOk = new JButton();
241 jButtonOk.setBounds(new java.awt.Rectangle(290, 187, 90, 20));
242 jButtonOk.setText("Ok");
243 jButtonOk.addActionListener(this);
244 }
245 return jButtonOk;
246 }
247
248 /**
249 * This method initializes jButtonCancel
250 *
251 * @return javax.swing.JButton
252 *
253 */
254 private JButton getJButtonCancel() {
255 if (jButtonCancel == null) {
256 jButtonCancel = new JButton();
257 jButtonCancel.setBounds(new java.awt.Rectangle(390, 187, 90, 20));
258 jButtonCancel.setText("Cancel");
259 jButtonCancel.addActionListener(this);
260 }
261 return jButtonCancel;
262 }
263
264 public static void main(String[] args) {
265
266 }
267
268 /**
269 * This method initializes this
270 *
271 */
272 private void init() {
273 this.setSize(505, 260);
274 this.setContentPane(getJScrollPane());
275 this.setTitle("Hobs");
276 initFrame();
277 this.setViewMode(false);
278 this.centerWindow();
279 }
280
281 /**
282 * This method initializes this Fill values to all fields if these values are
283 * not empty
284 *
285 * @param inHobsId
286 *
287 */
288 private void init(HobsIdentification inHobsId, ModuleIdentification mid) {
289 init();
290 this.id = inHobsId;
291
292 //
293 // Init arch with module's arch
294 //
295 this.jArchCheckBox.setEnabledItems(wt.getModuleArch(mid));
296
297 //
298 // Get defined guids from dependent packages
299 //
300 Vector<PackageIdentification> vpid = wt.getPackageDependenciesOfModule(mid);
301 if (vpid.size() <= 0) {
302 Log
303 .wrn("Init Guid",
304 "This module hasn't defined any package dependency, so there is no guid value can be added for hob");
305 }
306 //
307 // Init guids drop down list
308 //
309 Tools
310 .generateComboBoxByVector(jComboBoxGuidC_Name,
311 wt.getAllGuidDeclarationsFromPackages(vpid, EnumerationData.GUID_TYPE_HOB));
312
313
314 if (this.id != null) {
315 this.jComboBoxGuidC_Name.setSelectedItem(id.getName());
316 this.jComboBoxHobType.setSelectedItem(id.getType());
317 this.jComboBoxUsage.setSelectedItem(id.getUsage());
318 this.jTextAreaHelpText.setText(id.getHelp());
319 this.jTextFieldFeatureFlag.setText(id.getFeatureFlag());
320 this.jArchCheckBox.setSelectedItems(id.getSupArchList());
321 }
322 }
323
324 /**
325 * This is the override edit constructor
326 *
327 * @param inHobsIdentification
328 * @param iFrame
329 *
330 */
331 public HobsDlg(HobsIdentification inHobsIdentification, IFrame iFrame, ModuleIdentification mid) {
332 super(iFrame, true);
333 init(inHobsIdentification, mid);
334 }
335
336 /**
337 * Disable all components when the mode is view
338 *
339 * @param isView
340 * true - The view mode; false - The non-view mode
341 *
342 */
343 public void setViewMode(boolean isView) {
344 if (isView) {
345 this.jComboBoxGuidC_Name.setEnabled(!isView);
346 this.jComboBoxUsage.setEnabled(!isView);
347 this.jComboBoxHobType.setEnabled(!isView);
348 }
349 }
350
351 /**
352 * This method initializes jContentPane
353 *
354 * @return javax.swing.JPanel jContentPane
355 *
356 */
357 public JPanel getJContentPane() {
358 if (jContentPane == null) {
359 jStarLabel1 = new StarLabel();
360 jStarLabel1.setLocation(new java.awt.Point(2, 12));
361 jLabelC_Name = new JLabel();
362 jLabelC_Name.setText("Hob's Guid C Name");
363 jLabelC_Name.setBounds(new java.awt.Rectangle(12, 12, 155, 20));
364
365 jStarLabel2 = new StarLabel();
366 jStarLabel2.setLocation(new java.awt.Point(2, 37));
367 jLabelHobType = new JLabel();
368 jLabelHobType.setText("Hob Type");
369 jLabelHobType.setBounds(new java.awt.Rectangle(12, 37, 155, 20));
370
371 jStarLabel3 = new StarLabel();
372 jStarLabel3.setLocation(new java.awt.Point(2, 62));
373 jLabelUsage = new JLabel();
374 jLabelUsage.setText("Usage");
375 jLabelUsage.setBounds(new java.awt.Rectangle(12, 62, 155, 20));
376
377 jLabelHelpText = new JLabel();
378 jLabelHelpText.setBounds(new java.awt.Rectangle(12, 87, 155, 20));
379 jLabelHelpText.setText("Help Text");
380
381 jLabelFeatureFlag = new JLabel();
382 jLabelFeatureFlag.setBounds(new java.awt.Rectangle(12, 157, 155, 20));
383 jLabelFeatureFlag.setText("Feature Flag Expression");
384 jLabelFeatureFlag.setEnabled(false);
385
386 jLabelArch = new JLabel();
387 jLabelArch.setBounds(new java.awt.Rectangle(12, 132, 155, 20));
388 jLabelArch.setText("Supported Architectures");
389 jArchCheckBox = new ArchCheckBox();
390 jArchCheckBox.setBounds(new java.awt.Rectangle(168, 132, 320, 20));
391 jArchCheckBox.setPreferredSize(new java.awt.Dimension(320, 20));
392
393 jContentPane = new JPanel();
394 jContentPane.setLayout(null);
395 jContentPane.setPreferredSize(new java.awt.Dimension(485, 215));
396
397 jContentPane.add(jStarLabel1, null);
398 jContentPane.add(jLabelC_Name, null);
399 jContentPane.add(getJComboBoxGuidC_Name(), null);
400 jContentPane.add(jStarLabel2, null);
401 jContentPane.add(jLabelHobType, null);
402 jContentPane.add(getJComboBoxHobType(), null);
403 jContentPane.add(jStarLabel3, null);
404 jContentPane.add(jLabelUsage, null);
405 jContentPane.add(getJComboBoxUsage(), null);
406 jContentPane.add(jLabelHelpText, null);
407 jContentPane.add(getJScrollPaneHelpText(), null);
408 jContentPane.add(jLabelFeatureFlag, null);
409 jContentPane.add(getJTextFieldFeatureFlag(), null);
410 jContentPane.add(jLabelArch, null);
411 jContentPane.add(jArchCheckBox, null);
412 jContentPane.add(getJButtonOk(), null);
413 jContentPane.add(getJButtonCancel(), null);
414 }
415 return jContentPane;
416 }
417
418 /**
419 * This method initializes Usage type and Hob type
420 *
421 */
422 private void initFrame() {
423 Tools.generateComboBoxByVector(jComboBoxUsage, ed.getVHobUsage());
424 Tools.generateComboBoxByVector(jComboBoxHobType, ed.getVHobType());
425 }
426
427 /*
428 * (non-Javadoc)
429 *
430 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
431 *
432 * Override actionPerformed to listen all actions
433 *
434 */
435 public void actionPerformed(ActionEvent arg0) {
436 if (arg0.getSource() == jButtonOk) {
437 if (checkAdd()) {
438 getCurrentHobs();
439 this.returnType = DataType.RETURN_TYPE_OK;
440 this.setVisible(false);
441 }
442 }
443
444 if (arg0.getSource() == jButtonCancel) {
445 this.returnType = DataType.RETURN_TYPE_CANCEL;
446 this.setVisible(false);
447 }
448 }
449
450 /**
451 * Data validation for all fields
452 *
453 * @retval true - All datas are valid
454 * @retval false - At least one data is invalid
455 *
456 */
457 public boolean checkAdd() {
458 //
459 // Check if all fields have correct data types
460 //
461
462 //
463 // Check Name
464 //
465 if (this.jComboBoxGuidC_Name.getSelectedItem() == null) {
466 Log.wrn("Update Guids", "Please select one Hob Name");
467 return false;
468 }
469 //
470 // Check Name
471 //
472 if (isEmpty(this.jComboBoxGuidC_Name.getSelectedItem().toString())) {
473 Log.wrn("Update Hobs", "Hob Guid C Name must be entered!");
474 return false;
475 }
476
477 if (!isEmpty(this.jComboBoxGuidC_Name.getSelectedItem().toString())) {
478 if (!DataValidation.isC_NameType(this.jComboBoxGuidC_Name.getSelectedItem().toString())) {
479 Log.wrn("Update Hobs", "Incorrect data type for Hob Name");
480 return false;
481 }
482 }
483
484 //
485 // Check FeatureFlag
486 //
487 if (!isEmpty(this.jTextFieldFeatureFlag.getText())) {
488 if (!DataValidation.isFeatureFlag(this.jTextFieldFeatureFlag.getText())) {
489 Log.wrn("Update Hobs", "Incorrect data type for Feature Flag");
490 return false;
491 }
492 }
493
494 return true;
495 }
496
497 private HobsIdentification getCurrentHobs() {
498 String arg0 = this.jComboBoxGuidC_Name.getSelectedItem().toString();
499 String arg1 = this.jComboBoxHobType.getSelectedItem().toString();
500 String arg2 = this.jComboBoxUsage.getSelectedItem().toString();
501
502 String arg3 = this.jTextFieldFeatureFlag.getText();
503 Vector<String> arg4 = this.jArchCheckBox.getSelectedItemsVector();
504 String arg5 = this.jTextAreaHelpText.getText();
505 id = new HobsIdentification(arg0, arg1, arg2, arg3, arg4, arg5);
506 return id;
507 }
508
509 public HobsIdentification getId() {
510 return id;
511 }
512
513 public void setId(HobsIdentification id) {
514 this.id = id;
515 }
516 }