3 The file is used to create, update Variables 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.
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
;
27 import javax
.swing
.JTextArea
;
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
.common
.ui
.StarLabel
;
38 import org
.tianocore
.frameworkwizard
.module
.Identifications
.Variables
.VariablesIdentification
;
39 import org
.tianocore
.frameworkwizard
.workspace
.WorkspaceTools
;
42 * The class is used to create, update Variables section of the MSA file
46 public class VariablesDlg
extends IDialog
{
49 // / Define class Serial Version UID
51 private static final long serialVersionUID
= -6998982978030439446L;
54 // Define class members
56 private JPanel jContentPane
= null;
58 private JLabel jLabelVariableName
= null;
60 private JTextField jTextFieldVariableName
= null;
62 private JLabel jLabelUsage
= null;
64 private JComboBox jComboBoxUsage
= null;
66 private StarLabel jStarLabel1
= null;
68 private StarLabel jStarLabel2
= null;
70 private StarLabel jStarLabel3
= null;
72 private JScrollPane jScrollPane
= null;
74 private JLabel jLabelGuidCName
= null;
76 private JComboBox jComboBoxGuidC_Name
= null;
78 private JTextField jTextFieldFeatureFlag
= null;
80 private JLabel jLabelFeatureFlag
= null;
82 private JLabel jLabelArch
= null;
84 private JLabel jLabelHelpText
= null;
86 private JTextArea jTextAreaHelpText
= null;
88 private JScrollPane jScrollPaneHelpText
= null;
90 private ArchCheckBox jArchCheckBox
= null;
92 private JButton jButtonOk
= null;
94 private JButton jButtonCancel
= null;
99 private VariablesIdentification id
= null;
101 private EnumerationData ed
= new EnumerationData();
103 private WorkspaceTools wt
= new WorkspaceTools();
106 * This method initializes jTextFieldString
108 * @return javax.swing.JTextField jTextFieldString
111 private JTextField
getJTextFieldString() {
112 if (jTextFieldVariableName
== null) {
113 jTextFieldVariableName
= new JTextField();
114 jTextFieldVariableName
.setSize(new java
.awt
.Dimension(320, 20));
115 jTextFieldVariableName
.setPreferredSize(new java
.awt
.Dimension(320, 20));
116 jTextFieldVariableName
.setLocation(new java
.awt
.Point(168, 12));
117 jTextFieldVariableName
118 .setToolTipText("Enter a Hex Word Array, you must provide leading Zeros. 0x000a, 0x0010, 0x00FF");
120 return jTextFieldVariableName
;
124 * This method initializes jComboBoxUsage
126 * @return javax.swing.JComboBox jComboBoxUsage
129 private JComboBox
getJComboBoxUsage() {
130 if (jComboBoxUsage
== null) {
131 jComboBoxUsage
= new JComboBox();
132 jComboBoxUsage
.setBounds(new java
.awt
.Rectangle(168, 62, 320, 20));
133 jComboBoxUsage
.setPreferredSize(new java
.awt
.Dimension(320, 20));
135 .setToolTipText("<html><table>"
136 + "<tr><td>ALWAYS_CONSUMED</td><td>The module requires the variable entry to be set</td></tr>"
137 + "<tr><td>SOMETIMES_CONSUMED</td><td>The module will use the variable entry if it is set.</td></tr>"
138 + "<tr><td>ALWAYS_PRODUCED</td><td>The module will always write the variable.</td></tr>"
139 + "<tr><td>SOMETIMES_PRODUCED</td><td>The module will sometimes write the variable.</td></tr>"
140 + "</table></html>");
142 return jComboBoxUsage
;
146 * This method initializes jScrollPane
148 * @return javax.swing.JScrollPane
150 private JScrollPane
getJScrollPane() {
151 if (jScrollPane
== null) {
152 jScrollPane
= new JScrollPane();
153 jScrollPane
.setViewportView(getJContentPane());
159 * This method initializes jTextFieldFeatureFlag
161 * @return javax.swing.JTextField jTextFieldFeatureFlag
164 private JTextField
getJTextFieldFeatureFlag() {
165 if (jTextFieldFeatureFlag
== null) {
166 jTextFieldFeatureFlag
= new JTextField();
167 jTextFieldFeatureFlag
.setBounds(new java
.awt
.Rectangle(168, 132, 320, 20));
168 jTextFieldFeatureFlag
.setPreferredSize(new java
.awt
.Dimension(320, 20));
169 jTextFieldFeatureFlag
.setToolTipText("Postfix expression that must evaluate to TRUE or FALSE");
171 return jTextFieldFeatureFlag
;
175 * This method initializes jTextFieldHelpText
177 * @return javax.swing.JTextField
180 private JTextArea
getJTextAreaHelpText() {
181 if (jTextAreaHelpText
== null) {
182 jTextAreaHelpText
= new JTextArea();
183 jTextAreaHelpText
.setLineWrap(true);
184 jTextAreaHelpText
.setWrapStyleWord(true);
185 jTextAreaHelpText
.setToolTipText("Enter information on how to use this Variable.");
187 return jTextAreaHelpText
;
190 private JScrollPane
getJScrollPaneHelpText() {
191 if (jScrollPaneHelpText
== null) {
192 jScrollPaneHelpText
= new JScrollPane();
193 jScrollPaneHelpText
.setHorizontalScrollBarPolicy(javax
.swing
.JScrollPane
.HORIZONTAL_SCROLLBAR_NEVER
);
194 jScrollPaneHelpText
.setSize(new java
.awt
.Dimension(320, 40));
195 jScrollPaneHelpText
.setPreferredSize(new java
.awt
.Dimension(320, 40));
196 jScrollPaneHelpText
.setLocation(new java
.awt
.Point(168, 87));
197 jScrollPaneHelpText
.setViewportView(getJTextAreaHelpText());
199 return jScrollPaneHelpText
;
203 * This method initializes jComboBoxGuidC_Name
205 * @return javax.swing.JComboBox jComboBoxGuidC_Name
208 private JComboBox
getJComboBoxGuidC_Name() {
209 if (jComboBoxGuidC_Name
== null) {
210 jComboBoxGuidC_Name
= new JComboBox();
211 jComboBoxGuidC_Name
.setBounds(new java
.awt
.Rectangle(168, 37, 320, 20));
212 jComboBoxGuidC_Name
.setPreferredSize(new java
.awt
.Dimension(320, 20));
213 jComboBoxGuidC_Name
.setToolTipText("Select the GUID C Name of the Variable.");
215 return jComboBoxGuidC_Name
;
219 * This method initializes jButtonOk
221 * @return javax.swing.JButton
224 private JButton
getJButtonOk() {
225 if (jButtonOk
== null) {
226 jButtonOk
= new JButton();
227 jButtonOk
.setBounds(new java
.awt
.Rectangle(290, 187, 90, 20));
228 jButtonOk
.setText("Ok");
229 jButtonOk
.addActionListener(this);
235 * This method initializes jButtonCancel
237 * @return javax.swing.JButton
240 private JButton
getJButtonCancel() {
241 if (jButtonCancel
== null) {
242 jButtonCancel
= new JButton();
243 jButtonCancel
.setBounds(new java
.awt
.Rectangle(390, 187, 90, 20));
244 jButtonCancel
.setText("Cancel");
245 jButtonCancel
.addActionListener(this);
247 return jButtonCancel
;
250 public static void main(String
[] args
) {
255 * This method initializes this
258 private void init() {
259 this.setSize(505, 260);
260 this.setContentPane(getJScrollPane());
261 this.setTitle("Variables");
263 this.setViewMode(false);
268 * This method initializes this Fill values to all fields if these values are
271 * @param inVariablesId
274 private void init(VariablesIdentification inVariablesId
) {
276 this.id
= inVariablesId
;
278 if (this.id
!= null) {
279 this.jTextFieldVariableName
.setText(id
.getName());
280 this.jComboBoxGuidC_Name
.setSelectedItem(id
.getGuid());
281 this.jComboBoxUsage
.setSelectedItem(id
.getUsage());
282 this.jTextAreaHelpText
.setText(id
.getHelp());
283 this.jTextFieldFeatureFlag
.setText(id
.getFeatureFlag());
284 this.jArchCheckBox
.setSelectedItems(id
.getSupArchList());
289 * This is the override edit constructor
291 * @param inVariablesIdentification
295 public VariablesDlg(VariablesIdentification inVariablesIdentification
, IFrame iFrame
) {
297 init(inVariablesIdentification
);
301 * Disable all components when the mode is view
304 * true - The view mode; false - The non-view mode
307 public void setViewMode(boolean isView
) {
309 this.jTextFieldVariableName
.setEnabled(!isView
);
310 this.jComboBoxUsage
.setEnabled(!isView
);
315 * This method initializes jContentPane
317 * @return javax.swing.JPanel jContentPane
320 private JPanel
getJContentPane() {
321 if (jContentPane
== null) {
322 jStarLabel1
= new StarLabel();
323 jStarLabel1
.setLocation(new java
.awt
.Point(2, 12));
324 jLabelVariableName
= new JLabel();
325 jLabelVariableName
.setText("Variable Name");
326 jLabelVariableName
.setBounds(new java
.awt
.Rectangle(12, 12, 168, 20));
328 jStarLabel2
= new StarLabel();
329 jStarLabel2
.setLocation(new java
.awt
.Point(2, 37));
330 jLabelGuidCName
= new JLabel();
331 jLabelGuidCName
.setBounds(new java
.awt
.Rectangle(12, 37, 168, 20));
332 jLabelGuidCName
.setText("Variable Guid C Name");
334 jStarLabel3
= new StarLabel();
335 jStarLabel3
.setLocation(new java
.awt
.Point(2, 62));
336 jLabelUsage
= new JLabel();
337 jLabelUsage
.setText("Usage");
338 jLabelUsage
.setBounds(new java
.awt
.Rectangle(12, 62, 168, 20));
340 jLabelHelpText
= new JLabel();
341 jLabelHelpText
.setBounds(new java
.awt
.Rectangle(12, 87, 168, 20));
342 jLabelHelpText
.setText("Help Text");
344 jLabelFeatureFlag
= new JLabel();
345 jLabelFeatureFlag
.setText("Feature Flag Expression");
346 jLabelFeatureFlag
.setBounds(new java
.awt
.Rectangle(12, 132, 168, 20));
348 jLabelArch
= new JLabel();
349 jLabelArch
.setBounds(new java
.awt
.Rectangle(12, 157, 168, 20));
350 jLabelArch
.setText("Supported Architectures");
351 jArchCheckBox
= new ArchCheckBox();
352 jArchCheckBox
.setBounds(new java
.awt
.Rectangle(168, 157, 320, 20));
353 jArchCheckBox
.setPreferredSize(new java
.awt
.Dimension(320, 20));
355 jContentPane
= new JPanel();
356 jContentPane
.setLayout(null);
357 jContentPane
.setPreferredSize(new java
.awt
.Dimension(485, 215));
359 jContentPane
.add(jStarLabel1
, null);
360 jContentPane
.add(jLabelVariableName
, null);
361 jContentPane
.add(getJTextFieldString(), null);
362 jContentPane
.add(jStarLabel2
, null);
363 jContentPane
.add(jLabelGuidCName
, null);
364 jContentPane
.add(getJComboBoxGuidC_Name(), null);
365 jContentPane
.add(jStarLabel3
, null);
366 jContentPane
.add(jLabelUsage
, null);
367 jContentPane
.add(getJComboBoxUsage(), null);
368 jContentPane
.add(jLabelHelpText
, null);
369 jContentPane
.add(getJScrollPaneHelpText(), null);
370 jContentPane
.add(jLabelFeatureFlag
, null);
371 jContentPane
.add(getJTextFieldFeatureFlag(), null);
372 jContentPane
.add(jLabelArch
, null);
373 jContentPane
.add(jArchCheckBox
, null);
374 jContentPane
.add(getJButtonOk(), null);
375 jContentPane
.add(getJButtonCancel(), null);
383 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
385 * Override actionPerformed to listen all actions
388 public void actionPerformed(ActionEvent arg0
) {
389 if (arg0
.getSource() == jButtonOk
) {
391 getCurrentVariables();
392 this.returnType
= DataType
.RETURN_TYPE_OK
;
393 this.setVisible(false);
397 if (arg0
.getSource() == jButtonCancel
) {
398 this.returnType
= DataType
.RETURN_TYPE_CANCEL
;
399 this.setVisible(false);
404 * This method initializes Usage type
407 private void initFrame() {
408 Tools
.generateComboBoxByVector(jComboBoxUsage
, ed
.getVPpiUsage());
409 Tools
.generateComboBoxByVector(jComboBoxGuidC_Name
, wt
.getAllGuidDeclarationsFromWorkspace());
413 * Data validation for all fields
415 * @retval true - All datas are valid
416 * @retval false - At least one data is invalid
419 public boolean checkAdd() {
421 // Check if all fields have correct data types
425 // Check VariableName
427 if (isEmpty(this.jTextFieldVariableName
.getText())) {
428 Log
.wrn("Update Variables", "Variable Name must not be empty");
432 if (!isEmpty(this.jTextFieldVariableName
.getText())) {
433 if (!DataValidation
.isHexWordArrayType(this.jTextFieldVariableName
.getText())) {
434 Log
.wrn("Update Variables", "Incorrect data type for Variable Name");
442 if (!isEmpty(this.jTextFieldFeatureFlag
.getText())) {
443 if (!DataValidation
.isFeatureFlag(this.jTextFieldFeatureFlag
.getText())) {
444 Log
.wrn("Update Variables", "Incorrect data type for Feature Flag");
452 private VariablesIdentification
getCurrentVariables() {
453 String arg0
= this.jTextFieldVariableName
.getText();
454 String arg1
= this.jComboBoxGuidC_Name
.getSelectedItem().toString();
455 String arg2
= this.jComboBoxUsage
.getSelectedItem().toString();
457 String arg3
= this.jTextFieldFeatureFlag
.getText();
458 Vector
<String
> arg4
= this.jArchCheckBox
.getSelectedItemsVector();
459 String arg5
= this.jTextAreaHelpText
.getText();
461 id
= new VariablesIdentification(arg0
, arg1
, arg2
, arg3
, arg4
, arg5
);
465 public VariablesIdentification
getId() {
469 public void setId(VariablesIdentification id
) {