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
;
30 import org
.tianocore
.frameworkwizard
.common
.DataType
;
31 import org
.tianocore
.frameworkwizard
.common
.DataValidation
;
32 import org
.tianocore
.frameworkwizard
.common
.EnumerationData
;
33 import org
.tianocore
.frameworkwizard
.common
.Log
;
34 import org
.tianocore
.frameworkwizard
.common
.Tools
;
35 import org
.tianocore
.frameworkwizard
.common
.ui
.ArchCheckBox
;
36 import org
.tianocore
.frameworkwizard
.common
.ui
.IDialog
;
37 import org
.tianocore
.frameworkwizard
.common
.ui
.IFrame
;
38 import org
.tianocore
.frameworkwizard
.common
.ui
.StarLabel
;
39 import org
.tianocore
.frameworkwizard
.module
.Identifications
.Protocols
.ProtocolsIdentification
;
40 import org
.tianocore
.frameworkwizard
.workspace
.WorkspaceTools
;
43 The class is used to create, update Protocol of MSA/MBD file
44 It extends IInternalFrame
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 JLabel jLabelProtocolType
= null;
77 private JLabel jLabelArch
= null;
79 private JScrollPane jScrollPane
= null;
81 private JComboBox jComboBoxProtocolType
= null;
83 private JComboBox jComboBoxCName
= null;
85 private JLabel jLabelHelpText
= null;
87 private JTextField jTextFieldHelpText
= null;
89 private ArchCheckBox jArchCheckBox
= null;
91 private JButton jButtonOk
= null;
93 private JButton jButtonCancel
= null;
98 private ProtocolsIdentification id
= null;
100 private WorkspaceTools wt
= new WorkspaceTools();
102 private EnumerationData ed
= new EnumerationData();
105 This method initializes jTextFieldFeatureFlag
107 @return javax.swing.JTextField jTextFieldFeatureFlag
110 private JTextField
getJTextFieldFeatureFlag() {
111 if (jTextFieldFeatureFlag
== null) {
112 jTextFieldFeatureFlag
= new JTextField();
113 jTextFieldFeatureFlag
.setBounds(new java
.awt
.Rectangle(160, 110, 320, 20));
114 jTextFieldFeatureFlag
.setPreferredSize(new java
.awt
.Dimension(320, 20));
116 return jTextFieldFeatureFlag
;
120 This method initializes jComboBoxUsage
122 @return javax.swing.JComboBox jComboBoxUsage
125 private JComboBox
getJComboBoxProtocolUsage() {
126 if (jComboBoxUsage
== null) {
127 jComboBoxUsage
= new JComboBox();
128 jComboBoxUsage
.setBounds(new java
.awt
.Rectangle(160, 60, 320, 20));
129 jComboBoxUsage
.setPreferredSize(new java
.awt
.Dimension(320, 20));
130 jComboBoxUsage
.setToolTipText("ALWAYS_CONSUMED is the only valid usage for type ProtocolNotify.");
132 return jComboBoxUsage
;
136 This method initializes jScrollPane
138 @return javax.swing.JScrollPane
140 private JScrollPane
getJScrollPane() {
141 if (jScrollPane
== null) {
142 jScrollPane
= new JScrollPane();
143 jScrollPane
.setViewportView(getJContentPane());
149 * This method initializes jComboBoxProtocolType
151 * @return javax.swing.JComboBox
153 private JComboBox
getJComboBoxProtocolType() {
154 if (jComboBoxProtocolType
== null) {
155 jComboBoxProtocolType
= new JComboBox();
156 jComboBoxProtocolType
.setBounds(new java
.awt
.Rectangle(160, 10, 320, 20));
157 jComboBoxProtocolType
.setPreferredSize(new java
.awt
.Dimension(320, 20));
158 jComboBoxProtocolType
.addItemListener(this);
159 jComboBoxProtocolType
.setToolTipText("<html>Select Protocol Type<br>Protocol Notify is a register protocol notify mechanism.");
161 return jComboBoxProtocolType
;
165 * This method initializes jComboBoxCName
167 * @return javax.swing.JComboBox
169 private JComboBox
getJComboBoxCName() {
170 if (jComboBoxCName
== null) {
171 jComboBoxCName
= new JComboBox();
172 jComboBoxCName
.setBounds(new java
.awt
.Rectangle(160, 35, 320, 20));
173 jComboBoxCName
.setPreferredSize(new java
.awt
.Dimension(320, 20));
174 jComboBoxCName
.setToolTipText("Select Guid C Name of the Protocol");
177 return jComboBoxCName
;
181 This method initializes jTextFieldHelpText
183 @return javax.swing.JTextField
186 private JTextField
getJTextFieldHelpText() {
187 if (jTextFieldHelpText
== null) {
188 jTextFieldHelpText
= new JTextField();
189 jTextFieldHelpText
.setBounds(new java
.awt
.Rectangle(160, 85, 320, 20));
190 jTextFieldHelpText
.setPreferredSize(new java
.awt
.Dimension(320, 20));
192 return jTextFieldHelpText
;
196 This method initializes jButtonOk
198 @return javax.swing.JButton
201 private JButton
getJButtonOk() {
202 if (jButtonOk
== null) {
203 jButtonOk
= new JButton();
204 jButtonOk
.setBounds(new java
.awt
.Rectangle(290, 165, 90, 20));
205 jButtonOk
.setText("Ok");
206 jButtonOk
.addActionListener(this);
212 This method initializes jButtonCancel
214 @return javax.swing.JButton
217 private JButton
getJButtonCancel() {
218 if (jButtonCancel
== null) {
219 jButtonCancel
= new JButton();
220 jButtonCancel
.setBounds(new java
.awt
.Rectangle(390, 165, 90, 20));
221 jButtonCancel
.setText("Cancel");
222 jButtonCancel
.addActionListener(this);
224 return jButtonCancel
;
227 public static void main(String
[] args
) {
232 This method initializes this
235 private void init() {
236 this.setSize(510, 240);
237 this.setContentPane(getJScrollPane());
238 this.setTitle("Protocols");
240 this.setViewMode(false);
245 This method initializes this
246 Fill values to all fields if these values are not empty
251 private void init(ProtocolsIdentification inProtocolsId
) {
253 this.id
= inProtocolsId
;
255 if (this.id
!= null) {
256 this.jComboBoxCName
.setSelectedItem(id
.getName());
257 this.jComboBoxProtocolType
.setSelectedItem(id
.getType());
258 this.jComboBoxUsage
.setSelectedItem(id
.getUsage());
259 this.jTextFieldHelpText
.setText(id
.getHelp());
261 jTextFieldFeatureFlag
.setText(id
.getFeatureFlag());
262 this.jArchCheckBox
.setSelectedItems(id
.getSupArchList());
267 This is the override edit constructor
269 @param inProtocolsIdentification
273 public ProtocolsDlg(ProtocolsIdentification inProtocolsIdentification
, IFrame iFrame
) {
275 init(inProtocolsIdentification
);
279 Disable all components when the mode is view
281 @param isView true - The view mode; false - The non-view mode
284 public void setViewMode(boolean isView
) {
286 this.jComboBoxUsage
.setEnabled(!isView
);
287 this.jTextFieldFeatureFlag
.setEnabled(!isView
);
292 This method initializes jContentPane
294 @return javax.swing.JPanel jContentPane
297 private JPanel
getJContentPane() {
298 if (jContentPane
== null) {
299 jArchCheckBox
= new ArchCheckBox();
300 jArchCheckBox
.setBounds(new java
.awt
.Rectangle(160, 135, 320, 20));
301 jArchCheckBox
.setPreferredSize(new java
.awt
.Dimension(320, 20));
302 jLabelHelpText
= new JLabel();
303 jLabelHelpText
.setBounds(new java
.awt
.Rectangle(14, 85, 140, 20));
304 jLabelHelpText
.setText("Help Text");
305 jLabelArch
= new JLabel();
306 jLabelArch
.setBounds(new java
.awt
.Rectangle(15, 135, 140, 20));
307 jLabelArch
.setText("Arch Type");
308 jLabelProtocolType
= new JLabel();
309 jLabelProtocolType
.setBounds(new java
.awt
.Rectangle(15, 10, 140, 20));
310 jLabelProtocolType
.setText("Protocol Type");
311 jLabelUsage
= new JLabel();
312 jLabelUsage
.setText("Usage");
313 jLabelUsage
.setBounds(new java
.awt
.Rectangle(15, 60, 140, 20));
314 jLabelFeatureFlag
= new JLabel();
315 jLabelFeatureFlag
.setText("Feature Flag");
316 jLabelFeatureFlag
.setBounds(new java
.awt
.Rectangle(15, 110, 140, 20));
317 jLabelC_Name
= new JLabel();
318 jLabelC_Name
.setText("C Name Type");
319 jLabelC_Name
.setBounds(new java
.awt
.Rectangle(15, 35, 140, 20));
321 jContentPane
= new JPanel();
322 jContentPane
.setLayout(null);
323 jContentPane
.setPreferredSize(new java
.awt
.Dimension(490, 190));
325 jContentPane
.add(jLabelC_Name
, null);
326 jContentPane
.add(jLabelFeatureFlag
, null);
327 jContentPane
.add(getJTextFieldFeatureFlag(), null);
328 jContentPane
.add(jLabelUsage
, null);
329 jContentPane
.add(getJComboBoxProtocolUsage(), null);
330 jContentPane
.add(jLabelProtocolType
, null);
332 jStarLabel1
= new StarLabel();
333 jStarLabel1
.setBounds(new java
.awt
.Rectangle(0, 10, 10, 20));
334 jStarLabel2
= new StarLabel();
335 jStarLabel2
.setBounds(new java
.awt
.Rectangle(0, 35, 10, 20));
337 jContentPane
.add(jStarLabel1
, null);
338 jContentPane
.add(jStarLabel2
, null);
339 jContentPane
.add(jLabelArch
, null);
340 jContentPane
.add(getJComboBoxProtocolType(), null);
341 jContentPane
.add(getJComboBoxCName(), null);
342 jContentPane
.add(jLabelHelpText
, null);
343 jContentPane
.add(getJTextFieldHelpText(), null);
344 jContentPane
.add(jArchCheckBox
, null);
345 jContentPane
.add(getJButtonOk(), null);
346 jContentPane
.add(getJButtonCancel(), null);
352 This method initializes Usage type
355 private void initFrame() {
356 Tools
.generateComboBoxByVector(jComboBoxProtocolType
, ed
.getVProtocolType());
357 Tools
.generateComboBoxByVector(jComboBoxCName
, wt
.getAllProtocolDeclarationsFromWorkspace());
358 Tools
.generateComboBoxByVector(jComboBoxUsage
, ed
.getVProtocolUsage());
362 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
364 * Override actionPerformed to listen all actions
367 public void actionPerformed(ActionEvent arg0
) {
368 if (arg0
.getSource() == jButtonOk
) {
370 getCurrentProtocols();
371 this.returnType
= DataType
.RETURN_TYPE_OK
;
372 this.setVisible(false);
376 if (arg0
.getSource() == jButtonCancel
) {
377 this.returnType
= DataType
.RETURN_TYPE_CANCEL
;
378 this.setVisible(false);
383 Data validation for all fields
385 @retval true - All datas are valid
386 @retval false - At least one data is invalid
389 public boolean checkAdd() {
391 // Check if all fields have correct data types
397 if (!isEmpty(this.jComboBoxCName
.getSelectedItem().toString())) {
398 if (!DataValidation
.isC_NameType(this.jComboBoxCName
.getSelectedItem().toString())) {
399 Log
.wrn("Update Protocols", "Incorrect data type for Protocol/ProtocolNotify Name");
407 if (!isEmpty(this.jTextFieldFeatureFlag
.getText())) {
408 if (!DataValidation
.isFeatureFlag(this.jTextFieldFeatureFlag
.getText())) {
409 Log
.wrn("Update Protocols", "Incorrect data type for Feature Flag");
417 private ProtocolsIdentification
getCurrentProtocols() {
418 String arg0
= this.jComboBoxCName
.getSelectedItem().toString();
419 String arg1
= this.jComboBoxProtocolType
.getSelectedItem().toString();
420 String arg2
= this.jComboBoxUsage
.getSelectedItem().toString();
422 String arg3
= this.jTextFieldFeatureFlag
.getText();
423 Vector
<String
> arg4
= this.jArchCheckBox
.getSelectedItemsVector();
424 String arg5
= this.jTextFieldHelpText
.getText();
425 id
= new ProtocolsIdentification(arg0
, arg1
, arg2
, arg3
, arg4
, arg5
);
430 * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
432 * Reflesh the frame when selected item changed
435 public void itemStateChanged(ItemEvent arg0
) {
436 if (arg0
.getSource() == this.jComboBoxProtocolType
&& arg0
.getStateChange() == ItemEvent
.SELECTED
) {
437 if (this.jComboBoxProtocolType
.getSelectedItem().toString().equals(ed
.getVProtocolType().get(0))) {
438 Tools
.generateComboBoxByVector(this.jComboBoxUsage
, ed
.getVProtocolUsage());
440 Tools
.generateComboBoxByVector(this.jComboBoxUsage
, ed
.getVProtocolNotifyUsage());
445 public ProtocolsIdentification
getId() {
449 public void setId(ProtocolsIdentification id
) {