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