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