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
.ModuleIdentification
;
39 import org
.tianocore
.frameworkwizard
.module
.Identifications
.Variables
.VariablesIdentification
;
40 import org
.tianocore
.frameworkwizard
.packaging
.PackageIdentification
;
41 import org
.tianocore
.frameworkwizard
.workspace
.WorkspaceTools
;
44 * The class is used to create, update Variables section of the MSA file
49 public class VariablesDlg
extends IDialog
{
52 // / Define class Serial Version UID
54 private static final long serialVersionUID
= -6998982978030439446L;
57 // Define class members
59 private JPanel jContentPane
= null;
61 private JLabel jLabelVariableName
= null;
63 private JTextField jTextFieldVariableName
= null;
65 private JLabel jLabelUsage
= null;
67 private JComboBox jComboBoxUsage
= null;
69 private StarLabel jStarLabel1
= null;
71 private StarLabel jStarLabel2
= null;
73 private StarLabel jStarLabel3
= null;
75 private JScrollPane jScrollPane
= null;
77 private JLabel jLabelGuidCName
= null;
79 private JComboBox jComboBoxGuidC_Name
= null;
81 private JTextField jTextFieldFeatureFlag
= null;
83 private JLabel jLabelFeatureFlag
= null;
85 private JLabel jLabelArch
= null;
87 private JLabel jLabelHelpText
= null;
89 private JTextArea jTextAreaHelpText
= null;
91 private JScrollPane jScrollPaneHelpText
= null;
93 private ArchCheckBox jArchCheckBox
= null;
95 private JButton jButtonOk
= null;
97 private JButton jButtonCancel
= null;
102 private VariablesIdentification id
= null;
104 private EnumerationData ed
= new EnumerationData();
106 private WorkspaceTools wt
= new WorkspaceTools();
109 * This method initializes jTextFieldString
111 * @return javax.swing.JTextField jTextFieldString
114 private JTextField
getJTextFieldString() {
115 if (jTextFieldVariableName
== null) {
116 jTextFieldVariableName
= new JTextField();
117 jTextFieldVariableName
.setSize(new java
.awt
.Dimension(320, 20));
118 jTextFieldVariableName
.setPreferredSize(new java
.awt
.Dimension(320, 20));
119 jTextFieldVariableName
.setLocation(new java
.awt
.Point(168, 12));
120 jTextFieldVariableName
.setToolTipText("Enter a string; the tool will convert to Unicode hex");
122 return jTextFieldVariableName
;
126 * This method initializes jComboBoxUsage
128 * @return javax.swing.JComboBox jComboBoxUsage
131 private JComboBox
getJComboBoxUsage() {
132 if (jComboBoxUsage
== null) {
133 jComboBoxUsage
= new JComboBox();
134 jComboBoxUsage
.setBounds(new java
.awt
.Rectangle(168, 62, 320, 20));
135 jComboBoxUsage
.setPreferredSize(new java
.awt
.Dimension(320, 20));
137 .setToolTipText("<html><table>"
138 + "<tr><td>ALWAYS_CONSUMED</td><td>The module requires the variable entry to be set</td></tr>"
139 + "<tr><td>SOMETIMES_CONSUMED</td><td>The module will use the variable entry if it is set.</td></tr>"
140 + "<tr><td>ALWAYS_PRODUCED</td><td>The module will always write the variable.</td></tr>"
141 + "<tr><td>SOMETIMES_PRODUCED</td><td>The module will sometimes write the variable.</td></tr>"
142 + "</table></html>");
144 return jComboBoxUsage
;
148 * This method initializes jScrollPane
150 * @return javax.swing.JScrollPane
152 private JScrollPane
getJScrollPane() {
153 if (jScrollPane
== null) {
154 jScrollPane
= new JScrollPane();
155 jScrollPane
.setViewportView(getJContentPane());
161 * This method initializes jTextFieldFeatureFlag
163 * @return javax.swing.JTextField jTextFieldFeatureFlag
166 private JTextField
getJTextFieldFeatureFlag() {
167 if (jTextFieldFeatureFlag
== null) {
168 jTextFieldFeatureFlag
= new JTextField();
169 jTextFieldFeatureFlag
.setBounds(new java
.awt
.Rectangle(168, 157, 320, 20));
170 jTextFieldFeatureFlag
.setPreferredSize(new java
.awt
.Dimension(320, 20));
171 jTextFieldFeatureFlag
.setToolTipText("Postfix expression that must evaluate to TRUE or FALSE");
172 jTextFieldFeatureFlag
.setEnabled(false);
174 return jTextFieldFeatureFlag
;
178 * This method initializes jTextFieldHelpText
180 * @return javax.swing.JTextField
183 private JTextArea
getJTextAreaHelpText() {
184 if (jTextAreaHelpText
== null) {
185 jTextAreaHelpText
= new JTextArea();
186 jTextAreaHelpText
.setLineWrap(true);
187 jTextAreaHelpText
.setWrapStyleWord(true);
188 jTextAreaHelpText
.setToolTipText("Enter information on how to use this Variable.");
190 return jTextAreaHelpText
;
193 private JScrollPane
getJScrollPaneHelpText() {
194 if (jScrollPaneHelpText
== null) {
195 jScrollPaneHelpText
= new JScrollPane();
196 jScrollPaneHelpText
.setHorizontalScrollBarPolicy(javax
.swing
.JScrollPane
.HORIZONTAL_SCROLLBAR_NEVER
);
197 jScrollPaneHelpText
.setSize(new java
.awt
.Dimension(320, 40));
198 jScrollPaneHelpText
.setPreferredSize(new java
.awt
.Dimension(320, 40));
199 jScrollPaneHelpText
.setLocation(new java
.awt
.Point(168, 87));
200 jScrollPaneHelpText
.setViewportView(getJTextAreaHelpText());
202 return jScrollPaneHelpText
;
206 * This method initializes jComboBoxGuidC_Name
208 * @return javax.swing.JComboBox jComboBoxGuidC_Name
211 private JComboBox
getJComboBoxGuidC_Name() {
212 if (jComboBoxGuidC_Name
== null) {
213 jComboBoxGuidC_Name
= new JComboBox();
214 jComboBoxGuidC_Name
.setBounds(new java
.awt
.Rectangle(168, 37, 320, 20));
215 jComboBoxGuidC_Name
.setPreferredSize(new java
.awt
.Dimension(320, 20));
216 jComboBoxGuidC_Name
.setToolTipText("Select the GUID C Name of the Variable.");
218 return jComboBoxGuidC_Name
;
222 * This method initializes jButtonOk
224 * @return javax.swing.JButton
227 private JButton
getJButtonOk() {
228 if (jButtonOk
== null) {
229 jButtonOk
= new JButton();
230 jButtonOk
.setBounds(new java
.awt
.Rectangle(290, 187, 90, 20));
231 jButtonOk
.setText("Ok");
232 jButtonOk
.addActionListener(this);
238 * This method initializes jButtonCancel
240 * @return javax.swing.JButton
243 private JButton
getJButtonCancel() {
244 if (jButtonCancel
== null) {
245 jButtonCancel
= new JButton();
246 jButtonCancel
.setBounds(new java
.awt
.Rectangle(390, 187, 90, 20));
247 jButtonCancel
.setText("Cancel");
248 jButtonCancel
.addActionListener(this);
250 return jButtonCancel
;
253 public static void main(String
[] args
) {
258 * This method initializes this
261 private void init() {
262 this.setSize(505, 260);
263 this.setContentPane(getJScrollPane());
264 this.setTitle("Variables");
266 this.setViewMode(false);
271 * This method initializes this Fill values to all fields if these values are
274 * @param inVariablesId
277 private void init(VariablesIdentification inVariablesId
, ModuleIdentification mid
) {
279 this.id
= inVariablesId
;
282 // Init arch with module's arch
284 this.jArchCheckBox
.setEnabledItems(wt
.getModuleArch(mid
));
287 // Get defined guids from dependent packages
289 Vector
<PackageIdentification
> vpid
= wt
.getPackageDependenciesOfModule(mid
);
290 if (vpid
.size() <= 0) {
293 "This module hasn't defined any package dependency, so there is no guid value can be added for variable");
296 // Init guids drop down list
299 .generateComboBoxByVector(jComboBoxGuidC_Name
,
300 wt
.getAllGuidDeclarationsFromPackages(vpid
, EnumerationData
.GUID_TYPE_EFI_VARIABLE
));
302 if (this.id
!= null) {
303 this.jTextFieldVariableName
.setText(id
.getName());
304 this.jComboBoxGuidC_Name
.setSelectedItem(id
.getGuid());
305 this.jComboBoxUsage
.setSelectedItem(id
.getUsage());
306 this.jTextAreaHelpText
.setText(id
.getHelp());
307 this.jTextFieldFeatureFlag
.setText(id
.getFeatureFlag());
308 this.jArchCheckBox
.setSelectedItems(id
.getSupArchList());
313 * This is the override edit constructor
315 * @param inVariablesIdentification
319 public VariablesDlg(VariablesIdentification inVariablesIdentification
, IFrame iFrame
, ModuleIdentification mid
) {
321 init(inVariablesIdentification
, mid
);
325 * Disable all components when the mode is view
328 * true - The view mode; false - The non-view mode
331 public void setViewMode(boolean isView
) {
333 this.jTextFieldVariableName
.setEnabled(!isView
);
334 this.jComboBoxUsage
.setEnabled(!isView
);
339 * This method initializes jContentPane
341 * @return javax.swing.JPanel jContentPane
344 private JPanel
getJContentPane() {
345 if (jContentPane
== null) {
346 jStarLabel1
= new StarLabel();
347 jStarLabel1
.setLocation(new java
.awt
.Point(2, 12));
348 jLabelVariableName
= new JLabel();
349 jLabelVariableName
.setText("Variable Name");
350 jLabelVariableName
.setBounds(new java
.awt
.Rectangle(12, 12, 168, 20));
352 jStarLabel2
= new StarLabel();
353 jStarLabel2
.setLocation(new java
.awt
.Point(2, 37));
354 jLabelGuidCName
= new JLabel();
355 jLabelGuidCName
.setBounds(new java
.awt
.Rectangle(12, 37, 168, 20));
356 jLabelGuidCName
.setText("Variable Guid C Name");
358 jStarLabel3
= new StarLabel();
359 jStarLabel3
.setLocation(new java
.awt
.Point(2, 62));
360 jLabelUsage
= new JLabel();
361 jLabelUsage
.setText("Usage");
362 jLabelUsage
.setBounds(new java
.awt
.Rectangle(12, 62, 168, 20));
364 jLabelHelpText
= new JLabel();
365 jLabelHelpText
.setBounds(new java
.awt
.Rectangle(12, 87, 168, 20));
366 jLabelHelpText
.setText("Help Text");
368 jLabelFeatureFlag
= new JLabel();
369 jLabelFeatureFlag
.setText("Feature Flag Expression");
370 jLabelFeatureFlag
.setBounds(new java
.awt
.Rectangle(12, 157, 168, 20));
371 jLabelFeatureFlag
.setEnabled(false);
373 jLabelArch
= new JLabel();
374 jLabelArch
.setBounds(new java
.awt
.Rectangle(12, 132, 168, 20));
375 jLabelArch
.setText("Supported Architectures");
376 jArchCheckBox
= new ArchCheckBox();
377 jArchCheckBox
.setBounds(new java
.awt
.Rectangle(168, 132, 320, 20));
378 jArchCheckBox
.setPreferredSize(new java
.awt
.Dimension(320, 20));
380 jContentPane
= new JPanel();
381 jContentPane
.setLayout(null);
382 jContentPane
.setPreferredSize(new java
.awt
.Dimension(485, 215));
384 jContentPane
.add(jStarLabel1
, null);
385 jContentPane
.add(jLabelVariableName
, null);
386 jContentPane
.add(getJTextFieldString(), null);
387 jContentPane
.add(jStarLabel2
, null);
388 jContentPane
.add(jLabelGuidCName
, null);
389 jContentPane
.add(getJComboBoxGuidC_Name(), null);
390 jContentPane
.add(jStarLabel3
, null);
391 jContentPane
.add(jLabelUsage
, null);
392 jContentPane
.add(getJComboBoxUsage(), null);
393 jContentPane
.add(jLabelHelpText
, null);
394 jContentPane
.add(getJScrollPaneHelpText(), null);
395 jContentPane
.add(jLabelFeatureFlag
, null);
396 jContentPane
.add(getJTextFieldFeatureFlag(), null);
397 jContentPane
.add(jLabelArch
, null);
398 jContentPane
.add(jArchCheckBox
, null);
399 jContentPane
.add(getJButtonOk(), null);
400 jContentPane
.add(getJButtonCancel(), null);
408 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
410 * Override actionPerformed to listen all actions
413 public void actionPerformed(ActionEvent arg0
) {
414 if (arg0
.getSource() == jButtonOk
) {
416 getCurrentVariables();
417 this.returnType
= DataType
.RETURN_TYPE_OK
;
418 this.setVisible(false);
422 if (arg0
.getSource() == jButtonCancel
) {
423 this.returnType
= DataType
.RETURN_TYPE_CANCEL
;
424 this.setVisible(false);
429 * This method initializes Usage type
432 private void initFrame() {
433 Tools
.generateComboBoxByVector(jComboBoxUsage
, ed
.getVPpiUsage());
437 * Data validation for all fields
439 * @retval true - All datas are valid
440 * @retval false - At least one data is invalid
443 public boolean checkAdd() {
445 // Check if all fields have correct data types
449 // Check VariableName
451 if (isEmpty(this.jTextFieldVariableName
.getText())) {
452 Log
.wrn("Update Variables", "Variable Name must be entered!");
459 if (this.jComboBoxGuidC_Name
.getSelectedItem() == null) {
460 Log
.wrn("Update Guids", "Please select one Varibale Guid value");
467 if (!isEmpty(this.jTextFieldFeatureFlag
.getText())) {
468 if (!DataValidation
.isFeatureFlag(this.jTextFieldFeatureFlag
.getText())) {
469 Log
.wrn("Update Variables", "Incorrect data type for Feature Flag");
477 private VariablesIdentification
getCurrentVariables() {
478 String arg0
= this.jTextFieldVariableName
.getText();
479 String arg1
= this.jComboBoxGuidC_Name
.getSelectedItem().toString();
480 String arg2
= this.jComboBoxUsage
.getSelectedItem().toString();
482 String arg3
= this.jTextFieldFeatureFlag
.getText();
483 Vector
<String
> arg4
= this.jArchCheckBox
.getSelectedItemsVector();
484 String arg5
= this.jTextAreaHelpText
.getText();
486 id
= new VariablesIdentification(arg0
, arg1
, arg2
, arg3
, arg4
, arg5
);
490 public VariablesIdentification
getId() {
494 public void setId(VariablesIdentification id
) {