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