]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/module/ui/dialog/PCDsDlg.java
1. PcdUsage is added to PCD entry in schema so wizard tool is also updated to support...
[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 import javax.swing.JTextArea;
29
30 import org.tianocore.frameworkwizard.common.DataType;
31 import org.tianocore.frameworkwizard.common.DataValidation;
32 import org.tianocore.frameworkwizard.common.EnumerationData;
33 import org.tianocore.frameworkwizard.common.Log;
34 import org.tianocore.frameworkwizard.common.Tools;
35 import org.tianocore.frameworkwizard.common.ui.ArchCheckBox;
36 import org.tianocore.frameworkwizard.common.ui.IDialog;
37 import org.tianocore.frameworkwizard.common.ui.IFrame;
38 import org.tianocore.frameworkwizard.common.ui.StarLabel;
39 import org.tianocore.frameworkwizard.module.Identifications.PcdCoded.PcdCodedIdentification;
40 import org.tianocore.frameworkwizard.module.Identifications.PcdCoded.PcdVector;
41 import org.tianocore.frameworkwizard.workspace.WorkspaceTools;
42
43 /**
44 * The class is used to create, update PCD of MSA/MBD file It extends
45 * IInternalFrame
46 *
47 */
48 public class PCDsDlg extends IDialog implements ItemListener {
49
50 // /
51 // / Define class Serial Version UID
52 // /
53 private static final long serialVersionUID = 2227717658188438696L;
54
55 //
56 // Define class members
57 //
58 private JPanel jContentPane = null;
59
60 private JLabel jLabelItemType = null;
61
62 private JLabel jLabelC_Name = null;
63
64 private JComboBox jComboBoxItemType = null;
65
66 private JComboBox jComboBoxCName = null;
67
68 private JLabel jLabelDefaultValue = null;
69
70 private JTextField jTextFieldDefaultValue = null;
71
72 private StarLabel jStarLabel1 = null;
73
74 private StarLabel jStarLabel2 = null;
75
76 private StarLabel jStarLabel3 = null;
77
78 private JLabel jLabelHelpText = null;
79
80 private JTextArea jTextAreaHelpText = null;
81
82 private JScrollPane jScrollPane = null;
83
84 private JLabel jLabelTokenSpaceGuid = null;
85
86 private JTextField jTextFieldTokenSpaceGuid = null;
87
88 private JLabel jLabelFeatureFlag = null;
89
90 private JTextField jTextFieldFeatureFlag = null;
91
92 private JLabel jLabelArch = null;
93
94 private ArchCheckBox jArchCheckBox = null;
95
96 private JButton jButtonOk = null;
97
98 private JButton jButtonCancel = null;
99
100 private JScrollPane jScrollPaneHelpText = null;
101
102 private JLabel jLabelUsage = null;
103
104 private JComboBox jComboBoxUsage = null;
105
106 //
107 // Not used by UI
108 //
109 private PcdCodedIdentification id = null;
110
111 private EnumerationData ed = new EnumerationData();
112
113 private WorkspaceTools wt = new WorkspaceTools();
114
115 private PcdVector pcd = wt.getAllPcdDeclarationsFromWorkspace();
116
117 /**
118 * This method initializes jComboBoxItemType
119 *
120 * @return javax.swing.JComboBox jComboBoxItemType
121 *
122 */
123 private JComboBox getJComboBoxItemType() {
124 if (jComboBoxItemType == null) {
125 jComboBoxItemType = new JComboBox();
126 jComboBoxItemType.setBounds(new java.awt.Rectangle(160, 35, 320, 20));
127 jComboBoxItemType.setPreferredSize(new java.awt.Dimension(320, 20));
128 }
129 return jComboBoxItemType;
130 }
131
132 /**
133 * This method initializes jTextFieldC_Name
134 *
135 * @return javax.swing.JTextField jTextFieldC_Name
136 *
137 */
138 private JComboBox getJComboBoxCName() {
139 if (jComboBoxCName == null) {
140 jComboBoxCName = new JComboBox();
141 jComboBoxCName.setBounds(new java.awt.Rectangle(160, 10, 320, 20));
142 jComboBoxCName.setPreferredSize(new java.awt.Dimension(320, 20));
143 jComboBoxCName.addItemListener(this);
144 }
145 return jComboBoxCName;
146 }
147
148 /**
149 * This method initializes jTextFieldDefaultValue
150 *
151 * @return javax.swing.JTextField jTextFieldDefaultValue
152 *
153 */
154 private JTextField getJTextFieldDefaultValue() {
155 if (jTextFieldDefaultValue == null) {
156 jTextFieldDefaultValue = new JTextField();
157 jTextFieldDefaultValue.setBounds(new java.awt.Rectangle(160, 60, 320, 20));
158 jTextFieldDefaultValue.setPreferredSize(new java.awt.Dimension(320, 20));
159 }
160 return jTextFieldDefaultValue;
161 }
162
163 /**
164 * This method initializes jTextAreaHelpText
165 *
166 * @return javax.swing.JTextArea
167 */
168 private JTextArea getJTextAreaHelpText() {
169 if (jTextAreaHelpText == null) {
170 jTextAreaHelpText = new JTextArea();
171 jTextAreaHelpText.setLineWrap(true);
172 jTextAreaHelpText.setWrapStyleWord(true);
173 }
174 return jTextAreaHelpText;
175 }
176
177 /**
178 * This method initializes jScrollPaneHelpText
179 *
180 * @return javax.swing.JScrollPane
181 *
182 */
183 private JScrollPane getJScrollPaneHelpText() {
184 if (jScrollPaneHelpText == null) {
185 jScrollPaneHelpText = new JScrollPane();
186 jScrollPaneHelpText.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
187 jScrollPaneHelpText.setSize(new java.awt.Dimension(320, 40));
188 jScrollPaneHelpText.setPreferredSize(new java.awt.Dimension(320, 40));
189 jScrollPaneHelpText.setLocation(new java.awt.Point(160, 110));
190 jScrollPaneHelpText.setViewportView(getJTextAreaHelpText());
191 }
192 return jScrollPaneHelpText;
193 }
194
195 /**
196 * This method initializes jScrollPane
197 *
198 * @return javax.swing.JScrollPane
199 */
200 private JScrollPane getJScrollPane() {
201 if (jScrollPane == null) {
202 jScrollPane = new JScrollPane();
203 jScrollPane.setViewportView(getJContentPane());
204 }
205 return jScrollPane;
206 }
207
208 /**
209 * This method initializes jTextFieldTokenSpaceGuid
210 *
211 * @return javax.swing.JTextField
212 */
213 private JTextField getJTextFieldTokenSpaceGuid() {
214 if (jTextFieldTokenSpaceGuid == null) {
215 jTextFieldTokenSpaceGuid = new JTextField();
216 jTextFieldTokenSpaceGuid.setBounds(new java.awt.Rectangle(160, 60, 320, 20));
217 jTextFieldTokenSpaceGuid.setPreferredSize(new java.awt.Dimension(320, 20));
218 jTextFieldTokenSpaceGuid.setVisible(false);
219 }
220 return jTextFieldTokenSpaceGuid;
221 }
222
223 /**
224 * This method initializes jTextFieldFeatureFlag
225 *
226 * @return javax.swing.JTextField
227 */
228 private JTextField getJTextFieldFeatureFlag() {
229 if (jTextFieldFeatureFlag == null) {
230 jTextFieldFeatureFlag = new JTextField();
231 jTextFieldFeatureFlag.setBounds(new java.awt.Rectangle(160, 155, 320, 20));
232 jTextFieldFeatureFlag.setPreferredSize(new java.awt.Dimension(320, 20));
233 jTextFieldFeatureFlag.setToolTipText("Postfix expression that must evaluate to TRUE or FALSE");
234 }
235 return jTextFieldFeatureFlag;
236 }
237
238 /**
239 * This method initializes jButtonOk
240 *
241 * @return javax.swing.JButton
242 *
243 */
244 private JButton getJButtonOk() {
245 if (jButtonOk == null) {
246 jButtonOk = new JButton();
247 jButtonOk.setBounds(new java.awt.Rectangle(290, 205, 90, 20));
248 jButtonOk.setText("Ok");
249 jButtonOk.addActionListener(this);
250 }
251 return jButtonOk;
252 }
253
254 /**
255 * This method initializes jButtonCancel
256 *
257 * @return javax.swing.JButton
258 *
259 */
260 private JButton getJButtonCancel() {
261 if (jButtonCancel == null) {
262 jButtonCancel = new JButton();
263 jButtonCancel.setBounds(new java.awt.Rectangle(390, 205, 90, 20));
264 jButtonCancel.setText("Cancel");
265 jButtonCancel.addActionListener(this);
266 }
267 return jButtonCancel;
268 }
269
270 /**
271 * This method initializes jComboBoxUsage
272 *
273 * @return javax.swing.JComboBox
274 */
275 private JComboBox getJComboBoxUsage() {
276 if (jComboBoxUsage == null) {
277 jComboBoxUsage = new JComboBox();
278 jComboBoxUsage.setBounds(new java.awt.Rectangle(160, 85, 320, 20));
279 jComboBoxUsage.setPreferredSize(new java.awt.Dimension(320, 20));
280 }
281 return jComboBoxUsage;
282 }
283
284 public static void main(String[] args) {
285
286 }
287
288 /**
289 * This method initializes this
290 *
291 */
292 private void init() {
293 this.setSize(500, 270);
294 this.setContentPane(getJScrollPane());
295 this.setTitle("Pcd Coded");
296 initFrame();
297 this.setViewMode(false);
298 this.centerWindow();
299 }
300
301 /**
302 * This method initializes this Fill values to all fields if these values are
303 * not empty
304 *
305 * @param inPcdCodedId
306 *
307 */
308 private void init(PcdCodedIdentification inPcdCodedId) {
309 init();
310 this.id = inPcdCodedId;
311
312 if (this.id != null) {
313 this.jComboBoxCName.setSelectedItem(id.getName());
314 this.jTextFieldTokenSpaceGuid.setText(id.getGuid());
315 this.jTextFieldDefaultValue.setText(id.getValue());
316 this.jComboBoxUsage.setSelectedItem(id.getUsage());
317 this.jTextAreaHelpText.setText(id.getHelp());
318 this.jComboBoxItemType.setSelectedItem(id.getType());
319 this.jTextFieldFeatureFlag.setText(id.getFeatureFlag());
320 this.jArchCheckBox.setSelectedItems(id.getSupArchList());
321 }
322 }
323
324 /**
325 * This is the override edit constructor
326 *
327 * @param inPcdCodedId
328 * @param iFrame
329 *
330 */
331 public PCDsDlg(PcdCodedIdentification inPcdCodedId, IFrame iFrame) {
332 super(iFrame, true);
333 init(inPcdCodedId);
334 }
335
336 /**
337 * Disable all components when the mode is view
338 *
339 * @param isView
340 * true - The view mode; false - The non-view mode
341 *
342 */
343 public void setViewMode(boolean isView) {
344 if (isView) {
345 this.jTextFieldDefaultValue.setEnabled(!isView);
346 this.jComboBoxItemType.setEnabled(!isView);
347 }
348 }
349
350 /**
351 * This method initializes jContentPane
352 *
353 * @return javax.swing.JPanel jContentPane
354 *
355 */
356 private JPanel getJContentPane() {
357 if (jContentPane == null) {
358 jLabelUsage = new JLabel();
359 jLabelUsage.setBounds(new java.awt.Rectangle(15, 85, 140, 20));
360 jLabelUsage.setText("Usge");
361 jStarLabel1 = new StarLabel();
362 jStarLabel1.setLocation(new java.awt.Point(2, 10));
363 jLabelC_Name = new JLabel();
364 jLabelC_Name.setText("PCD C Name");
365 jLabelC_Name.setBounds(new java.awt.Rectangle(15, 10, 145, 20));
366
367 jStarLabel2 = new StarLabel();
368 jStarLabel2.setLocation(new java.awt.Point(2, 35));
369 jLabelItemType = new JLabel();
370 jLabelItemType.setText("PCD Item Type");
371 jLabelItemType.setBounds(new java.awt.Rectangle(15, 35, 145, 20));
372
373 jLabelDefaultValue = new JLabel();
374 jLabelDefaultValue.setText("Default Value");
375 jLabelDefaultValue.setBounds(new java.awt.Rectangle(15, 60, 145, 20));
376
377 jStarLabel3 = new StarLabel();
378 jStarLabel3.setLocation(new java.awt.Point(2, 110));
379 jLabelHelpText = new JLabel();
380 jLabelHelpText.setText("Help Text");
381 jLabelHelpText.setBounds(new java.awt.Rectangle(15, 110, 145, 20));
382
383 jLabelFeatureFlag = new JLabel();
384 jLabelFeatureFlag.setText("Feature Flag Expression");
385 jLabelFeatureFlag.setBounds(new java.awt.Rectangle(15, 155, 140, 20));
386
387 jLabelTokenSpaceGuid = new JLabel();
388 jLabelTokenSpaceGuid.setText("Token Space C Name");
389 jLabelTokenSpaceGuid.setVisible(false);
390
391 jLabelArch = new JLabel();
392 jLabelArch.setText("Supported Architectures");
393 jLabelArch.setBounds(new java.awt.Rectangle(15, 180, 145, 20));
394 jArchCheckBox = new ArchCheckBox();
395 jArchCheckBox.setPreferredSize(new java.awt.Dimension(320, 20));
396 jArchCheckBox.setBounds(new java.awt.Rectangle(160, 180, 320, 20));
397
398 // Hidden field
399 jLabelTokenSpaceGuid.setBounds(new java.awt.Rectangle(15, 60, 140, 20));
400
401 jContentPane = new JPanel();
402 jContentPane.setLayout(null);
403 jContentPane.setPreferredSize(new java.awt.Dimension(485, 235));
404
405 jContentPane.add(jStarLabel1, null);
406 jContentPane.add(jLabelC_Name, null);
407 jContentPane.add(getJComboBoxCName(), null);
408 jContentPane.add(jStarLabel2, null);
409 jContentPane.add(jLabelItemType, null);
410 jContentPane.add(getJComboBoxItemType(), null);
411 jContentPane.add(jLabelDefaultValue, null);
412 jContentPane.add(getJTextFieldDefaultValue(), null);
413 jContentPane.add(jStarLabel3, null);
414 jContentPane.add(jLabelHelpText, null);
415 jContentPane.add(getJScrollPaneHelpText(), null);
416 jContentPane.add(jLabelFeatureFlag, null);
417 jContentPane.add(getJTextFieldFeatureFlag(), null);
418 jContentPane.add(jLabelArch, null);
419 jContentPane.add(jArchCheckBox, null);
420 // Hidden
421 jContentPane.add(getJTextFieldTokenSpaceGuid(), null);
422 jContentPane.add(jLabelTokenSpaceGuid, null);
423 jContentPane.add(getJButtonOk(), null);
424 jContentPane.add(getJButtonCancel(), null);
425 jContentPane.add(jLabelUsage, null);
426 jContentPane.add(getJComboBoxUsage(), null);
427 }
428 return jContentPane;
429 }
430
431 /**
432 * This method initializes Usage type, Item type and Datum type
433 *
434 */
435 private void initFrame() {
436 for (int index = 0; index < pcd.size(); index++) {
437 jComboBoxCName.addItem(pcd.getPcd(index));
438 }
439
440 Tools.generateComboBoxByVector(jComboBoxUsage, ed.getVPcdUsage());
441 }
442
443 /*
444 * (non-Javadoc)
445 *
446 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
447 *
448 * Override actionPerformed to listen all actions
449 *
450 */
451 public void actionPerformed(ActionEvent arg0) {
452 if (arg0.getSource() == jButtonOk) {
453 if (checkAdd()) {
454 getCurrentPcdCoded();
455 this.returnType = DataType.RETURN_TYPE_OK;
456 this.setVisible(false);
457 }
458 }
459
460 if (arg0.getSource() == jButtonCancel) {
461 this.returnType = DataType.RETURN_TYPE_CANCEL;
462 this.setVisible(false);
463 }
464 }
465
466 /**
467 * Data validation for all fields
468 *
469 * @retval true - All datas are valid
470 * @retval false - At least one data is invalid
471 *
472 */
473 public boolean checkAdd() {
474 //
475 // Check if all fields have correct data types
476 //
477
478 //
479 // Check C_Name
480 //
481 if (!isEmpty(this.jComboBoxCName.getSelectedItem().toString())) {
482 if (!DataValidation.isC_NameType(this.jComboBoxCName.getSelectedItem().toString())) {
483 Log.wrn("Update PcdCoded", "Incorrect data type for C Name");
484 return false;
485 }
486 }
487
488 //
489 // Check TokenSpaceGuid
490 //
491 if (!isEmpty(this.jTextFieldTokenSpaceGuid.getText())) {
492 if (!DataValidation.isC_NameType(this.jTextFieldTokenSpaceGuid.getText())) {
493 Log.wrn("Update PcdCoded",
494 "Incorrect data type for the selected pcd entry, please check in in spd file");
495 return false;
496 }
497 }
498
499 //
500 // Check DefaultValue
501 //
502 if (!isEmpty(this.jTextFieldDefaultValue.getText())) {
503 if (!DataValidation.isDefaultValueType(this.jTextFieldDefaultValue.getText())) {
504 Log.wrn("Update PcdCoded", "Incorrect data type for Default Value");
505 return false;
506 }
507 }
508
509 //
510 // Check HelpText
511 //
512 if (isEmpty(this.jTextAreaHelpText.getText())) {
513 Log.wrn("Update PcdCoded", "Help Text should not be empty");
514 return false;
515 }
516
517 //
518 // Check FeatureFlag
519 //
520 if (!isEmpty(this.jTextFieldFeatureFlag.getText())) {
521 if (!DataValidation.isFeatureFlag(this.jTextFieldFeatureFlag.getText())) {
522 Log.wrn("Update PcdCoded", "Incorrect data type for Feature Flag");
523 return false;
524 }
525 }
526
527 return true;
528 }
529
530 private PcdCodedIdentification getCurrentPcdCoded() {
531 String arg0 = this.jComboBoxCName.getSelectedItem().toString();
532 String arg1 = this.jTextFieldTokenSpaceGuid.getText();
533
534 String arg2 = this.jTextFieldFeatureFlag.getText();
535 Vector<String> arg3 = this.jArchCheckBox.getSelectedItemsVector();
536
537 String arg4 = this.jTextFieldDefaultValue.getText();
538 String arg5 = this.jTextAreaHelpText.getText();
539 String arg6 = this.jComboBoxItemType.getSelectedItem().toString();
540 String arg7 = this.jComboBoxUsage.getSelectedItem().toString();
541 if (arg7.equals(DataType.EMPTY_SELECT_ITEM)) {
542 arg7 = "";
543 }
544
545 id = new PcdCodedIdentification(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
546 return id;
547 }
548
549 public PcdCodedIdentification getId() {
550 return id;
551 }
552
553 public void setId(PcdCodedIdentification id) {
554 this.id = id;
555 }
556
557 /*
558 * (non-Javadoc)
559 *
560 * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
561 *
562 * Reflesh the frame when selected item changed
563 *
564 */
565 public void itemStateChanged(ItemEvent arg0) {
566 int index = this.jComboBoxCName.getSelectedIndex();
567 if (arg0.getSource() == this.jComboBoxCName && arg0.getStateChange() == ItemEvent.SELECTED) {
568 if (pcd.getPcd(index).getGuidCName() == null || isEmpty(pcd.getPcd(index).getGuidCName())
569 || pcd.getPcd(index).getType() == null || pcd.getPcd(index).getHelp() == null
570 || isEmpty(pcd.getPcd(index).getHelp())) {
571 Log.wrn("select pcd entry when editing msa",
572 "The selected is defined incorrectly.\r\nPlease check it in spd file");
573 } else {
574 this.jTextFieldTokenSpaceGuid.setText(pcd.getPcd(index).getGuidCName());
575 Tools.generateComboBoxByVector(this.jComboBoxItemType, pcd.getPcd(index).getType());
576 this.jTextAreaHelpText.setText(pcd.getPcd(index).getHelp());
577 this.jTextAreaHelpText.setSelectionStart(0);
578 this.jTextAreaHelpText.setSelectionEnd(0);
579 }
580 }
581 }
582 }