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