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