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
;
28 import org
.tianocore
.frameworkwizard
.common
.DataType
;
29 import org
.tianocore
.frameworkwizard
.common
.DataValidation
;
30 import org
.tianocore
.frameworkwizard
.common
.EnumerationData
;
31 import org
.tianocore
.frameworkwizard
.common
.Log
;
32 import org
.tianocore
.frameworkwizard
.common
.Tools
;
33 import org
.tianocore
.frameworkwizard
.common
.ui
.ArchCheckBox
;
34 import org
.tianocore
.frameworkwizard
.common
.ui
.IDialog
;
35 import org
.tianocore
.frameworkwizard
.common
.ui
.IFrame
;
36 import org
.tianocore
.frameworkwizard
.common
.ui
.StarLabel
;
37 import org
.tianocore
.frameworkwizard
.module
.Identifications
.Variables
.VariablesIdentification
;
38 import org
.tianocore
.frameworkwizard
.workspace
.WorkspaceTools
;
41 The class is used to create, update Variable of MSA/MBD file
42 It extends IInternalFrame
45 public class VariablesDlg
extends IDialog
{
48 /// Define class Serial Version UID
50 private static final long serialVersionUID
= -6998982978030439446L;
53 //Define class members
55 private JPanel jContentPane
= null;
57 private JLabel jLabelVariableName
= null;
59 private JTextField jTextFieldVariableName
= null;
61 private JLabel jLabelUsage
= null;
63 private JComboBox jComboBoxUsage
= null;
65 private StarLabel jStarLabel1
= null;
67 private StarLabel jStarLabel2
= null;
69 private JScrollPane jScrollPane
= null;
71 private JLabel jLabelGuidCName
= null;
73 private JComboBox jComboBoxGuidC_Name
= null;
75 private JTextField jTextFieldFeatureFlag
= null;
77 private JLabel jLabelFeatureFlag
= null;
79 private JLabel jLabelArch
= null;
81 private JLabel jLabelHelpText
= null;
83 private JTextField jTextFieldHelpText
= null;
85 private ArchCheckBox jArchCheckBox
= null;
87 private JButton jButtonOk
= null;
89 private JButton jButtonCancel
= null;
94 private VariablesIdentification id
= null;
96 private EnumerationData ed
= new EnumerationData();
98 private WorkspaceTools wt
= new WorkspaceTools();
101 This method initializes jTextFieldString
103 @return javax.swing.JTextField jTextFieldString
106 private JTextField
getJTextFieldString() {
107 if (jTextFieldVariableName
== null) {
108 jTextFieldVariableName
= new JTextField();
109 jTextFieldVariableName
.setSize(new java
.awt
.Dimension(320, 20));
110 jTextFieldVariableName
.setPreferredSize(new java
.awt
.Dimension(320, 20));
111 jTextFieldVariableName
.setLocation(new java
.awt
.Point(160, 10));
112 jTextFieldVariableName
113 .setToolTipText("Enter a Hex Word Array, you must provide leading Zeros. 0x000a, 0x0010, 0x00FF");
115 return jTextFieldVariableName
;
119 This method initializes jComboBoxUsage
121 @return javax.swing.JComboBox jComboBoxUsage
124 private JComboBox
getJComboBoxUsage() {
125 if (jComboBoxUsage
== null) {
126 jComboBoxUsage
= new JComboBox();
127 jComboBoxUsage
.setBounds(new java
.awt
.Rectangle(160, 60, 320, 20));
128 jComboBoxUsage
.setPreferredSize(new java
.awt
.Dimension(320, 20));
130 return jComboBoxUsage
;
134 This method initializes jScrollPane
136 @return javax.swing.JScrollPane
138 private JScrollPane
getJScrollPane() {
139 if (jScrollPane
== null) {
140 jScrollPane
= new JScrollPane();
141 jScrollPane
.setViewportView(getJContentPane());
147 This method initializes jTextFieldFeatureFlag
149 @return javax.swing.JTextField jTextFieldFeatureFlag
152 private JTextField
getJTextFieldFeatureFlag() {
153 if (jTextFieldFeatureFlag
== null) {
154 jTextFieldFeatureFlag
= new JTextField();
155 jTextFieldFeatureFlag
.setBounds(new java
.awt
.Rectangle(160, 110, 320, 20));
156 jTextFieldFeatureFlag
.setPreferredSize(new java
.awt
.Dimension(320, 20));
158 return jTextFieldFeatureFlag
;
162 This method initializes jTextFieldHelpText
164 @return javax.swing.JTextField
167 private JTextField
getJTextFieldHelpText() {
168 if (jTextFieldHelpText
== null) {
169 jTextFieldHelpText
= new JTextField();
170 jTextFieldHelpText
.setBounds(new java
.awt
.Rectangle(160, 85, 320, 20));
171 jTextFieldHelpText
.setPreferredSize(new java
.awt
.Dimension(320, 20));
172 jTextFieldHelpText
.setToolTipText("Enter information on how to use this Variable.");
174 return jTextFieldHelpText
;
178 This method initializes jTextField
180 @return javax.swing.JTextField jTextFieldC_Name
183 private JComboBox
getJComboBoxGuidC_Name() {
184 if (jComboBoxGuidC_Name
== null) {
185 jComboBoxGuidC_Name
= new JComboBox();
186 jComboBoxGuidC_Name
.setBounds(new java
.awt
.Rectangle(160, 35, 320, 20));
187 jComboBoxGuidC_Name
.setPreferredSize(new java
.awt
.Dimension(320, 20));
188 jComboBoxGuidC_Name
.setToolTipText("Select the GUID C Name of the Variable.");
190 return jComboBoxGuidC_Name
;
194 This method initializes jButtonOk
196 @return javax.swing.JButton
199 private JButton
getJButtonOk() {
200 if (jButtonOk
== null) {
201 jButtonOk
= new JButton();
202 jButtonOk
.setBounds(new java
.awt
.Rectangle(290, 165, 90, 20));
203 jButtonOk
.setText("Ok");
204 jButtonOk
.addActionListener(this);
210 This method initializes jButtonCancel
212 @return javax.swing.JButton
215 private JButton
getJButtonCancel() {
216 if (jButtonCancel
== null) {
217 jButtonCancel
= new JButton();
218 jButtonCancel
.setBounds(new java
.awt
.Rectangle(390, 165, 90, 20));
219 jButtonCancel
.setText("Cancel");
220 jButtonCancel
.addActionListener(this);
222 return jButtonCancel
;
225 public static void main(String
[] args
) {
230 This method initializes this
233 private void init() {
234 this.setSize(510, 240);
235 this.setContentPane(getJScrollPane());
236 this.setTitle("Variables");
238 this.setViewMode(false);
243 This method initializes this
244 Fill values to all fields if these values are not empty
249 private void init(VariablesIdentification inVariablesId
) {
251 this.id
= inVariablesId
;
253 if (this.id
!= null) {
254 this.jTextFieldVariableName
.setText(id
.getName());
255 this.jComboBoxGuidC_Name
.setSelectedItem(id
.getGuid());
256 this.jComboBoxUsage
.setSelectedItem(id
.getUsage());
257 this.jTextFieldHelpText
.setText(id
.getHelp());
258 this.jTextFieldFeatureFlag
.setText(id
.getFeatureFlag());
259 this.jArchCheckBox
.setSelectedItems(id
.getSupArchList());
264 This is the override edit constructor
266 @param inVariablesIdentification
270 public VariablesDlg(VariablesIdentification inVariablesIdentification
, IFrame iFrame
) {
272 init(inVariablesIdentification
);
276 Disable all components when the mode is view
278 @param isView true - The view mode; false - The non-view mode
281 public void setViewMode(boolean isView
) {
283 this.jTextFieldVariableName
.setEnabled(!isView
);
284 this.jComboBoxUsage
.setEnabled(!isView
);
289 This method initializes jContentPane
291 @return javax.swing.JPanel jContentPane
294 private JPanel
getJContentPane() {
295 if (jContentPane
== null) {
296 jArchCheckBox
= new ArchCheckBox();
297 jArchCheckBox
.setBounds(new java
.awt
.Rectangle(160, 135, 320, 20));
298 jArchCheckBox
.setPreferredSize(new java
.awt
.Dimension(320, 20));
299 jLabelGuidCName
= new JLabel();
300 jLabelGuidCName
.setBounds(new java
.awt
.Rectangle(15, 35, 140, 20));
301 jLabelGuidCName
.setText("Guid C Name");
302 jLabelUsage
= new JLabel();
303 jLabelUsage
.setText("Usage");
304 jLabelUsage
.setBounds(new java
.awt
.Rectangle(15, 60, 140, 20));
305 jLabelVariableName
= new JLabel();
306 jLabelVariableName
.setText("Variable Name");
307 jLabelVariableName
.setLocation(new java
.awt
.Point(15, 10));
308 jLabelVariableName
.setSize(new java
.awt
.Dimension(140, 20));
309 jLabelArch
= new JLabel();
310 jLabelArch
.setBounds(new java
.awt
.Rectangle(15, 135, 140, 20));
311 jLabelArch
.setText("Arch");
312 jLabelFeatureFlag
= new JLabel();
313 jLabelFeatureFlag
.setText("Feature Flag");
314 jLabelFeatureFlag
.setBounds(new java
.awt
.Rectangle(15, 110, 140, 20));
316 jContentPane
= new JPanel();
317 jContentPane
.setLayout(null);
318 jContentPane
.setPreferredSize(new java
.awt
.Dimension(490, 190));
320 jContentPane
.add(jLabelVariableName
, null);
321 jContentPane
.add(jLabelGuidCName
, null);
322 jContentPane
.add(getJComboBoxGuidC_Name(), null);
323 jContentPane
.add(getJTextFieldString(), null);
324 jContentPane
.add(jLabelUsage
, null);
325 jContentPane
.add(getJComboBoxUsage(), null);
326 jStarLabel1
= new StarLabel();
327 jStarLabel1
.setLocation(new java
.awt
.Point(0, 10));
328 jStarLabel2
= new StarLabel();
329 jStarLabel2
.setLocation(new java
.awt
.Point(0, 35));
330 jLabelHelpText
= new JLabel();
331 jLabelHelpText
.setBounds(new java
.awt
.Rectangle(14, 85, 140, 20));
332 jLabelHelpText
.setText("Help Text");
334 jContentPane
.add(jStarLabel1
, null);
335 jContentPane
.add(jStarLabel2
, null);
337 jContentPane
.add(jLabelArch
, null);
338 jContentPane
.add(jLabelFeatureFlag
, null);
339 jContentPane
.add(getJTextFieldFeatureFlag(), null);
340 jContentPane
.add(jLabelHelpText
, null);
341 jContentPane
.add(getJTextFieldHelpText(), null);
342 jContentPane
.add(jArchCheckBox
, null);
343 jContentPane
.add(getJButtonOk(), null);
344 jContentPane
.add(getJButtonCancel(), null);
350 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
352 * Override actionPerformed to listen all actions
355 public void actionPerformed(ActionEvent arg0
) {
356 if (arg0
.getSource() == jButtonOk
) {
358 getCurrentVariables();
359 this.returnType
= DataType
.RETURN_TYPE_OK
;
360 this.setVisible(false);
364 if (arg0
.getSource() == jButtonCancel
) {
365 this.returnType
= DataType
.RETURN_TYPE_CANCEL
;
366 this.setVisible(false);
371 This method initializes Usage type
374 private void initFrame() {
375 Tools
.generateComboBoxByVector(jComboBoxUsage
, ed
.getVPpiUsage());
376 Tools
.generateComboBoxByVector(jComboBoxGuidC_Name
, wt
.getAllGuidDeclarationsFromWorkspace());
380 Data validation for all fields
382 @retval true - All datas are valid
383 @retval false - At least one data is invalid
386 public boolean checkAdd() {
388 // Check if all fields have correct data types
392 // Check VariableName
394 if (isEmpty(this.jTextFieldVariableName
.getText())) {
395 Log
.wrn("Update Variables", "Variable Name couldn't be empty");
399 if (!isEmpty(this.jTextFieldVariableName
.getText())) {
400 if (!DataValidation
.isHexWordArrayType(this.jTextFieldVariableName
.getText())) {
401 Log
.wrn("Update Variables", "Incorrect data type for Variable Name");
409 if (!isEmpty(this.jTextFieldFeatureFlag
.getText())) {
410 if (!DataValidation
.isFeatureFlag(this.jTextFieldFeatureFlag
.getText())) {
411 Log
.wrn("Update Variables", "Incorrect data type for Feature Flag");
419 private VariablesIdentification
getCurrentVariables() {
420 String arg0
= this.jTextFieldVariableName
.getText();
421 String arg1
= this.jComboBoxGuidC_Name
.getSelectedItem().toString();
422 String arg2
= this.jComboBoxUsage
.getSelectedItem().toString();
424 String arg3
= this.jTextFieldFeatureFlag
.getText();
425 Vector
<String
> arg4
= this.jArchCheckBox
.getSelectedItemsVector();
426 String arg5
= this.jTextFieldHelpText
.getText();
428 id
= new VariablesIdentification(arg0
, arg1
, arg2
, arg3
, arg4
, arg5
);
432 public VariablesIdentification
getId() {
436 public void setId(VariablesIdentification id
) {