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