3 The file is used to create, update Protocol of 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.
16 package org
.tianocore
.frameworkwizard
.module
.ui
.dialog
;
18 import java
.awt
.event
.ActionEvent
;
19 import java
.awt
.event
.ItemEvent
;
20 import java
.awt
.event
.ItemListener
;
21 import java
.util
.Vector
;
23 import javax
.swing
.JButton
;
24 import javax
.swing
.JComboBox
;
25 import javax
.swing
.JLabel
;
26 import javax
.swing
.JPanel
;
27 import javax
.swing
.JScrollPane
;
28 import javax
.swing
.JTextField
;
29 import javax
.swing
.JTextArea
;
31 import org
.tianocore
.frameworkwizard
.common
.DataType
;
32 import org
.tianocore
.frameworkwizard
.common
.DataValidation
;
33 import org
.tianocore
.frameworkwizard
.common
.EnumerationData
;
34 import org
.tianocore
.frameworkwizard
.common
.Log
;
35 import org
.tianocore
.frameworkwizard
.common
.Tools
;
36 import org
.tianocore
.frameworkwizard
.common
.ui
.ArchCheckBox
;
37 import org
.tianocore
.frameworkwizard
.common
.ui
.IComboBox
;
38 import org
.tianocore
.frameworkwizard
.common
.ui
.IDialog
;
39 import org
.tianocore
.frameworkwizard
.common
.ui
.IFrame
;
40 import org
.tianocore
.frameworkwizard
.common
.ui
.StarLabel
;
41 import org
.tianocore
.frameworkwizard
.module
.Identifications
.ModuleIdentification
;
42 import org
.tianocore
.frameworkwizard
.module
.Identifications
.Protocols
.ProtocolsIdentification
;
43 import org
.tianocore
.frameworkwizard
.packaging
.PackageIdentification
;
44 import org
.tianocore
.frameworkwizard
.workspace
.WorkspaceTools
;
47 * The class is used to create, update Protocol of MSA file
52 public class ProtocolsDlg
extends IDialog
implements ItemListener
{
55 // / Define class Serial Version UID
57 private static final long serialVersionUID
= -9084913640747858848L;
60 // Define class members
62 private JPanel jContentPane
= null;
64 private JLabel jLabelC_Name
= null;
66 private JLabel jLabelFeatureFlag
= null;
68 private JTextField jTextFieldFeatureFlag
= null;
70 private JLabel jLabelUsage
= null;
72 private JComboBox jComboBoxUsage
= null;
74 private StarLabel jStarLabel1
= null;
76 private StarLabel jStarLabel2
= null;
78 private StarLabel jStarLabel3
= null;
80 private JLabel jLabelProtocolType
= null;
82 private JLabel jLabelArch
= null;
84 private JScrollPane jScrollPane
= null;
86 private JComboBox jComboBoxProtocolType
= null;
88 private IComboBox iComboBoxCName
= null;
90 private JLabel jLabelHelpText
= null;
92 private JTextArea jTextAreaHelpText
= null;
94 private JScrollPane jScrollPaneHelpText
= null;
96 private ArchCheckBox jArchCheckBox
= null;
98 private JButton jButtonOk
= null;
100 private JButton jButtonCancel
= null;
105 private ProtocolsIdentification id
= null;
107 private WorkspaceTools wt
= new WorkspaceTools();
109 private EnumerationData ed
= new EnumerationData();
112 * This method initializes jTextFieldFeatureFlag
114 * @return javax.swing.JTextField jTextFieldFeatureFlag
117 private JTextField
getJTextFieldFeatureFlag() {
118 if (jTextFieldFeatureFlag
== null) {
119 jTextFieldFeatureFlag
= new JTextField();
120 jTextFieldFeatureFlag
.setBounds(new java
.awt
.Rectangle(168, 157, 320, 20));
121 jTextFieldFeatureFlag
.setPreferredSize(new java
.awt
.Dimension(320, 20));
122 jTextFieldFeatureFlag
.setToolTipText("Postfix expression that must evaluate to TRUE or FALSE");
123 jTextFieldFeatureFlag
.setEnabled(false);
125 return jTextFieldFeatureFlag
;
129 * This method initializes jComboBoxUsage
131 * @return javax.swing.JComboBox jComboBoxUsage
134 private JComboBox
getJComboBoxProtocolUsage() {
135 if (jComboBoxUsage
== null) {
136 jComboBoxUsage
= new JComboBox();
137 jComboBoxUsage
.setBounds(new java
.awt
.Rectangle(168, 62, 320, 20));
138 jComboBoxUsage
.setPreferredSize(new java
.awt
.Dimension(320, 20));
140 .setToolTipText("<html><table><tr><td colspan=2 align=center><b>Protocol</b></td></tr>"
141 + "<tr><td>ALWAYS_CONSUMED</td><td>Module always consumes the protocol</td></tr>"
142 + "<tr><td>SOMETIMES_CONSUMES</td><td>Module sometimes consumes the protocol</td></tr>"
143 + "<tr><td>ALWAYS_PRODUCED</td><td>Module always produces the protocol</td></tr>"
144 + "<tr><td>SOMETIMES_PRODUCED</td><td>Module sometimes produces the protocol</td></tr>"
145 + "<tr><td>TO_START</td><td>The protocol is consumed by a Driver Binding protocol <b>Start</b><br>function. The protocol is used in EFI 1.10 driver model</td></tr>"
146 + "<tr><td>BY_START</td><td>Protocol is produced by a Driver Binding protocol <b>Start</b><br>function. The protocol is used in EFI 1.10 driver model</td></tr>"
147 + "<tr><td colspan=2 align=center><b>Protocol Notify</b></td></tr>"
148 + "<tr><td>SOMETIMES_CONSUMED</td><td>Module will consume the protocol if it is produced.<br>Consumption is defined by executing the protocol notify<br>function.</td></tr></table></html>");
150 return jComboBoxUsage
;
154 * This method initializes jScrollPane
156 * @return javax.swing.JScrollPane
158 private JScrollPane
getJScrollPane() {
159 if (jScrollPane
== null) {
160 jScrollPane
= new JScrollPane();
161 jScrollPane
.setViewportView(getJContentPane());
167 * This method initializes jComboBoxProtocolType
169 * @return javax.swing.JComboBox
171 private JComboBox
getJComboBoxProtocolType() {
172 if (jComboBoxProtocolType
== null) {
173 jComboBoxProtocolType
= new JComboBox();
174 jComboBoxProtocolType
.setBounds(new java
.awt
.Rectangle(168, 12, 320, 20));
175 jComboBoxProtocolType
.setPreferredSize(new java
.awt
.Dimension(320, 20));
176 jComboBoxProtocolType
.addItemListener(this);
177 jComboBoxProtocolType
178 .setToolTipText("<html>Select Protocol Type<br>Protocol Notify is a register protocol notify mechanism.");
180 return jComboBoxProtocolType
;
184 * This method initializes iComboBoxCName
186 * @return javax.swing.JComboBox
188 private IComboBox
getIComboBoxCName() {
189 if (iComboBoxCName
== null) {
190 iComboBoxCName
= new IComboBox();
191 iComboBoxCName
.setBounds(new java
.awt
.Rectangle(168, 37, 320, 20));
192 iComboBoxCName
.setPreferredSize(new java
.awt
.Dimension(320, 20));
193 iComboBoxCName
.setToolTipText("Select Guid C Name of the Protocol");
196 return iComboBoxCName
;
200 * This method initializes jTextAreaHelpText
202 * @return javax.swing.JTextArea
205 private JTextArea
getJTextAreaHelpText() {
206 if (jTextAreaHelpText
== null) {
207 jTextAreaHelpText
= new JTextArea();
208 jTextAreaHelpText
.setLineWrap(true);
209 jTextAreaHelpText
.setWrapStyleWord(true);
211 return jTextAreaHelpText
;
215 * This method initializes jScrollPaneHelpText
217 * @return javax.swing.JScrollPane
220 private JScrollPane
getJScrollPaneHelpText() {
221 if (jScrollPaneHelpText
== null) {
222 jScrollPaneHelpText
= new JScrollPane();
223 jScrollPaneHelpText
.setHorizontalScrollBarPolicy(javax
.swing
.JScrollPane
.HORIZONTAL_SCROLLBAR_NEVER
);
224 jScrollPaneHelpText
.setSize(new java
.awt
.Dimension(320, 40));
225 jScrollPaneHelpText
.setPreferredSize(new java
.awt
.Dimension(320, 40));
226 jScrollPaneHelpText
.setLocation(new java
.awt
.Point(168, 87));
227 jScrollPaneHelpText
.setViewportView(getJTextAreaHelpText());
229 return jScrollPaneHelpText
;
233 * This method initializes jButtonOk
235 * @return javax.swing.JButton
238 private JButton
getJButtonOk() {
239 if (jButtonOk
== null) {
240 jButtonOk
= new JButton();
241 jButtonOk
.setBounds(new java
.awt
.Rectangle(290, 187, 90, 20));
242 jButtonOk
.setText("Ok");
243 jButtonOk
.addActionListener(this);
249 * This method initializes jButtonCancel
251 * @return javax.swing.JButton
254 private JButton
getJButtonCancel() {
255 if (jButtonCancel
== null) {
256 jButtonCancel
= new JButton();
257 jButtonCancel
.setBounds(new java
.awt
.Rectangle(390, 187, 90, 20));
258 jButtonCancel
.setText("Cancel");
259 jButtonCancel
.addActionListener(this);
261 return jButtonCancel
;
264 public static void main(String
[] args
) {
269 * This method initializes this
272 private void init() {
273 // Width must be 20 larger than Content Pane PreferredSize width for MSFT
274 // Height must be 45 larger than ContentPane PreferredSize height for MSFT
275 this.setSize(505, 260);
276 this.setContentPane(getJScrollPane());
277 this.setTitle("Protocols");
279 this.setViewMode(false);
284 * This method initializes this Fill values to all fields if these values are
287 * @param inProtocolsId
290 private void init(ProtocolsIdentification inProtocolsId
, ModuleIdentification mid
) {
292 this.id
= inProtocolsId
;
295 // Init arch with module's arch
297 this.jArchCheckBox
.setEnabledItems(wt
.getModuleArch(mid
));
300 // Get defined protocols from dependent packages
302 Vector
<PackageIdentification
> vpid
= wt
.getPackageDependenciesOfModule(mid
);
303 if (vpid
.size() <= 0) {
304 Log
.wrn("Init Protocol", "This module hasn't defined any package dependency, so there is no protocol can be added");
307 Tools
.generateComboBoxByVector(this.iComboBoxCName
,
308 wt
.getAllProtocolDeclarationsFromPackages(wt
.getPackageDependenciesOfModule(mid
)));
310 if (this.id
!= null) {
311 this.iComboBoxCName
.setSelectedItem(id
.getName());
312 this.jComboBoxProtocolType
.setSelectedItem(id
.getType());
313 this.jComboBoxUsage
.setSelectedItem(id
.getUsage());
314 this.jTextAreaHelpText
.setText(id
.getHelp());
315 this.jTextFieldFeatureFlag
.setText(id
.getFeatureFlag());
316 this.jArchCheckBox
.setSelectedItems(id
.getSupArchList());
321 * This is the override edit constructor
323 * @param inProtocolsIdentification
327 public ProtocolsDlg(ProtocolsIdentification inProtocolsIdentification
, IFrame iFrame
, ModuleIdentification mid
) {
329 init(inProtocolsIdentification
, mid
);
333 * Disable all components when the mode is view
336 * true - The view mode; false - The non-view mode
339 public void setViewMode(boolean isView
) {
341 this.jComboBoxUsage
.setEnabled(!isView
);
342 this.jTextFieldFeatureFlag
.setEnabled(!isView
);
347 * This method initializes jContentPane
349 * @return javax.swing.JPanel jContentPane
352 private JPanel
getJContentPane() {
353 if (jContentPane
== null) {
354 jStarLabel1
= new StarLabel();
355 jStarLabel1
.setLocation(new java
.awt
.Point(2, 12));
356 jLabelProtocolType
= new JLabel();
357 jLabelProtocolType
.setBounds(new java
.awt
.Rectangle(12, 12, 155, 20));
358 jLabelProtocolType
.setText("Select Protocol Type");
360 jStarLabel2
= new StarLabel();
361 jStarLabel2
.setLocation(new java
.awt
.Point(2, 37));
362 jLabelC_Name
= new JLabel();
363 jLabelC_Name
.setText("Protocol Guid C Name");
364 jLabelC_Name
.setBounds(new java
.awt
.Rectangle(12, 37, 155, 20));
366 jStarLabel3
= new StarLabel();
367 jStarLabel3
.setLocation(new java
.awt
.Point(2, 62));
368 jLabelUsage
= new JLabel();
369 jLabelUsage
.setText("Usage");
370 jLabelUsage
.setBounds(new java
.awt
.Rectangle(12, 62, 155, 20));
372 jLabelHelpText
= new JLabel();
373 jLabelHelpText
.setBounds(new java
.awt
.Rectangle(12, 87, 155, 20));
374 jLabelHelpText
.setText("Help Text");
376 jLabelFeatureFlag
= new JLabel();
377 jLabelFeatureFlag
.setText("Feature Flag Expression");
378 jLabelFeatureFlag
.setBounds(new java
.awt
.Rectangle(12, 157, 155, 20));
379 jLabelFeatureFlag
.setEnabled(false);
381 jLabelArch
= new JLabel();
382 jLabelArch
.setBounds(new java
.awt
.Rectangle(12, 132, 155, 20));
383 jLabelArch
.setText("Supported Architectures");
384 jArchCheckBox
= new ArchCheckBox();
385 jArchCheckBox
.setBounds(new java
.awt
.Rectangle(168, 132, 320, 20));
386 jArchCheckBox
.setPreferredSize(new java
.awt
.Dimension(320, 20));
388 jContentPane
= new JPanel();
389 jContentPane
.setLayout(null);
390 jContentPane
.setPreferredSize(new java
.awt
.Dimension(485, 215));
392 jContentPane
.add(jStarLabel1
, null);
393 jContentPane
.add(jLabelProtocolType
, null);
394 jContentPane
.add(getJComboBoxProtocolType(), null);
395 jContentPane
.add(jStarLabel2
, null);
396 jContentPane
.add(jLabelC_Name
, null);
397 jContentPane
.add(getIComboBoxCName(), null);
398 jContentPane
.add(jStarLabel3
, null);
399 jContentPane
.add(jLabelUsage
, null);
400 jContentPane
.add(getJComboBoxProtocolUsage(), null);
401 jContentPane
.add(jLabelHelpText
, null);
402 jContentPane
.add(getJScrollPaneHelpText(), null);
403 jContentPane
.add(jLabelFeatureFlag
, null);
404 jContentPane
.add(getJTextFieldFeatureFlag(), null);
405 jContentPane
.add(jLabelArch
, null);
406 jContentPane
.add(jArchCheckBox
, null);
407 jContentPane
.add(getJButtonOk(), null);
408 jContentPane
.add(getJButtonCancel(), null);
414 * This method initializes Usage type
417 private void initFrame() {
418 Tools
.generateComboBoxByVector(jComboBoxProtocolType
, ed
.getVProtocolType());
419 Tools
.generateComboBoxByVector(jComboBoxUsage
, ed
.getVProtocolUsage());
425 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
427 * Override actionPerformed to listen all actions
430 public void actionPerformed(ActionEvent arg0
) {
431 if (arg0
.getSource() == jButtonOk
) {
433 getCurrentProtocols();
434 this.returnType
= DataType
.RETURN_TYPE_OK
;
435 this.setVisible(false);
439 if (arg0
.getSource() == jButtonCancel
) {
440 this.returnType
= DataType
.RETURN_TYPE_CANCEL
;
441 this.setVisible(false);
446 * Data validation for all fields
448 * @retval true - All datas are valid
449 * @retval false - At least one data is invalid
452 public boolean checkAdd() {
454 // Check if all fields have correct data types
460 if (this.iComboBoxCName
.getSelectedItem() == null) {
461 Log
.wrn("Update protocols", "Please select one Protocol/ProtocolNotify Name");
465 if (!isEmpty(this.iComboBoxCName
.getSelectedItem().toString())) {
466 if (!DataValidation
.isC_NameType(this.iComboBoxCName
.getSelectedItem().toString())) {
467 Log
.wrn("Update Protocols", "Incorrect data type for Protocol/ProtocolNotify Name");
475 if (!isEmpty(this.jTextFieldFeatureFlag
.getText())) {
476 if (!DataValidation
.isFeatureFlag(this.jTextFieldFeatureFlag
.getText())) {
477 Log
.wrn("Update Protocols", "Incorrect data type for Feature Flag");
485 private ProtocolsIdentification
getCurrentProtocols() {
486 String arg0
= this.iComboBoxCName
.getSelectedItem().toString();
487 String arg1
= this.jComboBoxProtocolType
.getSelectedItem().toString();
488 String arg2
= this.jComboBoxUsage
.getSelectedItem().toString();
490 String arg3
= this.jTextFieldFeatureFlag
.getText();
491 Vector
<String
> arg4
= this.jArchCheckBox
.getSelectedItemsVector();
492 String arg5
= this.jTextAreaHelpText
.getText();
493 id
= new ProtocolsIdentification(arg0
, arg1
, arg2
, arg3
, arg4
, arg5
);
500 * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
502 * Reflesh the frame when selected item changed
506 public void itemStateChanged(ItemEvent arg0
) {
507 if (arg0
.getSource() == this.jComboBoxProtocolType
&& arg0
.getStateChange() == ItemEvent
.SELECTED
) {
508 if (this.jComboBoxProtocolType
.getSelectedItem().toString().equals(ed
.getVProtocolType().get(0))) {
509 Tools
.generateComboBoxByVector(this.jComboBoxUsage
, ed
.getVProtocolUsage());
511 Tools
.generateComboBoxByVector(this.jComboBoxUsage
, ed
.getVProtocolNotifyUsage());
516 public ProtocolsIdentification
getId() {
520 public void setId(ProtocolsIdentification id
) {