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
47 public class VariablesDlg
extends IDialog
{
50 // / Define class Serial Version UID
52 private static final long serialVersionUID
= -6998982978030439446L;
55 // Define class members
57 private JPanel jContentPane
= null;
59 private JLabel jLabelVariableName
= null;
61 private JTextField jTextFieldVariableName
= null;
63 private JLabel jLabelUsage
= null;
65 private JComboBox jComboBoxUsage
= null;
67 private StarLabel jStarLabel1
= null;
69 private StarLabel jStarLabel2
= null;
71 private StarLabel jStarLabel3
= null;
73 private JScrollPane jScrollPane
= null;
75 private JLabel jLabelGuidCName
= null;
77 private JComboBox jComboBoxGuidC_Name
= null;
79 private JTextField jTextFieldFeatureFlag
= null;
81 private JLabel jLabelFeatureFlag
= null;
83 private JLabel jLabelArch
= null;
85 private JLabel jLabelHelpText
= null;
87 private JTextArea jTextAreaHelpText
= null;
89 private JScrollPane jScrollPaneHelpText
= null;
91 private ArchCheckBox jArchCheckBox
= null;
93 private JButton jButtonOk
= null;
95 private JButton jButtonCancel
= null;
100 private VariablesIdentification id
= null;
102 private EnumerationData ed
= new EnumerationData();
104 private WorkspaceTools wt
= new WorkspaceTools();
107 * This method initializes jTextFieldString
109 * @return javax.swing.JTextField jTextFieldString
112 private JTextField
getJTextFieldString() {
113 if (jTextFieldVariableName
== null) {
114 jTextFieldVariableName
= new JTextField();
115 jTextFieldVariableName
.setSize(new java
.awt
.Dimension(320, 20));
116 jTextFieldVariableName
.setPreferredSize(new java
.awt
.Dimension(320, 20));
117 jTextFieldVariableName
.setLocation(new java
.awt
.Point(168, 12));
118 jTextFieldVariableName
119 .setToolTipText("Enter a string; the tool will convert to Unicode hex");
121 return jTextFieldVariableName
;
125 * This method initializes jComboBoxUsage
127 * @return javax.swing.JComboBox jComboBoxUsage
130 private JComboBox
getJComboBoxUsage() {
131 if (jComboBoxUsage
== null) {
132 jComboBoxUsage
= new JComboBox();
133 jComboBoxUsage
.setBounds(new java
.awt
.Rectangle(168, 62, 320, 20));
134 jComboBoxUsage
.setPreferredSize(new java
.awt
.Dimension(320, 20));
136 .setToolTipText("<html><table>"
137 + "<tr><td>ALWAYS_CONSUMED</td><td>The module requires the variable entry to be set</td></tr>"
138 + "<tr><td>SOMETIMES_CONSUMED</td><td>The module will use the variable entry if it is set.</td></tr>"
139 + "<tr><td>ALWAYS_PRODUCED</td><td>The module will always write the variable.</td></tr>"
140 + "<tr><td>SOMETIMES_PRODUCED</td><td>The module will sometimes write the variable.</td></tr>"
141 + "</table></html>");
143 return jComboBoxUsage
;
147 * This method initializes jScrollPane
149 * @return javax.swing.JScrollPane
151 private JScrollPane
getJScrollPane() {
152 if (jScrollPane
== null) {
153 jScrollPane
= new JScrollPane();
154 jScrollPane
.setViewportView(getJContentPane());
160 * This method initializes jTextFieldFeatureFlag
162 * @return javax.swing.JTextField jTextFieldFeatureFlag
165 private JTextField
getJTextFieldFeatureFlag() {
166 if (jTextFieldFeatureFlag
== null) {
167 jTextFieldFeatureFlag
= new JTextField();
168 jTextFieldFeatureFlag
.setBounds(new java
.awt
.Rectangle(168, 132, 320, 20));
169 jTextFieldFeatureFlag
.setPreferredSize(new java
.awt
.Dimension(320, 20));
170 jTextFieldFeatureFlag
.setToolTipText("Postfix expression that must evaluate to TRUE or FALSE");
172 return jTextFieldFeatureFlag
;
176 * This method initializes jTextFieldHelpText
178 * @return javax.swing.JTextField
181 private JTextArea
getJTextAreaHelpText() {
182 if (jTextAreaHelpText
== null) {
183 jTextAreaHelpText
= new JTextArea();
184 jTextAreaHelpText
.setLineWrap(true);
185 jTextAreaHelpText
.setWrapStyleWord(true);
186 jTextAreaHelpText
.setToolTipText("Enter information on how to use this Variable.");
188 return jTextAreaHelpText
;
191 private JScrollPane
getJScrollPaneHelpText() {
192 if (jScrollPaneHelpText
== null) {
193 jScrollPaneHelpText
= new JScrollPane();
194 jScrollPaneHelpText
.setHorizontalScrollBarPolicy(javax
.swing
.JScrollPane
.HORIZONTAL_SCROLLBAR_NEVER
);
195 jScrollPaneHelpText
.setSize(new java
.awt
.Dimension(320, 40));
196 jScrollPaneHelpText
.setPreferredSize(new java
.awt
.Dimension(320, 40));
197 jScrollPaneHelpText
.setLocation(new java
.awt
.Point(168, 87));
198 jScrollPaneHelpText
.setViewportView(getJTextAreaHelpText());
200 return jScrollPaneHelpText
;
204 * This method initializes jComboBoxGuidC_Name
206 * @return javax.swing.JComboBox jComboBoxGuidC_Name
209 private JComboBox
getJComboBoxGuidC_Name() {
210 if (jComboBoxGuidC_Name
== null) {
211 jComboBoxGuidC_Name
= new JComboBox();
212 jComboBoxGuidC_Name
.setBounds(new java
.awt
.Rectangle(168, 37, 320, 20));
213 jComboBoxGuidC_Name
.setPreferredSize(new java
.awt
.Dimension(320, 20));
214 jComboBoxGuidC_Name
.setToolTipText("Select the GUID C Name of the Variable.");
216 return jComboBoxGuidC_Name
;
220 * This method initializes jButtonOk
222 * @return javax.swing.JButton
225 private JButton
getJButtonOk() {
226 if (jButtonOk
== null) {
227 jButtonOk
= new JButton();
228 jButtonOk
.setBounds(new java
.awt
.Rectangle(290, 187, 90, 20));
229 jButtonOk
.setText("Ok");
230 jButtonOk
.addActionListener(this);
236 * This method initializes jButtonCancel
238 * @return javax.swing.JButton
241 private JButton
getJButtonCancel() {
242 if (jButtonCancel
== null) {
243 jButtonCancel
= new JButton();
244 jButtonCancel
.setBounds(new java
.awt
.Rectangle(390, 187, 90, 20));
245 jButtonCancel
.setText("Cancel");
246 jButtonCancel
.addActionListener(this);
248 return jButtonCancel
;
251 public static void main(String
[] args
) {
256 * This method initializes this
259 private void init() {
260 this.setSize(505, 260);
261 this.setContentPane(getJScrollPane());
262 this.setTitle("Variables");
264 this.setViewMode(false);
269 * This method initializes this Fill values to all fields if these values are
272 * @param inVariablesId
275 private void init(VariablesIdentification inVariablesId
) {
277 this.id
= inVariablesId
;
279 if (this.id
!= null) {
280 this.jTextFieldVariableName
.setText(id
.getName());
281 this.jComboBoxGuidC_Name
.setSelectedItem(id
.getGuid());
282 this.jComboBoxUsage
.setSelectedItem(id
.getUsage());
283 this.jTextAreaHelpText
.setText(id
.getHelp());
284 this.jTextFieldFeatureFlag
.setText(id
.getFeatureFlag());
285 this.jArchCheckBox
.setSelectedItems(id
.getSupArchList());
290 * This is the override edit constructor
292 * @param inVariablesIdentification
296 public VariablesDlg(VariablesIdentification inVariablesIdentification
, IFrame iFrame
) {
298 init(inVariablesIdentification
);
302 * Disable all components when the mode is view
305 * true - The view mode; false - The non-view mode
308 public void setViewMode(boolean isView
) {
310 this.jTextFieldVariableName
.setEnabled(!isView
);
311 this.jComboBoxUsage
.setEnabled(!isView
);
316 * This method initializes jContentPane
318 * @return javax.swing.JPanel jContentPane
321 private JPanel
getJContentPane() {
322 if (jContentPane
== null) {
323 jStarLabel1
= new StarLabel();
324 jStarLabel1
.setLocation(new java
.awt
.Point(2, 12));
325 jLabelVariableName
= new JLabel();
326 jLabelVariableName
.setText("Variable Name");
327 jLabelVariableName
.setBounds(new java
.awt
.Rectangle(12, 12, 168, 20));
329 jStarLabel2
= new StarLabel();
330 jStarLabel2
.setLocation(new java
.awt
.Point(2, 37));
331 jLabelGuidCName
= new JLabel();
332 jLabelGuidCName
.setBounds(new java
.awt
.Rectangle(12, 37, 168, 20));
333 jLabelGuidCName
.setText("Variable Guid C Name");
335 jStarLabel3
= new StarLabel();
336 jStarLabel3
.setLocation(new java
.awt
.Point(2, 62));
337 jLabelUsage
= new JLabel();
338 jLabelUsage
.setText("Usage");
339 jLabelUsage
.setBounds(new java
.awt
.Rectangle(12, 62, 168, 20));
341 jLabelHelpText
= new JLabel();
342 jLabelHelpText
.setBounds(new java
.awt
.Rectangle(12, 87, 168, 20));
343 jLabelHelpText
.setText("Help Text");
345 jLabelFeatureFlag
= new JLabel();
346 jLabelFeatureFlag
.setText("Feature Flag Expression");
347 jLabelFeatureFlag
.setBounds(new java
.awt
.Rectangle(12, 132, 168, 20));
349 jLabelArch
= new JLabel();
350 jLabelArch
.setBounds(new java
.awt
.Rectangle(12, 157, 168, 20));
351 jLabelArch
.setText("Supported Architectures");
352 jArchCheckBox
= new ArchCheckBox();
353 jArchCheckBox
.setBounds(new java
.awt
.Rectangle(168, 157, 320, 20));
354 jArchCheckBox
.setPreferredSize(new java
.awt
.Dimension(320, 20));
356 jContentPane
= new JPanel();
357 jContentPane
.setLayout(null);
358 jContentPane
.setPreferredSize(new java
.awt
.Dimension(485, 215));
360 jContentPane
.add(jStarLabel1
, null);
361 jContentPane
.add(jLabelVariableName
, null);
362 jContentPane
.add(getJTextFieldString(), null);
363 jContentPane
.add(jStarLabel2
, null);
364 jContentPane
.add(jLabelGuidCName
, null);
365 jContentPane
.add(getJComboBoxGuidC_Name(), null);
366 jContentPane
.add(jStarLabel3
, null);
367 jContentPane
.add(jLabelUsage
, null);
368 jContentPane
.add(getJComboBoxUsage(), null);
369 jContentPane
.add(jLabelHelpText
, null);
370 jContentPane
.add(getJScrollPaneHelpText(), null);
371 jContentPane
.add(jLabelFeatureFlag
, null);
372 jContentPane
.add(getJTextFieldFeatureFlag(), null);
373 jContentPane
.add(jLabelArch
, null);
374 jContentPane
.add(jArchCheckBox
, null);
375 jContentPane
.add(getJButtonOk(), null);
376 jContentPane
.add(getJButtonCancel(), null);
384 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
386 * Override actionPerformed to listen all actions
389 public void actionPerformed(ActionEvent arg0
) {
390 if (arg0
.getSource() == jButtonOk
) {
392 getCurrentVariables();
393 this.returnType
= DataType
.RETURN_TYPE_OK
;
394 this.setVisible(false);
398 if (arg0
.getSource() == jButtonCancel
) {
399 this.returnType
= DataType
.RETURN_TYPE_CANCEL
;
400 this.setVisible(false);
405 * This method initializes Usage type
408 private void initFrame() {
409 Tools
.generateComboBoxByVector(jComboBoxUsage
, ed
.getVPpiUsage());
410 Tools
.generateComboBoxByVector(jComboBoxGuidC_Name
, wt
.getAllGuidDeclarationsFromWorkspace());
414 * Data validation for all fields
416 * @retval true - All datas are valid
417 * @retval false - At least one data is invalid
420 public boolean checkAdd() {
422 // Check if all fields have correct data types
426 // Check VariableName
428 if (isEmpty(this.jTextFieldVariableName
.getText())) {
429 Log
.wrn("Update Variables", "Variable Name must not be empty");
436 if (!isEmpty(this.jTextFieldFeatureFlag
.getText())) {
437 if (!DataValidation
.isFeatureFlag(this.jTextFieldFeatureFlag
.getText())) {
438 Log
.wrn("Update Variables", "Incorrect data type for Feature Flag");
446 private VariablesIdentification
getCurrentVariables() {
447 String arg0
= this.jTextFieldVariableName
.getText();
448 String arg1
= this.jComboBoxGuidC_Name
.getSelectedItem().toString();
449 String arg2
= this.jComboBoxUsage
.getSelectedItem().toString();
451 String arg3
= this.jTextFieldFeatureFlag
.getText();
452 Vector
<String
> arg4
= this.jArchCheckBox
.getSelectedItemsVector();
453 String arg5
= this.jTextAreaHelpText
.getText();
455 id
= new VariablesIdentification(arg0
, arg1
, arg2
, arg3
, arg4
, arg5
);
459 public VariablesIdentification
getId() {
463 public void setId(VariablesIdentification id
) {