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