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