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