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