]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/module/ui/dialog/PCDsDlg.java
5cb598d9dabd7bba80f7d1c99f912c67b4dd1af8
[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.awt.event.ItemEvent;
19 import java.awt.event.ItemListener;
20 import java.util.Vector;
21
22 import javax.swing.JButton;
23 import javax.swing.JComboBox;
24 import javax.swing.JLabel;
25 import javax.swing.JPanel;
26 import javax.swing.JScrollPane;
27 import javax.swing.JTextField;
28
29 import org.tianocore.frameworkwizard.common.DataType;
30 import org.tianocore.frameworkwizard.common.DataValidation;
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.PcdCoded.PcdCodedIdentification;
38 import org.tianocore.frameworkwizard.module.Identifications.PcdCoded.PcdVector;
39 import org.tianocore.frameworkwizard.workspace.WorkspaceTools;
40
41 /**
42 The class is used to create, update PCD of MSA/MBD file
43 It extends IInternalFrame
44
45 **/
46 public class PCDsDlg extends IDialog implements ItemListener {
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 WorkspaceTools wt = new WorkspaceTools();
104
105 private PcdVector pcd = wt.getAllPcdDeclarationsFromWorkspace();
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 jComboBoxCName.addItemListener(this);
134 //jComboBoxCName.addActionListener(this);
135 }
136 return jComboBoxCName;
137 }
138
139 /**
140 This method initializes jTextFieldDefaultValue
141
142 @return javax.swing.JTextField jTextFieldDefaultValue
143
144 **/
145 private JTextField getJTextFieldDefaultValue() {
146 if (jTextFieldDefaultValue == null) {
147 jTextFieldDefaultValue = new JTextField();
148 jTextFieldDefaultValue.setBounds(new java.awt.Rectangle(160, 60, 320, 20));
149 jTextFieldDefaultValue.setPreferredSize(new java.awt.Dimension(320, 20));
150 }
151 return jTextFieldDefaultValue;
152 }
153
154 /**
155 * This method initializes jTextFieldHelpText
156 *
157 * @return javax.swing.JTextField
158 */
159 private JTextField getJTextFieldHelpText() {
160 if (jTextFieldHelpText == null) {
161 jTextFieldHelpText = new JTextField();
162 jTextFieldHelpText.setBounds(new java.awt.Rectangle(160, 85, 320, 20));
163 jTextFieldHelpText.setPreferredSize(new java.awt.Dimension(320, 20));
164 }
165 return jTextFieldHelpText;
166 }
167
168 /**
169 This method initializes jScrollPane
170
171 @return javax.swing.JScrollPane
172 */
173 private JScrollPane getJScrollPane() {
174 if (jScrollPane == null) {
175 jScrollPane = new JScrollPane();
176 jScrollPane.setViewportView(getJContentPane());
177 }
178 return jScrollPane;
179 }
180
181 /**
182 * This method initializes jTextFieldTokenSpaceGuid
183 *
184 * @return javax.swing.JTextField
185 */
186 private JTextField getJTextFieldTokenSpaceGuid() {
187 if (jTextFieldTokenSpaceGuid == null) {
188 jTextFieldTokenSpaceGuid = new JTextField();
189 jTextFieldTokenSpaceGuid.setBounds(new java.awt.Rectangle(160, 60, 320, 20));
190 jTextFieldTokenSpaceGuid.setPreferredSize(new java.awt.Dimension(320, 20));
191 jTextFieldTokenSpaceGuid.setVisible(false);
192 }
193 return jTextFieldTokenSpaceGuid;
194 }
195
196 /**
197 * This method initializes jTextFieldFeatureFlag
198 *
199 * @return javax.swing.JTextField
200 */
201 private JTextField getJTextFieldFeatureFlag() {
202 if (jTextFieldFeatureFlag == null) {
203 jTextFieldFeatureFlag = new JTextField();
204 jTextFieldFeatureFlag.setBounds(new java.awt.Rectangle(160, 110, 320, 20));
205 jTextFieldFeatureFlag.setPreferredSize(new java.awt.Dimension(320, 20));
206 }
207 return jTextFieldFeatureFlag;
208 }
209
210 /**
211 This method initializes jButtonOk
212
213 @return javax.swing.JButton
214
215 **/
216 private JButton getJButtonOk() {
217 if (jButtonOk == null) {
218 jButtonOk = new JButton();
219 jButtonOk.setBounds(new java.awt.Rectangle(290, 165, 90, 20));
220 jButtonOk.setText("Ok");
221 jButtonOk.addActionListener(this);
222 }
223 return jButtonOk;
224 }
225
226 /**
227 This method initializes jButtonCancel
228
229 @return javax.swing.JButton
230
231 **/
232 private JButton getJButtonCancel() {
233 if (jButtonCancel == null) {
234 jButtonCancel = new JButton();
235 jButtonCancel.setBounds(new java.awt.Rectangle(390, 165, 90, 20));
236 jButtonCancel.setText("Cancel");
237 jButtonCancel.addActionListener(this);
238 }
239 return jButtonCancel;
240 }
241
242 public static void main(String[] args) {
243
244 }
245
246 /**
247 This method initializes this
248
249 **/
250 private void init() {
251 this.setSize(508, 240);
252 this.setContentPane(getJScrollPane());
253 this.setTitle("Pcd Coded");
254 initFrame();
255 this.setViewMode(false);
256 this.centerWindow();
257 }
258
259 /**
260 This method initializes this
261 Fill values to all fields if these values are not empty
262
263 @param inPcdCodedId
264
265 **/
266 private void init(PcdCodedIdentification inPcdCodedId) {
267 init();
268 this.id = inPcdCodedId;
269
270 if (this.id != null) {
271 this.jComboBoxCName.setSelectedItem(id.getName());
272 this.jTextFieldTokenSpaceGuid.setText(id.getGuid());
273 this.jTextFieldDefaultValue.setText(id.getValue());
274 this.jTextFieldHelpText.setText(id.getHelp());
275 this.jComboBoxItemType.setSelectedItem(id.getType());
276 this.jTextFieldFeatureFlag.setText(id.getFeatureFlag());
277 this.jArchCheckBox.setSelectedItems(id.getSupArchList());
278 }
279 }
280
281 /**
282 This is the override edit constructor
283
284 @param inPcdCodedId
285 @param iFrame
286
287 **/
288 public PCDsDlg(PcdCodedIdentification inPcdCodedId, IFrame iFrame) {
289 super(iFrame, true);
290 init(inPcdCodedId);
291 }
292
293 /**
294 Disable all components when the mode is view
295
296 @param isView true - The view mode; false - The non-view mode
297
298 **/
299 public void setViewMode(boolean isView) {
300 if (isView) {
301 this.jTextFieldDefaultValue.setEnabled(!isView);
302 this.jComboBoxItemType.setEnabled(!isView);
303 }
304 }
305
306 /**
307 This method initializes jContentPane
308
309 @return javax.swing.JPanel jContentPane
310
311 **/
312 private JPanel getJContentPane() {
313 if (jContentPane == null) {
314 jArchCheckBox = new ArchCheckBox();
315 jArchCheckBox.setBounds(new java.awt.Rectangle(160, 135, 320, 20));
316 jArchCheckBox.setPreferredSize(new java.awt.Dimension(320, 20));
317 jLabelArch = new JLabel();
318 jLabelArch.setBounds(new java.awt.Rectangle(15, 135, 140, 20));
319 jLabelArch.setText("Sup Arch List");
320 jLabelFeatureFlag = new JLabel();
321 jLabelFeatureFlag.setBounds(new java.awt.Rectangle(15, 110, 140, 20));
322 jLabelFeatureFlag.setText("Feature Flag");
323 jLabelTokenSpaceGuid = new JLabel();
324 jLabelTokenSpaceGuid.setBounds(new java.awt.Rectangle(15, 60, 140, 20));
325 jLabelTokenSpaceGuid.setText("Token Space C Name");
326 jLabelTokenSpaceGuid.setVisible(false);
327 jLabelHelpText = new JLabel();
328 jLabelHelpText.setBounds(new java.awt.Rectangle(15, 85, 140, 20));
329 jLabelHelpText.setText("Help Text");
330 jLabelC_Name = new JLabel();
331 jLabelC_Name.setText("C Name");
332 jLabelC_Name.setBounds(new java.awt.Rectangle(15, 10, 140, 20));
333 jLabelDefaultValue = new JLabel();
334 jLabelDefaultValue.setText("Default Value");
335 jLabelDefaultValue.setBounds(new java.awt.Rectangle(15, 60, 140, 20));
336 jLabelItemType = new JLabel();
337 jLabelItemType.setText("Item Type");
338 jLabelItemType.setBounds(new java.awt.Rectangle(15, 35, 140, 20));
339
340 jContentPane = new JPanel();
341 jContentPane.setLayout(null);
342 jContentPane.setPreferredSize(new java.awt.Dimension(490, 190));
343
344 jContentPane.add(jLabelItemType, null);
345 jContentPane.add(jLabelC_Name, null);
346 jContentPane.add(getJComboBoxCName(), null);
347 jContentPane.add(jLabelDefaultValue, null);
348 jContentPane.add(getJTextFieldDefaultValue(), null);
349 jContentPane.add(getJComboBoxItemType(), null);
350 jStarLabel1 = new StarLabel();
351 jStarLabel1.setLocation(new java.awt.Point(0, 10));
352 jStarLabel2 = new StarLabel();
353 jStarLabel2.setLocation(new java.awt.Point(0, 35));
354 jStarLabel3 = new StarLabel();
355 jStarLabel3.setLocation(new java.awt.Point(0, 85));
356 jContentPane.add(jStarLabel1, null);
357 jContentPane.add(jStarLabel2, null);
358 jContentPane.add(jStarLabel3, null);
359 jContentPane.add(jLabelHelpText, null);
360 jContentPane.add(getJTextFieldHelpText(), null);
361
362 jContentPane.add(jLabelTokenSpaceGuid, null);
363 jContentPane.add(getJTextFieldTokenSpaceGuid(), null);
364 jContentPane.add(jLabelFeatureFlag, null);
365 jContentPane.add(getJTextFieldFeatureFlag(), null);
366 jContentPane.add(jLabelArch, null);
367 jContentPane.add(jArchCheckBox, null);
368 jContentPane.add(getJButtonOk(), null);
369 jContentPane.add(getJButtonCancel(), null);
370 }
371 return jContentPane;
372 }
373
374 /**
375 This method initializes Usage type, Item type and Datum type
376
377 **/
378 private void initFrame() {
379 for (int index = 0; index < pcd.size(); index++) {
380 jComboBoxCName.addItem(pcd.getPcd(index));
381 }
382
383 //Tools.generateComboBoxByVector(jComboBoxItemType, ed.getVPcdItemTypes());
384 }
385
386 /* (non-Javadoc)
387 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
388 *
389 * Override actionPerformed to listen all actions
390 *
391 */
392 public void actionPerformed(ActionEvent arg0) {
393 if (arg0.getSource() == jButtonOk) {
394 if (checkAdd()) {
395 getCurrentPcdCoded();
396 this.returnType = DataType.RETURN_TYPE_OK;
397 this.setVisible(false);
398 }
399 }
400
401 if (arg0.getSource() == jButtonCancel) {
402 this.returnType = DataType.RETURN_TYPE_CANCEL;
403 this.setVisible(false);
404 }
405 }
406
407 /**
408 Data validation for all fields
409
410 @retval true - All datas are valid
411 @retval false - At least one data is invalid
412
413 **/
414 public boolean checkAdd() {
415 //
416 // Check if all fields have correct data types
417 //
418
419 //
420 // Check C_Name
421 //
422 if (!isEmpty(this.jComboBoxCName.getSelectedItem().toString())) {
423 if (!DataValidation.isC_NameType(this.jComboBoxCName.getSelectedItem().toString())) {
424 Log.wrn("Update PcdCoded", "Incorrect data type for C Name");
425 return false;
426 }
427 }
428
429 //
430 // Check TokenSpaceGuid
431 //
432 if (!isEmpty(this.jTextFieldTokenSpaceGuid.getText())) {
433 if (!DataValidation.isC_NameType(this.jTextFieldTokenSpaceGuid.getText())) {
434 Log.wrn("Update PcdCoded", "Incorrect data type for the selected pcd entry, please check in in spd file");
435 return false;
436 }
437 }
438
439 //
440 // Check DefaultValue
441 //
442 if (!isEmpty(this.jTextFieldDefaultValue.getText())) {
443 if (!DataValidation.isDefaultValueType(this.jTextFieldDefaultValue.getText())) {
444 Log.wrn("Update PcdCoded", "Incorrect data type for Default Value");
445 return false;
446 }
447 }
448
449 //
450 // Check HelpText
451 //
452 if (isEmpty(this.jTextFieldHelpText.getText())) {
453 Log.wrn("Update PcdCoded", "Help Text couldn't be empty");
454 return false;
455 }
456
457 //
458 // Check FeatureFlag
459 //
460 if (!isEmpty(this.jTextFieldFeatureFlag.getText())) {
461 if (!DataValidation.isFeatureFlag(this.jTextFieldFeatureFlag.getText())) {
462 Log.wrn("Update PcdCoded", "Incorrect data type for Feature Flag");
463 return false;
464 }
465 }
466
467 return true;
468 }
469
470 private PcdCodedIdentification getCurrentPcdCoded() {
471 String arg0 = this.jComboBoxCName.getSelectedItem().toString();
472 String arg1 = this.jTextFieldTokenSpaceGuid.getText();
473
474 String arg2 = this.jTextFieldFeatureFlag.getText();
475 Vector<String> arg3 = this.jArchCheckBox.getSelectedItemsVector();
476
477 String arg4 = this.jTextFieldDefaultValue.getText();
478 String arg5 = this.jTextFieldHelpText.getText();
479 String arg6 = this.jComboBoxItemType.getSelectedItem().toString();
480 id = new PcdCodedIdentification(arg0, arg1, arg2, arg3, arg4, arg5, arg6);
481 return id;
482 }
483
484 public PcdCodedIdentification getId() {
485 return id;
486 }
487
488 public void setId(PcdCodedIdentification id) {
489 this.id = id;
490 }
491
492 /* (non-Javadoc)
493 * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
494 *
495 * Reflesh the frame when selected item changed
496 *
497 */
498 public void itemStateChanged(ItemEvent arg0) {
499 int index = this.jComboBoxCName.getSelectedIndex();
500 if (arg0.getSource() == this.jComboBoxCName && arg0.getStateChange() == ItemEvent.SELECTED ) {
501 if (pcd.getPcd(index).getGuidCName() == null || isEmpty(pcd.getPcd(index).getGuidCName())
502 || pcd.getPcd(index).getType() == null || pcd.getPcd(index).getHelp() == null || isEmpty(pcd.getPcd(index).getHelp())) {
503 Log.wrn("select pcd entry when editing msa", "The selected is defined incorrectly.\r\nPlease check it in spd file");
504 } else {
505 this.jTextFieldTokenSpaceGuid.setText(pcd.getPcd(index).getGuidCName());
506 Tools.generateComboBoxByVector(this.jComboBoxItemType, pcd.getPcd(index).getType());
507 this.jTextFieldHelpText.setText(pcd.getPcd(index).getHelp());
508 this.jTextFieldHelpText.setSelectionStart(0);
509 this.jTextFieldHelpText.setSelectionEnd(0);
510 }
511 }
512 }
513 }