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