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