3 The file is used to create, update Variable of MSA/MBD 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 Variable of MSA/MBD file It extends
46 public class VariablesDlg
extends IDialog
{
49 // / Define class Serial Version UID
51 private static final long serialVersionUID
= -6998982978030439446L;
54 // Define class members
56 private JPanel jContentPane
= null;
58 private JLabel jLabelVariableName
= null;
60 private JTextField jTextFieldVariableName
= null;
62 private JLabel jLabelUsage
= null;
64 private JComboBox jComboBoxUsage
= null;
66 private StarLabel jStarLabel1
= null;
68 private StarLabel jStarLabel2
= null;
70 private StarLabel jStarLabel3
= null;
72 private JScrollPane jScrollPane
= null;
74 private JLabel jLabelGuidCName
= null;
76 private JComboBox jComboBoxGuidC_Name
= null;
78 private JTextField jTextFieldFeatureFlag
= null;
80 private JLabel jLabelFeatureFlag
= null;
82 private JLabel jLabelArch
= null;
84 private JLabel jLabelHelpText
= null;
86 private JTextArea jTextAreaHelpText
= null;
88 private JScrollPane jScrollPaneHelpText
= null;
90 private ArchCheckBox jArchCheckBox
= null;
92 private JButton jButtonOk
= null;
94 private JButton jButtonCancel
= null;
99 private VariablesIdentification id
= null;
101 private EnumerationData ed
= new EnumerationData();
103 private WorkspaceTools wt
= new WorkspaceTools();
106 * This method initializes jTextFieldString
108 * @return javax.swing.JTextField jTextFieldString
111 private JTextField
getJTextFieldString() {
112 if (jTextFieldVariableName
== null) {
113 jTextFieldVariableName
= new JTextField();
114 jTextFieldVariableName
.setSize(new java
.awt
.Dimension(320, 20));
115 jTextFieldVariableName
.setPreferredSize(new java
.awt
.Dimension(320, 20));
116 jTextFieldVariableName
.setLocation(new java
.awt
.Point(160, 10));
117 jTextFieldVariableName
118 .setToolTipText("Enter a Hex Word Array, you must provide leading Zeros. 0x000a, 0x0010, 0x00FF");
120 return jTextFieldVariableName
;
124 * This method initializes jComboBoxUsage
126 * @return javax.swing.JComboBox jComboBoxUsage
129 private JComboBox
getJComboBoxUsage() {
130 if (jComboBoxUsage
== null) {
131 jComboBoxUsage
= new JComboBox();
132 jComboBoxUsage
.setBounds(new java
.awt
.Rectangle(160, 60, 320, 20));
133 jComboBoxUsage
.setPreferredSize(new java
.awt
.Dimension(320, 20));
135 .setToolTipText("<html><table><tr><td>ALWAYS_CONSUMED</td><td>The module requires the variable entry to be set</td></tr>"
136 + "<tr><td>SOMETIMES_CONSUMED</td><td>The module will use the variable entry if it’s set.</td></tr>"
137 + "<tr><td>ALWAYS_PRODUCED</td><td>The module will always write the variable.</td></tr>"
138 + "<tr><td>SOMETIMES_PRODUCED</td><td>The module will sometimes write the variable.</td></tr></table></html>");
140 return jComboBoxUsage
;
144 * This method initializes jScrollPane
146 * @return javax.swing.JScrollPane
148 private JScrollPane
getJScrollPane() {
149 if (jScrollPane
== null) {
150 jScrollPane
= new JScrollPane();
151 jScrollPane
.setViewportView(getJContentPane());
157 * This method initializes jTextFieldFeatureFlag
159 * @return javax.swing.JTextField jTextFieldFeatureFlag
162 private JTextField
getJTextFieldFeatureFlag() {
163 if (jTextFieldFeatureFlag
== null) {
164 jTextFieldFeatureFlag
= new JTextField();
165 jTextFieldFeatureFlag
166 .setBounds(new java
.awt
.Rectangle(160, 130, 320, 20));
167 jTextFieldFeatureFlag
.setPreferredSize(new java
.awt
.Dimension(320, 20));
168 jTextFieldFeatureFlag
.setToolTipText("Postfix expression that must evaluate to TRUE or FALSE");
170 return jTextFieldFeatureFlag
;
174 * This method initializes jTextFieldHelpText
176 * @return javax.swing.JTextField
179 private JTextArea
getJTextAreaHelpText() {
180 if (jTextAreaHelpText
== null) {
181 jTextAreaHelpText
= new JTextArea();
182 jTextAreaHelpText
.setLineWrap(true);
183 jTextAreaHelpText
.setWrapStyleWord(true);
185 .setToolTipText("Enter information on how to use this Variable.");
187 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(160,85));
198 jScrollPaneHelpText
.setViewportView(getJTextAreaHelpText());
200 return jScrollPaneHelpText
;
203 * This method initializes jComboBoxGuidC_Name
205 * @return javax.swing.JComboBox jComboBoxGuidC_Name
208 private JComboBox
getJComboBoxGuidC_Name() {
209 if (jComboBoxGuidC_Name
== null) {
210 jComboBoxGuidC_Name
= new JComboBox();
211 jComboBoxGuidC_Name
.setBounds(new java
.awt
.Rectangle(160, 35, 320, 20));
212 jComboBoxGuidC_Name
.setPreferredSize(new java
.awt
.Dimension(320, 20));
214 .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, 182, 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, 182, 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(500, 255);
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
,
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, 10));
326 jLabelVariableName
= new JLabel();
327 jLabelVariableName
.setText("Variable Name");
328 jLabelVariableName
.setBounds(new java
.awt
.Rectangle(15, 10, 145, 20));
330 jStarLabel2
= new StarLabel();
331 jStarLabel2
.setLocation(new java
.awt
.Point(2, 35));
332 jLabelGuidCName
= new JLabel();
333 jLabelGuidCName
.setBounds(new java
.awt
.Rectangle(15, 35, 145, 20));
334 jLabelGuidCName
.setText("Variable Guid C Name");
336 jStarLabel3
= new StarLabel();
337 jStarLabel3
.setLocation(new java
.awt
.Point(2, 60));
338 jLabelUsage
= new JLabel();
339 jLabelUsage
.setText("Usage");
340 jLabelUsage
.setBounds(new java
.awt
.Rectangle(15, 60, 145, 20));
342 jLabelHelpText
= new JLabel();
343 jLabelHelpText
.setBounds(new java
.awt
.Rectangle(14, 85, 145, 20));
344 jLabelHelpText
.setText("Help Text");
346 jLabelFeatureFlag
= new JLabel();
347 jLabelFeatureFlag
.setText("Feature Flag Expression");
348 jLabelFeatureFlag
.setBounds(new java
.awt
.Rectangle(15, 130, 145, 20));
350 jLabelArch
= new JLabel();
351 jLabelArch
.setBounds(new java
.awt
.Rectangle(15, 155, 145, 20));
352 jLabelArch
.setText("Supported Architectures");
353 jArchCheckBox
= new ArchCheckBox();
354 jArchCheckBox
.setBounds(new java
.awt
.Rectangle(160, 155, 320, 20));
355 jArchCheckBox
.setPreferredSize(new java
.awt
.Dimension(320, 20));
357 jContentPane
= new JPanel();
358 jContentPane
.setLayout(null);
359 jContentPane
.setPreferredSize(new java
.awt
.Dimension(485, 210));
361 jContentPane
.add(jStarLabel1
, null);
362 jContentPane
.add(jLabelVariableName
, null);
363 jContentPane
.add(getJTextFieldString(), null);
364 jContentPane
.add(jStarLabel2
, null);
365 jContentPane
.add(jLabelGuidCName
, null);
366 jContentPane
.add(getJComboBoxGuidC_Name(), null);
367 jContentPane
.add(jStarLabel3
, null);
368 jContentPane
.add(jLabelUsage
, null);
369 jContentPane
.add(getJComboBoxUsage(), null);
370 jContentPane
.add(jLabelHelpText
, null);
371 jContentPane
.add(getJScrollPaneHelpText(), null);
372 jContentPane
.add(jLabelFeatureFlag
, null);
373 jContentPane
.add(getJTextFieldFeatureFlag(), null);
374 jContentPane
.add(jLabelArch
, null);
375 jContentPane
.add(jArchCheckBox
, null);
376 jContentPane
.add(getJButtonOk(), null);
377 jContentPane
.add(getJButtonCancel(), null);
385 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
387 * Override actionPerformed to listen all actions
390 public void actionPerformed(ActionEvent arg0
) {
391 if (arg0
.getSource() == jButtonOk
) {
393 getCurrentVariables();
394 this.returnType
= DataType
.RETURN_TYPE_OK
;
395 this.setVisible(false);
399 if (arg0
.getSource() == jButtonCancel
) {
400 this.returnType
= DataType
.RETURN_TYPE_CANCEL
;
401 this.setVisible(false);
406 * This method initializes Usage type
409 private void initFrame() {
410 Tools
.generateComboBoxByVector(jComboBoxUsage
, ed
.getVPpiUsage());
411 Tools
.generateComboBoxByVector(jComboBoxGuidC_Name
, wt
412 .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");
435 if (!isEmpty(this.jTextFieldVariableName
.getText())) {
436 if (!DataValidation
.isHexWordArrayType(this.jTextFieldVariableName
438 Log
.wrn("Update Variables", "Incorrect data type for Variable Name");
446 if (!isEmpty(this.jTextFieldFeatureFlag
.getText())) {
447 if (!DataValidation
.isFeatureFlag(this.jTextFieldFeatureFlag
.getText())) {
448 Log
.wrn("Update Variables", "Incorrect data type for Feature Flag");
456 private VariablesIdentification
getCurrentVariables() {
457 String arg0
= this.jTextFieldVariableName
.getText();
458 String arg1
= this.jComboBoxGuidC_Name
.getSelectedItem().toString();
459 String arg2
= this.jComboBoxUsage
.getSelectedItem().toString();
461 String arg3
= this.jTextFieldFeatureFlag
.getText();
462 Vector
<String
> arg4
= this.jArchCheckBox
.getSelectedItemsVector();
463 String arg5
= this.jTextAreaHelpText
.getText();
465 id
= new VariablesIdentification(arg0
, arg1
, arg2
, arg3
, arg4
, arg5
);
469 public VariablesIdentification
getId() {
473 public void setId(VariablesIdentification id
) {