3 The file is used to create, update Events section of the MSA file
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
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.
15 package org
.tianocore
.frameworkwizard
.module
.ui
.dialog
;
17 import java
.awt
.event
.ActionEvent
;
18 import java
.util
.Vector
;
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 import javax
.swing
.JTextArea
;
28 import org
.tianocore
.frameworkwizard
.common
.DataType
;
29 import org
.tianocore
.frameworkwizard
.common
.DataValidation
;
30 import org
.tianocore
.frameworkwizard
.common
.EnumerationData
;
31 import org
.tianocore
.frameworkwizard
.common
.Log
;
32 import org
.tianocore
.frameworkwizard
.common
.Tools
;
33 import org
.tianocore
.frameworkwizard
.common
.ui
.ArchCheckBox
;
34 import org
.tianocore
.frameworkwizard
.common
.ui
.IComboBox
;
35 import org
.tianocore
.frameworkwizard
.common
.ui
.IDialog
;
36 import org
.tianocore
.frameworkwizard
.common
.ui
.IFrame
;
37 import org
.tianocore
.frameworkwizard
.common
.ui
.StarLabel
;
38 import org
.tianocore
.frameworkwizard
.module
.Identifications
.ModuleIdentification
;
39 import org
.tianocore
.frameworkwizard
.module
.Identifications
.Events
.EventsIdentification
;
40 import org
.tianocore
.frameworkwizard
.packaging
.PackageIdentification
;
41 import org
.tianocore
.frameworkwizard
.workspace
.WorkspaceTools
;
44 * The class is used to create, update Events section of the MSA file
47 * @since ModuleEditor 1.0
50 public class EventsDlg
extends IDialog
{
53 // / Define class Serial Version UID
55 private static final long serialVersionUID
= -4396143706422842331L;
58 // Define class members
60 private JPanel jContentPane
= null;
62 private JLabel jLabelEventType
= null;
64 private JLabel jLabelC_Name
= null;
66 private IComboBox iComboBoxGuidC_Name
= null;
68 private JLabel jLabelUsage
= null;
70 private JLabel jLabelGroup
= null;
72 private JComboBox jComboBoxUsage
= null;
74 private JComboBox jComboBoxEventGroup
= null;
76 private StarLabel jStarLabel1
= null;
78 private StarLabel jStarLabel2
= null;
80 private StarLabel jStarLabel3
= null;
82 private StarLabel jStarLabel4
= null;
84 private JComboBox jComboBoxEventsType
= null;
86 private JScrollPane jScrollPane
= null;
88 private JLabel jLabelArch
= null;
90 private JLabel jLabelHelpText
= null;
92 private JTextArea jTextAreaHelpText
= null;
94 private JScrollPane jScrollPaneHelpText
= null;
96 private JLabel jLabelFeatureFlag
= null;
98 private JTextField jTextFieldFeatureFlag
= null;
100 private ArchCheckBox jArchCheckBox
= null;
102 private JButton jButtonOk
= null;
104 private JButton jButtonCancel
= null;
109 private EventsIdentification id
= null;
111 private EnumerationData ed
= new EnumerationData();
113 private WorkspaceTools wt
= new WorkspaceTools();
116 * This method initializes jComboBoxType
118 * @return javax.swing.JComboBox jComboBoxType
121 private JComboBox
getJComboBoxEventsType() {
122 if (jComboBoxEventsType
== null) {
123 jComboBoxEventsType
= new JComboBox();
124 jComboBoxEventsType
.setBounds(new java
.awt
.Rectangle(168, 12, 320, 20));
125 jComboBoxEventsType
.setPreferredSize(new java
.awt
.Dimension(320, 20));
127 .setToolTipText("<html>Select CreateEvents if the Module has an event that is waiting to be signaled.<br>"
128 + "Select SignalEvents if the Module will signal all events in an event group.<br>"
129 + "NOTE: Signal events are named by GUID.</html>");
131 return jComboBoxEventsType
;
135 * This method initializes jTextFieldC_Name
137 * @return javax.swing.JTextField jTextFieldC_Name
140 private IComboBox
getIComboBoxGuidC_Name() {
141 if (iComboBoxGuidC_Name
== null) {
142 iComboBoxGuidC_Name
= new IComboBox();
143 iComboBoxGuidC_Name
.setBounds(new java
.awt
.Rectangle(168, 37, 320, 20));
144 iComboBoxGuidC_Name
.setPreferredSize(new java
.awt
.Dimension(320, 20));
145 iComboBoxGuidC_Name
.setToolTipText("Select the GUID C Name of the Event");
147 return iComboBoxGuidC_Name
;
151 * This method initializes jComboBoxEventsType
153 * @return javax.swing.JComboBox
155 private JComboBox
getJComboBoxEventGroup() {
156 if (jComboBoxEventGroup
== null) {
157 jComboBoxEventGroup
= new JComboBox();
158 jComboBoxEventGroup
.setBounds(new java
.awt
.Rectangle(168, 62, 320, 20));
159 jComboBoxEventGroup
.setPreferredSize(new java
.awt
.Dimension(320, 20));
160 jComboBoxEventGroup
.setToolTipText("Select Type of Event: Guid or Timer.");
163 return jComboBoxEventGroup
;
167 * This method initializes jComboBoxUsage
169 * @return javax.swing.JComboBox jComboBoxUsage
172 private JComboBox
getJComboBoxUsage() {
173 if (jComboBoxUsage
== null) {
174 jComboBoxUsage
= new JComboBox();
175 jComboBoxUsage
.setBounds(new java
.awt
.Rectangle(168, 87, 320, 20));
176 jComboBoxUsage
.setPreferredSize(new java
.awt
.Dimension(320, 20));
178 .setToolTipText("<html><table>"
179 + "<tr><td colspan=2 align=center><b>Create Events</b></td></tr>"
180 + "<tr><td>ALWAYS_CONSUMED</td><td>Module registers a notification function and REQUIRES that it be<br>"
181 + "executed for the module to fully function.</td></tr>"
182 + "<tr><td>SOMETIMES_CONSUMED</td><td>Module registers a notification function and calls the function<br>"
183 + "when it is signaled</td></tr><tr><td colspan=2 align=center><b>Signal Events</b></td></tr>"
184 + "<tr><td>ALWAYS_PRODUCED</td><td>Module will Always signal the event</td></tr>"
185 + "<tr><td>SOMETIMES_PRODUCED</td><td>Module will sometimes signal the event</td></tr>"
186 + "</table></html>");
188 return jComboBoxUsage
;
192 * This method initializes jScrollPane
194 * @return javax.swing.JScrollPane
196 private JScrollPane
getJScrollPane() {
197 if (jScrollPane
== null) {
198 jScrollPane
= new JScrollPane();
199 jScrollPane
.setViewportView(getJContentPane());
205 * This method initializes jTextFieldFeatureFlag
207 * @return javax.swing.JTextField
209 private JTextField
getJTextFieldFeatureFlag() {
210 if (jTextFieldFeatureFlag
== null) {
211 jTextFieldFeatureFlag
= new JTextField();
212 jTextFieldFeatureFlag
.setBounds(new java
.awt
.Rectangle(168, 182, 320, 20));
213 jTextFieldFeatureFlag
.setPreferredSize(new java
.awt
.Dimension(320, 20));
214 jTextFieldFeatureFlag
.setToolTipText("Postfix expression that must evaluate to TRUE or FALSE");
215 jTextFieldFeatureFlag
.setEnabled(false);
217 return jTextFieldFeatureFlag
;
221 * This method initializes jTextAreaHelpText
223 * @return javax.swing.JTextArea
226 private JTextArea
getJTextAreaHelpText() {
227 if (jTextAreaHelpText
== null) {
228 jTextAreaHelpText
= new JTextArea();
229 jTextAreaHelpText
.setLineWrap(true);
230 jTextAreaHelpText
.setWrapStyleWord(true);
232 return jTextAreaHelpText
;
236 * This method initializes jScrollPaneHelpText
238 * @return javax.swing.JScrollPane
241 private JScrollPane
getJScrollPaneHelpText() {
242 if (jScrollPaneHelpText
== null) {
243 jScrollPaneHelpText
= new JScrollPane();
244 jScrollPaneHelpText
.setHorizontalScrollBarPolicy(javax
.swing
.JScrollPane
.HORIZONTAL_SCROLLBAR_NEVER
);
245 jScrollPaneHelpText
.setSize(new java
.awt
.Dimension(320, 40));
246 jScrollPaneHelpText
.setPreferredSize(new java
.awt
.Dimension(320, 40));
247 jScrollPaneHelpText
.setLocation(new java
.awt
.Point(168, 112));
248 jScrollPaneHelpText
.setViewportView(getJTextAreaHelpText());
250 return jScrollPaneHelpText
;
254 * This method initializes jButtonOk
256 * @return javax.swing.JButton
259 private JButton
getJButtonOk() {
260 if (jButtonOk
== null) {
261 jButtonOk
= new JButton();
262 jButtonOk
.setBounds(new java
.awt
.Rectangle(290, 212, 90, 20));
263 jButtonOk
.setText("Ok");
264 jButtonOk
.addActionListener(this);
270 * This method initializes jButtonCancel
272 * @return javax.swing.JButton
275 private JButton
getJButtonCancel() {
276 if (jButtonCancel
== null) {
277 jButtonCancel
= new JButton();
278 jButtonCancel
.setBounds(new java
.awt
.Rectangle(390, 212, 90, 20));
279 jButtonCancel
.setText("Cancel");
280 jButtonCancel
.addActionListener(this);
282 return jButtonCancel
;
285 public static void main(String
[] args
) {
290 * This method initializes this
293 private void init() {
294 this.setSize(505, 280);
295 this.setContentPane(getJScrollPane());
296 this.setTitle("Events");
298 this.setViewMode(false);
303 * This method initializes this Fill values to all fields if these values are
309 private void init(EventsIdentification inEventsId
, ModuleIdentification mid
) {
311 this.id
= inEventsId
;
314 // Init arch with module's arch
316 this.jArchCheckBox
.setEnabledItems(wt
.getModuleArch(mid
));
319 // Get defined guids from dependent packages
321 Vector
<PackageIdentification
> vpid
= wt
.getPackageDependenciesOfModule(mid
);
322 if (vpid
.size() <= 0) {
325 "This module hasn't defined any package dependency, so there is no guid value can be added for event");
328 // Init guids drop down list
331 .generateComboBoxByVector(iComboBoxGuidC_Name
,
332 wt
.getAllGuidDeclarationsFromPackages(vpid
, EnumerationData
.GUID_TYPE_EFI_EVENT
));
334 this.iComboBoxGuidC_Name
.insertItemAt(DataType
.EMPTY_SELECT_ITEM
, 0);
335 this.iComboBoxGuidC_Name
.setSelectedIndex(0);
337 if (this.id
!= null) {
338 String tmpName
= id
.getName();
339 if (isEmpty(tmpName
)) {
340 tmpName
= DataType
.EMPTY_SELECT_ITEM
;
343 this.iComboBoxGuidC_Name
.setSelectedItem(tmpName
);
344 this.jComboBoxEventsType
.setSelectedItem(id
.getType());
345 this.jComboBoxUsage
.setSelectedItem(id
.getUsage());
346 this.jTextAreaHelpText
.setText(id
.getHelp());
348 jTextFieldFeatureFlag
.setText(id
.getFeatureFlag());
349 this.jArchCheckBox
.setSelectedItems(id
.getSupArchList());
350 this.jComboBoxEventGroup
.setSelectedItem(id
.getGroup());
355 * This is the override edit constructor
357 * @param inEventsIdentification
361 public EventsDlg(EventsIdentification inEventsIdentification
, IFrame iFrame
, ModuleIdentification mid
) {
363 init(inEventsIdentification
, mid
);
367 * Disable all components when the mode is view
370 * true - The view mode; false - The non-view mode
373 public void setViewMode(boolean isView
) {
375 this.iComboBoxGuidC_Name
.setEnabled(!isView
);
376 this.jComboBoxUsage
.setEnabled(!isView
);
381 * This method initializes jContentPane
383 * @return javax.swing.JPanel jContentPane
386 private JPanel
getJContentPane() {
387 if (jContentPane
== null) {
388 jStarLabel1
= new StarLabel();
389 jStarLabel1
.setLocation(new java
.awt
.Point(2, 12));
390 jLabelEventType
= new JLabel();
391 jLabelEventType
.setText("Select Event Type");
392 jLabelEventType
.setBounds(new java
.awt
.Rectangle(12, 12, 168, 20));
394 jStarLabel2
= new StarLabel();
395 jStarLabel2
.setLocation(new java
.awt
.Point(2, 37));
396 jLabelC_Name
= new JLabel();
397 jLabelC_Name
.setText("Guid C Name");
398 jLabelC_Name
.setBounds(new java
.awt
.Rectangle(12, 37, 168, 20));
400 jStarLabel3
= new StarLabel();
401 jStarLabel3
.setLocation(new java
.awt
.Point(2, 62));
402 jLabelGroup
= new JLabel();
403 jLabelGroup
.setText("Event Group Type");
404 jLabelGroup
.setBounds(new java
.awt
.Rectangle(12, 62, 168, 20));
406 jStarLabel4
= new StarLabel();
407 jStarLabel4
.setLocation(new java
.awt
.Point(2, 87));
408 jLabelUsage
= new JLabel();
409 jLabelUsage
.setText("Usage");
410 jLabelUsage
.setBounds(new java
.awt
.Rectangle(12, 87, 168, 20));
412 jLabelHelpText
= new JLabel();
413 jLabelHelpText
.setBounds(new java
.awt
.Rectangle(12, 112, 168, 20));
414 jLabelHelpText
.setText("Help Text");
416 jLabelFeatureFlag
= new JLabel();
417 jLabelFeatureFlag
.setBounds(new java
.awt
.Rectangle(12, 182, 168, 20));
418 jLabelFeatureFlag
.setText("Feature Flag Expression");
419 jLabelFeatureFlag
.setEnabled(false);
421 jLabelArch
= new JLabel();
422 jLabelArch
.setBounds(new java
.awt
.Rectangle(12, 157, 168, 20));
423 jLabelArch
.setText("Supported Architectures");
424 jArchCheckBox
= new ArchCheckBox();
425 jArchCheckBox
.setBounds(new java
.awt
.Rectangle(168, 157, 320, 20));
426 jArchCheckBox
.setPreferredSize(new java
.awt
.Dimension(320, 20));
428 jContentPane
= new JPanel();
429 jContentPane
.setLayout(null);
430 jContentPane
.setPreferredSize(new java
.awt
.Dimension(485, 235));
432 jContentPane
.add(jStarLabel1
, null);
433 jContentPane
.add(jLabelEventType
, null);
434 jContentPane
.add(getJComboBoxEventsType(), null);
435 //jContentPane.add(jStarLabel2, null);
436 jContentPane
.add(jLabelC_Name
, null);
437 jContentPane
.add(getIComboBoxGuidC_Name(), null);
438 jContentPane
.add(jStarLabel3
, null);
439 jContentPane
.add(jLabelGroup
, null);
440 jContentPane
.add(getJComboBoxEventGroup(), null);
441 jContentPane
.add(jStarLabel4
, null);
442 jContentPane
.add(jLabelUsage
, null);
443 jContentPane
.add(getJComboBoxUsage(), null);
444 jContentPane
.add(jLabelHelpText
, null);
445 jContentPane
.add(getJScrollPaneHelpText(), null);
446 jContentPane
.add(jLabelFeatureFlag
, null);
447 jContentPane
.add(getJTextFieldFeatureFlag(), null);
448 jContentPane
.add(jLabelArch
, null);
449 jContentPane
.add(jArchCheckBox
, null);
450 jContentPane
.add(getJButtonOk(), null);
451 jContentPane
.add(getJButtonCancel(), null);
458 * This method initializes events groups and usage type
461 private void initFrame() {
462 Tools
.generateComboBoxByVector(jComboBoxEventsType
, ed
.getVEventType());
463 Tools
.generateComboBoxByVector(jComboBoxEventGroup
, ed
.getVEventGroup());
464 Tools
.generateComboBoxByVector(jComboBoxUsage
, ed
.getVEventUsage());
470 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
472 * Override actionPerformed to listen all actions
475 public void actionPerformed(ActionEvent arg0
) {
476 if (arg0
.getSource() == jButtonOk
) {
479 this.returnType
= DataType
.RETURN_TYPE_OK
;
480 this.setVisible(false);
484 if (arg0
.getSource() == jButtonCancel
) {
485 this.returnType
= DataType
.RETURN_TYPE_CANCEL
;
486 this.setVisible(false);
491 * Data validation for all fields
493 * @retval true - All datas are valid
494 * @retval false - At least one data is invalid
497 public boolean checkAdd() {
499 // Check if all fields have correct data types
505 String tmpName
= this.iComboBoxGuidC_Name
.getSelectedItem().toString();
506 if (!tmpName
.equals(DataType
.EMPTY_SELECT_ITEM
) && isEmpty(tmpName
)) {
507 if (!DataValidation
.isC_NameType(this.iComboBoxGuidC_Name
.getSelectedItem().toString())) {
508 Log
.wrn("Update Events", "Incorrect data type for Event Name");
516 if (!isEmpty(this.jTextFieldFeatureFlag
.getText())) {
517 if (!DataValidation
.isFeatureFlag(this.jTextFieldFeatureFlag
.getText())) {
518 Log
.wrn("Update Events", "Incorrect data type for Feature Flag");
526 private EventsIdentification
getCurrentEvents() {
527 String arg0
= this.iComboBoxGuidC_Name
.getSelectedItem().toString();
528 String arg1
= this.jComboBoxEventsType
.getSelectedItem().toString();
529 String arg2
= this.jComboBoxUsage
.getSelectedItem().toString();
531 String arg3
= this.jTextFieldFeatureFlag
.getText();
532 Vector
<String
> arg4
= this.jArchCheckBox
.getSelectedItemsVector();
533 String arg5
= this.jTextAreaHelpText
.getText();
534 String arg6
= this.jComboBoxEventGroup
.getSelectedItem().toString();
535 id
= new EventsIdentification(arg0
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
539 public EventsIdentification
getId() {
543 public void setId(EventsIdentification id
) {