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
.workspace
.WorkspaceTools
;
43 * The class is used to create, update Variables section of the MSA file
48 public class VariablesDlg
extends IDialog
{
51 // / Define class Serial Version UID
53 private static final long serialVersionUID
= -6998982978030439446L;
56 // Define class members
58 private JPanel jContentPane
= null;
60 private JLabel jLabelVariableName
= null;
62 private JTextField jTextFieldVariableName
= null;
64 private JLabel jLabelUsage
= null;
66 private JComboBox jComboBoxUsage
= null;
68 private StarLabel jStarLabel1
= null;
70 private StarLabel jStarLabel2
= null;
72 private StarLabel jStarLabel3
= null;
74 private JScrollPane jScrollPane
= null;
76 private JLabel jLabelGuidCName
= null;
78 private JComboBox jComboBoxGuidC_Name
= null;
80 private JTextField jTextFieldFeatureFlag
= null;
82 private JLabel jLabelFeatureFlag
= null;
84 private JLabel jLabelArch
= null;
86 private JLabel jLabelHelpText
= null;
88 private JTextArea jTextAreaHelpText
= null;
90 private JScrollPane jScrollPaneHelpText
= null;
92 private ArchCheckBox jArchCheckBox
= null;
94 private JButton jButtonOk
= null;
96 private JButton jButtonCancel
= null;
101 private VariablesIdentification id
= null;
103 private EnumerationData ed
= new EnumerationData();
105 private WorkspaceTools wt
= new WorkspaceTools();
108 * This method initializes jTextFieldString
110 * @return javax.swing.JTextField jTextFieldString
113 private JTextField
getJTextFieldString() {
114 if (jTextFieldVariableName
== null) {
115 jTextFieldVariableName
= new JTextField();
116 jTextFieldVariableName
.setSize(new java
.awt
.Dimension(320, 20));
117 jTextFieldVariableName
.setPreferredSize(new java
.awt
.Dimension(320, 20));
118 jTextFieldVariableName
.setLocation(new java
.awt
.Point(168, 12));
119 jTextFieldVariableName
120 .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
));
286 if (this.id
!= null) {
287 this.jTextFieldVariableName
.setText(id
.getName());
288 this.jComboBoxGuidC_Name
.setSelectedItem(id
.getGuid());
289 this.jComboBoxUsage
.setSelectedItem(id
.getUsage());
290 this.jTextAreaHelpText
.setText(id
.getHelp());
291 this.jTextFieldFeatureFlag
.setText(id
.getFeatureFlag());
292 this.jArchCheckBox
.setSelectedItems(id
.getSupArchList());
297 * This is the override edit constructor
299 * @param inVariablesIdentification
303 public VariablesDlg(VariablesIdentification inVariablesIdentification
, IFrame iFrame
, ModuleIdentification mid
) {
305 init(inVariablesIdentification
, mid
);
309 * Disable all components when the mode is view
312 * true - The view mode; false - The non-view mode
315 public void setViewMode(boolean isView
) {
317 this.jTextFieldVariableName
.setEnabled(!isView
);
318 this.jComboBoxUsage
.setEnabled(!isView
);
323 * This method initializes jContentPane
325 * @return javax.swing.JPanel jContentPane
328 private JPanel
getJContentPane() {
329 if (jContentPane
== null) {
330 jStarLabel1
= new StarLabel();
331 jStarLabel1
.setLocation(new java
.awt
.Point(2, 12));
332 jLabelVariableName
= new JLabel();
333 jLabelVariableName
.setText("Variable Name");
334 jLabelVariableName
.setBounds(new java
.awt
.Rectangle(12, 12, 168, 20));
336 jStarLabel2
= new StarLabel();
337 jStarLabel2
.setLocation(new java
.awt
.Point(2, 37));
338 jLabelGuidCName
= new JLabel();
339 jLabelGuidCName
.setBounds(new java
.awt
.Rectangle(12, 37, 168, 20));
340 jLabelGuidCName
.setText("Variable Guid C Name");
342 jStarLabel3
= new StarLabel();
343 jStarLabel3
.setLocation(new java
.awt
.Point(2, 62));
344 jLabelUsage
= new JLabel();
345 jLabelUsage
.setText("Usage");
346 jLabelUsage
.setBounds(new java
.awt
.Rectangle(12, 62, 168, 20));
348 jLabelHelpText
= new JLabel();
349 jLabelHelpText
.setBounds(new java
.awt
.Rectangle(12, 87, 168, 20));
350 jLabelHelpText
.setText("Help Text");
352 jLabelFeatureFlag
= new JLabel();
353 jLabelFeatureFlag
.setText("Feature Flag Expression");
354 jLabelFeatureFlag
.setBounds(new java
.awt
.Rectangle(12, 157, 168, 20));
355 jLabelFeatureFlag
.setEnabled(false);
357 jLabelArch
= new JLabel();
358 jLabelArch
.setBounds(new java
.awt
.Rectangle(12, 132, 168, 20));
359 jLabelArch
.setText("Supported Architectures");
360 jArchCheckBox
= new ArchCheckBox();
361 jArchCheckBox
.setBounds(new java
.awt
.Rectangle(168, 132, 320, 20));
362 jArchCheckBox
.setPreferredSize(new java
.awt
.Dimension(320, 20));
364 jContentPane
= new JPanel();
365 jContentPane
.setLayout(null);
366 jContentPane
.setPreferredSize(new java
.awt
.Dimension(485, 215));
368 jContentPane
.add(jStarLabel1
, null);
369 jContentPane
.add(jLabelVariableName
, null);
370 jContentPane
.add(getJTextFieldString(), null);
371 jContentPane
.add(jStarLabel2
, null);
372 jContentPane
.add(jLabelGuidCName
, null);
373 jContentPane
.add(getJComboBoxGuidC_Name(), null);
374 jContentPane
.add(jStarLabel3
, null);
375 jContentPane
.add(jLabelUsage
, null);
376 jContentPane
.add(getJComboBoxUsage(), null);
377 jContentPane
.add(jLabelHelpText
, null);
378 jContentPane
.add(getJScrollPaneHelpText(), null);
379 jContentPane
.add(jLabelFeatureFlag
, null);
380 jContentPane
.add(getJTextFieldFeatureFlag(), null);
381 jContentPane
.add(jLabelArch
, null);
382 jContentPane
.add(jArchCheckBox
, null);
383 jContentPane
.add(getJButtonOk(), null);
384 jContentPane
.add(getJButtonCancel(), null);
392 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
394 * Override actionPerformed to listen all actions
397 public void actionPerformed(ActionEvent arg0
) {
398 if (arg0
.getSource() == jButtonOk
) {
400 getCurrentVariables();
401 this.returnType
= DataType
.RETURN_TYPE_OK
;
402 this.setVisible(false);
406 if (arg0
.getSource() == jButtonCancel
) {
407 this.returnType
= DataType
.RETURN_TYPE_CANCEL
;
408 this.setVisible(false);
413 * This method initializes Usage type
416 private void initFrame() {
417 Tools
.generateComboBoxByVector(jComboBoxUsage
, ed
.getVPpiUsage());
418 Tools
.generateComboBoxByVector(jComboBoxGuidC_Name
, wt
.getAllGuidDeclarationsFromWorkspace());
422 * Data validation for all fields
424 * @retval true - All datas are valid
425 * @retval false - At least one data is invalid
428 public boolean checkAdd() {
430 // Check if all fields have correct data types
434 // Check VariableName
436 if (isEmpty(this.jTextFieldVariableName
.getText())) {
437 Log
.wrn("Update Variables", "Variable Name must be entered!");
444 if (!isEmpty(this.jTextFieldFeatureFlag
.getText())) {
445 if (!DataValidation
.isFeatureFlag(this.jTextFieldFeatureFlag
.getText())) {
446 Log
.wrn("Update Variables", "Incorrect data type for Feature Flag");
454 private VariablesIdentification
getCurrentVariables() {
455 String arg0
= this.jTextFieldVariableName
.getText();
456 String arg1
= this.jComboBoxGuidC_Name
.getSelectedItem().toString();
457 String arg2
= this.jComboBoxUsage
.getSelectedItem().toString();
459 String arg3
= this.jTextFieldFeatureFlag
.getText();
460 Vector
<String
> arg4
= this.jArchCheckBox
.getSelectedItemsVector();
461 String arg5
= this.jTextAreaHelpText
.getText();
463 id
= new VariablesIdentification(arg0
, arg1
, arg2
, arg3
, arg4
, arg5
);
467 public VariablesIdentification
getId() {
471 public void setId(VariablesIdentification id
) {