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