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
.IDialog
;
38 import org
.tianocore
.frameworkwizard
.common
.ui
.IFrame
;
39 import org
.tianocore
.frameworkwizard
.common
.ui
.StarLabel
;
40 import org
.tianocore
.frameworkwizard
.module
.Identifications
.ModuleIdentification
;
41 import org
.tianocore
.frameworkwizard
.module
.Identifications
.Protocols
.ProtocolsIdentification
;
42 import org
.tianocore
.frameworkwizard
.packaging
.PackageIdentification
;
43 import org
.tianocore
.frameworkwizard
.workspace
.WorkspaceTools
;
46 * The class is used to create, update Protocol of MSA file
51 public class ProtocolsDlg
extends IDialog
implements ItemListener
{
54 // / Define class Serial Version UID
56 private static final long serialVersionUID
= -9084913640747858848L;
59 // Define class members
61 private JPanel jContentPane
= null;
63 private JLabel jLabelC_Name
= null;
65 private JLabel jLabelFeatureFlag
= null;
67 private JTextField jTextFieldFeatureFlag
= null;
69 private JLabel jLabelUsage
= null;
71 private JComboBox jComboBoxUsage
= null;
73 private StarLabel jStarLabel1
= null;
75 private StarLabel jStarLabel2
= null;
77 private StarLabel jStarLabel3
= null;
79 private JLabel jLabelProtocolType
= null;
81 private JLabel jLabelArch
= null;
83 private JScrollPane jScrollPane
= null;
85 private JComboBox jComboBoxProtocolType
= null;
87 private JComboBox jComboBoxCName
= null;
89 private JLabel jLabelHelpText
= null;
91 private JTextArea jTextAreaHelpText
= null;
93 private JScrollPane jScrollPaneHelpText
= null;
95 private ArchCheckBox jArchCheckBox
= null;
97 private JButton jButtonOk
= null;
99 private JButton jButtonCancel
= null;
104 private ProtocolsIdentification id
= null;
106 private WorkspaceTools wt
= new WorkspaceTools();
108 private EnumerationData ed
= new EnumerationData();
111 * This method initializes jTextFieldFeatureFlag
113 * @return javax.swing.JTextField jTextFieldFeatureFlag
116 private JTextField
getJTextFieldFeatureFlag() {
117 if (jTextFieldFeatureFlag
== null) {
118 jTextFieldFeatureFlag
= new JTextField();
119 jTextFieldFeatureFlag
.setBounds(new java
.awt
.Rectangle(168, 157, 320, 20));
120 jTextFieldFeatureFlag
.setPreferredSize(new java
.awt
.Dimension(320, 20));
121 jTextFieldFeatureFlag
.setToolTipText("Postfix expression that must evaluate to TRUE or FALSE");
122 jTextFieldFeatureFlag
.setEnabled(false);
124 return jTextFieldFeatureFlag
;
128 * This method initializes jComboBoxUsage
130 * @return javax.swing.JComboBox jComboBoxUsage
133 private JComboBox
getJComboBoxProtocolUsage() {
134 if (jComboBoxUsage
== null) {
135 jComboBoxUsage
= new JComboBox();
136 jComboBoxUsage
.setBounds(new java
.awt
.Rectangle(168, 62, 320, 20));
137 jComboBoxUsage
.setPreferredSize(new java
.awt
.Dimension(320, 20));
139 .setToolTipText("<html><table><tr><td colspan=2 align=center><b>Protocol</b></td></tr>"
140 + "<tr><td>ALWAYS_CONSUMED</td><td>Module always consumes the protocol</td></tr>"
141 + "<tr><td>SOMETIMES_CONSUMES</td><td>Module sometimes consumes the protocol</td></tr>"
142 + "<tr><td>ALWAYS_PRODUCED</td><td>Module always produces the protocol</td></tr>"
143 + "<tr><td>SOMETIMES_PRODUCED</td><td>Module sometimes produces the protocol</td></tr>"
144 + "<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>"
145 + "<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>"
146 + "<tr><td colspan=2 align=center><b>Protocol Notify</b></td></tr>"
147 + "<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>");
149 return jComboBoxUsage
;
153 * This method initializes jScrollPane
155 * @return javax.swing.JScrollPane
157 private JScrollPane
getJScrollPane() {
158 if (jScrollPane
== null) {
159 jScrollPane
= new JScrollPane();
160 jScrollPane
.setViewportView(getJContentPane());
166 * This method initializes jComboBoxProtocolType
168 * @return javax.swing.JComboBox
170 private JComboBox
getJComboBoxProtocolType() {
171 if (jComboBoxProtocolType
== null) {
172 jComboBoxProtocolType
= new JComboBox();
173 jComboBoxProtocolType
.setBounds(new java
.awt
.Rectangle(168, 12, 320, 20));
174 jComboBoxProtocolType
.setPreferredSize(new java
.awt
.Dimension(320, 20));
175 jComboBoxProtocolType
.addItemListener(this);
176 jComboBoxProtocolType
177 .setToolTipText("<html>Select Protocol Type<br>Protocol Notify is a register protocol notify mechanism.");
179 return jComboBoxProtocolType
;
183 * This method initializes jComboBoxCName
185 * @return javax.swing.JComboBox
187 private JComboBox
getJComboBoxCName() {
188 if (jComboBoxCName
== null) {
189 jComboBoxCName
= new JComboBox();
190 jComboBoxCName
.setBounds(new java
.awt
.Rectangle(168, 37, 320, 20));
191 jComboBoxCName
.setPreferredSize(new java
.awt
.Dimension(320, 20));
192 jComboBoxCName
.setToolTipText("Select Guid C Name of the Protocol");
195 return jComboBoxCName
;
199 * This method initializes jTextAreaHelpText
201 * @return javax.swing.JTextArea
204 private JTextArea
getJTextAreaHelpText() {
205 if (jTextAreaHelpText
== null) {
206 jTextAreaHelpText
= new JTextArea();
207 jTextAreaHelpText
.setLineWrap(true);
208 jTextAreaHelpText
.setWrapStyleWord(true);
210 return jTextAreaHelpText
;
214 * This method initializes jScrollPaneHelpText
216 * @return javax.swing.JScrollPane
219 private JScrollPane
getJScrollPaneHelpText() {
220 if (jScrollPaneHelpText
== null) {
221 jScrollPaneHelpText
= new JScrollPane();
222 jScrollPaneHelpText
.setHorizontalScrollBarPolicy(javax
.swing
.JScrollPane
.HORIZONTAL_SCROLLBAR_NEVER
);
223 jScrollPaneHelpText
.setSize(new java
.awt
.Dimension(320, 40));
224 jScrollPaneHelpText
.setPreferredSize(new java
.awt
.Dimension(320, 40));
225 jScrollPaneHelpText
.setLocation(new java
.awt
.Point(168, 87));
226 jScrollPaneHelpText
.setViewportView(getJTextAreaHelpText());
228 return jScrollPaneHelpText
;
232 * This method initializes jButtonOk
234 * @return javax.swing.JButton
237 private JButton
getJButtonOk() {
238 if (jButtonOk
== null) {
239 jButtonOk
= new JButton();
240 jButtonOk
.setBounds(new java
.awt
.Rectangle(290, 187, 90, 20));
241 jButtonOk
.setText("Ok");
242 jButtonOk
.addActionListener(this);
248 * This method initializes jButtonCancel
250 * @return javax.swing.JButton
253 private JButton
getJButtonCancel() {
254 if (jButtonCancel
== null) {
255 jButtonCancel
= new JButton();
256 jButtonCancel
.setBounds(new java
.awt
.Rectangle(390, 187, 90, 20));
257 jButtonCancel
.setText("Cancel");
258 jButtonCancel
.addActionListener(this);
260 return jButtonCancel
;
263 public static void main(String
[] args
) {
268 * This method initializes this
271 private void init() {
272 // Width must be 20 larger than Content Pane PreferredSize width for MSFT
273 // Height must be 45 larger than ContentPane PreferredSize height for MSFT
274 this.setSize(505, 260);
275 this.setContentPane(getJScrollPane());
276 this.setTitle("Protocols");
278 this.setViewMode(false);
283 * This method initializes this Fill values to all fields if these values are
286 * @param inProtocolsId
289 private void init(ProtocolsIdentification inProtocolsId
, ModuleIdentification mid
) {
291 this.id
= inProtocolsId
;
294 // Init arch with module's arch
296 this.jArchCheckBox
.setEnabledItems(wt
.getModuleArch(mid
));
299 // Get defined protocols from dependent packages
301 Vector
<PackageIdentification
> vpid
= wt
.getPackageDependenciesOfModule(mid
);
302 if (vpid
.size() <= 0) {
303 Log
.wrn("Init Protocol", "This module hasn't defined any package dependency, so there is no protocol can be added");
306 Tools
.generateComboBoxByVector(this.jComboBoxCName
,
307 wt
.getAllProtocolDeclarationsFromPackages(wt
.getPackageDependenciesOfModule(mid
)));
309 if (this.id
!= null) {
310 this.jComboBoxCName
.setSelectedItem(id
.getName());
311 this.jComboBoxProtocolType
.setSelectedItem(id
.getType());
312 this.jComboBoxUsage
.setSelectedItem(id
.getUsage());
313 this.jTextAreaHelpText
.setText(id
.getHelp());
314 this.jTextFieldFeatureFlag
.setText(id
.getFeatureFlag());
315 this.jArchCheckBox
.setSelectedItems(id
.getSupArchList());
320 * This is the override edit constructor
322 * @param inProtocolsIdentification
326 public ProtocolsDlg(ProtocolsIdentification inProtocolsIdentification
, IFrame iFrame
, ModuleIdentification mid
) {
328 init(inProtocolsIdentification
, mid
);
332 * Disable all components when the mode is view
335 * true - The view mode; false - The non-view mode
338 public void setViewMode(boolean isView
) {
340 this.jComboBoxUsage
.setEnabled(!isView
);
341 this.jTextFieldFeatureFlag
.setEnabled(!isView
);
346 * This method initializes jContentPane
348 * @return javax.swing.JPanel jContentPane
351 private JPanel
getJContentPane() {
352 if (jContentPane
== null) {
353 jStarLabel1
= new StarLabel();
354 jStarLabel1
.setLocation(new java
.awt
.Point(2, 12));
355 jLabelProtocolType
= new JLabel();
356 jLabelProtocolType
.setBounds(new java
.awt
.Rectangle(12, 12, 155, 20));
357 jLabelProtocolType
.setText("Select Protocol Type");
359 jStarLabel2
= new StarLabel();
360 jStarLabel2
.setLocation(new java
.awt
.Point(2, 37));
361 jLabelC_Name
= new JLabel();
362 jLabelC_Name
.setText("Protocol Guid C Name");
363 jLabelC_Name
.setBounds(new java
.awt
.Rectangle(12, 37, 155, 20));
365 jStarLabel3
= new StarLabel();
366 jStarLabel3
.setLocation(new java
.awt
.Point(2, 62));
367 jLabelUsage
= new JLabel();
368 jLabelUsage
.setText("Usage");
369 jLabelUsage
.setBounds(new java
.awt
.Rectangle(12, 62, 155, 20));
371 jLabelHelpText
= new JLabel();
372 jLabelHelpText
.setBounds(new java
.awt
.Rectangle(12, 87, 155, 20));
373 jLabelHelpText
.setText("Help Text");
375 jLabelFeatureFlag
= new JLabel();
376 jLabelFeatureFlag
.setText("Feature Flag Expression");
377 jLabelFeatureFlag
.setBounds(new java
.awt
.Rectangle(12, 157, 155, 20));
378 jLabelFeatureFlag
.setEnabled(false);
380 jLabelArch
= new JLabel();
381 jLabelArch
.setBounds(new java
.awt
.Rectangle(12, 132, 155, 20));
382 jLabelArch
.setText("Supported Architectures");
383 jArchCheckBox
= new ArchCheckBox();
384 jArchCheckBox
.setBounds(new java
.awt
.Rectangle(168, 132, 320, 20));
385 jArchCheckBox
.setPreferredSize(new java
.awt
.Dimension(320, 20));
387 jContentPane
= new JPanel();
388 jContentPane
.setLayout(null);
389 jContentPane
.setPreferredSize(new java
.awt
.Dimension(485, 215));
391 jContentPane
.add(jStarLabel1
, null);
392 jContentPane
.add(jLabelProtocolType
, null);
393 jContentPane
.add(getJComboBoxProtocolType(), null);
394 jContentPane
.add(jStarLabel2
, null);
395 jContentPane
.add(jLabelC_Name
, null);
396 jContentPane
.add(getJComboBoxCName(), null);
397 jContentPane
.add(jStarLabel3
, null);
398 jContentPane
.add(jLabelUsage
, null);
399 jContentPane
.add(getJComboBoxProtocolUsage(), null);
400 jContentPane
.add(jLabelHelpText
, null);
401 jContentPane
.add(getJScrollPaneHelpText(), null);
402 jContentPane
.add(jLabelFeatureFlag
, null);
403 jContentPane
.add(getJTextFieldFeatureFlag(), null);
404 jContentPane
.add(jLabelArch
, null);
405 jContentPane
.add(jArchCheckBox
, null);
406 jContentPane
.add(getJButtonOk(), null);
407 jContentPane
.add(getJButtonCancel(), null);
413 * This method initializes Usage type
416 private void initFrame() {
417 Tools
.generateComboBoxByVector(jComboBoxProtocolType
, ed
.getVProtocolType());
418 Tools
.generateComboBoxByVector(jComboBoxUsage
, ed
.getVProtocolUsage());
424 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
426 * Override actionPerformed to listen all actions
429 public void actionPerformed(ActionEvent arg0
) {
430 if (arg0
.getSource() == jButtonOk
) {
432 getCurrentProtocols();
433 this.returnType
= DataType
.RETURN_TYPE_OK
;
434 this.setVisible(false);
438 if (arg0
.getSource() == jButtonCancel
) {
439 this.returnType
= DataType
.RETURN_TYPE_CANCEL
;
440 this.setVisible(false);
445 * Data validation for all fields
447 * @retval true - All datas are valid
448 * @retval false - At least one data is invalid
451 public boolean checkAdd() {
453 // Check if all fields have correct data types
459 if (this.jComboBoxCName
.getSelectedItem() == null) {
460 Log
.wrn("Update protocols", "Please select one Protocol/ProtocolNotify Name");
464 if (!isEmpty(this.jComboBoxCName
.getSelectedItem().toString())) {
465 if (!DataValidation
.isC_NameType(this.jComboBoxCName
.getSelectedItem().toString())) {
466 Log
.wrn("Update Protocols", "Incorrect data type for Protocol/ProtocolNotify Name");
474 if (!isEmpty(this.jTextFieldFeatureFlag
.getText())) {
475 if (!DataValidation
.isFeatureFlag(this.jTextFieldFeatureFlag
.getText())) {
476 Log
.wrn("Update Protocols", "Incorrect data type for Feature Flag");
484 private ProtocolsIdentification
getCurrentProtocols() {
485 String arg0
= this.jComboBoxCName
.getSelectedItem().toString();
486 String arg1
= this.jComboBoxProtocolType
.getSelectedItem().toString();
487 String arg2
= this.jComboBoxUsage
.getSelectedItem().toString();
489 String arg3
= this.jTextFieldFeatureFlag
.getText();
490 Vector
<String
> arg4
= this.jArchCheckBox
.getSelectedItemsVector();
491 String arg5
= this.jTextAreaHelpText
.getText();
492 id
= new ProtocolsIdentification(arg0
, arg1
, arg2
, arg3
, arg4
, arg5
);
499 * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
501 * Reflesh the frame when selected item changed
505 public void itemStateChanged(ItemEvent arg0
) {
506 if (arg0
.getSource() == this.jComboBoxProtocolType
&& arg0
.getStateChange() == ItemEvent
.SELECTED
) {
507 if (this.jComboBoxProtocolType
.getSelectedItem().toString().equals(ed
.getVProtocolType().get(0))) {
508 Tools
.generateComboBoxByVector(this.jComboBoxUsage
, ed
.getVProtocolUsage());
510 Tools
.generateComboBoxByVector(this.jComboBoxUsage
, ed
.getVProtocolNotifyUsage());
515 public ProtocolsIdentification
getId() {
519 public void setId(ProtocolsIdentification id
) {