3 The file is used to create, update Externs section of the MSA 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.
15 package org
.tianocore
.frameworkwizard
.module
.ui
.dialog
;
17 import java
.awt
.event
.ActionEvent
;
18 import java
.awt
.event
.ItemEvent
;
19 import java
.awt
.event
.ItemListener
;
20 import java
.util
.Vector
;
22 import javax
.swing
.JButton
;
23 import javax
.swing
.JComboBox
;
24 import javax
.swing
.JLabel
;
25 import javax
.swing
.JPanel
;
26 import javax
.swing
.JScrollPane
;
27 import javax
.swing
.JTextField
;
29 import org
.tianocore
.frameworkwizard
.common
.DataType
;
30 import org
.tianocore
.frameworkwizard
.common
.DataValidation
;
31 import org
.tianocore
.frameworkwizard
.common
.EnumerationData
;
32 import org
.tianocore
.frameworkwizard
.common
.Log
;
33 import org
.tianocore
.frameworkwizard
.common
.Tools
;
34 import org
.tianocore
.frameworkwizard
.common
.ui
.ArchCheckBox
;
35 import org
.tianocore
.frameworkwizard
.common
.ui
.IDialog
;
36 import org
.tianocore
.frameworkwizard
.common
.ui
.IFrame
;
37 import org
.tianocore
.frameworkwizard
.module
.Identifications
.Externs
.ExternsIdentification
;
40 * The class is used to create, update Externs section of the MSA file
45 public class ExternsDlg
extends IDialog
implements ItemListener
{
48 /// Define class Serial Version UID
50 private static final long serialVersionUID
= -7382008402932047191L;
53 //Define class members
55 private JPanel jContentPane
= null;
57 private JLabel jLabelName
= null;
59 private JComboBox jComboBoxType
= null;
61 private JScrollPane jScrollPane
= null;
63 private JComboBox jComboBoxPcdIsDriver
= null;
65 private JLabel jLabelC_Name
= null;
67 private JTextField jTextFieldC_Name
= null;
69 private JLabel jLabelFeatureFlag
= null;
71 private JLabel jLabelArch
= null;
73 private JTextField jTextFieldFeatureFlag
= null;
75 private ArchCheckBox jArchCheckBox
= null;
77 private JButton jButtonOk
= null;
79 private JButton jButtonCancel
= null;
84 private ExternsIdentification id
= null;
86 private EnumerationData ed
= new EnumerationData();
89 This method initializes jComboBoxType
91 @return javax.swing.JComboBox jComboBoxType
94 private JComboBox
getJComboBoxType() {
95 if (jComboBoxType
== null) {
96 jComboBoxType
= new JComboBox();
97 jComboBoxType
.setBounds(new java
.awt
.Rectangle(168, 12, 320, 20));
98 jComboBoxType
.setPreferredSize(new java
.awt
.Dimension(320, 20));
99 jComboBoxType
.addItemListener(this);
101 return jComboBoxType
;
105 This method initializes jScrollPane
107 @return javax.swing.JScrollPane
109 private JScrollPane
getJScrollPane() {
110 if (jScrollPane
== null) {
111 jScrollPane
= new JScrollPane();
112 jScrollPane
.setViewportView(getJContentPane());
118 * This method initializes jComboBoxPcdIsDriver
120 * @return javax.swing.JComboBox
122 private JComboBox
getJComboBoxPcdIsDriver() {
123 if (jComboBoxPcdIsDriver
== null) {
124 jComboBoxPcdIsDriver
= new JComboBox();
125 jComboBoxPcdIsDriver
.setLocation(new java
.awt
.Point(168, 37));
126 jComboBoxPcdIsDriver
.setPreferredSize(new java
.awt
.Dimension(320, 20));
127 jComboBoxPcdIsDriver
.setSize(new java
.awt
.Dimension(320, 20));
128 jComboBoxPcdIsDriver
.addItemListener(this);
130 return jComboBoxPcdIsDriver
;
134 This method initializes jTextFieldC_Name
136 @return javax.swing.JTextField
139 private JTextField
getJTextFieldC_Name() {
140 if (jTextFieldC_Name
== null) {
141 jTextFieldC_Name
= new JTextField();
142 jTextFieldC_Name
.setBounds(new java
.awt
.Rectangle(168, 37, 320, 20));
143 jTextFieldC_Name
.setPreferredSize(new java
.awt
.Dimension(320, 20));
145 return jTextFieldC_Name
;
149 This method initializes jTextFieldFeatureFlag
151 @return javax.swing.JTextField
154 private JTextField
getJTextFieldFeatureFlag() {
155 if (jTextFieldFeatureFlag
== null) {
156 jTextFieldFeatureFlag
= new JTextField();
157 jTextFieldFeatureFlag
.setBounds(new java
.awt
.Rectangle(168, 87, 320, 20));
158 jTextFieldFeatureFlag
.setPreferredSize(new java
.awt
.Dimension(320, 20));
159 jTextFieldFeatureFlag
.setEnabled(false);
161 return jTextFieldFeatureFlag
;
165 This method initializes jButtonOk
167 @return javax.swing.JButton
170 private JButton
getJButtonOk() {
171 if (jButtonOk
== null) {
172 jButtonOk
= new JButton();
173 jButtonOk
.setBounds(new java
.awt
.Rectangle(300, 122, 90, 20));
174 jButtonOk
.setText("Ok");
175 jButtonOk
.addActionListener(this);
181 This method initializes jButtonCancel
183 @return javax.swing.JButton
186 private JButton
getJButtonCancel() {
187 if (jButtonCancel
== null) {
188 jButtonCancel
= new JButton();
189 jButtonCancel
.setBounds(new java
.awt
.Rectangle(400, 122, 90, 20));
190 jButtonCancel
.setText("Cancel");
191 jButtonCancel
.addActionListener(this);
193 return jButtonCancel
;
196 public static void main(String
[] args
) {
201 This method initializes this
204 private void init() {
205 this.setSize(515, 200);
206 this.setContentPane(getJScrollPane());
207 this.setTitle("Externs");
213 This method initializes this
214 Fill values to all fields if these values are not empty
219 private void init(ExternsIdentification inExternsId
) {
221 this.id
= inExternsId
;
223 if (this.id
!= null) {
224 if (id
.getType().equals(EnumerationData
.EXTERNS_PCD_IS_DRIVER
)) {
225 this.jComboBoxPcdIsDriver
.setSelectedItem(id
.getName());
227 this.jTextFieldC_Name
.setText(id
.getName());
229 this.jComboBoxType
.setSelectedItem(id
.getType());
230 this.jTextFieldFeatureFlag
.setText(id
.getFeatureFlag());
231 this.jArchCheckBox
.setSelectedItems(id
.getSupArchList());
236 This is the override edit constructor
238 @param inBootModesIdentification
242 public ExternsDlg(ExternsIdentification inExternsIdentification
, IFrame iFrame
) {
244 init(inExternsIdentification
);
248 This method initializes jContentPane
250 @return javax.swing.JPanel jContentPane
253 private JPanel
getJContentPane() {
254 if (jContentPane
== null) {
255 jArchCheckBox
= new ArchCheckBox();
256 jArchCheckBox
.setBounds(new java
.awt
.Rectangle(168, 62, 320, 20));
257 jArchCheckBox
.setPreferredSize(new java
.awt
.Dimension(320, 20));
258 jLabelC_Name
= new JLabel();
259 jLabelC_Name
.setBounds(new java
.awt
.Rectangle(12, 37, 140, 20));
260 jLabelC_Name
.setText("Enter Value");
261 jLabelName
= new JLabel();
262 jLabelName
.setText("Choose Extern Type");
263 jLabelName
.setBounds(new java
.awt
.Rectangle(12, 12, 168, 20));
264 jLabelArch
= new JLabel();
265 jLabelArch
.setBounds(new java
.awt
.Rectangle(12, 62, 168, 20));
266 jLabelArch
.setText("Supported Architectures");
267 jLabelFeatureFlag
= new JLabel();
268 jLabelFeatureFlag
.setBounds(new java
.awt
.Rectangle(12, 87, 168, 20));
269 jLabelFeatureFlag
.setText("Feature Flag Expression");
270 jLabelFeatureFlag
.setEnabled(false);
272 jContentPane
= new JPanel();
273 jContentPane
.setLayout(null);
274 jContentPane
.setPreferredSize(new java
.awt
.Dimension(505, 155));
276 jContentPane
.add(jLabelName
, null);
277 jContentPane
.add(getJComboBoxType(), null);
278 jContentPane
.add(jLabelFeatureFlag
, null);
279 jContentPane
.add(jLabelArch
, null);
280 jContentPane
.add(getJTextFieldFeatureFlag(), null);
282 jContentPane
.add(getJComboBoxPcdIsDriver(), null);
283 jContentPane
.add(jLabelC_Name
, null);
284 jContentPane
.add(getJTextFieldC_Name(), null);
285 jContentPane
.add(jArchCheckBox
, null);
286 jContentPane
.add(getJButtonOk(), null);
287 jContentPane
.add(getJButtonCancel(), null);
293 This method initializes Usage type and Externs type
296 private void initFrame() {
297 Tools
.generateComboBoxByVector(this.jComboBoxType
, ed
.getVExternTypes());
298 Tools
.generateComboBoxByVector(this.jComboBoxPcdIsDriver
, ed
.getVPcdDriverTypes());
302 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
304 * Override actionPerformed to listen all actions
307 public void actionPerformed(ActionEvent arg0
) {
308 if (arg0
.getSource() == jButtonOk
) {
311 this.returnType
= DataType
.RETURN_TYPE_OK
;
312 this.setVisible(false);
316 if (arg0
.getSource() == jButtonCancel
) {
317 this.returnType
= DataType
.RETURN_TYPE_CANCEL
;
318 this.setVisible(false);
323 Data validation for all fields
325 @retval true - All datas are valid
326 @retval false - At least one data is invalid
329 public boolean checkAdd() {
331 // Check if all fields have correct data types
335 // When and only When type is not "Pcd Is Driver"
337 if (!this.jComboBoxType
.getSelectedItem().toString().equals(EnumerationData
.EXTERNS_PCD_IS_DRIVER
)) {
341 if (isEmpty(this.jTextFieldC_Name
.getText())) {
342 Log
.wrn("Update Externs", "Value couldn't be empty");
346 if (!isEmpty(this.jTextFieldC_Name
.getText())) {
347 if (this.jComboBoxType
.getSelectedItem().toString().equals(EnumerationData
.EXTERNS_SPECIFICATION
)) {
348 if (!DataValidation
.isSentence(this.jTextFieldC_Name
.getText())) {
349 Log
.wrn("Update Externs", "Incorrect data type for Specification");
353 if (!DataValidation
.isC_NameType(this.jTextFieldC_Name
.getText())) {
354 Log
.wrn("Update Externs", "Incorrect data type for C Name");
363 if (!isEmpty(this.jTextFieldFeatureFlag
.getText())) {
364 if (!DataValidation
.isFeatureFlag(this.jTextFieldFeatureFlag
.getText())) {
365 Log
.wrn("Update Externs", "Incorrect data type for Feature Flag");
370 if (this.jComboBoxPcdIsDriver
.getSelectedItem().toString().equals(DataType
.EMPTY_SELECT_ITEM
)) {
371 Log
.wrn("Update Externs", "You must select one PCD DRIVER type");
379 private ExternsIdentification
getCurrentExterns() {
381 if (this.jComboBoxType
.getSelectedItem().toString().equals(EnumerationData
.EXTERNS_PCD_IS_DRIVER
)) {
382 arg0
= this.jComboBoxPcdIsDriver
.getSelectedItem().toString();
384 arg0
= this.jTextFieldC_Name
.getText();
386 String arg1
= this.jComboBoxType
.getSelectedItem().toString();
388 String arg2
= this.jTextFieldFeatureFlag
.getText();
389 Vector
<String
> arg3
= this.jArchCheckBox
.getSelectedItemsVector();
391 id
= new ExternsIdentification(arg0
, arg1
, arg2
, arg3
);
396 * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
398 * Reflesh the frame when selected item changed
401 public void itemStateChanged(ItemEvent arg0
) {
402 if (arg0
.getSource() == jComboBoxType
&& arg0
.getStateChange() == ItemEvent
.SELECTED
) {
403 if (jComboBoxType
.getSelectedItem().toString().equals(EnumerationData
.EXTERNS_PCD_IS_DRIVER
)) {
404 this.jComboBoxPcdIsDriver
.setVisible(true);
405 this.jTextFieldC_Name
.setVisible(false);
407 this.jComboBoxPcdIsDriver
.setVisible(false);
408 this.jTextFieldC_Name
.setVisible(true);
413 public ExternsIdentification
getId() {
417 public void setId(ExternsIdentification id
) {