3 The file is used to create, update Protocol of MSA/MBD 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
.Protocols
.ProtocolsIdentification
;
41 import org
.tianocore
.frameworkwizard
.workspace
.WorkspaceTools
;
44 * The class is used to create, update Protocol of MSA file
49 public class ProtocolsDlg
extends IDialog
implements ItemListener
{
52 // / Define class Serial Version UID
54 private static final long serialVersionUID
= -9084913640747858848L;
57 // Define class members
59 private JPanel jContentPane
= null;
61 private JLabel jLabelC_Name
= null;
63 private JLabel jLabelFeatureFlag
= null;
65 private JTextField jTextFieldFeatureFlag
= null;
67 private JLabel jLabelUsage
= null;
69 private JComboBox jComboBoxUsage
= null;
71 private StarLabel jStarLabel1
= null;
73 private StarLabel jStarLabel2
= null;
75 private StarLabel jStarLabel3
= null;
77 private JLabel jLabelProtocolType
= null;
79 private JLabel jLabelArch
= null;
81 private JScrollPane jScrollPane
= null;
83 private JComboBox jComboBoxProtocolType
= null;
85 private JComboBox jComboBoxCName
= null;
87 private JLabel jLabelHelpText
= null;
89 private JTextArea jTextAreaHelpText
= null;
91 private JScrollPane jScrollPaneHelpText
= null;
93 private ArchCheckBox jArchCheckBox
= null;
95 private JButton jButtonOk
= null;
97 private JButton jButtonCancel
= null;
102 private ProtocolsIdentification id
= null;
104 private WorkspaceTools wt
= new WorkspaceTools();
106 private EnumerationData ed
= new EnumerationData();
109 * This method initializes jTextFieldFeatureFlag
111 * @return javax.swing.JTextField jTextFieldFeatureFlag
114 private JTextField
getJTextFieldFeatureFlag() {
115 if (jTextFieldFeatureFlag
== null) {
116 jTextFieldFeatureFlag
= new JTextField();
117 jTextFieldFeatureFlag
118 .setBounds(new java
.awt
.Rectangle(160, 130, 320, 20));
119 jTextFieldFeatureFlag
.setPreferredSize(new java
.awt
.Dimension(320, 20));
120 jTextFieldFeatureFlag
121 .setToolTipText("Postfix expression that must evaluate to TRUE or FALSE");
123 return jTextFieldFeatureFlag
;
127 * This method initializes jComboBoxUsage
129 * @return javax.swing.JComboBox jComboBoxUsage
132 private JComboBox
getJComboBoxProtocolUsage() {
133 if (jComboBoxUsage
== null) {
134 jComboBoxUsage
= new JComboBox();
135 jComboBoxUsage
.setBounds(new java
.awt
.Rectangle(160, 60, 320, 20));
136 jComboBoxUsage
.setPreferredSize(new java
.awt
.Dimension(320, 20));
138 .setToolTipText("<html><table><tr><td colspan=2 align=center><b>Protocol</b></td></tr>"
139 + "<tr><td>ALWAYS_CONSUMED</td><td>Module always consumes the protocol</td></tr>"
140 + "<tr><td>SOMETIMES_CONSUMES</td><td>Module sometimes consumes the protocol</td></tr>"
141 + "<tr><td>ALWAYS_PRODUCED</td><td>Module always produces the protocol</td></tr>"
142 + "<tr><td>SOMETIMES_PRODUCED</td><td>Module sometimes produces the protocol</td></tr>"
143 + "<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>"
144 + "<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>"
145 + "<tr><td colspan=2 align=center><b>Protocol Notify</b></td></tr>"
146 + "<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>");
148 return jComboBoxUsage
;
152 * This method initializes jScrollPane
154 * @return javax.swing.JScrollPane
156 private JScrollPane
getJScrollPane() {
157 if (jScrollPane
== null) {
158 jScrollPane
= new JScrollPane();
159 jScrollPane
.setViewportView(getJContentPane());
165 * This method initializes jComboBoxProtocolType
167 * @return javax.swing.JComboBox
169 private JComboBox
getJComboBoxProtocolType() {
170 if (jComboBoxProtocolType
== null) {
171 jComboBoxProtocolType
= new JComboBox();
172 jComboBoxProtocolType
.setBounds(new java
.awt
.Rectangle(160, 10, 320, 20));
173 jComboBoxProtocolType
.setPreferredSize(new java
.awt
.Dimension(320, 20));
174 jComboBoxProtocolType
.addItemListener(this);
175 jComboBoxProtocolType
176 .setToolTipText("<html>Select Protocol Type<br>Protocol Notify is a register protocol notify mechanism.");
178 return jComboBoxProtocolType
;
182 * This method initializes jComboBoxCName
184 * @return javax.swing.JComboBox
186 private JComboBox
getJComboBoxCName() {
187 if (jComboBoxCName
== null) {
188 jComboBoxCName
= new JComboBox();
189 jComboBoxCName
.setBounds(new java
.awt
.Rectangle(160, 35, 320, 20));
190 jComboBoxCName
.setPreferredSize(new java
.awt
.Dimension(320, 20));
191 jComboBoxCName
.setToolTipText("Select Guid C Name of the Protocol");
194 return jComboBoxCName
;
198 * This method initializes jTextAreaHelpText
200 * @return javax.swing.JTextArea
203 private JTextArea
getJTextAreaHelpText() {
204 if (jTextAreaHelpText
== null) {
205 jTextAreaHelpText
= new JTextArea();
206 jTextAreaHelpText
.setLineWrap(true);
207 jTextAreaHelpText
.setWrapStyleWord(true);
209 return jTextAreaHelpText
;
213 * This method initializes jScrollPaneHelpText
215 * @return javax.swing.JScrollPane
218 private JScrollPane
getJScrollPaneHelpText() {
219 if (jScrollPaneHelpText
== null) {
220 jScrollPaneHelpText
= new JScrollPane();
222 .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(160, 85));
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, 182, 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, 182, 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 this.setSize(500, 255);
273 this.setContentPane(getJScrollPane());
274 this.setTitle("Protocols");
276 this.setViewMode(false);
281 * This method initializes this Fill values to all fields if these values are
284 * @param inProtocolsId
287 private void init(ProtocolsIdentification inProtocolsId
) {
289 this.id
= inProtocolsId
;
291 if (this.id
!= null) {
292 this.jComboBoxCName
.setSelectedItem(id
.getName());
293 this.jComboBoxProtocolType
.setSelectedItem(id
.getType());
294 this.jComboBoxUsage
.setSelectedItem(id
.getUsage());
295 this.jTextAreaHelpText
.setText(id
.getHelp());
296 this.jTextFieldFeatureFlag
.setText(id
.getFeatureFlag());
297 this.jArchCheckBox
.setSelectedItems(id
.getSupArchList());
302 * This is the override edit constructor
304 * @param inProtocolsIdentification
308 public ProtocolsDlg(ProtocolsIdentification inProtocolsIdentification
,
311 init(inProtocolsIdentification
);
315 * Disable all components when the mode is view
318 * true - The view mode; false - The non-view mode
321 public void setViewMode(boolean isView
) {
323 this.jComboBoxUsage
.setEnabled(!isView
);
324 this.jTextFieldFeatureFlag
.setEnabled(!isView
);
329 * This method initializes jContentPane
331 * @return javax.swing.JPanel jContentPane
334 private JPanel
getJContentPane() {
335 if (jContentPane
== null) {
336 jStarLabel1
= new StarLabel();
337 jStarLabel1
.setLocation(new java
.awt
.Point(2, 10));
338 jLabelProtocolType
= new JLabel();
339 jLabelProtocolType
.setBounds(new java
.awt
.Rectangle(15, 10, 145, 20));
340 jLabelProtocolType
.setText("Select Protocol Type");
342 jStarLabel2
= new StarLabel();
343 jStarLabel2
.setLocation(new java
.awt
.Point(2, 35));
344 jLabelC_Name
= new JLabel();
345 jLabelC_Name
.setText("Protocol Guid C Name");
346 jLabelC_Name
.setBounds(new java
.awt
.Rectangle(15, 35, 145, 20));
348 jStarLabel3
= new StarLabel();
349 jStarLabel3
.setLocation(new java
.awt
.Point(2, 60));
350 jLabelUsage
= new JLabel();
351 jLabelUsage
.setText("Usage");
352 jLabelUsage
.setBounds(new java
.awt
.Rectangle(15, 60, 145, 20));
354 jLabelHelpText
= new JLabel();
355 jLabelHelpText
.setBounds(new java
.awt
.Rectangle(15, 85, 145, 20));
356 jLabelHelpText
.setText("Help Text");
358 jLabelFeatureFlag
= new JLabel();
359 jLabelFeatureFlag
.setText("Feature Flag Expression");
360 jLabelFeatureFlag
.setBounds(new java
.awt
.Rectangle(15, 130, 145, 20));
362 jLabelArch
= new JLabel();
363 jLabelArch
.setBounds(new java
.awt
.Rectangle(15, 155, 145, 20));
364 jLabelArch
.setText("Supported Architectures");
365 jArchCheckBox
= new ArchCheckBox();
366 jArchCheckBox
.setBounds(new java
.awt
.Rectangle(160, 155, 320, 20));
367 jArchCheckBox
.setPreferredSize(new java
.awt
.Dimension(320, 20));
369 jContentPane
= new JPanel();
370 jContentPane
.setLayout(null);
371 jContentPane
.setPreferredSize(new java
.awt
.Dimension(485, 210));
373 jContentPane
.add(jStarLabel1
, null);
374 jContentPane
.add(jLabelProtocolType
, null);
375 jContentPane
.add(getJComboBoxProtocolType(), null);
376 jContentPane
.add(jStarLabel2
, null);
377 jContentPane
.add(jLabelC_Name
, null);
378 jContentPane
.add(getJComboBoxCName(), null);
379 jContentPane
.add(jStarLabel3
, null);
380 jContentPane
.add(jLabelUsage
, null);
381 jContentPane
.add(getJComboBoxProtocolUsage(), null);
382 jContentPane
.add(jLabelHelpText
, null);
383 jContentPane
.add(getJScrollPaneHelpText(), null);
384 jContentPane
.add(jLabelFeatureFlag
, null);
385 jContentPane
.add(getJTextFieldFeatureFlag(), null);
386 jContentPane
.add(jLabelArch
, null);
387 jContentPane
.add(jArchCheckBox
, null);
388 jContentPane
.add(getJButtonOk(), null);
389 jContentPane
.add(getJButtonCancel(), null);
395 * This method initializes Usage type
398 private void initFrame() {
400 .generateComboBoxByVector(jComboBoxProtocolType
, ed
.getVProtocolType());
401 Tools
.generateComboBoxByVector(jComboBoxCName
, wt
402 .getAllProtocolDeclarationsFromWorkspace());
403 Tools
.generateComboBoxByVector(jComboBoxUsage
, ed
.getVProtocolUsage());
409 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
411 * Override actionPerformed to listen all actions
414 public void actionPerformed(ActionEvent arg0
) {
415 if (arg0
.getSource() == jButtonOk
) {
417 getCurrentProtocols();
418 this.returnType
= DataType
.RETURN_TYPE_OK
;
419 this.setVisible(false);
423 if (arg0
.getSource() == jButtonCancel
) {
424 this.returnType
= DataType
.RETURN_TYPE_CANCEL
;
425 this.setVisible(false);
430 * Data validation for all fields
432 * @retval true - All datas are valid
433 * @retval false - At least one data is invalid
436 public boolean checkAdd() {
438 // Check if all fields have correct data types
444 if (!isEmpty(this.jComboBoxCName
.getSelectedItem().toString())) {
445 if (!DataValidation
.isC_NameType(this.jComboBoxCName
.getSelectedItem()
447 Log
.wrn("Update Protocols",
448 "Incorrect data type for Protocol/ProtocolNotify Name");
456 if (!isEmpty(this.jTextFieldFeatureFlag
.getText())) {
457 if (!DataValidation
.isFeatureFlag(this.jTextFieldFeatureFlag
.getText())) {
458 Log
.wrn("Update Protocols", "Incorrect data type for Feature Flag");
466 private ProtocolsIdentification
getCurrentProtocols() {
467 String arg0
= this.jComboBoxCName
.getSelectedItem().toString();
468 String arg1
= this.jComboBoxProtocolType
.getSelectedItem().toString();
469 String arg2
= this.jComboBoxUsage
.getSelectedItem().toString();
471 String arg3
= this.jTextFieldFeatureFlag
.getText();
472 Vector
<String
> arg4
= this.jArchCheckBox
.getSelectedItemsVector();
473 String arg5
= this.jTextAreaHelpText
.getText();
474 id
= new ProtocolsIdentification(arg0
, arg1
, arg2
, arg3
, arg4
, arg5
);
481 * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
483 * Reflesh the frame when selected item changed
487 public void itemStateChanged(ItemEvent arg0
) {
488 if (arg0
.getSource() == this.jComboBoxProtocolType
489 && arg0
.getStateChange() == ItemEvent
.SELECTED
) {
490 if (this.jComboBoxProtocolType
.getSelectedItem().toString().equals(
491 ed
.getVProtocolType().get(0))) {
492 Tools
.generateComboBoxByVector(this.jComboBoxUsage
, ed
493 .getVProtocolUsage());
495 Tools
.generateComboBoxByVector(this.jComboBoxUsage
, ed
496 .getVProtocolNotifyUsage());
501 public ProtocolsIdentification
getId() {
505 public void setId(ProtocolsIdentification id
) {