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