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
;
293 Vector
<PackageIdentification
> vpid
= wt
.getPackageDependenciesOfModule(mid
);
294 if (vpid
.size() <= 0) {
295 Log
.wrn("Init Protocol", "This module hasn't defined any package dependency, so there is no protocol can be added");
298 Tools
.generateComboBoxByVector(this.jComboBoxCName
,
299 wt
.getAllProtocolDeclarationsFromPackages(wt
.getPackageDependenciesOfModule(mid
)));
301 if (this.id
!= null) {
302 this.jComboBoxCName
.setSelectedItem(id
.getName());
303 this.jComboBoxProtocolType
.setSelectedItem(id
.getType());
304 this.jComboBoxUsage
.setSelectedItem(id
.getUsage());
305 this.jTextAreaHelpText
.setText(id
.getHelp());
306 this.jTextFieldFeatureFlag
.setText(id
.getFeatureFlag());
307 this.jArchCheckBox
.setSelectedItems(id
.getSupArchList());
312 * This is the override edit constructor
314 * @param inProtocolsIdentification
318 public ProtocolsDlg(ProtocolsIdentification inProtocolsIdentification
, IFrame iFrame
, ModuleIdentification mid
) {
320 init(inProtocolsIdentification
, mid
);
324 * Disable all components when the mode is view
327 * true - The view mode; false - The non-view mode
330 public void setViewMode(boolean isView
) {
332 this.jComboBoxUsage
.setEnabled(!isView
);
333 this.jTextFieldFeatureFlag
.setEnabled(!isView
);
338 * This method initializes jContentPane
340 * @return javax.swing.JPanel jContentPane
343 private JPanel
getJContentPane() {
344 if (jContentPane
== null) {
345 jStarLabel1
= new StarLabel();
346 jStarLabel1
.setLocation(new java
.awt
.Point(2, 12));
347 jLabelProtocolType
= new JLabel();
348 jLabelProtocolType
.setBounds(new java
.awt
.Rectangle(12, 12, 155, 20));
349 jLabelProtocolType
.setText("Select Protocol Type");
351 jStarLabel2
= new StarLabel();
352 jStarLabel2
.setLocation(new java
.awt
.Point(2, 37));
353 jLabelC_Name
= new JLabel();
354 jLabelC_Name
.setText("Protocol Guid C Name");
355 jLabelC_Name
.setBounds(new java
.awt
.Rectangle(12, 37, 155, 20));
357 jStarLabel3
= new StarLabel();
358 jStarLabel3
.setLocation(new java
.awt
.Point(2, 62));
359 jLabelUsage
= new JLabel();
360 jLabelUsage
.setText("Usage");
361 jLabelUsage
.setBounds(new java
.awt
.Rectangle(12, 62, 155, 20));
363 jLabelHelpText
= new JLabel();
364 jLabelHelpText
.setBounds(new java
.awt
.Rectangle(12, 87, 155, 20));
365 jLabelHelpText
.setText("Help Text");
367 jLabelFeatureFlag
= new JLabel();
368 jLabelFeatureFlag
.setText("Feature Flag Expression");
369 jLabelFeatureFlag
.setBounds(new java
.awt
.Rectangle(12, 157, 155, 20));
370 jLabelFeatureFlag
.setEnabled(false);
372 jLabelArch
= new JLabel();
373 jLabelArch
.setBounds(new java
.awt
.Rectangle(12, 132, 155, 20));
374 jLabelArch
.setText("Supported Architectures");
375 jArchCheckBox
= new ArchCheckBox();
376 jArchCheckBox
.setBounds(new java
.awt
.Rectangle(168, 132, 320, 20));
377 jArchCheckBox
.setPreferredSize(new java
.awt
.Dimension(320, 20));
379 jContentPane
= new JPanel();
380 jContentPane
.setLayout(null);
381 jContentPane
.setPreferredSize(new java
.awt
.Dimension(485, 215));
383 jContentPane
.add(jStarLabel1
, null);
384 jContentPane
.add(jLabelProtocolType
, null);
385 jContentPane
.add(getJComboBoxProtocolType(), null);
386 jContentPane
.add(jStarLabel2
, null);
387 jContentPane
.add(jLabelC_Name
, null);
388 jContentPane
.add(getJComboBoxCName(), null);
389 jContentPane
.add(jStarLabel3
, null);
390 jContentPane
.add(jLabelUsage
, null);
391 jContentPane
.add(getJComboBoxProtocolUsage(), null);
392 jContentPane
.add(jLabelHelpText
, null);
393 jContentPane
.add(getJScrollPaneHelpText(), null);
394 jContentPane
.add(jLabelFeatureFlag
, null);
395 jContentPane
.add(getJTextFieldFeatureFlag(), null);
396 jContentPane
.add(jLabelArch
, null);
397 jContentPane
.add(jArchCheckBox
, null);
398 jContentPane
.add(getJButtonOk(), null);
399 jContentPane
.add(getJButtonCancel(), null);
405 * This method initializes Usage type
408 private void initFrame() {
409 Tools
.generateComboBoxByVector(jComboBoxProtocolType
, ed
.getVProtocolType());
410 Tools
.generateComboBoxByVector(jComboBoxUsage
, ed
.getVProtocolUsage());
416 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
418 * Override actionPerformed to listen all actions
421 public void actionPerformed(ActionEvent arg0
) {
422 if (arg0
.getSource() == jButtonOk
) {
424 getCurrentProtocols();
425 this.returnType
= DataType
.RETURN_TYPE_OK
;
426 this.setVisible(false);
430 if (arg0
.getSource() == jButtonCancel
) {
431 this.returnType
= DataType
.RETURN_TYPE_CANCEL
;
432 this.setVisible(false);
437 * Data validation for all fields
439 * @retval true - All datas are valid
440 * @retval false - At least one data is invalid
443 public boolean checkAdd() {
445 // Check if all fields have correct data types
451 if (this.jComboBoxCName
.getSelectedItem() == null) {
452 Log
.wrn("Update protocols", "Please select one Protocol/ProtocolNotify Name");
456 if (!isEmpty(this.jComboBoxCName
.getSelectedItem().toString())) {
457 if (!DataValidation
.isC_NameType(this.jComboBoxCName
.getSelectedItem().toString())) {
458 Log
.wrn("Update Protocols", "Incorrect data type for Protocol/ProtocolNotify Name");
466 if (!isEmpty(this.jTextFieldFeatureFlag
.getText())) {
467 if (!DataValidation
.isFeatureFlag(this.jTextFieldFeatureFlag
.getText())) {
468 Log
.wrn("Update Protocols", "Incorrect data type for Feature Flag");
476 private ProtocolsIdentification
getCurrentProtocols() {
477 String arg0
= this.jComboBoxCName
.getSelectedItem().toString();
478 String arg1
= this.jComboBoxProtocolType
.getSelectedItem().toString();
479 String arg2
= this.jComboBoxUsage
.getSelectedItem().toString();
481 String arg3
= this.jTextFieldFeatureFlag
.getText();
482 Vector
<String
> arg4
= this.jArchCheckBox
.getSelectedItemsVector();
483 String arg5
= this.jTextAreaHelpText
.getText();
484 id
= new ProtocolsIdentification(arg0
, arg1
, arg2
, arg3
, arg4
, arg5
);
491 * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
493 * Reflesh the frame when selected item changed
497 public void itemStateChanged(ItemEvent arg0
) {
498 if (arg0
.getSource() == this.jComboBoxProtocolType
&& arg0
.getStateChange() == ItemEvent
.SELECTED
) {
499 if (this.jComboBoxProtocolType
.getSelectedItem().toString().equals(ed
.getVProtocolType().get(0))) {
500 Tools
.generateComboBoxByVector(this.jComboBoxUsage
, ed
.getVProtocolUsage());
502 Tools
.generateComboBoxByVector(this.jComboBoxUsage
, ed
.getVProtocolNotifyUsage());
507 public ProtocolsIdentification
getId() {
511 public void setId(ProtocolsIdentification id
) {