]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/module/ui/dialog/VariablesDlg.java
Fixed Absolute position of fields, Added ToolTipText and made HelpText a Scrolling...
[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 Variable of MSA/MBD 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 Variable of MSA/MBD file It extends
43 * 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(160, 10));
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(160, 60, 320, 20));
133 jComboBoxUsage.setPreferredSize(new java.awt.Dimension(320, 20));
134 jComboBoxUsage
135 .setToolTipText("<html><table><tr><td>ALWAYS_CONSUMED</td><td>The module requires the variable entry to be set</td></tr>"
136 + "<tr><td>SOMETIMES_CONSUMED</td><td>The module will use the variable entry if it’s set.</td></tr>"
137 + "<tr><td>ALWAYS_PRODUCED</td><td>The module will always write the variable.</td></tr>"
138 + "<tr><td>SOMETIMES_PRODUCED</td><td>The module will sometimes write the variable.</td></tr></table></html>");
139 }
140 return jComboBoxUsage;
141 }
142
143 /**
144 * This method initializes jScrollPane
145 *
146 * @return javax.swing.JScrollPane
147 */
148 private JScrollPane getJScrollPane() {
149 if (jScrollPane == null) {
150 jScrollPane = new JScrollPane();
151 jScrollPane.setViewportView(getJContentPane());
152 }
153 return jScrollPane;
154 }
155
156 /**
157 * This method initializes jTextFieldFeatureFlag
158 *
159 * @return javax.swing.JTextField jTextFieldFeatureFlag
160 *
161 */
162 private JTextField getJTextFieldFeatureFlag() {
163 if (jTextFieldFeatureFlag == null) {
164 jTextFieldFeatureFlag = new JTextField();
165 jTextFieldFeatureFlag
166 .setBounds(new java.awt.Rectangle(160, 130, 320, 20));
167 jTextFieldFeatureFlag.setPreferredSize(new java.awt.Dimension(320, 20));
168 jTextFieldFeatureFlag.setToolTipText("Postfix expression that must evaluate to TRUE or FALSE");
169 }
170 return jTextFieldFeatureFlag;
171 }
172
173 /**
174 * This method initializes jTextFieldHelpText
175 *
176 * @return javax.swing.JTextField
177 *
178 */
179 private JTextArea getJTextAreaHelpText() {
180 if (jTextAreaHelpText == null) {
181 jTextAreaHelpText = new JTextArea();
182 jTextAreaHelpText.setLineWrap(true);
183 jTextAreaHelpText.setWrapStyleWord(true);
184 jTextAreaHelpText
185 .setToolTipText("Enter information on how to use this Variable.");
186 }
187 return jTextAreaHelpText;
188 }
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(160,85));
198 jScrollPaneHelpText.setViewportView(getJTextAreaHelpText());
199 }
200 return jScrollPaneHelpText;
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(160, 35, 320, 20));
212 jComboBoxGuidC_Name.setPreferredSize(new java.awt.Dimension(320, 20));
213 jComboBoxGuidC_Name
214 .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, 182, 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, 182, 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(500, 255);
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,
297 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, 10));
326 jLabelVariableName = new JLabel();
327 jLabelVariableName.setText("Variable Name");
328 jLabelVariableName.setBounds(new java.awt.Rectangle(15, 10, 145, 20));
329
330 jStarLabel2 = new StarLabel();
331 jStarLabel2.setLocation(new java.awt.Point(2, 35));
332 jLabelGuidCName = new JLabel();
333 jLabelGuidCName.setBounds(new java.awt.Rectangle(15, 35, 145, 20));
334 jLabelGuidCName.setText("Variable Guid C Name");
335
336 jStarLabel3 = new StarLabel();
337 jStarLabel3.setLocation(new java.awt.Point(2, 60));
338 jLabelUsage = new JLabel();
339 jLabelUsage.setText("Usage");
340 jLabelUsage.setBounds(new java.awt.Rectangle(15, 60, 145, 20));
341
342 jLabelHelpText = new JLabel();
343 jLabelHelpText.setBounds(new java.awt.Rectangle(14, 85, 145, 20));
344 jLabelHelpText.setText("Help Text");
345
346 jLabelFeatureFlag = new JLabel();
347 jLabelFeatureFlag.setText("Feature Flag Expression");
348 jLabelFeatureFlag.setBounds(new java.awt.Rectangle(15, 130, 145, 20));
349
350 jLabelArch = new JLabel();
351 jLabelArch.setBounds(new java.awt.Rectangle(15, 155, 145, 20));
352 jLabelArch.setText("Supported Architectures");
353 jArchCheckBox = new ArchCheckBox();
354 jArchCheckBox.setBounds(new java.awt.Rectangle(160, 155, 320, 20));
355 jArchCheckBox.setPreferredSize(new java.awt.Dimension(320, 20));
356
357 jContentPane = new JPanel();
358 jContentPane.setLayout(null);
359 jContentPane.setPreferredSize(new java.awt.Dimension(485, 210));
360
361 jContentPane.add(jStarLabel1, null);
362 jContentPane.add(jLabelVariableName, null);
363 jContentPane.add(getJTextFieldString(), null);
364 jContentPane.add(jStarLabel2, null);
365 jContentPane.add(jLabelGuidCName, null);
366 jContentPane.add(getJComboBoxGuidC_Name(), null);
367 jContentPane.add(jStarLabel3, null);
368 jContentPane.add(jLabelUsage, null);
369 jContentPane.add(getJComboBoxUsage(), null);
370 jContentPane.add(jLabelHelpText, null);
371 jContentPane.add(getJScrollPaneHelpText(), null);
372 jContentPane.add(jLabelFeatureFlag, null);
373 jContentPane.add(getJTextFieldFeatureFlag(), null);
374 jContentPane.add(jLabelArch, null);
375 jContentPane.add(jArchCheckBox, null);
376 jContentPane.add(getJButtonOk(), null);
377 jContentPane.add(getJButtonCancel(), null);
378 }
379 return jContentPane;
380 }
381
382 /*
383 * (non-Javadoc)
384 *
385 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
386 *
387 * Override actionPerformed to listen all actions
388 *
389 */
390 public void actionPerformed(ActionEvent arg0) {
391 if (arg0.getSource() == jButtonOk) {
392 if (checkAdd()) {
393 getCurrentVariables();
394 this.returnType = DataType.RETURN_TYPE_OK;
395 this.setVisible(false);
396 }
397 }
398
399 if (arg0.getSource() == jButtonCancel) {
400 this.returnType = DataType.RETURN_TYPE_CANCEL;
401 this.setVisible(false);
402 }
403 }
404
405 /**
406 * This method initializes Usage type
407 *
408 */
409 private void initFrame() {
410 Tools.generateComboBoxByVector(jComboBoxUsage, ed.getVPpiUsage());
411 Tools.generateComboBoxByVector(jComboBoxGuidC_Name, wt
412 .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 not be empty");
432 return false;
433 }
434
435 if (!isEmpty(this.jTextFieldVariableName.getText())) {
436 if (!DataValidation.isHexWordArrayType(this.jTextFieldVariableName
437 .getText())) {
438 Log.wrn("Update Variables", "Incorrect data type for Variable Name");
439 return false;
440 }
441 }
442
443 //
444 // Check FeatureFlag
445 //
446 if (!isEmpty(this.jTextFieldFeatureFlag.getText())) {
447 if (!DataValidation.isFeatureFlag(this.jTextFieldFeatureFlag.getText())) {
448 Log.wrn("Update Variables", "Incorrect data type for Feature Flag");
449 return false;
450 }
451 }
452
453 return true;
454 }
455
456 private VariablesIdentification getCurrentVariables() {
457 String arg0 = this.jTextFieldVariableName.getText();
458 String arg1 = this.jComboBoxGuidC_Name.getSelectedItem().toString();
459 String arg2 = this.jComboBoxUsage.getSelectedItem().toString();
460
461 String arg3 = this.jTextFieldFeatureFlag.getText();
462 Vector<String> arg4 = this.jArchCheckBox.getSelectedItemsVector();
463 String arg5 = this.jTextAreaHelpText.getText();
464
465 id = new VariablesIdentification(arg0, arg1, arg2, arg3, arg4, arg5);
466 return id;
467 }
468
469 public VariablesIdentification getId() {
470 return id;
471 }
472
473 public void setId(VariablesIdentification id) {
474 this.id = id;
475 }
476 }