3 The file is used to create, update Variable 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
.util
.Vector
;
21 import javax
.swing
.JButton
;
22 import javax
.swing
.JComboBox
;
23 import javax
.swing
.JLabel
;
24 import javax
.swing
.JPanel
;
25 import javax
.swing
.JScrollPane
;
26 import javax
.swing
.JTextField
;
28 import org
.tianocore
.frameworkwizard
.common
.DataType
;
29 import org
.tianocore
.frameworkwizard
.common
.DataValidation
;
30 import org
.tianocore
.frameworkwizard
.common
.EnumerationData
;
31 import org
.tianocore
.frameworkwizard
.common
.Log
;
32 import org
.tianocore
.frameworkwizard
.common
.Tools
;
33 import org
.tianocore
.frameworkwizard
.common
.ui
.ArchCheckBox
;
34 import org
.tianocore
.frameworkwizard
.common
.ui
.IDialog
;
35 import org
.tianocore
.frameworkwizard
.common
.ui
.IFrame
;
36 import org
.tianocore
.frameworkwizard
.common
.ui
.StarLabel
;
37 import org
.tianocore
.frameworkwizard
.module
.Identifications
.Variables
.VariablesIdentification
;
38 import org
.tianocore
.frameworkwizard
.workspace
.WorkspaceTools
;
41 The class is used to create, update Variable of MSA/MBD file
42 It extends IInternalFrame
45 public class VariablesDlg
extends IDialog
{
48 /// Define class Serial Version UID
50 private static final long serialVersionUID
= -6998982978030439446L;
53 //Define class members
55 private JPanel jContentPane
= null;
57 private JLabel jLabelVariableName
= null;
59 private JTextField jTextFieldVariableName
= null;
61 private JLabel jLabelUsage
= null;
63 private JComboBox jComboBoxUsage
= null;
65 private StarLabel jStarLabel1
= null;
67 private StarLabel jStarLabel2
= null;
69 private JScrollPane jScrollPane
= null;
71 private JLabel jLabelGuidCName
= null;
73 private JComboBox jComboBoxGuidC_Name
= null;
75 private JTextField jTextFieldFeatureFlag
= null;
77 private JLabel jLabelFeatureFlag
= null;
79 private JLabel jLabelArch
= null;
81 private JLabel jLabelHelpText
= null;
83 private JTextField jTextFieldHelpText
= null;
85 private ArchCheckBox jArchCheckBox
= null;
87 private JButton jButtonOk
= null;
89 private JButton jButtonCancel
= null;
94 private VariablesIdentification id
= null;
96 private EnumerationData ed
= new EnumerationData();
98 private WorkspaceTools wt
= new WorkspaceTools();
101 This method initializes jTextFieldString
103 @return javax.swing.JTextField jTextFieldString
106 private JTextField
getJTextFieldString() {
107 if (jTextFieldVariableName
== null) {
108 jTextFieldVariableName
= new JTextField();
109 jTextFieldVariableName
.setSize(new java
.awt
.Dimension(320, 20));
110 jTextFieldVariableName
.setPreferredSize(new java
.awt
.Dimension(320, 20));
111 jTextFieldVariableName
.setLocation(new java
.awt
.Point(160, 10));
112 jTextFieldVariableName
113 .setToolTipText("Enter a Hex Word Array, you must provide leading Zeros. 0x000a, 0x0010, ¡");
115 return jTextFieldVariableName
;
119 This method initializes jComboBoxUsage
121 @return javax.swing.JComboBox jComboBoxUsage
124 private JComboBox
getJComboBoxUsage() {
125 if (jComboBoxUsage
== null) {
126 jComboBoxUsage
= new JComboBox();
127 jComboBoxUsage
.setBounds(new java
.awt
.Rectangle(160, 60, 320, 20));
128 jComboBoxUsage
.setPreferredSize(new java
.awt
.Dimension(320, 20));
130 return jComboBoxUsage
;
134 This method initializes jScrollPane
136 @return javax.swing.JScrollPane
138 private JScrollPane
getJScrollPane() {
139 if (jScrollPane
== null) {
140 jScrollPane
= new JScrollPane();
141 jScrollPane
.setViewportView(getJContentPane());
147 This method initializes jTextFieldFeatureFlag
149 @return javax.swing.JTextField jTextFieldFeatureFlag
152 private JTextField
getJTextFieldFeatureFlag() {
153 if (jTextFieldFeatureFlag
== null) {
154 jTextFieldFeatureFlag
= new JTextField();
155 jTextFieldFeatureFlag
.setBounds(new java
.awt
.Rectangle(160, 110, 320, 20));
156 jTextFieldFeatureFlag
.setPreferredSize(new java
.awt
.Dimension(320, 20));
158 return jTextFieldFeatureFlag
;
162 This method initializes jTextFieldHelpText
164 @return javax.swing.JTextField
167 private JTextField
getJTextFieldHelpText() {
168 if (jTextFieldHelpText
== null) {
169 jTextFieldHelpText
= new JTextField();
170 jTextFieldHelpText
.setBounds(new java
.awt
.Rectangle(160, 85, 320, 20));
171 jTextFieldHelpText
.setPreferredSize(new java
.awt
.Dimension(320, 20));
173 return jTextFieldHelpText
;
177 This method initializes jTextField
179 @return javax.swing.JTextField jTextFieldC_Name
182 private JComboBox
getJComboBoxGuidC_Name() {
183 if (jComboBoxGuidC_Name
== null) {
184 jComboBoxGuidC_Name
= new JComboBox();
185 jComboBoxGuidC_Name
.setBounds(new java
.awt
.Rectangle(160, 35, 320, 20));
186 jComboBoxGuidC_Name
.setPreferredSize(new java
.awt
.Dimension(320, 20));
187 jComboBoxGuidC_Name
.setToolTipText("Select the GUID C Name of the Hob");
189 return jComboBoxGuidC_Name
;
193 This method initializes jButtonOk
195 @return javax.swing.JButton
198 private JButton
getJButtonOk() {
199 if (jButtonOk
== null) {
200 jButtonOk
= new JButton();
201 jButtonOk
.setBounds(new java
.awt
.Rectangle(290, 165, 90, 20));
202 jButtonOk
.setText("Ok");
203 jButtonOk
.addActionListener(this);
209 This method initializes jButtonCancel
211 @return javax.swing.JButton
214 private JButton
getJButtonCancel() {
215 if (jButtonCancel
== null) {
216 jButtonCancel
= new JButton();
217 jButtonCancel
.setBounds(new java
.awt
.Rectangle(390, 165, 90, 20));
218 jButtonCancel
.setText("Cancel");
219 jButtonCancel
.addActionListener(this);
221 return jButtonCancel
;
224 public static void main(String
[] args
) {
229 This method initializes this
232 private void init() {
233 this.setSize(500, 225);
234 this.setContentPane(getJScrollPane());
235 this.setTitle("Variables");
237 this.setViewMode(false);
242 This method initializes this
243 Fill values to all fields if these values are not empty
248 private void init(VariablesIdentification inVariablesId
) {
250 this.id
= inVariablesId
;
252 if (this.id
!= null) {
253 this.jTextFieldVariableName
.setText(id
.getName());
254 this.jComboBoxGuidC_Name
.setSelectedItem(id
.getGuid());
255 this.jComboBoxUsage
.setSelectedItem(id
.getUsage());
256 this.jTextFieldHelpText
.setText(id
.getHelp());
257 this.jTextFieldFeatureFlag
.setText(id
.getFeatureFlag());
258 this.jArchCheckBox
.setSelectedItems(id
.getSupArchList());
263 This is the override edit constructor
265 @param inHobsIdentification
269 public VariablesDlg(VariablesIdentification inVariablesIdentification
, IFrame iFrame
) {
271 init(inVariablesIdentification
);
275 Disable all components when the mode is view
277 @param isView true - The view mode; false - The non-view mode
280 public void setViewMode(boolean isView
) {
282 this.jTextFieldVariableName
.setEnabled(!isView
);
283 this.jComboBoxUsage
.setEnabled(!isView
);
288 This method initializes jContentPane
290 @return javax.swing.JPanel jContentPane
293 private JPanel
getJContentPane() {
294 if (jContentPane
== null) {
295 jArchCheckBox
= new ArchCheckBox();
296 jArchCheckBox
.setBounds(new java
.awt
.Rectangle(160, 135, 320, 20));
297 jArchCheckBox
.setPreferredSize(new java
.awt
.Dimension(320, 20));
298 jLabelGuidCName
= new JLabel();
299 jLabelGuidCName
.setBounds(new java
.awt
.Rectangle(15, 35, 140, 20));
300 jLabelGuidCName
.setText("Guid C_Name");
301 jLabelUsage
= new JLabel();
302 jLabelUsage
.setText("Usage");
303 jLabelUsage
.setBounds(new java
.awt
.Rectangle(15, 60, 140, 20));
304 jLabelVariableName
= new JLabel();
305 jLabelVariableName
.setText("Variable Name");
306 jLabelVariableName
.setLocation(new java
.awt
.Point(15, 10));
307 jLabelVariableName
.setSize(new java
.awt
.Dimension(140, 20));
308 jLabelArch
= new JLabel();
309 jLabelArch
.setBounds(new java
.awt
.Rectangle(15, 135, 140, 20));
310 jLabelArch
.setText("Arch");
311 jLabelFeatureFlag
= new JLabel();
312 jLabelFeatureFlag
.setText("Feature Flag");
313 jLabelFeatureFlag
.setBounds(new java
.awt
.Rectangle(15, 110, 140, 20));
315 jContentPane
= new JPanel();
316 jContentPane
.setLayout(null);
317 jContentPane
.setPreferredSize(new java
.awt
.Dimension(490, 190));
319 jContentPane
.add(jLabelVariableName
, null);
320 jContentPane
.add(jLabelGuidCName
, null);
321 jContentPane
.add(getJComboBoxGuidC_Name(), null);
322 jContentPane
.add(getJTextFieldString(), null);
323 jContentPane
.add(jLabelUsage
, null);
324 jContentPane
.add(getJComboBoxUsage(), null);
325 jStarLabel1
= new StarLabel();
326 jStarLabel1
.setLocation(new java
.awt
.Point(0, 10));
327 jStarLabel2
= new StarLabel();
328 jStarLabel2
.setLocation(new java
.awt
.Point(0, 35));
329 jLabelHelpText
= new JLabel();
330 jLabelHelpText
.setBounds(new java
.awt
.Rectangle(14, 85, 140, 20));
331 jLabelHelpText
.setText("Help Text");
333 jContentPane
.add(jStarLabel1
, null);
334 jContentPane
.add(jStarLabel2
, null);
336 jContentPane
.add(jLabelArch
, null);
337 jContentPane
.add(jLabelFeatureFlag
, null);
338 jContentPane
.add(getJTextFieldFeatureFlag(), null);
339 jContentPane
.add(jLabelHelpText
, null);
340 jContentPane
.add(getJTextFieldHelpText(), null);
341 jContentPane
.add(jArchCheckBox
, null);
342 jContentPane
.add(getJButtonOk(), null);
343 jContentPane
.add(getJButtonCancel(), null);
349 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
351 * Override actionPerformed to listen all actions
354 public void actionPerformed(ActionEvent arg0
) {
355 if (arg0
.getSource() == jButtonOk
) {
357 getCurrentVariables();
358 this.returnType
= DataType
.RETURN_TYPE_OK
;
359 this.setVisible(false);
363 if (arg0
.getSource() == jButtonCancel
) {
364 this.returnType
= DataType
.RETURN_TYPE_CANCEL
;
365 this.setVisible(false);
370 This method initializes Usage type
373 private void initFrame() {
374 Tools
.generateComboBoxByVector(jComboBoxUsage
, ed
.getVPpiUsage());
375 Tools
.generateComboBoxByVector(jComboBoxGuidC_Name
, wt
.getAllGuidDeclarationsFromWorkspace());
379 Data validation for all fields
381 @retval true - All datas are valid
382 @retval false - At least one data is invalid
385 public boolean checkAdd() {
387 // Check if all fields have correct data types
391 // Check VariableName
393 if (isEmpty(this.jTextFieldVariableName
.getText())) {
394 Log
.err("Variable Name couldn't be empty");
398 if (!isEmpty(this.jTextFieldVariableName
.getText())) {
399 if (!DataValidation
.isHexWordArrayType(this.jTextFieldVariableName
.getText())) {
400 Log
.err("Incorrect data type for Variable Name");
408 if (!isEmpty(this.jTextFieldFeatureFlag
.getText())) {
409 if (!DataValidation
.isFeatureFlag(this.jTextFieldFeatureFlag
.getText())) {
410 Log
.err("Incorrect data type for Feature Flag");
418 private VariablesIdentification
getCurrentVariables() {
419 String arg0
= this.jTextFieldVariableName
.getText();
420 String arg1
= this.jComboBoxGuidC_Name
.getSelectedItem().toString();
421 String arg2
= this.jComboBoxUsage
.getSelectedItem().toString();
423 String arg3
= this.jTextFieldFeatureFlag
.getText();
424 Vector
<String
> arg4
= this.jArchCheckBox
.getSelectedItemsVector();
425 String arg5
= this.jTextFieldHelpText
.getText();
427 id
= new VariablesIdentification(arg0
, arg1
, arg2
, arg3
, arg4
, arg5
);
431 public VariablesIdentification
getId() {
435 public void setId(VariablesIdentification id
) {