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