]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/module/ui/dialog/EventsDlg.java
552a77dd463232aaf81f1ed7fe3b3e147023ff0b
[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 if (this.id != null) {
335 this.iComboBoxGuidC_Name.setSelectedItem(id.getName());
336 this.jComboBoxEventsType.setSelectedItem(id.getType());
337 this.jComboBoxUsage.setSelectedItem(id.getUsage());
338 this.jTextAreaHelpText.setText(id.getHelp());
339
340 jTextFieldFeatureFlag.setText(id.getFeatureFlag());
341 this.jArchCheckBox.setSelectedItems(id.getSupArchList());
342 this.jComboBoxEventGroup.setSelectedItem(id.getGroup());
343 }
344 }
345
346 /**
347 * This is the override edit constructor
348 *
349 * @param inEventsIdentification
350 * @param iFrame
351 *
352 */
353 public EventsDlg(EventsIdentification inEventsIdentification, IFrame iFrame, ModuleIdentification mid) {
354 super(iFrame, true);
355 init(inEventsIdentification, mid);
356 }
357
358 /**
359 * Disable all components when the mode is view
360 *
361 * @param isView
362 * true - The view mode; false - The non-view mode
363 *
364 */
365 public void setViewMode(boolean isView) {
366 if (isView) {
367 this.iComboBoxGuidC_Name.setEnabled(!isView);
368 this.jComboBoxUsage.setEnabled(!isView);
369 }
370 }
371
372 /**
373 * This method initializes jContentPane
374 *
375 * @return javax.swing.JPanel jContentPane
376 *
377 */
378 private JPanel getJContentPane() {
379 if (jContentPane == null) {
380 jStarLabel1 = new StarLabel();
381 jStarLabel1.setLocation(new java.awt.Point(2, 12));
382 jLabelEventType = new JLabel();
383 jLabelEventType.setText("Select Event Type");
384 jLabelEventType.setBounds(new java.awt.Rectangle(12, 12, 168, 20));
385
386 jStarLabel2 = new StarLabel();
387 jStarLabel2.setLocation(new java.awt.Point(2, 37));
388 jLabelC_Name = new JLabel();
389 jLabelC_Name.setText("Guid C Name");
390 jLabelC_Name.setBounds(new java.awt.Rectangle(12, 37, 168, 20));
391
392 jStarLabel3 = new StarLabel();
393 jStarLabel3.setLocation(new java.awt.Point(2, 62));
394 jLabelGroup = new JLabel();
395 jLabelGroup.setText("Event Group Type");
396 jLabelGroup.setBounds(new java.awt.Rectangle(12, 62, 168, 20));
397
398 jStarLabel4 = new StarLabel();
399 jStarLabel4.setLocation(new java.awt.Point(2, 87));
400 jLabelUsage = new JLabel();
401 jLabelUsage.setText("Usage");
402 jLabelUsage.setBounds(new java.awt.Rectangle(12, 87, 168, 20));
403
404 jLabelHelpText = new JLabel();
405 jLabelHelpText.setBounds(new java.awt.Rectangle(12, 112, 168, 20));
406 jLabelHelpText.setText("Help Text");
407
408 jLabelFeatureFlag = new JLabel();
409 jLabelFeatureFlag.setBounds(new java.awt.Rectangle(12, 182, 168, 20));
410 jLabelFeatureFlag.setText("Feature Flag Expression");
411 jLabelFeatureFlag.setEnabled(false);
412
413 jLabelArch = new JLabel();
414 jLabelArch.setBounds(new java.awt.Rectangle(12, 157, 168, 20));
415 jLabelArch.setText("Supported Architectures");
416 jArchCheckBox = new ArchCheckBox();
417 jArchCheckBox.setBounds(new java.awt.Rectangle(168, 157, 320, 20));
418 jArchCheckBox.setPreferredSize(new java.awt.Dimension(320, 20));
419
420 jContentPane = new JPanel();
421 jContentPane.setLayout(null);
422 jContentPane.setPreferredSize(new java.awt.Dimension(485, 235));
423
424 jContentPane.add(jStarLabel1, null);
425 jContentPane.add(jLabelEventType, null);
426 jContentPane.add(getJComboBoxEventsType(), null);
427 jContentPane.add(jStarLabel2, null);
428 jContentPane.add(jLabelC_Name, null);
429 jContentPane.add(getIComboBoxGuidC_Name(), null);
430 jContentPane.add(jStarLabel3, null);
431 jContentPane.add(jLabelGroup, null);
432 jContentPane.add(getJComboBoxEventGroup(), null);
433 jContentPane.add(jStarLabel4, null);
434 jContentPane.add(jLabelUsage, null);
435 jContentPane.add(getJComboBoxUsage(), null);
436 jContentPane.add(jLabelHelpText, null);
437 jContentPane.add(getJScrollPaneHelpText(), null);
438 jContentPane.add(jLabelFeatureFlag, null);
439 jContentPane.add(getJTextFieldFeatureFlag(), null);
440 jContentPane.add(jLabelArch, null);
441 jContentPane.add(jArchCheckBox, null);
442 jContentPane.add(getJButtonOk(), null);
443 jContentPane.add(getJButtonCancel(), null);
444
445 }
446 return jContentPane;
447 }
448
449 /**
450 * This method initializes events groups and usage type
451 *
452 */
453 private void initFrame() {
454 Tools.generateComboBoxByVector(jComboBoxEventsType, ed.getVEventType());
455 Tools.generateComboBoxByVector(jComboBoxEventGroup, ed.getVEventGroup());
456 Tools.generateComboBoxByVector(jComboBoxUsage, ed.getVEventUsage());
457 }
458
459 /*
460 * (non-Javadoc)
461 *
462 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
463 *
464 * Override actionPerformed to listen all actions
465 *
466 */
467 public void actionPerformed(ActionEvent arg0) {
468 if (arg0.getSource() == jButtonOk) {
469 if (checkAdd()) {
470 getCurrentEvents();
471 this.returnType = DataType.RETURN_TYPE_OK;
472 this.setVisible(false);
473 }
474 }
475
476 if (arg0.getSource() == jButtonCancel) {
477 this.returnType = DataType.RETURN_TYPE_CANCEL;
478 this.setVisible(false);
479 }
480 }
481
482 /**
483 * Data validation for all fields
484 *
485 * @retval true - All datas are valid
486 * @retval false - At least one data is invalid
487 *
488 */
489 public boolean checkAdd() {
490 //
491 // Check if all fields have correct data types
492 //
493
494 //
495 // Check Name
496 //
497 if (this.iComboBoxGuidC_Name.getSelectedItem() == null) {
498 Log.wrn("Update Guids", "Please select one Event Name");
499 return false;
500 }
501
502 //
503 // Check Name
504 //
505 if (isEmpty(this.iComboBoxGuidC_Name.getSelectedItem().toString())) {
506 Log.wrn("Update Events", "Event Name couldn't be empty");
507 return false;
508 }
509
510 if (!isEmpty(this.iComboBoxGuidC_Name.getSelectedItem().toString())) {
511 if (!DataValidation.isC_NameType(this.iComboBoxGuidC_Name.getSelectedItem().toString())) {
512 Log.wrn("Update Events", "Incorrect data type for Event Name");
513 return false;
514 }
515 }
516
517 //
518 // Check FeatureFlag
519 //
520 if (!isEmpty(this.jTextFieldFeatureFlag.getText())) {
521 if (!DataValidation.isFeatureFlag(this.jTextFieldFeatureFlag.getText())) {
522 Log.wrn("Update Events", "Incorrect data type for Feature Flag");
523 return false;
524 }
525 }
526
527 return true;
528 }
529
530 private EventsIdentification getCurrentEvents() {
531 String arg0 = this.iComboBoxGuidC_Name.getSelectedItem().toString();
532 String arg1 = this.jComboBoxEventsType.getSelectedItem().toString();
533 String arg2 = this.jComboBoxUsage.getSelectedItem().toString();
534
535 String arg3 = this.jTextFieldFeatureFlag.getText();
536 Vector<String> arg4 = this.jArchCheckBox.getSelectedItemsVector();
537 String arg5 = this.jTextAreaHelpText.getText();
538 String arg6 = this.jComboBoxEventGroup.getSelectedItem().toString();
539 id = new EventsIdentification(arg0, arg1, arg2, arg3, arg4, arg5, arg6);
540 return id;
541 }
542
543 public EventsIdentification getId() {
544 return id;
545 }
546
547 public void setId(EventsIdentification id) {
548 this.id = id;
549 }
550 }