]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/module/ui/dialog/PCDsDlg.java
58b983dad7c64f12ece2b82168bcb5f1515d0f24
[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 Vector<PackageIdentification> vpid = wt.getPackageDependenciesOfModule(mid);
317 if (vpid.size() <= 0) {
318 Log.wrn("Init Pcd", "This module hasn't defined any package dependency, so there is no pcd can be added");
319 }
320
321 pcd = wt.getAllPcdDeclarationsFromPackages(wt.getPackageDependenciesOfModule(mid));
322 for (int index = 0; index < pcd.size(); index++) {
323 jComboBoxCName.addItem(pcd.getPcd(index));
324 }
325
326 if (this.id != null) {
327 for (int index = 0; index < this.jComboBoxCName.getItemCount(); index++) {
328 if (this.jComboBoxCName.getItemAt(index).toString().equals(id.getName())) {
329 this.jComboBoxCName.setSelectedIndex(index);
330 break;
331 }
332 }
333 this.jTextFieldTokenSpaceGuid.setText(id.getGuid());
334 this.jTextFieldDefaultValue.setText(id.getValue());
335 this.jComboBoxUsage.setSelectedItem(id.getUsage());
336 this.jTextAreaHelpText.setText(id.getHelp());
337 this.jComboBoxItemType.setSelectedItem(id.getType());
338 this.jTextFieldFeatureFlag.setText(id.getFeatureFlag());
339 this.jArchCheckBox.setSelectedItems(id.getSupArchList());
340 }
341 }
342
343 /**
344 * This is the override edit constructor
345 *
346 * @param inPcdCodedId
347 * @param iFrame
348 *
349 */
350 public PCDsDlg(PcdCodedIdentification inPcdCodedId, IFrame iFrame, ModuleIdentification mid) {
351 super(iFrame, true);
352 init(inPcdCodedId, mid);
353 }
354
355 /**
356 * Disable all components when the mode is view
357 *
358 * @param isView
359 * true - The view mode; false - The non-view mode
360 *
361 */
362 public void setViewMode(boolean isView) {
363 if (isView) {
364 this.jTextFieldDefaultValue.setEnabled(!isView);
365 this.jComboBoxItemType.setEnabled(!isView);
366 }
367 }
368
369 /**
370 * This method initializes jContentPane
371 *
372 * @return javax.swing.JPanel jContentPane
373 *
374 */
375 private JPanel getJContentPane() {
376 if (jContentPane == null) {
377 jLabelUsage = new JLabel();
378 jLabelUsage.setBounds(new java.awt.Rectangle(12, 87, 168, 20));
379 jLabelUsage.setText("Usge");
380 jStarLabel1 = new StarLabel();
381 jStarLabel1.setLocation(new java.awt.Point(2, 12));
382 jLabelC_Name = new JLabel();
383 jLabelC_Name.setText("PCD C Name");
384 jLabelC_Name.setBounds(new java.awt.Rectangle(12, 12, 168, 20));
385
386 jStarLabel2 = new StarLabel();
387 jStarLabel2.setLocation(new java.awt.Point(2, 37));
388 jLabelItemType = new JLabel();
389 jLabelItemType.setText("PCD Item Type");
390 jLabelItemType.setBounds(new java.awt.Rectangle(12, 37, 168, 20));
391
392 jLabelDefaultValue = new JLabel();
393 jLabelDefaultValue.setText("Default Value");
394 jLabelDefaultValue.setBounds(new java.awt.Rectangle(12, 62, 168, 20));
395
396 jStarLabel3 = new StarLabel();
397 jStarLabel3.setLocation(new java.awt.Point(2, 112));
398 jLabelHelpText = new JLabel();
399 jLabelHelpText.setText("Help Text");
400 jLabelHelpText.setBounds(new java.awt.Rectangle(12, 112, 168, 20));
401
402 jLabelFeatureFlag = new JLabel();
403 jLabelFeatureFlag.setText("Feature Flag Expression");
404 jLabelFeatureFlag.setBounds(new java.awt.Rectangle(12, 182, 168, 20));
405 jLabelFeatureFlag.setEnabled(false);
406
407 jLabelTokenSpaceGuid = new JLabel();
408 jLabelTokenSpaceGuid.setText("Token Space C Name");
409 jLabelTokenSpaceGuid.setVisible(false);
410
411 jLabelArch = new JLabel();
412 jLabelArch.setText("Supported Architectures");
413 jLabelArch.setBounds(new java.awt.Rectangle(12, 157, 168, 20));
414 jArchCheckBox = new ArchCheckBox();
415 jArchCheckBox.setPreferredSize(new java.awt.Dimension(320, 20));
416 jArchCheckBox.setBounds(new java.awt.Rectangle(168, 157, 320, 20));
417
418 // Hidden field
419 jLabelTokenSpaceGuid.setBounds(new java.awt.Rectangle(12, 62, 140, 20));
420
421 jContentPane = new JPanel();
422 jContentPane.setLayout(null);
423 jContentPane.setPreferredSize(new java.awt.Dimension(485, 235));
424
425 jContentPane.add(jStarLabel1, null);
426 jContentPane.add(jLabelC_Name, null);
427 jContentPane.add(getJComboBoxCName(), null);
428 jContentPane.add(jStarLabel2, null);
429 jContentPane.add(jLabelItemType, null);
430 jContentPane.add(getJComboBoxItemType(), null);
431 jContentPane.add(jLabelDefaultValue, null);
432 jContentPane.add(getJTextFieldDefaultValue(), null);
433 jContentPane.add(jStarLabel3, null);
434 jContentPane.add(jLabelHelpText, null);
435 jContentPane.add(getJScrollPaneHelpText(), null);
436 jContentPane.add(jLabelFeatureFlag, null);
437 jContentPane.add(getJTextFieldFeatureFlag(), null);
438 jContentPane.add(jLabelArch, null);
439 jContentPane.add(jArchCheckBox, null);
440 // Hidden
441 jContentPane.add(getJTextFieldTokenSpaceGuid(), null);
442 jContentPane.add(jLabelTokenSpaceGuid, null);
443 jContentPane.add(getJButtonOk(), null);
444 jContentPane.add(getJButtonCancel(), null);
445 jContentPane.add(jLabelUsage, null);
446 jContentPane.add(getJComboBoxUsage(), null);
447 }
448 return jContentPane;
449 }
450
451 /**
452 * This method initializes Usage type, Item type and Datum type
453 *
454 */
455 private void initFrame() {
456 Tools.generateComboBoxByVector(jComboBoxUsage, ed.getVPcdUsage());
457 }
458
459 /*
460 * (non-Javadoc)
461 *
462 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
463 *
464 * Override actionPerformed to listen all actions
465 *
466 */
467 public void actionPerformed(ActionEvent arg0) {
468 if (arg0.getSource() == jButtonOk) {
469 if (checkAdd()) {
470 getCurrentPcdCoded();
471 this.returnType = DataType.RETURN_TYPE_OK;
472 this.setVisible(false);
473 }
474 }
475
476 if (arg0.getSource() == jButtonCancel) {
477 this.returnType = DataType.RETURN_TYPE_CANCEL;
478 this.setVisible(false);
479 }
480 }
481
482 /**
483 * Data validation for all fields
484 *
485 * @retval true - All datas are valid
486 * @retval false - At least one data is invalid
487 *
488 */
489 public boolean checkAdd() {
490 //
491 // Check if all fields have correct data types
492 //
493
494 //
495 // Check C_Name
496 //
497 if (this.jComboBoxCName.getSelectedItem() == null) {
498 Log.wrn("Update Pcd", "Please select one Pcd Name");
499 return false;
500 }
501
502 if (!isEmpty(this.jComboBoxCName.getSelectedItem().toString())) {
503 if (!DataValidation.isC_NameType(this.jComboBoxCName.getSelectedItem().toString())) {
504 Log.wrn("Update PcdCoded", "Incorrect data type for C Name");
505 return false;
506 }
507 }
508
509 //
510 // Check TokenSpaceGuid
511 //
512 if (!isEmpty(this.jTextFieldTokenSpaceGuid.getText())) {
513 if (!DataValidation.isC_NameType(this.jTextFieldTokenSpaceGuid.getText())) {
514 Log.wrn("Update PcdCoded",
515 "Incorrect data type for the selected pcd entry, please check the datatype specified in the spd file");
516 return false;
517 }
518 }
519
520 //
521 // Check DefaultValue
522 //
523 if (!isEmpty(this.jTextFieldDefaultValue.getText())) {
524 if (!DataValidation.isDefaultValueType(this.jTextFieldDefaultValue.getText())) {
525 Log.wrn("Update PcdCoded", "Incorrect data type for Default Value");
526 return false;
527 }
528 }
529
530 //
531 // Check HelpText
532 //
533 if (isEmpty(this.jTextAreaHelpText.getText())) {
534 Log.wrn("Update PcdCoded", "Help Text should not be empty");
535 return false;
536 }
537
538 //
539 // Check FeatureFlag
540 //
541 if (!isEmpty(this.jTextFieldFeatureFlag.getText())) {
542 if (!DataValidation.isFeatureFlag(this.jTextFieldFeatureFlag.getText())) {
543 Log.wrn("Update PcdCoded", "Incorrect data type for Feature Flag");
544 return false;
545 }
546 }
547
548 return true;
549 }
550
551 private PcdCodedIdentification getCurrentPcdCoded() {
552 String arg0 = this.jComboBoxCName.getSelectedItem().toString();
553 String arg1 = this.jTextFieldTokenSpaceGuid.getText();
554
555 String arg2 = this.jTextFieldFeatureFlag.getText();
556 Vector<String> arg3 = this.jArchCheckBox.getSelectedItemsVector();
557
558 String arg4 = this.jTextFieldDefaultValue.getText();
559 String arg5 = this.jTextAreaHelpText.getText();
560 String arg6 = this.jComboBoxItemType.getSelectedItem().toString();
561 String arg7 = this.jComboBoxUsage.getSelectedItem().toString();
562 if (arg7.equals(DataType.EMPTY_SELECT_ITEM)) {
563 arg7 = "";
564 }
565
566 id = new PcdCodedIdentification(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
567 return id;
568 }
569
570 public PcdCodedIdentification getId() {
571 return id;
572 }
573
574 public void setId(PcdCodedIdentification id) {
575 this.id = id;
576 }
577
578 /*
579 * (non-Javadoc)
580 *
581 * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
582 *
583 * Reflesh the frame when selected item changed
584 *
585 */
586 public void itemStateChanged(ItemEvent arg0) {
587 int index = this.jComboBoxCName.getSelectedIndex();
588 if (arg0.getSource() == this.jComboBoxCName && arg0.getStateChange() == ItemEvent.SELECTED) {
589 if (pcd.getPcd(index).getGuidCName() == null || isEmpty(pcd.getPcd(index).getGuidCName())
590 || pcd.getPcd(index).getType() == null || pcd.getPcd(index).getHelp() == null
591 || isEmpty(pcd.getPcd(index).getHelp())) {
592 Log.wrn("select pcd entry when editing msa",
593 "The selected value is defined incorrectly.\r\nPlease check it in the spd file");
594 } else {
595 this.jTextFieldTokenSpaceGuid.setText(pcd.getPcd(index).getGuidCName());
596 Tools.generateComboBoxByVector(this.jComboBoxItemType, pcd.getPcd(index).getType());
597 this.jTextAreaHelpText.setText(pcd.getPcd(index).getHelp());
598 this.jTextAreaHelpText.setSelectionStart(0);
599 this.jTextAreaHelpText.setSelectionEnd(0);
600 }
601 }
602 }
603 }