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