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