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