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, 157, 320, 20));
169 jTextFieldFeatureFlag
.setPreferredSize(new java
.awt
.Dimension(320, 20));
170 jTextFieldFeatureFlag
.setToolTipText("Postfix expression that must evaluate to TRUE or FALSE");
171 jTextFieldFeatureFlag
.setEnabled(false);
173 return jTextFieldFeatureFlag
;
177 * This method initializes jTextFieldHelpText
179 * @return javax.swing.JTextField
182 private JTextArea
getJTextAreaHelpText() {
183 if (jTextAreaHelpText
== null) {
184 jTextAreaHelpText
= new JTextArea();
185 jTextAreaHelpText
.setLineWrap(true);
186 jTextAreaHelpText
.setWrapStyleWord(true);
187 jTextAreaHelpText
.setToolTipText("Enter information on how to use this Variable.");
189 return jTextAreaHelpText
;
192 private JScrollPane
getJScrollPaneHelpText() {
193 if (jScrollPaneHelpText
== null) {
194 jScrollPaneHelpText
= new JScrollPane();
195 jScrollPaneHelpText
.setHorizontalScrollBarPolicy(javax
.swing
.JScrollPane
.HORIZONTAL_SCROLLBAR_NEVER
);
196 jScrollPaneHelpText
.setSize(new java
.awt
.Dimension(320, 40));
197 jScrollPaneHelpText
.setPreferredSize(new java
.awt
.Dimension(320, 40));
198 jScrollPaneHelpText
.setLocation(new java
.awt
.Point(168, 87));
199 jScrollPaneHelpText
.setViewportView(getJTextAreaHelpText());
201 return jScrollPaneHelpText
;
205 * This method initializes jComboBoxGuidC_Name
207 * @return javax.swing.JComboBox jComboBoxGuidC_Name
210 private JComboBox
getJComboBoxGuidC_Name() {
211 if (jComboBoxGuidC_Name
== null) {
212 jComboBoxGuidC_Name
= new JComboBox();
213 jComboBoxGuidC_Name
.setBounds(new java
.awt
.Rectangle(168, 37, 320, 20));
214 jComboBoxGuidC_Name
.setPreferredSize(new java
.awt
.Dimension(320, 20));
215 jComboBoxGuidC_Name
.setToolTipText("Select the GUID C Name of the Variable.");
217 return jComboBoxGuidC_Name
;
221 * This method initializes jButtonOk
223 * @return javax.swing.JButton
226 private JButton
getJButtonOk() {
227 if (jButtonOk
== null) {
228 jButtonOk
= new JButton();
229 jButtonOk
.setBounds(new java
.awt
.Rectangle(290, 187, 90, 20));
230 jButtonOk
.setText("Ok");
231 jButtonOk
.addActionListener(this);
237 * This method initializes jButtonCancel
239 * @return javax.swing.JButton
242 private JButton
getJButtonCancel() {
243 if (jButtonCancel
== null) {
244 jButtonCancel
= new JButton();
245 jButtonCancel
.setBounds(new java
.awt
.Rectangle(390, 187, 90, 20));
246 jButtonCancel
.setText("Cancel");
247 jButtonCancel
.addActionListener(this);
249 return jButtonCancel
;
252 public static void main(String
[] args
) {
257 * This method initializes this
260 private void init() {
261 this.setSize(505, 260);
262 this.setContentPane(getJScrollPane());
263 this.setTitle("Variables");
265 this.setViewMode(false);
270 * This method initializes this Fill values to all fields if these values are
273 * @param inVariablesId
276 private void init(VariablesIdentification inVariablesId
) {
278 this.id
= inVariablesId
;
280 if (this.id
!= null) {
281 this.jTextFieldVariableName
.setText(id
.getName());
282 this.jComboBoxGuidC_Name
.setSelectedItem(id
.getGuid());
283 this.jComboBoxUsage
.setSelectedItem(id
.getUsage());
284 this.jTextAreaHelpText
.setText(id
.getHelp());
285 this.jTextFieldFeatureFlag
.setText(id
.getFeatureFlag());
286 this.jArchCheckBox
.setSelectedItems(id
.getSupArchList());
291 * This is the override edit constructor
293 * @param inVariablesIdentification
297 public VariablesDlg(VariablesIdentification inVariablesIdentification
, IFrame iFrame
) {
299 init(inVariablesIdentification
);
303 * Disable all components when the mode is view
306 * true - The view mode; false - The non-view mode
309 public void setViewMode(boolean isView
) {
311 this.jTextFieldVariableName
.setEnabled(!isView
);
312 this.jComboBoxUsage
.setEnabled(!isView
);
317 * This method initializes jContentPane
319 * @return javax.swing.JPanel jContentPane
322 private JPanel
getJContentPane() {
323 if (jContentPane
== null) {
324 jStarLabel1
= new StarLabel();
325 jStarLabel1
.setLocation(new java
.awt
.Point(2, 12));
326 jLabelVariableName
= new JLabel();
327 jLabelVariableName
.setText("Variable Name");
328 jLabelVariableName
.setBounds(new java
.awt
.Rectangle(12, 12, 168, 20));
330 jStarLabel2
= new StarLabel();
331 jStarLabel2
.setLocation(new java
.awt
.Point(2, 37));
332 jLabelGuidCName
= new JLabel();
333 jLabelGuidCName
.setBounds(new java
.awt
.Rectangle(12, 37, 168, 20));
334 jLabelGuidCName
.setText("Variable Guid C Name");
336 jStarLabel3
= new StarLabel();
337 jStarLabel3
.setLocation(new java
.awt
.Point(2, 62));
338 jLabelUsage
= new JLabel();
339 jLabelUsage
.setText("Usage");
340 jLabelUsage
.setBounds(new java
.awt
.Rectangle(12, 62, 168, 20));
342 jLabelHelpText
= new JLabel();
343 jLabelHelpText
.setBounds(new java
.awt
.Rectangle(12, 87, 168, 20));
344 jLabelHelpText
.setText("Help Text");
346 jLabelFeatureFlag
= new JLabel();
347 jLabelFeatureFlag
.setText("Feature Flag Expression");
348 jLabelFeatureFlag
.setBounds(new java
.awt
.Rectangle(12, 157, 168, 20));
349 jLabelFeatureFlag
.setEnabled(false);
351 jLabelArch
= new JLabel();
352 jLabelArch
.setBounds(new java
.awt
.Rectangle(12, 132, 168, 20));
353 jLabelArch
.setText("Supported Architectures");
354 jArchCheckBox
= new ArchCheckBox();
355 jArchCheckBox
.setBounds(new java
.awt
.Rectangle(168, 132, 320, 20));
356 jArchCheckBox
.setPreferredSize(new java
.awt
.Dimension(320, 20));
358 jContentPane
= new JPanel();
359 jContentPane
.setLayout(null);
360 jContentPane
.setPreferredSize(new java
.awt
.Dimension(485, 215));
362 jContentPane
.add(jStarLabel1
, null);
363 jContentPane
.add(jLabelVariableName
, null);
364 jContentPane
.add(getJTextFieldString(), null);
365 jContentPane
.add(jStarLabel2
, null);
366 jContentPane
.add(jLabelGuidCName
, null);
367 jContentPane
.add(getJComboBoxGuidC_Name(), null);
368 jContentPane
.add(jStarLabel3
, null);
369 jContentPane
.add(jLabelUsage
, null);
370 jContentPane
.add(getJComboBoxUsage(), null);
371 jContentPane
.add(jLabelHelpText
, null);
372 jContentPane
.add(getJScrollPaneHelpText(), null);
373 jContentPane
.add(jLabelFeatureFlag
, null);
374 jContentPane
.add(getJTextFieldFeatureFlag(), null);
375 jContentPane
.add(jLabelArch
, null);
376 jContentPane
.add(jArchCheckBox
, null);
377 jContentPane
.add(getJButtonOk(), null);
378 jContentPane
.add(getJButtonCancel(), null);
386 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
388 * Override actionPerformed to listen all actions
391 public void actionPerformed(ActionEvent arg0
) {
392 if (arg0
.getSource() == jButtonOk
) {
394 getCurrentVariables();
395 this.returnType
= DataType
.RETURN_TYPE_OK
;
396 this.setVisible(false);
400 if (arg0
.getSource() == jButtonCancel
) {
401 this.returnType
= DataType
.RETURN_TYPE_CANCEL
;
402 this.setVisible(false);
407 * This method initializes Usage type
410 private void initFrame() {
411 Tools
.generateComboBoxByVector(jComboBoxUsage
, ed
.getVPpiUsage());
412 Tools
.generateComboBoxByVector(jComboBoxGuidC_Name
, wt
.getAllGuidDeclarationsFromWorkspace());
416 * Data validation for all fields
418 * @retval true - All datas are valid
419 * @retval false - At least one data is invalid
422 public boolean checkAdd() {
424 // Check if all fields have correct data types
428 // Check VariableName
430 if (isEmpty(this.jTextFieldVariableName
.getText())) {
431 Log
.wrn("Update Variables", "Variable Name must not be empty");
438 if (!isEmpty(this.jTextFieldFeatureFlag
.getText())) {
439 if (!DataValidation
.isFeatureFlag(this.jTextFieldFeatureFlag
.getText())) {
440 Log
.wrn("Update Variables", "Incorrect data type for Feature Flag");
448 private VariablesIdentification
getCurrentVariables() {
449 String arg0
= this.jTextFieldVariableName
.getText();
450 String arg1
= this.jComboBoxGuidC_Name
.getSelectedItem().toString();
451 String arg2
= this.jComboBoxUsage
.getSelectedItem().toString();
453 String arg3
= this.jTextFieldFeatureFlag
.getText();
454 Vector
<String
> arg4
= this.jArchCheckBox
.getSelectedItemsVector();
455 String arg5
= this.jTextAreaHelpText
.getText();
457 id
= new VariablesIdentification(arg0
, arg1
, arg2
, arg3
, arg4
, arg5
);
461 public VariablesIdentification
getId() {
465 public void setId(VariablesIdentification id
) {