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