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));
131 return jComboBoxUsage
;
135 This method initializes jScrollPane
137 @return javax.swing.JScrollPane
139 private JScrollPane
getJScrollPane() {
140 if (jScrollPane
== null) {
141 jScrollPane
= new JScrollPane();
142 jScrollPane
.setViewportView(getJContentPane());
148 * This method initializes jComboBoxProtocolType
150 * @return javax.swing.JComboBox
152 private JComboBox
getJComboBoxProtocolType() {
153 if (jComboBoxProtocolType
== null) {
154 jComboBoxProtocolType
= new JComboBox();
155 jComboBoxProtocolType
.setBounds(new java
.awt
.Rectangle(160, 10, 320, 20));
156 jComboBoxProtocolType
.setPreferredSize(new java
.awt
.Dimension(320, 20));
157 jComboBoxProtocolType
.addItemListener(this);
158 jComboBoxProtocolType
.setToolTipText("Select Protocol Type");
160 return jComboBoxProtocolType
;
164 * This method initializes jComboBoxCName
166 * @return javax.swing.JComboBox
168 private JComboBox
getJComboBoxCName() {
169 if (jComboBoxCName
== null) {
170 jComboBoxCName
= new JComboBox();
171 jComboBoxCName
.setBounds(new java
.awt
.Rectangle(160, 35, 320, 20));
172 jComboBoxCName
.setPreferredSize(new java
.awt
.Dimension(320, 20));
175 return jComboBoxCName
;
179 This method initializes jTextFieldHelpText
181 @return javax.swing.JTextField
184 private JTextField
getJTextFieldHelpText() {
185 if (jTextFieldHelpText
== null) {
186 jTextFieldHelpText
= new JTextField();
187 jTextFieldHelpText
.setBounds(new java
.awt
.Rectangle(160, 85, 320, 20));
188 jTextFieldHelpText
.setPreferredSize(new java
.awt
.Dimension(320, 20));
190 return jTextFieldHelpText
;
194 This method initializes jButtonOk
196 @return javax.swing.JButton
199 private JButton
getJButtonOk() {
200 if (jButtonOk
== null) {
201 jButtonOk
= new JButton();
202 jButtonOk
.setBounds(new java
.awt
.Rectangle(290, 165, 90, 20));
203 jButtonOk
.setText("Ok");
204 jButtonOk
.addActionListener(this);
210 This method initializes jButtonCancel
212 @return javax.swing.JButton
215 private JButton
getJButtonCancel() {
216 if (jButtonCancel
== null) {
217 jButtonCancel
= new JButton();
218 jButtonCancel
.setBounds(new java
.awt
.Rectangle(390, 165, 90, 20));
219 jButtonCancel
.setText("Cancel");
220 jButtonCancel
.addActionListener(this);
222 return jButtonCancel
;
225 public static void main(String
[] args
) {
230 This method initializes this
233 private void init() {
234 this.setSize(500, 225);
235 this.setContentPane(getJScrollPane());
236 this.setTitle("Protocols");
238 this.setViewMode(false);
243 This method initializes this
244 Fill values to all fields if these values are not empty
249 private void init(ProtocolsIdentification inProtocolsId
) {
251 this.id
= inProtocolsId
;
253 if (this.id
!= null) {
254 this.jComboBoxCName
.setSelectedItem(id
.getName());
255 this.jComboBoxProtocolType
.setSelectedItem(id
.getType());
256 this.jComboBoxUsage
.setSelectedItem(id
.getUsage());
257 this.jTextFieldHelpText
.setText(id
.getHelp());
259 jTextFieldFeatureFlag
.setText(id
.getFeatureFlag());
260 this.jArchCheckBox
.setSelectedItems(id
.getSupArchList());
265 This is the override edit constructor
267 @param inProtocolsIdentification
271 public ProtocolsDlg(ProtocolsIdentification inProtocolsIdentification
, IFrame iFrame
) {
273 init(inProtocolsIdentification
);
277 Disable all components when the mode is view
279 @param isView true - The view mode; false - The non-view mode
282 public void setViewMode(boolean isView
) {
284 this.jComboBoxUsage
.setEnabled(!isView
);
285 this.jTextFieldFeatureFlag
.setEnabled(!isView
);
290 This method initializes jContentPane
292 @return javax.swing.JPanel jContentPane
295 private JPanel
getJContentPane() {
296 if (jContentPane
== null) {
297 jArchCheckBox
= new ArchCheckBox();
298 jArchCheckBox
.setBounds(new java
.awt
.Rectangle(160, 135, 320, 20));
299 jArchCheckBox
.setPreferredSize(new java
.awt
.Dimension(320, 20));
300 jLabelHelpText
= new JLabel();
301 jLabelHelpText
.setBounds(new java
.awt
.Rectangle(14, 85, 140, 20));
302 jLabelHelpText
.setText("Help Text");
303 jLabelArch
= new JLabel();
304 jLabelArch
.setBounds(new java
.awt
.Rectangle(15, 135, 140, 20));
305 jLabelArch
.setText("Arch Type");
306 jLabelProtocolType
= new JLabel();
307 jLabelProtocolType
.setBounds(new java
.awt
.Rectangle(15, 10, 140, 20));
308 jLabelProtocolType
.setText("Protocol Type");
309 jLabelUsage
= new JLabel();
310 jLabelUsage
.setText("Usage");
311 jLabelUsage
.setBounds(new java
.awt
.Rectangle(15, 60, 140, 20));
312 jLabelFeatureFlag
= new JLabel();
313 jLabelFeatureFlag
.setText("Feature Flag");
314 jLabelFeatureFlag
.setBounds(new java
.awt
.Rectangle(15, 110, 140, 20));
315 jLabelC_Name
= new JLabel();
316 jLabelC_Name
.setText("C_Name Type");
317 jLabelC_Name
.setBounds(new java
.awt
.Rectangle(15, 35, 140, 20));
319 jContentPane
= new JPanel();
320 jContentPane
.setLayout(null);
321 jContentPane
.setPreferredSize(new java
.awt
.Dimension(490, 190));
323 jContentPane
.add(jLabelC_Name
, null);
324 jContentPane
.add(jLabelFeatureFlag
, null);
325 jContentPane
.add(getJTextFieldFeatureFlag(), null);
326 jContentPane
.add(jLabelUsage
, null);
327 jContentPane
.add(getJComboBoxProtocolUsage(), null);
328 jContentPane
.add(jLabelProtocolType
, null);
330 jStarLabel1
= new StarLabel();
331 jStarLabel1
.setBounds(new java
.awt
.Rectangle(0, 10, 10, 20));
332 jStarLabel2
= new StarLabel();
333 jStarLabel2
.setBounds(new java
.awt
.Rectangle(0, 35, 10, 20));
335 jContentPane
.add(jStarLabel1
, null);
336 jContentPane
.add(jStarLabel2
, null);
337 jContentPane
.add(jLabelArch
, null);
338 jContentPane
.add(getJComboBoxProtocolType(), null);
339 jContentPane
.add(getJComboBoxCName(), null);
340 jContentPane
.add(jLabelHelpText
, null);
341 jContentPane
.add(getJTextFieldHelpText(), null);
342 jContentPane
.add(jArchCheckBox
, null);
343 jContentPane
.add(getJButtonOk(), null);
344 jContentPane
.add(getJButtonCancel(), null);
350 This method initializes Usage type
353 private void initFrame() {
354 Tools
.generateComboBoxByVector(jComboBoxProtocolType
, ed
.getVProtocolType());
355 Tools
.generateComboBoxByVector(jComboBoxCName
, wt
.getAllProtocolDeclarationsFromWorkspace());
356 Tools
.generateComboBoxByVector(jComboBoxUsage
, ed
.getVProtocolUsage());
360 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
362 * Override actionPerformed to listen all actions
365 public void actionPerformed(ActionEvent arg0
) {
366 if (arg0
.getSource() == jButtonOk
) {
368 getCurrentProtocols();
369 this.returnType
= DataType
.RETURN_TYPE_OK
;
370 this.setVisible(false);
374 if (arg0
.getSource() == jButtonCancel
) {
375 this.returnType
= DataType
.RETURN_TYPE_CANCEL
;
376 this.setVisible(false);
381 Data validation for all fields
383 @retval true - All datas are valid
384 @retval false - At least one data is invalid
387 public boolean checkAdd() {
389 // Check if all fields have correct data types
395 if (!isEmpty(this.jComboBoxCName
.getSelectedItem().toString())) {
396 if (!DataValidation
.isC_NameType(this.jComboBoxCName
.getSelectedItem().toString())) {
397 Log
.err("Incorrect data type for Protocol/ProtocolNotify Name");
405 if (!isEmpty(this.jTextFieldFeatureFlag
.getText())) {
406 if (!DataValidation
.isFeatureFlag(this.jTextFieldFeatureFlag
.getText())) {
407 Log
.err("Incorrect data type for Feature Flag");
415 private ProtocolsIdentification
getCurrentProtocols() {
416 String arg0
= this.jComboBoxCName
.getSelectedItem().toString();
417 String arg1
= this.jComboBoxProtocolType
.getSelectedItem().toString();
418 String arg2
= this.jComboBoxUsage
.getSelectedItem().toString();
420 String arg3
= this.jTextFieldFeatureFlag
.getText();
421 Vector
<String
> arg4
= this.jArchCheckBox
.getSelectedItemsVector();
422 String arg5
= this.jTextFieldHelpText
.getText();
423 id
= new ProtocolsIdentification(arg0
, arg1
, arg2
, arg3
, arg4
, arg5
);
428 * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
430 * Reflesh the frame when selected item changed
433 public void itemStateChanged(ItemEvent arg0
) {
434 if (arg0
.getSource() == this.jComboBoxProtocolType
&& arg0
.getStateChange() == ItemEvent
.SELECTED
) {
435 if (this.jComboBoxProtocolType
.getSelectedItem().toString().equals(ed
.getVProtocolType().get(0))) {
436 Tools
.generateComboBoxByVector(this.jComboBoxUsage
, ed
.getVProtocolUsage());
438 Tools
.generateComboBoxByVector(this.jComboBoxUsage
, ed
.getVProtocolNotifyUsage());
443 public ProtocolsIdentification
getId() {
447 public void setId(ProtocolsIdentification id
) {