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