]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/module/ui/dialog/VariablesDlg.java
1. Fix EDKT321 A module's all top level elements' arch should be in range of the...
[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.workspace.WorkspaceTools;
41
42 /**
43 * The class is used to create, update Variables section of the MSA file
44 *
45 * It extends IDialog
46 *
47 */
48 public class VariablesDlg extends IDialog {
49
50 // /
51 // / Define class Serial Version UID
52 // /
53 private static final long serialVersionUID = -6998982978030439446L;
54
55 //
56 // Define class members
57 //
58 private JPanel jContentPane = null;
59
60 private JLabel jLabelVariableName = null;
61
62 private JTextField jTextFieldVariableName = null;
63
64 private JLabel jLabelUsage = null;
65
66 private JComboBox jComboBoxUsage = null;
67
68 private StarLabel jStarLabel1 = null;
69
70 private StarLabel jStarLabel2 = null;
71
72 private StarLabel jStarLabel3 = null;
73
74 private JScrollPane jScrollPane = null;
75
76 private JLabel jLabelGuidCName = null;
77
78 private JComboBox jComboBoxGuidC_Name = null;
79
80 private JTextField jTextFieldFeatureFlag = null;
81
82 private JLabel jLabelFeatureFlag = null;
83
84 private JLabel jLabelArch = null;
85
86 private JLabel jLabelHelpText = null;
87
88 private JTextArea jTextAreaHelpText = null;
89
90 private JScrollPane jScrollPaneHelpText = null;
91
92 private ArchCheckBox jArchCheckBox = null;
93
94 private JButton jButtonOk = null;
95
96 private JButton jButtonCancel = null;
97
98 //
99 // Not used by UI
100 //
101 private VariablesIdentification id = null;
102
103 private EnumerationData ed = new EnumerationData();
104
105 private WorkspaceTools wt = new WorkspaceTools();
106
107 /**
108 * This method initializes jTextFieldString
109 *
110 * @return javax.swing.JTextField jTextFieldString
111 *
112 */
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");
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 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());
293 }
294 }
295
296 /**
297 * This is the override edit constructor
298 *
299 * @param inVariablesIdentification
300 * @param iFrame
301 *
302 */
303 public VariablesDlg(VariablesIdentification inVariablesIdentification, IFrame iFrame, ModuleIdentification mid) {
304 super(iFrame, true);
305 init(inVariablesIdentification, mid);
306 }
307
308 /**
309 * Disable all components when the mode is view
310 *
311 * @param isView
312 * true - The view mode; false - The non-view mode
313 *
314 */
315 public void setViewMode(boolean isView) {
316 if (isView) {
317 this.jTextFieldVariableName.setEnabled(!isView);
318 this.jComboBoxUsage.setEnabled(!isView);
319 }
320 }
321
322 /**
323 * This method initializes jContentPane
324 *
325 * @return javax.swing.JPanel jContentPane
326 *
327 */
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));
335
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");
341
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));
347
348 jLabelHelpText = new JLabel();
349 jLabelHelpText.setBounds(new java.awt.Rectangle(12, 87, 168, 20));
350 jLabelHelpText.setText("Help Text");
351
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);
356
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));
363
364 jContentPane = new JPanel();
365 jContentPane.setLayout(null);
366 jContentPane.setPreferredSize(new java.awt.Dimension(485, 215));
367
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);
385 }
386 return jContentPane;
387 }
388
389 /*
390 * (non-Javadoc)
391 *
392 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
393 *
394 * Override actionPerformed to listen all actions
395 *
396 */
397 public void actionPerformed(ActionEvent arg0) {
398 if (arg0.getSource() == jButtonOk) {
399 if (checkAdd()) {
400 getCurrentVariables();
401 this.returnType = DataType.RETURN_TYPE_OK;
402 this.setVisible(false);
403 }
404 }
405
406 if (arg0.getSource() == jButtonCancel) {
407 this.returnType = DataType.RETURN_TYPE_CANCEL;
408 this.setVisible(false);
409 }
410 }
411
412 /**
413 * This method initializes Usage type
414 *
415 */
416 private void initFrame() {
417 Tools.generateComboBoxByVector(jComboBoxUsage, ed.getVPpiUsage());
418 Tools.generateComboBoxByVector(jComboBoxGuidC_Name, wt.getAllGuidDeclarationsFromWorkspace());
419 }
420
421 /**
422 * Data validation for all fields
423 *
424 * @retval true - All datas are valid
425 * @retval false - At least one data is invalid
426 *
427 */
428 public boolean checkAdd() {
429 //
430 // Check if all fields have correct data types
431 //
432
433 //
434 // Check VariableName
435 //
436 if (isEmpty(this.jTextFieldVariableName.getText())) {
437 Log.wrn("Update Variables", "Variable Name must be entered!");
438 return false;
439 }
440
441 //
442 // Check FeatureFlag
443 //
444 if (!isEmpty(this.jTextFieldFeatureFlag.getText())) {
445 if (!DataValidation.isFeatureFlag(this.jTextFieldFeatureFlag.getText())) {
446 Log.wrn("Update Variables", "Incorrect data type for Feature Flag");
447 return false;
448 }
449 }
450
451 return true;
452 }
453
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();
458
459 String arg3 = this.jTextFieldFeatureFlag.getText();
460 Vector<String> arg4 = this.jArchCheckBox.getSelectedItemsVector();
461 String arg5 = this.jTextAreaHelpText.getText();
462
463 id = new VariablesIdentification(arg0, arg1, arg2, arg3, arg4, arg5);
464 return id;
465 }
466
467 public VariablesIdentification getId() {
468 return id;
469 }
470
471 public void setId(VariablesIdentification id) {
472 this.id = id;
473 }
474 }