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