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