]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/module/ui/dialog/EventsDlg.java
Fixed spelling and grammar, also fixed the size of the pop up dialog boxes and 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 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.awt.event.ItemEvent;
19 import java.awt.event.ItemListener;
20 import java.util.Vector;
21
22 import javax.swing.JButton;
23 import javax.swing.JComboBox;
24 import javax.swing.JLabel;
25 import javax.swing.JPanel;
26 import javax.swing.JScrollPane;
27 import javax.swing.JTextField;
28
29 import org.tianocore.frameworkwizard.common.DataType;
30 import org.tianocore.frameworkwizard.common.DataValidation;
31 import org.tianocore.frameworkwizard.common.EnumerationData;
32 import org.tianocore.frameworkwizard.common.Log;
33 import org.tianocore.frameworkwizard.common.Tools;
34 import org.tianocore.frameworkwizard.common.ui.ArchCheckBox;
35 import org.tianocore.frameworkwizard.common.ui.IDialog;
36 import org.tianocore.frameworkwizard.common.ui.IFrame;
37 import org.tianocore.frameworkwizard.common.ui.StarLabel;
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 Event of MSA/MBD file
43 It extends IInternalFrame
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 JComboBox jComboBoxEventsType = null;
81
82 private JScrollPane jScrollPane = null;
83
84 private JLabel jLabelArch = null;
85
86 private JLabel jLabelHelpText = null;
87
88 private JTextField jTextFieldHelpText = null;
89
90 private JLabel jLabelFeatureFlag = null;
91
92 private JTextField jTextFieldFeatureFlag = null;
93
94 private ArchCheckBox jArchCheckBox = null;
95
96 private JButton jButtonOk = null;
97
98 private JButton jButtonCancel = null;
99
100 //
101 // Not used by UI
102 //
103 private EventsIdentification id = null;
104
105 private EnumerationData ed = new EnumerationData();
106
107 private WorkspaceTools wt = new WorkspaceTools();
108
109 /**
110 This method initializes jTextFieldC_Name
111
112 @return javax.swing.JTextField jTextFieldC_Name
113
114 **/
115 private JComboBox getJComboBoxGuidC_Name() {
116 if (jComboBoxGuidC_Name == null) {
117 jComboBoxGuidC_Name = new JComboBox();
118 jComboBoxGuidC_Name.setBounds(new java.awt.Rectangle(160, 35, 320, 20));
119 jComboBoxGuidC_Name.setPreferredSize(new java.awt.Dimension(320, 20));
120 jComboBoxGuidC_Name.setToolTipText("Select the GUID C Name of the Event");
121 }
122 return jComboBoxGuidC_Name;
123 }
124
125 /**
126 This method initializes jComboBoxUsage
127
128 @return javax.swing.JComboBox jComboBoxUsage
129
130 **/
131 private JComboBox getJComboBoxUsage() {
132 if (jComboBoxUsage == null) {
133 jComboBoxUsage = new JComboBox();
134 jComboBoxUsage.setBounds(new java.awt.Rectangle(160, 85, 320, 20));
135 jComboBoxUsage.setPreferredSize(new java.awt.Dimension(320, 20));
136 }
137 return jComboBoxUsage;
138 }
139
140 /**
141 This method initializes jComboBoxType
142
143 @return javax.swing.JComboBox jComboBoxType
144
145 **/
146 private JComboBox getJComboBoxEventsType() {
147 if (jComboBoxEventsType == null) {
148 jComboBoxEventsType = new JComboBox();
149 jComboBoxEventsType.setBounds(new java.awt.Rectangle(160, 10, 320, 20));
150 jComboBoxEventsType.setPreferredSize(new java.awt.Dimension(320, 20));
151 jComboBoxEventsType
152 .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>");
153 }
154 return jComboBoxEventsType;
155 }
156
157 /**
158 * This method initializes jComboBoxEventsType
159 *
160 * @return javax.swing.JComboBox
161 */
162 private JComboBox getJComboBoxEventGroup() {
163 if (jComboBoxEventGroup == null) {
164 jComboBoxEventGroup = new JComboBox();
165 jComboBoxEventGroup.setBounds(new java.awt.Rectangle(160, 60, 320, 20));
166 jComboBoxEventGroup.setPreferredSize(new java.awt.Dimension(320, 20));
167 jComboBoxEventGroup.setToolTipText("Select Type of Event, Guid or Timer.");
168
169 }
170 return jComboBoxEventGroup;
171 }
172
173 /**
174 This method initializes jScrollPane
175
176 @return javax.swing.JScrollPane
177 */
178 private JScrollPane getJScrollPane() {
179 if (jScrollPane == null) {
180 jScrollPane = new JScrollPane();
181 jScrollPane.setViewportView(getJContentPane());
182 }
183 return jScrollPane;
184 }
185
186 /**
187 * This method initializes jTextFieldFeatureFlag
188 *
189 * @return javax.swing.JTextField
190 */
191 private JTextField getJTextFieldFeatureFlag() {
192 if (jTextFieldFeatureFlag == null) {
193 jTextFieldFeatureFlag = new JTextField();
194 jTextFieldFeatureFlag.setBounds(new java.awt.Rectangle(160, 135, 320, 20));
195 jTextFieldFeatureFlag.setPreferredSize(new java.awt.Dimension(320, 20));
196 }
197 return jTextFieldFeatureFlag;
198 }
199
200 /**
201 This method initializes jTextFieldHelpText
202
203 @return javax.swing.JTextField
204
205 **/
206 private JTextField getJTextFieldHelpText() {
207 if (jTextFieldHelpText == null) {
208 jTextFieldHelpText = new JTextField();
209 jTextFieldHelpText.setBounds(new java.awt.Rectangle(160, 110, 320, 20));
210 jTextFieldHelpText.setPreferredSize(new java.awt.Dimension(320, 20));
211 }
212 return jTextFieldHelpText;
213 }
214
215 /**
216 This method initializes jButtonOk
217
218 @return javax.swing.JButton
219
220 **/
221 private JButton getJButtonOk() {
222 if (jButtonOk == null) {
223 jButtonOk = new JButton();
224 jButtonOk.setBounds(new java.awt.Rectangle(290, 190, 90, 20));
225 jButtonOk.setText("Ok");
226 jButtonOk.addActionListener(this);
227 }
228 return jButtonOk;
229 }
230
231 /**
232 This method initializes jButtonCancel
233
234 @return javax.swing.JButton
235
236 **/
237 private JButton getJButtonCancel() {
238 if (jButtonCancel == null) {
239 jButtonCancel = new JButton();
240 jButtonCancel.setBounds(new java.awt.Rectangle(390, 190, 90, 20));
241 jButtonCancel.setText("Cancel");
242 jButtonCancel.addActionListener(this);
243 }
244 return jButtonCancel;
245 }
246
247 public static void main(String[] args) {
248
249 }
250
251 /**
252 This method initializes this
253
254 **/
255 private void init() {
256 this.setSize(508, 265);
257 this.setContentPane(getJScrollPane());
258 this.setTitle("Events");
259 initFrame();
260 this.setViewMode(false);
261 this.centerWindow();
262 }
263
264 /**
265 This method initializes this
266 Fill values to all fields if these values are not empty
267
268 @param inEventsId
269
270 **/
271 private void init(EventsIdentification inEventsId) {
272 init();
273 this.id = inEventsId;
274
275 if (this.id != null) {
276 this.jComboBoxGuidC_Name.setSelectedItem(id.getName());
277 this.jComboBoxEventsType.setSelectedItem(id.getType());
278 this.jComboBoxUsage.setSelectedItem(id.getUsage());
279 this.jTextFieldHelpText.setText(id.getHelp());
280
281 jTextFieldFeatureFlag.setText(id.getFeatureFlag());
282 this.jArchCheckBox.setSelectedItems(id.getSupArchList());
283 this.jComboBoxEventGroup.setSelectedItem(id.getGroup());
284 }
285 }
286
287 /**
288 This is the override edit constructor
289
290 @param inEventsIdentification
291 @param iFrame
292
293 **/
294 public EventsDlg(EventsIdentification inEventsIdentification, IFrame iFrame) {
295 super(iFrame, true);
296 init(inEventsIdentification);
297 }
298
299 /**
300 Disable all components when the mode is view
301
302 @param isView true - The view mode; false - The non-view mode
303
304 **/
305 public void setViewMode(boolean isView) {
306 if (isView) {
307 this.jComboBoxGuidC_Name.setEnabled(!isView);
308 this.jComboBoxUsage.setEnabled(!isView);
309 }
310 }
311
312 /**
313 This method initializes jContentPane
314
315 @return javax.swing.JPanel jContentPane
316
317 **/
318 private JPanel getJContentPane() {
319 if (jContentPane == null) {
320 jArchCheckBox = new ArchCheckBox();
321 jArchCheckBox.setBounds(new java.awt.Rectangle(160, 160, 320, 20));
322 jArchCheckBox.setPreferredSize(new java.awt.Dimension(320, 20));
323 jLabelFeatureFlag = new JLabel();
324 jLabelFeatureFlag.setBounds(new java.awt.Rectangle(15, 135, 140, 20));
325 jLabelFeatureFlag.setText("Feature Flag");
326 jLabelArch = new JLabel();
327 jLabelArch.setBounds(new java.awt.Rectangle(15, 160, 140, 20));
328 jLabelArch.setText("Arch");
329 jLabelUsage = new JLabel();
330 jLabelUsage.setText("Usage");
331 jLabelUsage.setBounds(new java.awt.Rectangle(15, 85, 140, 20));
332 jLabelC_Name = new JLabel();
333 jLabelC_Name.setText("Guid C Name");
334 jLabelC_Name.setBounds(new java.awt.Rectangle(15, 35, 140, 20));
335 jLabelGroup = new JLabel();
336 jLabelGroup.setText("Event Type");
337 jLabelGroup.setBounds(new java.awt.Rectangle(15, 60, 140, 20));
338 jLabelEventType = new JLabel();
339 jLabelEventType.setText("Type");
340 jLabelEventType.setBounds(new java.awt.Rectangle(15, 10, 140, 20));
341 jLabelHelpText = new JLabel();
342 jLabelHelpText.setBounds(new java.awt.Rectangle(14, 110, 140, 20));
343 jLabelHelpText.setText("Help Text");
344
345 jContentPane = new JPanel();
346 jContentPane.setLayout(null);
347 jContentPane.setPreferredSize(new java.awt.Dimension(490, 220));
348
349 jContentPane.add(jLabelEventType, null);
350 jContentPane.add(jLabelGroup, null);
351 jContentPane.add(jLabelC_Name, null);
352 jContentPane.add(getJComboBoxGuidC_Name(), null);
353 jContentPane.add(jLabelUsage, null);
354 jContentPane.add(getJComboBoxUsage(), null);
355 jStarLabel1 = new StarLabel();
356 jStarLabel1.setBounds(new java.awt.Rectangle(0, 10, 10, 20));
357 jStarLabel2 = new StarLabel();
358 jStarLabel2.setBounds(new java.awt.Rectangle(0, 35, 10, 20));
359 jStarLabel3 = new StarLabel();
360 jStarLabel3.setBounds(new java.awt.Rectangle(0, 60, 10, 20));
361
362 jContentPane.add(jStarLabel1, null);
363 jContentPane.add(jStarLabel2, null);
364 jContentPane.add(jStarLabel3, null);
365 jContentPane.add(getJComboBoxEventsType(), null);
366
367 jContentPane.add(jLabelArch, null);
368 jContentPane.add(jLabelFeatureFlag, null);
369 jContentPane.add(getJTextFieldFeatureFlag(), null);
370 jContentPane.add(jLabelHelpText, null);
371 jContentPane.add(getJTextFieldHelpText(), null);
372 jContentPane.add(jArchCheckBox, null);
373 jContentPane.add(getJButtonOk(), null);
374 jContentPane.add(getJButtonCancel(), null);
375 jContentPane.add(getJComboBoxEventGroup(), null);
376 }
377 return jContentPane;
378 }
379
380 /**
381 This method initializes events groups and usage type
382
383 **/
384 private void initFrame() {
385 Tools.generateComboBoxByVector(jComboBoxEventsType, ed.getVEventType());
386 Tools.generateComboBoxByVector(jComboBoxEventGroup, ed.getVEventGroup());
387 Tools.generateComboBoxByVector(jComboBoxUsage, ed.getVEventUsage());
388 Tools.generateComboBoxByVector(jComboBoxGuidC_Name, wt.getAllGuidDeclarationsFromWorkspace());
389 }
390
391 /* (non-Javadoc)
392 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
393 *
394 * Override actionPerformed to listen all actions
395 *
396 */
397 public void actionPerformed(ActionEvent arg0) {
398 if (arg0.getSource() == jButtonOk) {
399 if (checkAdd()) {
400 getCurrentEvents();
401 this.returnType = DataType.RETURN_TYPE_OK;
402 this.setVisible(false);
403 }
404 }
405
406 if (arg0.getSource() == jButtonCancel) {
407 this.returnType = DataType.RETURN_TYPE_CANCEL;
408 this.setVisible(false);
409 }
410 }
411
412 /**
413 Data validation for all fields
414
415 @retval true - All datas are valid
416 @retval false - At least one data is invalid
417
418 **/
419 public boolean checkAdd() {
420 //
421 // Check if all fields have correct data types
422 //
423
424 //
425 // Check Name
426 //
427 if (isEmpty(this.jComboBoxGuidC_Name.getSelectedItem().toString())) {
428 Log.wrn("Update Events", "Event Name couldn't be empty");
429 return false;
430 }
431
432 if (!isEmpty(this.jComboBoxGuidC_Name.getSelectedItem().toString())) {
433 if (!DataValidation.isC_NameType(this.jComboBoxGuidC_Name.getSelectedItem().toString())) {
434 Log.wrn("Update Events", "Incorrect data type for Event Name");
435 return false;
436 }
437 }
438
439 //
440 // Check FeatureFlag
441 //
442 if (!isEmpty(this.jTextFieldFeatureFlag.getText())) {
443 if (!DataValidation.isFeatureFlag(this.jTextFieldFeatureFlag.getText())) {
444 Log.wrn("Update Events", "Incorrect data type for Feature Flag");
445 return false;
446 }
447 }
448
449 return true;
450 }
451
452 private EventsIdentification getCurrentEvents() {
453 String arg0 = this.jComboBoxGuidC_Name.getSelectedItem().toString();
454 String arg1 = this.jComboBoxEventsType.getSelectedItem().toString();
455 String arg2 = this.jComboBoxUsage.getSelectedItem().toString();
456
457 String arg3 = this.jTextFieldFeatureFlag.getText();
458 Vector<String> arg4 = this.jArchCheckBox.getSelectedItemsVector();
459 String arg5 = this.jTextFieldHelpText.getText();
460 String arg6 = this.jComboBoxEventGroup.getSelectedItem().toString();
461 id = new EventsIdentification(arg0, arg1, arg2, arg3, arg4, arg5, arg6);
462 return id;
463 }
464
465 public EventsIdentification getId() {
466 return id;
467 }
468
469 public void setId(EventsIdentification id) {
470 this.id = id;
471 }
472 }