]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/module/ui/dialog/VariablesDlg.java
Changed spelling to manifest
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / module / ui / dialog / VariablesDlg.java
1 /** @file
2
3 The file is used to create, update Variables section of the MSA file
4
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
10
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.
13
14 **/
15
16 package org.tianocore.frameworkwizard.module.ui.dialog;
17
18 import java.awt.event.ActionEvent;
19 import java.util.Vector;
20
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;
28
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.packaging.PackageIdentification;
41 import org.tianocore.frameworkwizard.workspace.WorkspaceTools;
42
43 /**
44 * The class is used to create, update Variables section of the MSA file
45 *
46 * It extends IDialog
47 *
48 */
49 public class VariablesDlg extends IDialog {
50
51 // /
52 // / Define class Serial Version UID
53 // /
54 private static final long serialVersionUID = -6998982978030439446L;
55
56 //
57 // Define class members
58 //
59 private JPanel jContentPane = null;
60
61 private JLabel jLabelVariableName = null;
62
63 private JTextField jTextFieldVariableName = null;
64
65 private JLabel jLabelUsage = null;
66
67 private JComboBox jComboBoxUsage = null;
68
69 private StarLabel jStarLabel1 = null;
70
71 private StarLabel jStarLabel2 = null;
72
73 private StarLabel jStarLabel3 = null;
74
75 private JScrollPane jScrollPane = null;
76
77 private JLabel jLabelGuidCName = null;
78
79 private JComboBox jComboBoxGuidC_Name = null;
80
81 private JTextField jTextFieldFeatureFlag = null;
82
83 private JLabel jLabelFeatureFlag = null;
84
85 private JLabel jLabelArch = null;
86
87 private JLabel jLabelHelpText = null;
88
89 private JTextArea jTextAreaHelpText = null;
90
91 private JScrollPane jScrollPaneHelpText = null;
92
93 private ArchCheckBox jArchCheckBox = null;
94
95 private JButton jButtonOk = null;
96
97 private JButton jButtonCancel = null;
98
99 //
100 // Not used by UI
101 //
102 private VariablesIdentification id = null;
103
104 private EnumerationData ed = new EnumerationData();
105
106 private WorkspaceTools wt = new WorkspaceTools();
107
108 /**
109 * This method initializes jTextFieldString
110 *
111 * @return javax.swing.JTextField jTextFieldString
112 *
113 */
114 private JTextField getJTextFieldString() {
115 if (jTextFieldVariableName == null) {
116 jTextFieldVariableName = new JTextField();
117 jTextFieldVariableName.setSize(new java.awt.Dimension(320, 20));
118 jTextFieldVariableName.setPreferredSize(new java.awt.Dimension(320, 20));
119 jTextFieldVariableName.setLocation(new java.awt.Point(168, 12));
120 jTextFieldVariableName.setToolTipText("Enter a string; the tool will convert to Unicode hex");
121 }
122 return jTextFieldVariableName;
123 }
124
125 /**
126 * This method initializes jComboBoxUsage
127 *
128 * @return javax.swing.JComboBox jComboBoxUsage
129 *
130 */
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));
136 jComboBoxUsage
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>");
143 }
144 return jComboBoxUsage;
145 }
146
147 /**
148 * This method initializes jScrollPane
149 *
150 * @return javax.swing.JScrollPane
151 */
152 private JScrollPane getJScrollPane() {
153 if (jScrollPane == null) {
154 jScrollPane = new JScrollPane();
155 jScrollPane.setViewportView(getJContentPane());
156 }
157 return jScrollPane;
158 }
159
160 /**
161 * This method initializes jTextFieldFeatureFlag
162 *
163 * @return javax.swing.JTextField jTextFieldFeatureFlag
164 *
165 */
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);
173 }
174 return jTextFieldFeatureFlag;
175 }
176
177 /**
178 * This method initializes jTextFieldHelpText
179 *
180 * @return javax.swing.JTextField
181 *
182 */
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.");
189 }
190 return jTextAreaHelpText;
191 }
192
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());
201 }
202 return jScrollPaneHelpText;
203 }
204
205 /**
206 * This method initializes jComboBoxGuidC_Name
207 *
208 * @return javax.swing.JComboBox jComboBoxGuidC_Name
209 *
210 */
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.");
217 }
218 return jComboBoxGuidC_Name;
219 }
220
221 /**
222 * This method initializes jButtonOk
223 *
224 * @return javax.swing.JButton
225 *
226 */
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);
233 }
234 return jButtonOk;
235 }
236
237 /**
238 * This method initializes jButtonCancel
239 *
240 * @return javax.swing.JButton
241 *
242 */
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);
249 }
250 return jButtonCancel;
251 }
252
253 public static void main(String[] args) {
254
255 }
256
257 /**
258 * This method initializes this
259 *
260 */
261 private void init() {
262 this.setSize(505, 260);
263 this.setContentPane(getJScrollPane());
264 this.setTitle("Variables");
265 initFrame();
266 this.setViewMode(false);
267 this.centerWindow();
268 }
269
270 /**
271 * This method initializes this Fill values to all fields if these values are
272 * not empty
273 *
274 * @param inVariablesId
275 *
276 */
277 private void init(VariablesIdentification inVariablesId, ModuleIdentification mid) {
278 init();
279 this.id = inVariablesId;
280
281 //
282 // Init arch with module's arch
283 //
284 this.jArchCheckBox.setEnabledItems(wt.getModuleArch(mid));
285
286 //
287 // Get defined guids from dependent packages
288 //
289 Vector<PackageIdentification> vpid = wt.getPackageDependenciesOfModule(mid);
290 if (vpid.size() <= 0) {
291 Log
292 .wrn("Init Guid",
293 "This module hasn't defined any package dependency, so there is no guid value can be added for variable");
294 }
295 //
296 // Init guids drop down list
297 //
298 Tools
299 .generateComboBoxByVector(jComboBoxGuidC_Name,
300 wt.getAllGuidDeclarationsFromPackages(vpid, EnumerationData.GUID_TYPE_EFI_VARIABLE));
301
302 if (this.id != null) {
303 this.jTextFieldVariableName.setText(id.getName());
304 this.jComboBoxGuidC_Name.setSelectedItem(id.getGuid());
305 this.jComboBoxUsage.setSelectedItem(id.getUsage());
306 this.jTextAreaHelpText.setText(id.getHelp());
307 this.jTextFieldFeatureFlag.setText(id.getFeatureFlag());
308 this.jArchCheckBox.setSelectedItems(id.getSupArchList());
309 }
310 }
311
312 /**
313 * This is the override edit constructor
314 *
315 * @param inVariablesIdentification
316 * @param iFrame
317 *
318 */
319 public VariablesDlg(VariablesIdentification inVariablesIdentification, IFrame iFrame, ModuleIdentification mid) {
320 super(iFrame, true);
321 init(inVariablesIdentification, mid);
322 }
323
324 /**
325 * Disable all components when the mode is view
326 *
327 * @param isView
328 * true - The view mode; false - The non-view mode
329 *
330 */
331 public void setViewMode(boolean isView) {
332 if (isView) {
333 this.jTextFieldVariableName.setEnabled(!isView);
334 this.jComboBoxUsage.setEnabled(!isView);
335 }
336 }
337
338 /**
339 * This method initializes jContentPane
340 *
341 * @return javax.swing.JPanel jContentPane
342 *
343 */
344 private JPanel getJContentPane() {
345 if (jContentPane == null) {
346 jStarLabel1 = new StarLabel();
347 jStarLabel1.setLocation(new java.awt.Point(2, 12));
348 jLabelVariableName = new JLabel();
349 jLabelVariableName.setText("Variable Name");
350 jLabelVariableName.setBounds(new java.awt.Rectangle(12, 12, 168, 20));
351
352 jStarLabel2 = new StarLabel();
353 jStarLabel2.setLocation(new java.awt.Point(2, 37));
354 jLabelGuidCName = new JLabel();
355 jLabelGuidCName.setBounds(new java.awt.Rectangle(12, 37, 168, 20));
356 jLabelGuidCName.setText("Variable Guid C Name");
357
358 jStarLabel3 = new StarLabel();
359 jStarLabel3.setLocation(new java.awt.Point(2, 62));
360 jLabelUsage = new JLabel();
361 jLabelUsage.setText("Usage");
362 jLabelUsage.setBounds(new java.awt.Rectangle(12, 62, 168, 20));
363
364 jLabelHelpText = new JLabel();
365 jLabelHelpText.setBounds(new java.awt.Rectangle(12, 87, 168, 20));
366 jLabelHelpText.setText("Help Text");
367
368 jLabelFeatureFlag = new JLabel();
369 jLabelFeatureFlag.setText("Feature Flag Expression");
370 jLabelFeatureFlag.setBounds(new java.awt.Rectangle(12, 157, 168, 20));
371 jLabelFeatureFlag.setEnabled(false);
372
373 jLabelArch = new JLabel();
374 jLabelArch.setBounds(new java.awt.Rectangle(12, 132, 168, 20));
375 jLabelArch.setText("Supported Architectures");
376 jArchCheckBox = new ArchCheckBox();
377 jArchCheckBox.setBounds(new java.awt.Rectangle(168, 132, 320, 20));
378 jArchCheckBox.setPreferredSize(new java.awt.Dimension(320, 20));
379
380 jContentPane = new JPanel();
381 jContentPane.setLayout(null);
382 jContentPane.setPreferredSize(new java.awt.Dimension(485, 215));
383
384 jContentPane.add(jStarLabel1, null);
385 jContentPane.add(jLabelVariableName, null);
386 jContentPane.add(getJTextFieldString(), null);
387 jContentPane.add(jStarLabel2, null);
388 jContentPane.add(jLabelGuidCName, null);
389 jContentPane.add(getJComboBoxGuidC_Name(), null);
390 jContentPane.add(jStarLabel3, null);
391 jContentPane.add(jLabelUsage, null);
392 jContentPane.add(getJComboBoxUsage(), null);
393 jContentPane.add(jLabelHelpText, null);
394 jContentPane.add(getJScrollPaneHelpText(), null);
395 jContentPane.add(jLabelFeatureFlag, null);
396 jContentPane.add(getJTextFieldFeatureFlag(), null);
397 jContentPane.add(jLabelArch, null);
398 jContentPane.add(jArchCheckBox, null);
399 jContentPane.add(getJButtonOk(), null);
400 jContentPane.add(getJButtonCancel(), null);
401 }
402 return jContentPane;
403 }
404
405 /*
406 * (non-Javadoc)
407 *
408 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
409 *
410 * Override actionPerformed to listen all actions
411 *
412 */
413 public void actionPerformed(ActionEvent arg0) {
414 if (arg0.getSource() == jButtonOk) {
415 if (checkAdd()) {
416 getCurrentVariables();
417 this.returnType = DataType.RETURN_TYPE_OK;
418 this.setVisible(false);
419 }
420 }
421
422 if (arg0.getSource() == jButtonCancel) {
423 this.returnType = DataType.RETURN_TYPE_CANCEL;
424 this.setVisible(false);
425 }
426 }
427
428 /**
429 * This method initializes Usage type
430 *
431 */
432 private void initFrame() {
433 Tools.generateComboBoxByVector(jComboBoxUsage, ed.getVPpiUsage());
434 }
435
436 /**
437 * Data validation for all fields
438 *
439 * @retval true - All datas are valid
440 * @retval false - At least one data is invalid
441 *
442 */
443 public boolean checkAdd() {
444 //
445 // Check if all fields have correct data types
446 //
447
448 //
449 // Check VariableName
450 //
451 if (isEmpty(this.jTextFieldVariableName.getText())) {
452 Log.wrn("Update Variables", "Variable Name must be entered!");
453 return false;
454 }
455
456 //
457 // Check Guid Value
458 //
459 if (this.jComboBoxGuidC_Name.getSelectedItem() == null) {
460 Log.wrn("Update Guids", "Please select one Varibale Guid value");
461 return false;
462 }
463
464 //
465 // Check FeatureFlag
466 //
467 if (!isEmpty(this.jTextFieldFeatureFlag.getText())) {
468 if (!DataValidation.isFeatureFlag(this.jTextFieldFeatureFlag.getText())) {
469 Log.wrn("Update Variables", "Incorrect data type for Feature Flag");
470 return false;
471 }
472 }
473
474 return true;
475 }
476
477 private VariablesIdentification getCurrentVariables() {
478 String arg0 = this.jTextFieldVariableName.getText();
479 String arg1 = this.jComboBoxGuidC_Name.getSelectedItem().toString();
480 String arg2 = this.jComboBoxUsage.getSelectedItem().toString();
481
482 String arg3 = this.jTextFieldFeatureFlag.getText();
483 Vector<String> arg4 = this.jArchCheckBox.getSelectedItemsVector();
484 String arg5 = this.jTextAreaHelpText.getText();
485
486 id = new VariablesIdentification(arg0, arg1, arg2, arg3, arg4, arg5);
487 return id;
488 }
489
490 public VariablesIdentification getId() {
491 return id;
492 }
493
494 public void setId(VariablesIdentification id) {
495 this.id = id;
496 }
497 }