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