]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/module/ui/dialog/EventsDlg.java
624fae71df2eedf8fc2820d8930fd7f25128a5d3
[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, 157, 320, 20));
210 jTextFieldFeatureFlag.setPreferredSize(new java.awt.Dimension(320, 20));
211 jTextFieldFeatureFlag.setToolTipText("Postfix expression that must evaluate to TRUE or FALSE");
212 }
213 return jTextFieldFeatureFlag;
214 }
215
216 /**
217 * This method initializes jTextAreaHelpText
218 *
219 * @return javax.swing.JTextArea
220 *
221 */
222 private JTextArea getJTextAreaHelpText() {
223 if (jTextAreaHelpText == null) {
224 jTextAreaHelpText = new JTextArea();
225 jTextAreaHelpText.setLineWrap(true);
226 jTextAreaHelpText.setWrapStyleWord(true);
227 }
228 return jTextAreaHelpText;
229 }
230
231 /**
232 * This method initializes jScrollPaneHelpText
233 *
234 * @return javax.swing.JScrollPane
235 *
236 */
237 private JScrollPane getJScrollPaneHelpText() {
238 if (jScrollPaneHelpText == null) {
239 jScrollPaneHelpText = new JScrollPane();
240 jScrollPaneHelpText.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
241 jScrollPaneHelpText.setSize(new java.awt.Dimension(320, 40));
242 jScrollPaneHelpText.setPreferredSize(new java.awt.Dimension(320, 40));
243 jScrollPaneHelpText.setLocation(new java.awt.Point(168, 112));
244 jScrollPaneHelpText.setViewportView(getJTextAreaHelpText());
245 }
246 return jScrollPaneHelpText;
247 }
248
249 /**
250 * This method initializes jButtonOk
251 *
252 * @return javax.swing.JButton
253 *
254 */
255 private JButton getJButtonOk() {
256 if (jButtonOk == null) {
257 jButtonOk = new JButton();
258 jButtonOk.setBounds(new java.awt.Rectangle(290, 212, 90, 20));
259 jButtonOk.setText("Ok");
260 jButtonOk.addActionListener(this);
261 }
262 return jButtonOk;
263 }
264
265 /**
266 * This method initializes jButtonCancel
267 *
268 * @return javax.swing.JButton
269 *
270 */
271 private JButton getJButtonCancel() {
272 if (jButtonCancel == null) {
273 jButtonCancel = new JButton();
274 jButtonCancel.setBounds(new java.awt.Rectangle(390, 212, 90, 20));
275 jButtonCancel.setText("Cancel");
276 jButtonCancel.addActionListener(this);
277 }
278 return jButtonCancel;
279 }
280
281 public static void main(String[] args) {
282
283 }
284
285 /**
286 * This method initializes this
287 *
288 */
289 private void init() {
290 this.setSize(505, 280);
291 this.setContentPane(getJScrollPane());
292 this.setTitle("Events");
293 initFrame();
294 this.setViewMode(false);
295 this.centerWindow();
296 }
297
298 /**
299 * This method initializes this Fill values to all fields if these values are
300 * not empty
301 *
302 * @param inEventsId
303 *
304 */
305 private void init(EventsIdentification inEventsId) {
306 init();
307 this.id = inEventsId;
308
309 if (this.id != null) {
310 this.jComboBoxGuidC_Name.setSelectedItem(id.getName());
311 this.jComboBoxEventsType.setSelectedItem(id.getType());
312 this.jComboBoxUsage.setSelectedItem(id.getUsage());
313 this.jTextAreaHelpText.setText(id.getHelp());
314
315 jTextFieldFeatureFlag.setText(id.getFeatureFlag());
316 this.jArchCheckBox.setSelectedItems(id.getSupArchList());
317 this.jComboBoxEventGroup.setSelectedItem(id.getGroup());
318 }
319 }
320
321 /**
322 * This is the override edit constructor
323 *
324 * @param inEventsIdentification
325 * @param iFrame
326 *
327 */
328 public EventsDlg(EventsIdentification inEventsIdentification, IFrame iFrame) {
329 super(iFrame, true);
330 init(inEventsIdentification);
331 }
332
333 /**
334 * Disable all components when the mode is view
335 *
336 * @param isView
337 * true - The view mode; false - The non-view mode
338 *
339 */
340 public void setViewMode(boolean isView) {
341 if (isView) {
342 this.jComboBoxGuidC_Name.setEnabled(!isView);
343 this.jComboBoxUsage.setEnabled(!isView);
344 }
345 }
346
347 /**
348 * This method initializes jContentPane
349 *
350 * @return javax.swing.JPanel jContentPane
351 *
352 */
353 private JPanel getJContentPane() {
354 if (jContentPane == null) {
355 jStarLabel1 = new StarLabel();
356 jStarLabel1.setLocation(new java.awt.Point(2, 12));
357 jLabelEventType = new JLabel();
358 jLabelEventType.setText("Select Event Type");
359 jLabelEventType.setBounds(new java.awt.Rectangle(12, 12, 168, 20));
360
361 jStarLabel2 = new StarLabel();
362 jStarLabel2.setLocation(new java.awt.Point(2, 37));
363 jLabelC_Name = new JLabel();
364 jLabelC_Name.setText("Guid C Name");
365 jLabelC_Name.setBounds(new java.awt.Rectangle(12, 37, 168, 20));
366
367 jStarLabel3 = new StarLabel();
368 jStarLabel3.setLocation(new java.awt.Point(2, 62));
369 jLabelGroup = new JLabel();
370 jLabelGroup.setText("Event Group Type");
371 jLabelGroup.setBounds(new java.awt.Rectangle(12, 62, 168, 20));
372
373 jStarLabel4 = new StarLabel();
374 jStarLabel4.setLocation(new java.awt.Point(2, 87));
375 jLabelUsage = new JLabel();
376 jLabelUsage.setText("Usage");
377 jLabelUsage.setBounds(new java.awt.Rectangle(12, 87, 168, 20));
378
379 jLabelHelpText = new JLabel();
380 jLabelHelpText.setBounds(new java.awt.Rectangle(12, 112, 168, 20));
381 jLabelHelpText.setText("Help Text");
382
383 jLabelFeatureFlag = new JLabel();
384 jLabelFeatureFlag.setBounds(new java.awt.Rectangle(12, 157, 168, 20));
385 jLabelFeatureFlag.setText("Feature Flag Expression");
386
387 jLabelArch = new JLabel();
388 jLabelArch.setBounds(new java.awt.Rectangle(12, 182, 168, 20));
389 jLabelArch.setText("Supported Architectures");
390 jArchCheckBox = new ArchCheckBox();
391 jArchCheckBox.setBounds(new java.awt.Rectangle(168, 182, 320, 20));
392 jArchCheckBox.setPreferredSize(new java.awt.Dimension(320, 20));
393
394 jContentPane = new JPanel();
395 jContentPane.setLayout(null);
396 jContentPane.setPreferredSize(new java.awt.Dimension(485, 235));
397
398 jContentPane.add(jStarLabel1, null);
399 jContentPane.add(jLabelEventType, null);
400 jContentPane.add(getJComboBoxEventsType(), null);
401 jContentPane.add(jStarLabel2, null);
402 jContentPane.add(jLabelC_Name, null);
403 jContentPane.add(getJComboBoxGuidC_Name(), null);
404 jContentPane.add(jStarLabel3, null);
405 jContentPane.add(jLabelGroup, null);
406 jContentPane.add(getJComboBoxEventGroup(), null);
407 jContentPane.add(jStarLabel4, null);
408 jContentPane.add(jLabelUsage, null);
409 jContentPane.add(getJComboBoxUsage(), null);
410 jContentPane.add(jLabelHelpText, null);
411 jContentPane.add(getJScrollPaneHelpText(), null);
412 jContentPane.add(jLabelFeatureFlag, null);
413 jContentPane.add(getJTextFieldFeatureFlag(), null);
414 jContentPane.add(jLabelArch, null);
415 jContentPane.add(jArchCheckBox, null);
416 jContentPane.add(getJButtonOk(), null);
417 jContentPane.add(getJButtonCancel(), null);
418
419 }
420 return jContentPane;
421 }
422
423 /**
424 * This method initializes events groups and usage type
425 *
426 */
427 private void initFrame() {
428 Tools.generateComboBoxByVector(jComboBoxEventsType, ed.getVEventType());
429 Tools.generateComboBoxByVector(jComboBoxEventGroup, ed.getVEventGroup());
430 Tools.generateComboBoxByVector(jComboBoxUsage, ed.getVEventUsage());
431 Tools.generateComboBoxByVector(jComboBoxGuidC_Name, wt.getAllGuidDeclarationsFromWorkspace());
432 }
433
434 /*
435 * (non-Javadoc)
436 *
437 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
438 *
439 * Override actionPerformed to listen all actions
440 *
441 */
442 public void actionPerformed(ActionEvent arg0) {
443 if (arg0.getSource() == jButtonOk) {
444 if (checkAdd()) {
445 getCurrentEvents();
446 this.returnType = DataType.RETURN_TYPE_OK;
447 this.setVisible(false);
448 }
449 }
450
451 if (arg0.getSource() == jButtonCancel) {
452 this.returnType = DataType.RETURN_TYPE_CANCEL;
453 this.setVisible(false);
454 }
455 }
456
457 /**
458 * Data validation for all fields
459 *
460 * @retval true - All datas are valid
461 * @retval false - At least one data is invalid
462 *
463 */
464 public boolean checkAdd() {
465 //
466 // Check if all fields have correct data types
467 //
468
469 //
470 // Check Name
471 //
472 if (isEmpty(this.jComboBoxGuidC_Name.getSelectedItem().toString())) {
473 Log.wrn("Update Events", "Event Name couldn't be empty");
474 return false;
475 }
476
477 if (!isEmpty(this.jComboBoxGuidC_Name.getSelectedItem().toString())) {
478 if (!DataValidation.isC_NameType(this.jComboBoxGuidC_Name.getSelectedItem().toString())) {
479 Log.wrn("Update Events", "Incorrect data type for Event Name");
480 return false;
481 }
482 }
483
484 //
485 // Check FeatureFlag
486 //
487 if (!isEmpty(this.jTextFieldFeatureFlag.getText())) {
488 if (!DataValidation.isFeatureFlag(this.jTextFieldFeatureFlag.getText())) {
489 Log.wrn("Update Events", "Incorrect data type for Feature Flag");
490 return false;
491 }
492 }
493
494 return true;
495 }
496
497 private EventsIdentification getCurrentEvents() {
498 String arg0 = this.jComboBoxGuidC_Name.getSelectedItem().toString();
499 String arg1 = this.jComboBoxEventsType.getSelectedItem().toString();
500 String arg2 = this.jComboBoxUsage.getSelectedItem().toString();
501
502 String arg3 = this.jTextFieldFeatureFlag.getText();
503 Vector<String> arg4 = this.jArchCheckBox.getSelectedItemsVector();
504 String arg5 = this.jTextAreaHelpText.getText();
505 String arg6 = this.jComboBoxEventGroup.getSelectedItem().toString();
506 id = new EventsIdentification(arg0, arg1, arg2, arg3, arg4, arg5, arg6);
507 return id;
508 }
509
510 public EventsIdentification getId() {
511 return id;
512 }
513
514 public void setId(EventsIdentification id) {
515 this.id = id;
516 }
517 }