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/MBD file
48 public class ProtocolsDlg
extends IDialog
implements ItemListener
{
51 // / Define class Serial Version UID
53 private static final long serialVersionUID
= -9084913640747858848L;
56 // Define class members
58 private JPanel jContentPane
= null;
60 private JLabel jLabelC_Name
= null;
62 private JLabel jLabelFeatureFlag
= null;
64 private JTextField jTextFieldFeatureFlag
= null;
66 private JLabel jLabelUsage
= null;
68 private JComboBox jComboBoxUsage
= null;
70 private StarLabel jStarLabel1
= null;
72 private StarLabel jStarLabel2
= null;
74 private StarLabel jStarLabel3
= null;
76 private JLabel jLabelProtocolType
= null;
78 private JLabel jLabelArch
= null;
80 private JScrollPane jScrollPane
= null;
82 private JComboBox jComboBoxProtocolType
= null;
84 private JComboBox jComboBoxCName
= null;
86 private JLabel jLabelHelpText
= null;
88 private JTextArea jTextAreaHelpText
= null;
90 private JScrollPane jScrollPaneHelpText
= null;
92 private ArchCheckBox jArchCheckBox
= null;
94 private JButton jButtonOk
= null;
96 private JButton jButtonCancel
= null;
101 private ProtocolsIdentification id
= null;
103 private WorkspaceTools wt
= new WorkspaceTools();
105 private EnumerationData ed
= new EnumerationData();
108 * This method initializes jTextFieldFeatureFlag
110 * @return javax.swing.JTextField jTextFieldFeatureFlag
113 private JTextField
getJTextFieldFeatureFlag() {
114 if (jTextFieldFeatureFlag
== null) {
115 jTextFieldFeatureFlag
= new JTextField();
116 jTextFieldFeatureFlag
117 .setBounds(new java
.awt
.Rectangle(160, 130, 320, 20));
118 jTextFieldFeatureFlag
.setPreferredSize(new java
.awt
.Dimension(320, 20));
119 jTextFieldFeatureFlag
120 .setToolTipText("Postfix expression that must evaluate to TRUE or FALSE");
122 return jTextFieldFeatureFlag
;
126 * This method initializes jComboBoxUsage
128 * @return javax.swing.JComboBox jComboBoxUsage
131 private JComboBox
getJComboBoxProtocolUsage() {
132 if (jComboBoxUsage
== null) {
133 jComboBoxUsage
= new JComboBox();
134 jComboBoxUsage
.setBounds(new java
.awt
.Rectangle(160, 60, 320, 20));
135 jComboBoxUsage
.setPreferredSize(new java
.awt
.Dimension(320, 20));
137 .setToolTipText("<html><table><tr><td colspan=2>Protocol</td></tr><tr><td>ALWAYS_CONSUMED</td><td>Module always consumes the protocol</td></tr><tr><td>SOMETIMES_CONSUMES</td><td>Module sometimes consumes the protocol</td></tr><tr><td>ALWAYS_PRODUCED</td><td>Module always produces the protocol</td></tr><tr><td>SOMETIMES_PRODUCED</td><td>Module sometimes produces the protocol</td></tr><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><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><tr><td colspan=2>Protocol Notify</td></tr><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>");
139 return jComboBoxUsage
;
143 * This method initializes jScrollPane
145 * @return javax.swing.JScrollPane
147 private JScrollPane
getJScrollPane() {
148 if (jScrollPane
== null) {
149 jScrollPane
= new JScrollPane();
150 jScrollPane
.setViewportView(getJContentPane());
156 * This method initializes jComboBoxProtocolType
158 * @return javax.swing.JComboBox
160 private JComboBox
getJComboBoxProtocolType() {
161 if (jComboBoxProtocolType
== null) {
162 jComboBoxProtocolType
= new JComboBox();
163 jComboBoxProtocolType
.setBounds(new java
.awt
.Rectangle(160, 10, 320, 20));
164 jComboBoxProtocolType
.setPreferredSize(new java
.awt
.Dimension(320, 20));
165 jComboBoxProtocolType
.addItemListener(this);
166 jComboBoxProtocolType
167 .setToolTipText("<html>Select Protocol Type<br>Protocol Notify is a register protocol notify mechanism.");
169 return jComboBoxProtocolType
;
173 * This method initializes jComboBoxCName
175 * @return javax.swing.JComboBox
177 private JComboBox
getJComboBoxCName() {
178 if (jComboBoxCName
== null) {
179 jComboBoxCName
= new JComboBox();
180 jComboBoxCName
.setBounds(new java
.awt
.Rectangle(160, 35, 320, 20));
181 jComboBoxCName
.setPreferredSize(new java
.awt
.Dimension(320, 20));
182 jComboBoxCName
.setToolTipText("Select Guid C Name of the Protocol");
185 return jComboBoxCName
;
189 * This method initializes jTextAreaHelpText
191 * @return javax.swing.JTextArea
194 private JTextArea
getJTextAreaHelpText() {
195 if (jTextAreaHelpText
== null) {
196 jTextAreaHelpText
= new JTextArea();
197 jTextAreaHelpText
.setLineWrap(true);
198 jTextAreaHelpText
.setWrapStyleWord(true);
200 return jTextAreaHelpText
;
204 * This method initializes jScrollPaneHelpText
206 * @return javax.swing.JScrollPane
209 private JScrollPane
getJScrollPaneHelpText() {
210 if (jScrollPaneHelpText
== null) {
211 jScrollPaneHelpText
= new JScrollPane();
213 .setHorizontalScrollBarPolicy(javax
.swing
.JScrollPane
.HORIZONTAL_SCROLLBAR_NEVER
);
214 jScrollPaneHelpText
.setSize(new java
.awt
.Dimension(320, 40));
215 jScrollPaneHelpText
.setPreferredSize(new java
.awt
.Dimension(320, 40));
216 jScrollPaneHelpText
.setLocation(new java
.awt
.Point(160, 85));
217 jScrollPaneHelpText
.setViewportView(getJTextAreaHelpText());
219 return jScrollPaneHelpText
;
223 * This method initializes jButtonOk
225 * @return javax.swing.JButton
228 private JButton
getJButtonOk() {
229 if (jButtonOk
== null) {
230 jButtonOk
= new JButton();
231 jButtonOk
.setBounds(new java
.awt
.Rectangle(290, 182, 90, 20));
232 jButtonOk
.setText("Ok");
233 jButtonOk
.addActionListener(this);
239 * This method initializes jButtonCancel
241 * @return javax.swing.JButton
244 private JButton
getJButtonCancel() {
245 if (jButtonCancel
== null) {
246 jButtonCancel
= new JButton();
247 jButtonCancel
.setBounds(new java
.awt
.Rectangle(390, 182, 90, 20));
248 jButtonCancel
.setText("Cancel");
249 jButtonCancel
.addActionListener(this);
251 return jButtonCancel
;
254 public static void main(String
[] args
) {
259 * This method initializes this
262 private void init() {
263 this.setSize(500, 255);
264 this.setContentPane(getJScrollPane());
265 this.setTitle("Protocols");
267 this.setViewMode(false);
272 * This method initializes this Fill values to all fields if these values are
275 * @param inProtocolsId
278 private void init(ProtocolsIdentification inProtocolsId
) {
280 this.id
= inProtocolsId
;
282 if (this.id
!= null) {
283 this.jComboBoxCName
.setSelectedItem(id
.getName());
284 this.jComboBoxProtocolType
.setSelectedItem(id
.getType());
285 this.jComboBoxUsage
.setSelectedItem(id
.getUsage());
286 this.jTextAreaHelpText
.setText(id
.getHelp());
287 this.jTextFieldFeatureFlag
.setText(id
.getFeatureFlag());
288 this.jArchCheckBox
.setSelectedItems(id
.getSupArchList());
293 * This is the override edit constructor
295 * @param inProtocolsIdentification
299 public ProtocolsDlg(ProtocolsIdentification inProtocolsIdentification
,
302 init(inProtocolsIdentification
);
306 * Disable all components when the mode is view
309 * true - The view mode; false - The non-view mode
312 public void setViewMode(boolean isView
) {
314 this.jComboBoxUsage
.setEnabled(!isView
);
315 this.jTextFieldFeatureFlag
.setEnabled(!isView
);
320 * This method initializes jContentPane
322 * @return javax.swing.JPanel jContentPane
325 private JPanel
getJContentPane() {
326 if (jContentPane
== null) {
327 jStarLabel1
= new StarLabel();
328 jStarLabel1
.setLocation(new java
.awt
.Point(2, 10));
329 jLabelProtocolType
= new JLabel();
330 jLabelProtocolType
.setBounds(new java
.awt
.Rectangle(15, 10, 145, 20));
331 jLabelProtocolType
.setText("Select Protocol Type");
333 jStarLabel2
= new StarLabel();
334 jStarLabel2
.setLocation(new java
.awt
.Point(2, 35));
335 jLabelC_Name
= new JLabel();
336 jLabelC_Name
.setText("Protocol Guid C Name");
337 jLabelC_Name
.setBounds(new java
.awt
.Rectangle(15, 35, 145, 20));
339 jStarLabel3
= new StarLabel();
340 jStarLabel3
.setLocation(new java
.awt
.Point(2, 60));
341 jLabelUsage
= new JLabel();
342 jLabelUsage
.setText("Usage");
343 jLabelUsage
.setBounds(new java
.awt
.Rectangle(15, 60, 145, 20));
345 jLabelHelpText
= new JLabel();
346 jLabelHelpText
.setBounds(new java
.awt
.Rectangle(15, 85, 145, 20));
347 jLabelHelpText
.setText("Help Text");
349 jLabelFeatureFlag
= new JLabel();
350 jLabelFeatureFlag
.setText("Feature Flag Expression");
351 jLabelFeatureFlag
.setBounds(new java
.awt
.Rectangle(15, 130, 145, 20));
353 jLabelArch
= new JLabel();
354 jLabelArch
.setBounds(new java
.awt
.Rectangle(15, 155, 145, 20));
355 jLabelArch
.setText("Supported Architectures");
356 jArchCheckBox
= new ArchCheckBox();
357 jArchCheckBox
.setBounds(new java
.awt
.Rectangle(160, 155, 320, 20));
358 jArchCheckBox
.setPreferredSize(new java
.awt
.Dimension(320, 20));
360 jContentPane
= new JPanel();
361 jContentPane
.setLayout(null);
362 jContentPane
.setPreferredSize(new java
.awt
.Dimension(485, 210));
364 jContentPane
.add(jStarLabel1
, null);
365 jContentPane
.add(jLabelProtocolType
, null);
366 jContentPane
.add(getJComboBoxProtocolType(), null);
367 jContentPane
.add(jStarLabel2
, null);
368 jContentPane
.add(jLabelC_Name
, null);
369 jContentPane
.add(getJComboBoxCName(), null);
370 jContentPane
.add(jStarLabel3
, null);
371 jContentPane
.add(jLabelUsage
, null);
372 jContentPane
.add(getJComboBoxProtocolUsage(), null);
373 jContentPane
.add(jLabelHelpText
, null);
374 jContentPane
.add(getJScrollPaneHelpText(), null);
375 jContentPane
.add(jLabelFeatureFlag
, null);
376 jContentPane
.add(getJTextFieldFeatureFlag(), null);
377 jContentPane
.add(jLabelArch
, null);
378 jContentPane
.add(jArchCheckBox
, null);
379 jContentPane
.add(getJButtonOk(), null);
380 jContentPane
.add(getJButtonCancel(), null);
386 * This method initializes Usage type
389 private void initFrame() {
391 .generateComboBoxByVector(jComboBoxProtocolType
, ed
.getVProtocolType());
392 Tools
.generateComboBoxByVector(jComboBoxCName
, wt
393 .getAllProtocolDeclarationsFromWorkspace());
394 Tools
.generateComboBoxByVector(jComboBoxUsage
, ed
.getVProtocolUsage());
400 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
402 * Override actionPerformed to listen all actions
405 public void actionPerformed(ActionEvent arg0
) {
406 if (arg0
.getSource() == jButtonOk
) {
408 getCurrentProtocols();
409 this.returnType
= DataType
.RETURN_TYPE_OK
;
410 this.setVisible(false);
414 if (arg0
.getSource() == jButtonCancel
) {
415 this.returnType
= DataType
.RETURN_TYPE_CANCEL
;
416 this.setVisible(false);
421 * Data validation for all fields
423 * @retval true - All datas are valid
424 * @retval false - At least one data is invalid
427 public boolean checkAdd() {
429 // Check if all fields have correct data types
435 if (!isEmpty(this.jComboBoxCName
.getSelectedItem().toString())) {
436 if (!DataValidation
.isC_NameType(this.jComboBoxCName
.getSelectedItem()
438 Log
.wrn("Update Protocols",
439 "Incorrect data type for Protocol/ProtocolNotify Name");
447 if (!isEmpty(this.jTextFieldFeatureFlag
.getText())) {
448 if (!DataValidation
.isFeatureFlag(this.jTextFieldFeatureFlag
.getText())) {
449 Log
.wrn("Update Protocols", "Incorrect data type for Feature Flag");
457 private ProtocolsIdentification
getCurrentProtocols() {
458 String arg0
= this.jComboBoxCName
.getSelectedItem().toString();
459 String arg1
= this.jComboBoxProtocolType
.getSelectedItem().toString();
460 String arg2
= this.jComboBoxUsage
.getSelectedItem().toString();
462 String arg3
= this.jTextFieldFeatureFlag
.getText();
463 Vector
<String
> arg4
= this.jArchCheckBox
.getSelectedItemsVector();
464 String arg5
= this.jTextAreaHelpText
.getText();
465 id
= new ProtocolsIdentification(arg0
, arg1
, arg2
, arg3
, arg4
, arg5
);
472 * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
474 * Reflesh the frame when selected item changed
478 public void itemStateChanged(ItemEvent arg0
) {
479 if (arg0
.getSource() == this.jComboBoxProtocolType
480 && arg0
.getStateChange() == ItemEvent
.SELECTED
) {
481 if (this.jComboBoxProtocolType
.getSelectedItem().toString().equals(
482 ed
.getVProtocolType().get(0))) {
483 Tools
.generateComboBoxByVector(this.jComboBoxUsage
, ed
484 .getVProtocolUsage());
486 Tools
.generateComboBoxByVector(this.jComboBoxUsage
, ed
487 .getVProtocolNotifyUsage());
492 public ProtocolsIdentification
getId() {
496 public void setId(ProtocolsIdentification id
) {