]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/module/ui/dialog/VariablesDlg.java
Fixed grammar in messages.
[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, 157, 320, 20));
169 jTextFieldFeatureFlag.setPreferredSize(new java.awt.Dimension(320, 20));
170 jTextFieldFeatureFlag.setToolTipText("Postfix expression that must evaluate to TRUE or FALSE");
171 jTextFieldFeatureFlag.setEnabled(false);
172 }
173 return jTextFieldFeatureFlag;
174 }
175
176 /**
177 * This method initializes jTextFieldHelpText
178 *
179 * @return javax.swing.JTextField
180 *
181 */
182 private JTextArea getJTextAreaHelpText() {
183 if (jTextAreaHelpText == null) {
184 jTextAreaHelpText = new JTextArea();
185 jTextAreaHelpText.setLineWrap(true);
186 jTextAreaHelpText.setWrapStyleWord(true);
187 jTextAreaHelpText.setToolTipText("Enter information on how to use this Variable.");
188 }
189 return jTextAreaHelpText;
190 }
191
192 private JScrollPane getJScrollPaneHelpText() {
193 if (jScrollPaneHelpText == null) {
194 jScrollPaneHelpText = new JScrollPane();
195 jScrollPaneHelpText.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
196 jScrollPaneHelpText.setSize(new java.awt.Dimension(320, 40));
197 jScrollPaneHelpText.setPreferredSize(new java.awt.Dimension(320, 40));
198 jScrollPaneHelpText.setLocation(new java.awt.Point(168, 87));
199 jScrollPaneHelpText.setViewportView(getJTextAreaHelpText());
200 }
201 return jScrollPaneHelpText;
202 }
203
204 /**
205 * This method initializes jComboBoxGuidC_Name
206 *
207 * @return javax.swing.JComboBox jComboBoxGuidC_Name
208 *
209 */
210 private JComboBox getJComboBoxGuidC_Name() {
211 if (jComboBoxGuidC_Name == null) {
212 jComboBoxGuidC_Name = new JComboBox();
213 jComboBoxGuidC_Name.setBounds(new java.awt.Rectangle(168, 37, 320, 20));
214 jComboBoxGuidC_Name.setPreferredSize(new java.awt.Dimension(320, 20));
215 jComboBoxGuidC_Name.setToolTipText("Select the GUID C Name of the Variable.");
216 }
217 return jComboBoxGuidC_Name;
218 }
219
220 /**
221 * This method initializes jButtonOk
222 *
223 * @return javax.swing.JButton
224 *
225 */
226 private JButton getJButtonOk() {
227 if (jButtonOk == null) {
228 jButtonOk = new JButton();
229 jButtonOk.setBounds(new java.awt.Rectangle(290, 187, 90, 20));
230 jButtonOk.setText("Ok");
231 jButtonOk.addActionListener(this);
232 }
233 return jButtonOk;
234 }
235
236 /**
237 * This method initializes jButtonCancel
238 *
239 * @return javax.swing.JButton
240 *
241 */
242 private JButton getJButtonCancel() {
243 if (jButtonCancel == null) {
244 jButtonCancel = new JButton();
245 jButtonCancel.setBounds(new java.awt.Rectangle(390, 187, 90, 20));
246 jButtonCancel.setText("Cancel");
247 jButtonCancel.addActionListener(this);
248 }
249 return jButtonCancel;
250 }
251
252 public static void main(String[] args) {
253
254 }
255
256 /**
257 * This method initializes this
258 *
259 */
260 private void init() {
261 this.setSize(505, 260);
262 this.setContentPane(getJScrollPane());
263 this.setTitle("Variables");
264 initFrame();
265 this.setViewMode(false);
266 this.centerWindow();
267 }
268
269 /**
270 * This method initializes this Fill values to all fields if these values are
271 * not empty
272 *
273 * @param inVariablesId
274 *
275 */
276 private void init(VariablesIdentification inVariablesId) {
277 init();
278 this.id = inVariablesId;
279
280 if (this.id != null) {
281 this.jTextFieldVariableName.setText(id.getName());
282 this.jComboBoxGuidC_Name.setSelectedItem(id.getGuid());
283 this.jComboBoxUsage.setSelectedItem(id.getUsage());
284 this.jTextAreaHelpText.setText(id.getHelp());
285 this.jTextFieldFeatureFlag.setText(id.getFeatureFlag());
286 this.jArchCheckBox.setSelectedItems(id.getSupArchList());
287 }
288 }
289
290 /**
291 * This is the override edit constructor
292 *
293 * @param inVariablesIdentification
294 * @param iFrame
295 *
296 */
297 public VariablesDlg(VariablesIdentification inVariablesIdentification, IFrame iFrame) {
298 super(iFrame, true);
299 init(inVariablesIdentification);
300 }
301
302 /**
303 * Disable all components when the mode is view
304 *
305 * @param isView
306 * true - The view mode; false - The non-view mode
307 *
308 */
309 public void setViewMode(boolean isView) {
310 if (isView) {
311 this.jTextFieldVariableName.setEnabled(!isView);
312 this.jComboBoxUsage.setEnabled(!isView);
313 }
314 }
315
316 /**
317 * This method initializes jContentPane
318 *
319 * @return javax.swing.JPanel jContentPane
320 *
321 */
322 private JPanel getJContentPane() {
323 if (jContentPane == null) {
324 jStarLabel1 = new StarLabel();
325 jStarLabel1.setLocation(new java.awt.Point(2, 12));
326 jLabelVariableName = new JLabel();
327 jLabelVariableName.setText("Variable Name");
328 jLabelVariableName.setBounds(new java.awt.Rectangle(12, 12, 168, 20));
329
330 jStarLabel2 = new StarLabel();
331 jStarLabel2.setLocation(new java.awt.Point(2, 37));
332 jLabelGuidCName = new JLabel();
333 jLabelGuidCName.setBounds(new java.awt.Rectangle(12, 37, 168, 20));
334 jLabelGuidCName.setText("Variable Guid C Name");
335
336 jStarLabel3 = new StarLabel();
337 jStarLabel3.setLocation(new java.awt.Point(2, 62));
338 jLabelUsage = new JLabel();
339 jLabelUsage.setText("Usage");
340 jLabelUsage.setBounds(new java.awt.Rectangle(12, 62, 168, 20));
341
342 jLabelHelpText = new JLabel();
343 jLabelHelpText.setBounds(new java.awt.Rectangle(12, 87, 168, 20));
344 jLabelHelpText.setText("Help Text");
345
346 jLabelFeatureFlag = new JLabel();
347 jLabelFeatureFlag.setText("Feature Flag Expression");
348 jLabelFeatureFlag.setBounds(new java.awt.Rectangle(12, 157, 168, 20));
349 jLabelFeatureFlag.setEnabled(false);
350
351 jLabelArch = new JLabel();
352 jLabelArch.setBounds(new java.awt.Rectangle(12, 132, 168, 20));
353 jLabelArch.setText("Supported Architectures");
354 jArchCheckBox = new ArchCheckBox();
355 jArchCheckBox.setBounds(new java.awt.Rectangle(168, 132, 320, 20));
356 jArchCheckBox.setPreferredSize(new java.awt.Dimension(320, 20));
357
358 jContentPane = new JPanel();
359 jContentPane.setLayout(null);
360 jContentPane.setPreferredSize(new java.awt.Dimension(485, 215));
361
362 jContentPane.add(jStarLabel1, null);
363 jContentPane.add(jLabelVariableName, null);
364 jContentPane.add(getJTextFieldString(), null);
365 jContentPane.add(jStarLabel2, null);
366 jContentPane.add(jLabelGuidCName, null);
367 jContentPane.add(getJComboBoxGuidC_Name(), null);
368 jContentPane.add(jStarLabel3, null);
369 jContentPane.add(jLabelUsage, null);
370 jContentPane.add(getJComboBoxUsage(), null);
371 jContentPane.add(jLabelHelpText, null);
372 jContentPane.add(getJScrollPaneHelpText(), null);
373 jContentPane.add(jLabelFeatureFlag, null);
374 jContentPane.add(getJTextFieldFeatureFlag(), null);
375 jContentPane.add(jLabelArch, null);
376 jContentPane.add(jArchCheckBox, null);
377 jContentPane.add(getJButtonOk(), null);
378 jContentPane.add(getJButtonCancel(), null);
379 }
380 return jContentPane;
381 }
382
383 /*
384 * (non-Javadoc)
385 *
386 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
387 *
388 * Override actionPerformed to listen all actions
389 *
390 */
391 public void actionPerformed(ActionEvent arg0) {
392 if (arg0.getSource() == jButtonOk) {
393 if (checkAdd()) {
394 getCurrentVariables();
395 this.returnType = DataType.RETURN_TYPE_OK;
396 this.setVisible(false);
397 }
398 }
399
400 if (arg0.getSource() == jButtonCancel) {
401 this.returnType = DataType.RETURN_TYPE_CANCEL;
402 this.setVisible(false);
403 }
404 }
405
406 /**
407 * This method initializes Usage type
408 *
409 */
410 private void initFrame() {
411 Tools.generateComboBoxByVector(jComboBoxUsage, ed.getVPpiUsage());
412 Tools.generateComboBoxByVector(jComboBoxGuidC_Name, wt.getAllGuidDeclarationsFromWorkspace());
413 }
414
415 /**
416 * Data validation for all fields
417 *
418 * @retval true - All datas are valid
419 * @retval false - At least one data is invalid
420 *
421 */
422 public boolean checkAdd() {
423 //
424 // Check if all fields have correct data types
425 //
426
427 //
428 // Check VariableName
429 //
430 if (isEmpty(this.jTextFieldVariableName.getText())) {
431 Log.wrn("Update Variables", "Variable Name must be entered!");
432 return false;
433 }
434
435 //
436 // Check FeatureFlag
437 //
438 if (!isEmpty(this.jTextFieldFeatureFlag.getText())) {
439 if (!DataValidation.isFeatureFlag(this.jTextFieldFeatureFlag.getText())) {
440 Log.wrn("Update Variables", "Incorrect data type for Feature Flag");
441 return false;
442 }
443 }
444
445 return true;
446 }
447
448 private VariablesIdentification getCurrentVariables() {
449 String arg0 = this.jTextFieldVariableName.getText();
450 String arg1 = this.jComboBoxGuidC_Name.getSelectedItem().toString();
451 String arg2 = this.jComboBoxUsage.getSelectedItem().toString();
452
453 String arg3 = this.jTextFieldFeatureFlag.getText();
454 Vector<String> arg4 = this.jArchCheckBox.getSelectedItemsVector();
455 String arg5 = this.jTextAreaHelpText.getText();
456
457 id = new VariablesIdentification(arg0, arg1, arg2, arg3, arg4, arg5);
458 return id;
459 }
460
461 public VariablesIdentification getId() {
462 return id;
463 }
464
465 public void setId(VariablesIdentification id) {
466 this.id = id;
467 }
468 }