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