]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/module/ui/dialog/EventsDlg.java
3bb8b3b717c9943c474923bbef1f90ded367fa67
[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 Create event if the Module has an event that<br> is waiting to be signaled. Select Signal if the Module will signal all events in an event group. Signal Event The 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
166 }
167 return jComboBoxEventGroup;
168 }
169
170 /**
171 This method initializes jScrollPane
172
173 @return javax.swing.JScrollPane
174 */
175 private JScrollPane getJScrollPane() {
176 if (jScrollPane == null) {
177 jScrollPane = new JScrollPane();
178 jScrollPane.setViewportView(getJContentPane());
179 }
180 return jScrollPane;
181 }
182
183 /**
184 * This method initializes jTextFieldFeatureFlag
185 *
186 * @return javax.swing.JTextField
187 */
188 private JTextField getJTextFieldFeatureFlag() {
189 if (jTextFieldFeatureFlag == null) {
190 jTextFieldFeatureFlag = new JTextField();
191 jTextFieldFeatureFlag.setBounds(new java.awt.Rectangle(160, 135, 320, 20));
192 jTextFieldFeatureFlag.setPreferredSize(new java.awt.Dimension(320, 20));
193 }
194 return jTextFieldFeatureFlag;
195 }
196
197 /**
198 This method initializes jTextFieldHelpText
199
200 @return javax.swing.JTextField
201
202 **/
203 private JTextField getJTextFieldHelpText() {
204 if (jTextFieldHelpText == null) {
205 jTextFieldHelpText = new JTextField();
206 jTextFieldHelpText.setBounds(new java.awt.Rectangle(160, 110, 320, 20));
207 jTextFieldHelpText.setPreferredSize(new java.awt.Dimension(320, 20));
208 }
209 return jTextFieldHelpText;
210 }
211
212 /**
213 This method initializes jButtonOk
214
215 @return javax.swing.JButton
216
217 **/
218 private JButton getJButtonOk() {
219 if (jButtonOk == null) {
220 jButtonOk = new JButton();
221 jButtonOk.setBounds(new java.awt.Rectangle(290, 190, 90, 20));
222 jButtonOk.setText("Ok");
223 jButtonOk.addActionListener(this);
224 }
225 return jButtonOk;
226 }
227
228 /**
229 This method initializes jButtonCancel
230
231 @return javax.swing.JButton
232
233 **/
234 private JButton getJButtonCancel() {
235 if (jButtonCancel == null) {
236 jButtonCancel = new JButton();
237 jButtonCancel.setBounds(new java.awt.Rectangle(390, 190, 90, 20));
238 jButtonCancel.setText("Cancel");
239 jButtonCancel.addActionListener(this);
240 }
241 return jButtonCancel;
242 }
243
244 public static void main(String[] args) {
245
246 }
247
248 /**
249 This method initializes this
250
251 **/
252 private void init() {
253 this.setSize(500, 255);
254 this.setContentPane(getJScrollPane());
255 this.setTitle("Events");
256 initFrame();
257 this.setViewMode(false);
258 this.centerWindow();
259 }
260
261 /**
262 This method initializes this
263 Fill values to all fields if these values are not empty
264
265 @param inEventsId
266
267 **/
268 private void init(EventsIdentification inEventsId) {
269 init();
270 this.id = inEventsId;
271
272 if (this.id != null) {
273 this.jComboBoxGuidC_Name.setSelectedItem(id.getName());
274 this.jComboBoxEventsType.setSelectedItem(id.getType());
275 this.jComboBoxUsage.setSelectedItem(id.getUsage());
276 this.jTextFieldHelpText.setText(id.getHelp());
277
278 jTextFieldFeatureFlag.setText(id.getFeatureFlag());
279 this.jArchCheckBox.setSelectedItems(id.getSupArchList());
280 this.jComboBoxEventGroup.setSelectedItem(id.getGroup());
281 }
282 }
283
284 /**
285 This is the override edit constructor
286
287 @param inEventsIdentification
288 @param iFrame
289
290 **/
291 public EventsDlg(EventsIdentification inEventsIdentification, IFrame iFrame) {
292 super(iFrame, true);
293 init(inEventsIdentification);
294 }
295
296 /**
297 Disable all components when the mode is view
298
299 @param isView true - The view mode; false - The non-view mode
300
301 **/
302 public void setViewMode(boolean isView) {
303 if (isView) {
304 this.jComboBoxGuidC_Name.setEnabled(!isView);
305 this.jComboBoxUsage.setEnabled(!isView);
306 }
307 }
308
309 /**
310 This method initializes jContentPane
311
312 @return javax.swing.JPanel jContentPane
313
314 **/
315 private JPanel getJContentPane() {
316 if (jContentPane == null) {
317 jArchCheckBox = new ArchCheckBox();
318 jArchCheckBox.setBounds(new java.awt.Rectangle(160, 135, 320, 20));
319 jArchCheckBox.setPreferredSize(new java.awt.Dimension(320, 20));
320 jLabelFeatureFlag = new JLabel();
321 jLabelFeatureFlag.setBounds(new java.awt.Rectangle(15, 135, 140, 20));
322 jLabelFeatureFlag.setText("Feature Flag");
323 jLabelArch = new JLabel();
324 jLabelArch.setBounds(new java.awt.Rectangle(15, 160, 140, 20));
325 jLabelArch.setText("Arch");
326 jLabelUsage = new JLabel();
327 jLabelUsage.setText("Usage");
328 jLabelUsage.setBounds(new java.awt.Rectangle(15, 85, 140, 20));
329 jLabelC_Name = new JLabel();
330 jLabelC_Name.setText("Guid C_Name");
331 jLabelC_Name.setBounds(new java.awt.Rectangle(15, 35, 140, 20));
332 jLabelGroup = new JLabel();
333 jLabelGroup.setText("Even Type");
334 jLabelGroup.setBounds(new java.awt.Rectangle(15, 60, 140, 20));
335 jLabelEventType = new JLabel();
336 jLabelEventType.setText("Type");
337 jLabelEventType.setBounds(new java.awt.Rectangle(15, 10, 140, 20));
338 jLabelHelpText = new JLabel();
339 jLabelHelpText.setBounds(new java.awt.Rectangle(14, 110, 140, 20));
340 jLabelHelpText.setText("Help Text");
341
342 jContentPane = new JPanel();
343 jContentPane.setLayout(null);
344 jContentPane.setPreferredSize(new java.awt.Dimension(490, 220));
345
346 jContentPane.add(jLabelEventType, null);
347 jContentPane.add(jLabelGroup, null);
348 jContentPane.add(jLabelC_Name, null);
349 jContentPane.add(getJComboBoxGuidC_Name(), null);
350 jContentPane.add(jLabelUsage, null);
351 jContentPane.add(getJComboBoxUsage(), null);
352 jStarLabel1 = new StarLabel();
353 jStarLabel1.setBounds(new java.awt.Rectangle(0, 10, 10, 20));
354 jStarLabel2 = new StarLabel();
355 jStarLabel2.setBounds(new java.awt.Rectangle(0, 35, 10, 20));
356 jStarLabel3 = new StarLabel();
357 jStarLabel3.setBounds(new java.awt.Rectangle(0, 60, 10, 20));
358
359 jContentPane.add(jStarLabel1, null);
360 jContentPane.add(jStarLabel2, null);
361 jContentPane.add(jStarLabel3, null);
362 jContentPane.add(getJComboBoxEventsType(), null);
363
364 jContentPane.add(jLabelArch, null);
365 jContentPane.add(jLabelFeatureFlag, null);
366 jContentPane.add(getJTextFieldFeatureFlag(), null);
367 jContentPane.add(jLabelHelpText, null);
368 jContentPane.add(getJTextFieldHelpText(), null);
369 jContentPane.add(jArchCheckBox, null);
370 jContentPane.add(getJButtonOk(), null);
371 jContentPane.add(getJButtonCancel(), null);
372 jContentPane.add(getJComboBoxEventGroup(), null);
373 }
374 return jContentPane;
375 }
376
377 /**
378 This method initializes events groups and usage type
379
380 **/
381 private void initFrame() {
382 Tools.generateComboBoxByVector(jComboBoxEventsType, ed.getVEventType());
383 Tools.generateComboBoxByVector(jComboBoxEventGroup, ed.getVEventGroup());
384 Tools.generateComboBoxByVector(jComboBoxUsage, ed.getVEventUsage());
385 Tools.generateComboBoxByVector(jComboBoxGuidC_Name, wt.getAllGuidDeclarationsFromWorkspace());
386 }
387
388 /* (non-Javadoc)
389 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
390 *
391 * Override actionPerformed to listen all actions
392 *
393 */
394 public void actionPerformed(ActionEvent arg0) {
395 if (arg0.getSource() == jButtonOk) {
396 if (checkAdd()) {
397 getCurrentEvents();
398 this.returnType = DataType.RETURN_TYPE_OK;
399 this.setVisible(false);
400 }
401 }
402
403 if (arg0.getSource() == jButtonCancel) {
404 this.returnType = DataType.RETURN_TYPE_CANCEL;
405 this.setVisible(false);
406 }
407 }
408
409 /**
410 Data validation for all fields
411
412 @retval true - All datas are valid
413 @retval false - At least one data is invalid
414
415 **/
416 public boolean checkAdd() {
417 //
418 // Check if all fields have correct data types
419 //
420
421 //
422 // Check Name
423 //
424 if (isEmpty(this.jComboBoxGuidC_Name.getSelectedItem().toString())) {
425 Log.wrn("Update Events", "Event Name couldn't be empty");
426 return false;
427 }
428
429 if (!isEmpty(this.jComboBoxGuidC_Name.getSelectedItem().toString())) {
430 if (!DataValidation.isC_NameType(this.jComboBoxGuidC_Name.getSelectedItem().toString())) {
431 Log.wrn("Update Events", "Incorrect data type for Event Name");
432 return false;
433 }
434 }
435
436 //
437 // Check FeatureFlag
438 //
439 if (!isEmpty(this.jTextFieldFeatureFlag.getText())) {
440 if (!DataValidation.isFeatureFlag(this.jTextFieldFeatureFlag.getText())) {
441 Log.wrn("Update Events", "Incorrect data type for Feature Flag");
442 return false;
443 }
444 }
445
446 return true;
447 }
448
449 private EventsIdentification getCurrentEvents() {
450 String arg0 = this.jComboBoxGuidC_Name.getSelectedItem().toString();
451 String arg1 = this.jComboBoxEventsType.getSelectedItem().toString();
452 String arg2 = this.jComboBoxUsage.getSelectedItem().toString();
453
454 String arg3 = this.jTextFieldFeatureFlag.getText();
455 Vector<String> arg4 = this.jArchCheckBox.getSelectedItemsVector();
456 String arg5 = this.jTextFieldHelpText.getText();
457 String arg6 = this.jComboBoxEventGroup.getSelectedItem().toString();
458 id = new EventsIdentification(arg0, arg1, arg2, arg3, arg4, arg5, arg6);
459 return id;
460 }
461
462 public EventsIdentification getId() {
463 return id;
464 }
465
466 public void setId(EventsIdentification id) {
467 this.id = id;
468 }
469 }