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
.IComboBox
;
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
.ModuleIdentification
;
40 import org
.tianocore
.frameworkwizard
.module
.Identifications
.Variables
.VariablesIdentification
;
41 import org
.tianocore
.frameworkwizard
.packaging
.PackageIdentification
;
42 import org
.tianocore
.frameworkwizard
.workspace
.WorkspaceTools
;
45 * The class is used to create, update Variables section of the MSA file
50 public class VariablesDlg
extends IDialog
{
53 // / Define class Serial Version UID
55 private static final long serialVersionUID
= -6998982978030439446L;
58 // Define class members
60 private JPanel jContentPane
= null;
62 private JLabel jLabelVariableName
= null;
64 private JTextField jTextFieldVariableName
= null;
66 private JLabel jLabelUsage
= null;
68 private JComboBox jComboBoxUsage
= null;
70 private StarLabel jStarLabel1
= null;
72 private StarLabel jStarLabel2
= null;
74 private StarLabel jStarLabel3
= null;
76 private JScrollPane jScrollPane
= null;
78 private JLabel jLabelGuidCName
= null;
80 private IComboBox iComboBoxGuidC_Name
= null;
82 private JTextField jTextFieldFeatureFlag
= null;
84 private JLabel jLabelFeatureFlag
= null;
86 private JLabel jLabelArch
= null;
88 private JLabel jLabelHelpText
= null;
90 private JTextArea jTextAreaHelpText
= null;
92 private JScrollPane jScrollPaneHelpText
= null;
94 private ArchCheckBox jArchCheckBox
= null;
96 private JButton jButtonOk
= null;
98 private JButton jButtonCancel
= null;
103 private VariablesIdentification id
= null;
105 private EnumerationData ed
= new EnumerationData();
107 private WorkspaceTools wt
= new WorkspaceTools();
110 * This method initializes jTextFieldString
112 * @return javax.swing.JTextField jTextFieldString
115 private JTextField
getJTextFieldString() {
116 if (jTextFieldVariableName
== null) {
117 jTextFieldVariableName
= new JTextField();
118 jTextFieldVariableName
.setSize(new java
.awt
.Dimension(320, 20));
119 jTextFieldVariableName
.setPreferredSize(new java
.awt
.Dimension(320, 20));
120 jTextFieldVariableName
.setLocation(new java
.awt
.Point(168, 12));
121 jTextFieldVariableName
.setToolTipText("Enter a string; the tool will convert to Unicode hex");
123 return jTextFieldVariableName
;
127 * This method initializes jComboBoxUsage
129 * @return javax.swing.JComboBox jComboBoxUsage
132 private JComboBox
getJComboBoxUsage() {
133 if (jComboBoxUsage
== null) {
134 jComboBoxUsage
= new JComboBox();
135 jComboBoxUsage
.setBounds(new java
.awt
.Rectangle(168, 62, 320, 20));
136 jComboBoxUsage
.setPreferredSize(new java
.awt
.Dimension(320, 20));
138 .setToolTipText("<html><table>"
139 + "<tr><td>ALWAYS_CONSUMED</td><td>The module requires the variable entry to be set</td></tr>"
140 + "<tr><td>SOMETIMES_CONSUMED</td><td>The module will use the variable entry if it is set.</td></tr>"
141 + "<tr><td>ALWAYS_PRODUCED</td><td>The module will always write the variable.</td></tr>"
142 + "<tr><td>SOMETIMES_PRODUCED</td><td>The module will sometimes write the variable.</td></tr>"
143 + "</table></html>");
145 return jComboBoxUsage
;
149 * This method initializes jScrollPane
151 * @return javax.swing.JScrollPane
153 private JScrollPane
getJScrollPane() {
154 if (jScrollPane
== null) {
155 jScrollPane
= new JScrollPane();
156 jScrollPane
.setViewportView(getJContentPane());
162 * This method initializes jTextFieldFeatureFlag
164 * @return javax.swing.JTextField jTextFieldFeatureFlag
167 private JTextField
getJTextFieldFeatureFlag() {
168 if (jTextFieldFeatureFlag
== null) {
169 jTextFieldFeatureFlag
= new JTextField();
170 jTextFieldFeatureFlag
.setBounds(new java
.awt
.Rectangle(168, 157, 320, 20));
171 jTextFieldFeatureFlag
.setPreferredSize(new java
.awt
.Dimension(320, 20));
172 jTextFieldFeatureFlag
.setToolTipText("Postfix expression that must evaluate to TRUE or FALSE");
173 jTextFieldFeatureFlag
.setEnabled(false);
175 return jTextFieldFeatureFlag
;
179 * This method initializes jTextFieldHelpText
181 * @return javax.swing.JTextField
184 private JTextArea
getJTextAreaHelpText() {
185 if (jTextAreaHelpText
== null) {
186 jTextAreaHelpText
= new JTextArea();
187 jTextAreaHelpText
.setLineWrap(true);
188 jTextAreaHelpText
.setWrapStyleWord(true);
189 jTextAreaHelpText
.setToolTipText("Enter information on how to use this Variable.");
191 return jTextAreaHelpText
;
194 private JScrollPane
getJScrollPaneHelpText() {
195 if (jScrollPaneHelpText
== null) {
196 jScrollPaneHelpText
= new JScrollPane();
197 jScrollPaneHelpText
.setHorizontalScrollBarPolicy(javax
.swing
.JScrollPane
.HORIZONTAL_SCROLLBAR_NEVER
);
198 jScrollPaneHelpText
.setSize(new java
.awt
.Dimension(320, 40));
199 jScrollPaneHelpText
.setPreferredSize(new java
.awt
.Dimension(320, 40));
200 jScrollPaneHelpText
.setLocation(new java
.awt
.Point(168, 87));
201 jScrollPaneHelpText
.setViewportView(getJTextAreaHelpText());
203 return jScrollPaneHelpText
;
207 * This method initializes iComboBoxGuidC_Name
209 * @return javax.swing.JComboBox iComboBoxGuidC_Name
212 private IComboBox
getIComboBoxGuidC_Name() {
213 if (iComboBoxGuidC_Name
== null) {
214 iComboBoxGuidC_Name
= new IComboBox();
215 iComboBoxGuidC_Name
.setBounds(new java
.awt
.Rectangle(168, 37, 320, 20));
216 iComboBoxGuidC_Name
.setPreferredSize(new java
.awt
.Dimension(320, 20));
217 iComboBoxGuidC_Name
.setToolTipText("Select the GUID C Name of the Variable.");
219 return iComboBoxGuidC_Name
;
223 * This method initializes jButtonOk
225 * @return javax.swing.JButton
228 private JButton
getJButtonOk() {
229 if (jButtonOk
== null) {
230 jButtonOk
= new JButton();
231 jButtonOk
.setBounds(new java
.awt
.Rectangle(290, 187, 90, 20));
232 jButtonOk
.setText("Ok");
233 jButtonOk
.addActionListener(this);
239 * This method initializes jButtonCancel
241 * @return javax.swing.JButton
244 private JButton
getJButtonCancel() {
245 if (jButtonCancel
== null) {
246 jButtonCancel
= new JButton();
247 jButtonCancel
.setBounds(new java
.awt
.Rectangle(390, 187, 90, 20));
248 jButtonCancel
.setText("Cancel");
249 jButtonCancel
.addActionListener(this);
251 return jButtonCancel
;
254 public static void main(String
[] args
) {
259 * This method initializes this
262 private void init() {
263 this.setSize(505, 260);
264 this.setContentPane(getJScrollPane());
265 this.setTitle("Variables");
267 this.setViewMode(false);
272 * This method initializes this Fill values to all fields if these values are
275 * @param inVariablesId
278 private void init(VariablesIdentification inVariablesId
, ModuleIdentification mid
) {
280 this.id
= inVariablesId
;
283 // Init arch with module's arch
285 this.jArchCheckBox
.setEnabledItems(wt
.getModuleArch(mid
));
288 // Get defined guids from dependent packages
290 Vector
<PackageIdentification
> vpid
= wt
.getPackageDependenciesOfModule(mid
);
291 if (vpid
.size() <= 0) {
294 "This module hasn't defined any package dependency, so there is no guid value can be added for variable");
297 // Init guids drop down list
300 .generateComboBoxByVector(iComboBoxGuidC_Name
,
301 wt
.getAllGuidDeclarationsFromPackages(vpid
, EnumerationData
.GUID_TYPE_EFI_VARIABLE
));
303 if (this.id
!= null) {
304 this.jTextFieldVariableName
.setText(id
.getName());
305 this.iComboBoxGuidC_Name
.setSelectedItem(id
.getGuid());
306 this.jComboBoxUsage
.setSelectedItem(id
.getUsage());
307 this.jTextAreaHelpText
.setText(id
.getHelp());
308 this.jTextFieldFeatureFlag
.setText(id
.getFeatureFlag());
309 this.jArchCheckBox
.setSelectedItems(id
.getSupArchList());
314 * This is the override edit constructor
316 * @param inVariablesIdentification
320 public VariablesDlg(VariablesIdentification inVariablesIdentification
, IFrame iFrame
, ModuleIdentification mid
) {
322 init(inVariablesIdentification
, mid
);
326 * Disable all components when the mode is view
329 * true - The view mode; false - The non-view mode
332 public void setViewMode(boolean isView
) {
334 this.jTextFieldVariableName
.setEnabled(!isView
);
335 this.jComboBoxUsage
.setEnabled(!isView
);
340 * This method initializes jContentPane
342 * @return javax.swing.JPanel jContentPane
345 private JPanel
getJContentPane() {
346 if (jContentPane
== null) {
347 jStarLabel1
= new StarLabel();
348 jStarLabel1
.setLocation(new java
.awt
.Point(2, 12));
349 jLabelVariableName
= new JLabel();
350 jLabelVariableName
.setText("Variable Name");
351 jLabelVariableName
.setBounds(new java
.awt
.Rectangle(12, 12, 168, 20));
353 jStarLabel2
= new StarLabel();
354 jStarLabel2
.setLocation(new java
.awt
.Point(2, 37));
355 jLabelGuidCName
= new JLabel();
356 jLabelGuidCName
.setBounds(new java
.awt
.Rectangle(12, 37, 168, 20));
357 jLabelGuidCName
.setText("Variable Guid C Name");
359 jStarLabel3
= new StarLabel();
360 jStarLabel3
.setLocation(new java
.awt
.Point(2, 62));
361 jLabelUsage
= new JLabel();
362 jLabelUsage
.setText("Usage");
363 jLabelUsage
.setBounds(new java
.awt
.Rectangle(12, 62, 168, 20));
365 jLabelHelpText
= new JLabel();
366 jLabelHelpText
.setBounds(new java
.awt
.Rectangle(12, 87, 168, 20));
367 jLabelHelpText
.setText("Help Text");
369 jLabelFeatureFlag
= new JLabel();
370 jLabelFeatureFlag
.setText("Feature Flag Expression");
371 jLabelFeatureFlag
.setBounds(new java
.awt
.Rectangle(12, 157, 168, 20));
372 jLabelFeatureFlag
.setEnabled(false);
374 jLabelArch
= new JLabel();
375 jLabelArch
.setBounds(new java
.awt
.Rectangle(12, 132, 168, 20));
376 jLabelArch
.setText("Supported Architectures");
377 jArchCheckBox
= new ArchCheckBox();
378 jArchCheckBox
.setBounds(new java
.awt
.Rectangle(168, 132, 320, 20));
379 jArchCheckBox
.setPreferredSize(new java
.awt
.Dimension(320, 20));
381 jContentPane
= new JPanel();
382 jContentPane
.setLayout(null);
383 jContentPane
.setPreferredSize(new java
.awt
.Dimension(485, 215));
385 jContentPane
.add(jStarLabel1
, null);
386 jContentPane
.add(jLabelVariableName
, null);
387 jContentPane
.add(getJTextFieldString(), null);
388 jContentPane
.add(jStarLabel2
, null);
389 jContentPane
.add(jLabelGuidCName
, null);
390 jContentPane
.add(getIComboBoxGuidC_Name(), null);
391 jContentPane
.add(jStarLabel3
, null);
392 jContentPane
.add(jLabelUsage
, null);
393 jContentPane
.add(getJComboBoxUsage(), null);
394 jContentPane
.add(jLabelHelpText
, null);
395 jContentPane
.add(getJScrollPaneHelpText(), null);
396 jContentPane
.add(jLabelFeatureFlag
, null);
397 jContentPane
.add(getJTextFieldFeatureFlag(), null);
398 jContentPane
.add(jLabelArch
, null);
399 jContentPane
.add(jArchCheckBox
, null);
400 jContentPane
.add(getJButtonOk(), null);
401 jContentPane
.add(getJButtonCancel(), null);
409 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
411 * Override actionPerformed to listen all actions
414 public void actionPerformed(ActionEvent arg0
) {
415 if (arg0
.getSource() == jButtonOk
) {
417 getCurrentVariables();
418 this.returnType
= DataType
.RETURN_TYPE_OK
;
419 this.setVisible(false);
423 if (arg0
.getSource() == jButtonCancel
) {
424 this.returnType
= DataType
.RETURN_TYPE_CANCEL
;
425 this.setVisible(false);
430 * This method initializes Usage type
433 private void initFrame() {
434 Tools
.generateComboBoxByVector(jComboBoxUsage
, ed
.getVPpiUsage());
438 * Data validation for all fields
440 * @retval true - All datas are valid
441 * @retval false - At least one data is invalid
444 public boolean checkAdd() {
446 // Check if all fields have correct data types
450 // Check VariableName
452 if (isEmpty(this.jTextFieldVariableName
.getText())) {
453 Log
.wrn("Update Variables", "Variable Name must be entered!");
460 if (this.iComboBoxGuidC_Name
.getSelectedItem() == null) {
461 Log
.wrn("Update Guids", "Please select one Varibale Guid value");
468 if (!isEmpty(this.jTextFieldFeatureFlag
.getText())) {
469 if (!DataValidation
.isFeatureFlag(this.jTextFieldFeatureFlag
.getText())) {
470 Log
.wrn("Update Variables", "Incorrect data type for Feature Flag");
478 private VariablesIdentification
getCurrentVariables() {
479 String arg0
= this.jTextFieldVariableName
.getText();
480 String arg1
= this.iComboBoxGuidC_Name
.getSelectedItem().toString();
481 String arg2
= this.jComboBoxUsage
.getSelectedItem().toString();
483 String arg3
= this.jTextFieldFeatureFlag
.getText();
484 Vector
<String
> arg4
= this.jArchCheckBox
.getSelectedItemsVector();
485 String arg5
= this.jTextAreaHelpText
.getText();
487 id
= new VariablesIdentification(arg0
, arg1
, arg2
, arg3
, arg4
, arg5
);
491 public VariablesIdentification
getId() {
495 public void setId(VariablesIdentification id
) {