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
.setBounds(new java
.awt
.Rectangle(160, 130, 320, 20));
118 jTextFieldFeatureFlag
.setPreferredSize(new java
.awt
.Dimension(320, 20));
119 jTextFieldFeatureFlag
.setToolTipText("Postfix expression that must evaluate to TRUE or FALSE");
121 return jTextFieldFeatureFlag
;
125 * This method initializes jComboBoxUsage
127 * @return javax.swing.JComboBox jComboBoxUsage
130 private JComboBox
getJComboBoxProtocolUsage() {
131 if (jComboBoxUsage
== null) {
132 jComboBoxUsage
= new JComboBox();
133 jComboBoxUsage
.setBounds(new java
.awt
.Rectangle(160, 60, 320, 20));
134 jComboBoxUsage
.setPreferredSize(new java
.awt
.Dimension(320, 20));
136 .setToolTipText("<html><table><tr><td colspan=2 align=center><b>Protocol</b></td></tr>"
137 + "<tr><td>ALWAYS_CONSUMED</td><td>Module always consumes the protocol</td></tr>"
138 + "<tr><td>SOMETIMES_CONSUMES</td><td>Module sometimes consumes the protocol</td></tr>"
139 + "<tr><td>ALWAYS_PRODUCED</td><td>Module always produces the protocol</td></tr>"
140 + "<tr><td>SOMETIMES_PRODUCED</td><td>Module sometimes produces the protocol</td></tr>"
141 + "<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>"
142 + "<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>"
143 + "<tr><td colspan=2 align=center><b>Protocol Notify</b></td></tr>"
144 + "<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>");
146 return jComboBoxUsage
;
150 * This method initializes jScrollPane
152 * @return javax.swing.JScrollPane
154 private JScrollPane
getJScrollPane() {
155 if (jScrollPane
== null) {
156 jScrollPane
= new JScrollPane();
157 jScrollPane
.setViewportView(getJContentPane());
163 * This method initializes jComboBoxProtocolType
165 * @return javax.swing.JComboBox
167 private JComboBox
getJComboBoxProtocolType() {
168 if (jComboBoxProtocolType
== null) {
169 jComboBoxProtocolType
= new JComboBox();
170 jComboBoxProtocolType
.setBounds(new java
.awt
.Rectangle(160, 10, 320, 20));
171 jComboBoxProtocolType
.setPreferredSize(new java
.awt
.Dimension(320, 20));
172 jComboBoxProtocolType
.addItemListener(this);
173 jComboBoxProtocolType
174 .setToolTipText("<html>Select Protocol Type<br>Protocol Notify is a register protocol notify mechanism.");
176 return jComboBoxProtocolType
;
180 * This method initializes jComboBoxCName
182 * @return javax.swing.JComboBox
184 private JComboBox
getJComboBoxCName() {
185 if (jComboBoxCName
== null) {
186 jComboBoxCName
= new JComboBox();
187 jComboBoxCName
.setBounds(new java
.awt
.Rectangle(160, 35, 320, 20));
188 jComboBoxCName
.setPreferredSize(new java
.awt
.Dimension(320, 20));
189 jComboBoxCName
.setToolTipText("Select Guid C Name of the Protocol");
192 return jComboBoxCName
;
196 * This method initializes jTextAreaHelpText
198 * @return javax.swing.JTextArea
201 private JTextArea
getJTextAreaHelpText() {
202 if (jTextAreaHelpText
== null) {
203 jTextAreaHelpText
= new JTextArea();
204 jTextAreaHelpText
.setLineWrap(true);
205 jTextAreaHelpText
.setWrapStyleWord(true);
207 return jTextAreaHelpText
;
211 * This method initializes jScrollPaneHelpText
213 * @return javax.swing.JScrollPane
216 private JScrollPane
getJScrollPaneHelpText() {
217 if (jScrollPaneHelpText
== null) {
218 jScrollPaneHelpText
= new JScrollPane();
219 jScrollPaneHelpText
.setHorizontalScrollBarPolicy(javax
.swing
.JScrollPane
.HORIZONTAL_SCROLLBAR_NEVER
);
220 jScrollPaneHelpText
.setSize(new java
.awt
.Dimension(320, 40));
221 jScrollPaneHelpText
.setPreferredSize(new java
.awt
.Dimension(320, 40));
222 jScrollPaneHelpText
.setLocation(new java
.awt
.Point(160, 85));
223 jScrollPaneHelpText
.setViewportView(getJTextAreaHelpText());
225 return jScrollPaneHelpText
;
229 * This method initializes jButtonOk
231 * @return javax.swing.JButton
234 private JButton
getJButtonOk() {
235 if (jButtonOk
== null) {
236 jButtonOk
= new JButton();
237 jButtonOk
.setBounds(new java
.awt
.Rectangle(290, 182, 90, 20));
238 jButtonOk
.setText("Ok");
239 jButtonOk
.addActionListener(this);
245 * This method initializes jButtonCancel
247 * @return javax.swing.JButton
250 private JButton
getJButtonCancel() {
251 if (jButtonCancel
== null) {
252 jButtonCancel
= new JButton();
253 jButtonCancel
.setBounds(new java
.awt
.Rectangle(390, 182, 90, 20));
254 jButtonCancel
.setText("Cancel");
255 jButtonCancel
.addActionListener(this);
257 return jButtonCancel
;
260 public static void main(String
[] args
) {
265 * This method initializes this
268 private void init() {
269 this.setSize(500, 255);
270 this.setContentPane(getJScrollPane());
271 this.setTitle("Protocols");
273 this.setViewMode(false);
278 * This method initializes this Fill values to all fields if these values are
281 * @param inProtocolsId
284 private void init(ProtocolsIdentification inProtocolsId
) {
286 this.id
= inProtocolsId
;
288 if (this.id
!= null) {
289 this.jComboBoxCName
.setSelectedItem(id
.getName());
290 this.jComboBoxProtocolType
.setSelectedItem(id
.getType());
291 this.jComboBoxUsage
.setSelectedItem(id
.getUsage());
292 this.jTextAreaHelpText
.setText(id
.getHelp());
293 this.jTextFieldFeatureFlag
.setText(id
.getFeatureFlag());
294 this.jArchCheckBox
.setSelectedItems(id
.getSupArchList());
299 * This is the override edit constructor
301 * @param inProtocolsIdentification
305 public ProtocolsDlg(ProtocolsIdentification inProtocolsIdentification
, IFrame iFrame
) {
307 init(inProtocolsIdentification
);
311 * Disable all components when the mode is view
314 * true - The view mode; false - The non-view mode
317 public void setViewMode(boolean isView
) {
319 this.jComboBoxUsage
.setEnabled(!isView
);
320 this.jTextFieldFeatureFlag
.setEnabled(!isView
);
325 * This method initializes jContentPane
327 * @return javax.swing.JPanel jContentPane
330 private JPanel
getJContentPane() {
331 if (jContentPane
== null) {
332 jStarLabel1
= new StarLabel();
333 jStarLabel1
.setLocation(new java
.awt
.Point(2, 10));
334 jLabelProtocolType
= new JLabel();
335 jLabelProtocolType
.setBounds(new java
.awt
.Rectangle(15, 10, 145, 20));
336 jLabelProtocolType
.setText("Select Protocol Type");
338 jStarLabel2
= new StarLabel();
339 jStarLabel2
.setLocation(new java
.awt
.Point(2, 35));
340 jLabelC_Name
= new JLabel();
341 jLabelC_Name
.setText("Protocol Guid C Name");
342 jLabelC_Name
.setBounds(new java
.awt
.Rectangle(15, 35, 145, 20));
344 jStarLabel3
= new StarLabel();
345 jStarLabel3
.setLocation(new java
.awt
.Point(2, 60));
346 jLabelUsage
= new JLabel();
347 jLabelUsage
.setText("Usage");
348 jLabelUsage
.setBounds(new java
.awt
.Rectangle(15, 60, 145, 20));
350 jLabelHelpText
= new JLabel();
351 jLabelHelpText
.setBounds(new java
.awt
.Rectangle(15, 85, 145, 20));
352 jLabelHelpText
.setText("Help Text");
354 jLabelFeatureFlag
= new JLabel();
355 jLabelFeatureFlag
.setText("Feature Flag Expression");
356 jLabelFeatureFlag
.setBounds(new java
.awt
.Rectangle(15, 130, 145, 20));
358 jLabelArch
= new JLabel();
359 jLabelArch
.setBounds(new java
.awt
.Rectangle(15, 155, 145, 20));
360 jLabelArch
.setText("Supported Architectures");
361 jArchCheckBox
= new ArchCheckBox();
362 jArchCheckBox
.setBounds(new java
.awt
.Rectangle(160, 155, 320, 20));
363 jArchCheckBox
.setPreferredSize(new java
.awt
.Dimension(320, 20));
365 jContentPane
= new JPanel();
366 jContentPane
.setLayout(null);
367 jContentPane
.setPreferredSize(new java
.awt
.Dimension(485, 210));
369 jContentPane
.add(jStarLabel1
, null);
370 jContentPane
.add(jLabelProtocolType
, null);
371 jContentPane
.add(getJComboBoxProtocolType(), null);
372 jContentPane
.add(jStarLabel2
, null);
373 jContentPane
.add(jLabelC_Name
, null);
374 jContentPane
.add(getJComboBoxCName(), null);
375 jContentPane
.add(jStarLabel3
, null);
376 jContentPane
.add(jLabelUsage
, null);
377 jContentPane
.add(getJComboBoxProtocolUsage(), null);
378 jContentPane
.add(jLabelHelpText
, null);
379 jContentPane
.add(getJScrollPaneHelpText(), null);
380 jContentPane
.add(jLabelFeatureFlag
, null);
381 jContentPane
.add(getJTextFieldFeatureFlag(), null);
382 jContentPane
.add(jLabelArch
, null);
383 jContentPane
.add(jArchCheckBox
, null);
384 jContentPane
.add(getJButtonOk(), null);
385 jContentPane
.add(getJButtonCancel(), null);
391 * This method initializes Usage type
394 private void initFrame() {
395 Tools
.generateComboBoxByVector(jComboBoxProtocolType
, ed
.getVProtocolType());
396 Tools
.generateComboBoxByVector(jComboBoxCName
, wt
.getAllProtocolDeclarationsFromWorkspace());
397 Tools
.generateComboBoxByVector(jComboBoxUsage
, ed
.getVProtocolUsage());
403 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
405 * Override actionPerformed to listen all actions
408 public void actionPerformed(ActionEvent arg0
) {
409 if (arg0
.getSource() == jButtonOk
) {
411 getCurrentProtocols();
412 this.returnType
= DataType
.RETURN_TYPE_OK
;
413 this.setVisible(false);
417 if (arg0
.getSource() == jButtonCancel
) {
418 this.returnType
= DataType
.RETURN_TYPE_CANCEL
;
419 this.setVisible(false);
424 * Data validation for all fields
426 * @retval true - All datas are valid
427 * @retval false - At least one data is invalid
430 public boolean checkAdd() {
432 // Check if all fields have correct data types
438 if (!isEmpty(this.jComboBoxCName
.getSelectedItem().toString())) {
439 if (!DataValidation
.isC_NameType(this.jComboBoxCName
.getSelectedItem().toString())) {
440 Log
.wrn("Update Protocols", "Incorrect data type for Protocol/ProtocolNotify Name");
448 if (!isEmpty(this.jTextFieldFeatureFlag
.getText())) {
449 if (!DataValidation
.isFeatureFlag(this.jTextFieldFeatureFlag
.getText())) {
450 Log
.wrn("Update Protocols", "Incorrect data type for Feature Flag");
458 private ProtocolsIdentification
getCurrentProtocols() {
459 String arg0
= this.jComboBoxCName
.getSelectedItem().toString();
460 String arg1
= this.jComboBoxProtocolType
.getSelectedItem().toString();
461 String arg2
= this.jComboBoxUsage
.getSelectedItem().toString();
463 String arg3
= this.jTextFieldFeatureFlag
.getText();
464 Vector
<String
> arg4
= this.jArchCheckBox
.getSelectedItemsVector();
465 String arg5
= this.jTextAreaHelpText
.getText();
466 id
= new ProtocolsIdentification(arg0
, arg1
, arg2
, arg3
, arg4
, arg5
);
473 * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
475 * Reflesh the frame when selected item changed
479 public void itemStateChanged(ItemEvent arg0
) {
480 if (arg0
.getSource() == this.jComboBoxProtocolType
&& arg0
.getStateChange() == ItemEvent
.SELECTED
) {
481 if (this.jComboBoxProtocolType
.getSelectedItem().toString().equals(ed
.getVProtocolType().get(0))) {
482 Tools
.generateComboBoxByVector(this.jComboBoxUsage
, ed
.getVProtocolUsage());
484 Tools
.generateComboBoxByVector(this.jComboBoxUsage
, ed
.getVProtocolNotifyUsage());
489 public ProtocolsIdentification
getId() {
493 public void setId(ProtocolsIdentification id
) {