]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/ModuleEditor/src/org/tianocore/packaging/module/ui/ModulePCDs.java
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@671 6f19259b...
[mirror_edk2.git] / Tools / Source / ModuleEditor / src / org / tianocore / packaging / module / ui / ModulePCDs.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.packaging.module.ui;
16
17 import java.awt.event.ActionEvent;
18
19 import javax.swing.JButton;
20 import javax.swing.JComboBox;
21 import javax.swing.JLabel;
22 import javax.swing.JPanel;
23 import javax.swing.JTextField;
24
25 import org.tianocore.PCDsDocument;
26 import org.tianocore.PcdDataTypes;
27 import org.tianocore.PcdItemTypes;
28 import org.tianocore.PcdUsage;
29 import org.tianocore.common.DataValidation;
30 import org.tianocore.common.Log;
31 import org.tianocore.packaging.common.ui.IInternalFrame;
32 import org.tianocore.packaging.common.ui.StarLabel;
33
34 /**
35 The class is used to create, update PCD of MSA/MBD file
36 It extends IInternalFrame
37
38 @since ModuleEditor 1.0
39
40 **/
41 public class ModulePCDs extends IInternalFrame {
42
43 ///
44 /// Define class Serial Version UID
45 ///
46 private static final long serialVersionUID = 2227717658188438696L;
47
48 //
49 //Define class members
50 //
51 private PCDsDocument.PCDs pcds = null;
52
53 private int location = -1;
54
55 private JPanel jContentPane = null;
56
57 private JLabel jLabelItemType = null;
58
59 private JLabel jLabelC_Name = null;
60
61 private JComboBox jComboBoxItemType = null;
62
63 private JTextField jTextFieldC_Name = null;
64
65 private JLabel jLabelToken = null;
66
67 private JTextField jTextFieldToken = null;
68
69 private JLabel jLabelDefaultValue = null;
70
71 private JTextField jTextFieldDefaultValue = null;
72
73 private JLabel jLabelUsage = null;
74
75 private JComboBox jComboBoxUsage = null;
76
77 private JButton jButtonOk = null;
78
79 private JButton jButtonCancel = null;
80
81 private JLabel jLabelDatumType = null;
82
83 private JComboBox jComboBoxDatumType = null;
84
85 private StarLabel jStarLabel1 = null;
86
87 private StarLabel jStarLabel2 = null;
88
89 private StarLabel jStarLabel3 = null;
90
91 private StarLabel jStarLabel4 = null;
92
93 /**
94 This method initializes jComboBoxItemType
95
96 @return javax.swing.JComboBox jComboBoxItemType
97
98 **/
99 private JComboBox getJComboBoxItemType() {
100 if (jComboBoxItemType == null) {
101 jComboBoxItemType = new JComboBox();
102 jComboBoxItemType.setBounds(new java.awt.Rectangle(160, 110, 320, 20));
103 }
104 return jComboBoxItemType;
105 }
106
107 /**
108 This method initializes jTextFieldC_Name
109
110 @return javax.swing.JTextField jTextFieldC_Name
111
112 **/
113 private JTextField getJTextFieldC_Name() {
114 if (jTextFieldC_Name == null) {
115 jTextFieldC_Name = new JTextField();
116 jTextFieldC_Name.setBounds(new java.awt.Rectangle(160, 10, 320, 20));
117 }
118 return jTextFieldC_Name;
119 }
120
121 /**
122 This method initializes jTextFieldToken
123
124 @return javax.swing.JTextField jTextFieldToken
125
126 **/
127 private JTextField getJTextFieldToken() {
128 if (jTextFieldToken == null) {
129 jTextFieldToken = new JTextField();
130 jTextFieldToken.setBounds(new java.awt.Rectangle(160, 35, 320, 20));
131 }
132 return jTextFieldToken;
133 }
134
135 /**
136 This method initializes jTextFieldDefaultValue
137
138 @return javax.swing.JTextField jTextFieldDefaultValue
139
140 **/
141 private JTextField getJTextFieldDefaultValue() {
142 if (jTextFieldDefaultValue == null) {
143 jTextFieldDefaultValue = new JTextField();
144 jTextFieldDefaultValue.setBounds(new java.awt.Rectangle(160, 85, 320, 20));
145 }
146 return jTextFieldDefaultValue;
147 }
148
149 /**
150 This method initializes jComboBoxUsage
151
152 @return javax.swing.JComboBox jComboBoxUsage
153
154 **/
155 private JComboBox getJComboBoxUsage() {
156 if (jComboBoxUsage == null) {
157 jComboBoxUsage = new JComboBox();
158 jComboBoxUsage.setBounds(new java.awt.Rectangle(160, 135, 320, 20));
159 }
160 return jComboBoxUsage;
161 }
162
163 /**
164 This method initializes jButtonOk
165
166 @return javax.swing.JButton jButtonOk
167
168 **/
169 private JButton getJButtonOk() {
170 if (jButtonOk == null) {
171 jButtonOk = new JButton();
172 jButtonOk.setText("OK");
173 jButtonOk.setBounds(new java.awt.Rectangle(280, 290, 90, 20));
174 jButtonOk.addActionListener(this);
175 }
176 return jButtonOk;
177 }
178
179 /**
180 This method initializes jButtonCancel
181
182 @return javax.swing.JButton jButtonCancel
183
184 **/
185 private JButton getJButtonCancel() {
186 if (jButtonCancel == null) {
187 jButtonCancel = new JButton();
188 jButtonCancel.setText("Cancel");
189 jButtonCancel.setBounds(new java.awt.Rectangle(390, 290, 90, 20));
190 jButtonCancel.addActionListener(this);
191 }
192 return jButtonCancel;
193 }
194
195 /**
196 This method initializes jTextFieldDatumType
197
198 @return javax.swing.JTextField jComboBoxDatumType
199
200 **/
201 private JComboBox getJComboBoxDatumType() {
202 if (jComboBoxDatumType == null) {
203 jComboBoxDatumType = new JComboBox();
204 jComboBoxDatumType.setBounds(new java.awt.Rectangle(160, 60, 320, 20));
205 }
206 return jComboBoxDatumType;
207 }
208
209 public static void main(String[] args) {
210
211 }
212
213 /**
214 This is the default constructor
215
216 **/
217 public ModulePCDs() {
218 super();
219 init();
220 this.setVisible(true);
221 }
222
223 /**
224 This is the override edit constructor
225
226 @param inPcds The input data of PCDsDocument.PCDs
227
228 **/
229 public ModulePCDs(PCDsDocument.PCDs inPcds) {
230 super();
231 init(inPcds);
232 this.setVisible(true);
233 }
234
235 /**
236 This is the override edit constructor
237
238 @param inPcds The input data of PCDsDocument.PCDs
239 @param type The input data of node type
240 @param index The input data of node index
241
242 **/
243 public ModulePCDs(PCDsDocument.PCDs inPcds, int type, int index) {
244 super();
245 init(inPcds, type, index);
246 this.setVisible(true);
247 }
248
249 /**
250 This method initializes this
251
252 @param inPcds The input data of PCDsDocument.PCDs
253
254 **/
255 private void init(PCDsDocument.PCDs inPcds) {
256 init();
257 this.setPcds(inPcds);
258 }
259
260 /**
261 This method initializes this
262 Fill values to all fields if these values are not empty
263
264 @param inPcds The input data of PCDsDocument.PCDs
265 @param type The input data of node type
266 @param index The input data of node index
267
268 **/
269 private void init(PCDsDocument.PCDs inPcds, int type, int index) {
270 init(inPcds);
271 this.location = index;
272 if (this.pcds.getPcdDataList().size() > 0) {
273 if (this.pcds.getPcdDataArray(index).getCName() != null) {
274 this.jTextFieldC_Name.setText(this.pcds.getPcdDataArray(index).getCName());
275 }
276 if (this.pcds.getPcdDataArray(index).getToken() != null) {
277 this.jTextFieldToken.setText(this.pcds.getPcdDataArray(index).getToken());
278 }
279 if (this.pcds.getPcdDataArray(index).getDatumType() != null) {
280 this.jComboBoxDatumType.setSelectedItem(this.pcds.getPcdDataArray(index).getDatumType().toString());
281 }
282 if (this.pcds.getPcdDataArray(index).getDefaultValue() != null) {
283 this.jTextFieldDefaultValue.setText(this.pcds.getPcdDataArray(index).getDefaultValue());
284 }
285 if (this.pcds.getPcdDataArray(index).getPcdUsage() != null) {
286 this.jComboBoxUsage.setSelectedItem(this.pcds.getPcdDataArray(index).getPcdUsage().toString());
287 }
288 if (this.pcds.getPcdDataArray(index).getItemType() != null) {
289 this.jComboBoxItemType.setSelectedItem(this.pcds.getPcdDataArray(index).getItemType().toString());
290 }
291 }
292 }
293
294 /**
295 This method initializes this
296
297 **/
298 private void init() {
299 this.setSize(500, 515);
300 this.setContentPane(getJContentPane());
301 this.setTitle("PCDs");
302 initFrame();
303 this.setViewMode(false);
304 }
305
306 /**
307 Disable all components when the mode is view
308
309 @param isView true - The view mode; false - The non-view mode
310
311 **/
312 public void setViewMode(boolean isView) {
313 this.jButtonOk.setVisible(false);
314 this.jButtonCancel.setVisible(false);
315 if (isView) {
316 this.jTextFieldC_Name.setEnabled(!isView);
317 this.jTextFieldToken.setEnabled(!isView);
318 this.jComboBoxDatumType.setEnabled(!isView);
319 this.jTextFieldDefaultValue.setEnabled(!isView);
320 this.jComboBoxUsage.setEnabled(!isView);
321 this.jComboBoxItemType.setEnabled(!isView);
322 }
323 }
324
325 /**
326 This method initializes jContentPane
327
328 @return javax.swing.JPanel jContentPane
329
330 **/
331 private JPanel getJContentPane() {
332 if (jContentPane == null) {
333 jLabelDatumType = new JLabel();
334 jLabelDatumType.setBounds(new java.awt.Rectangle(15, 60, 140, 20));
335 jLabelDatumType.setText("Datum Type");
336 jLabelC_Name = new JLabel();
337 jLabelC_Name.setText("C_Name");
338 jLabelC_Name.setBounds(new java.awt.Rectangle(15, 10, 140, 20));
339 jLabelUsage = new JLabel();
340 jLabelUsage.setText("Usage");
341 jLabelUsage.setBounds(new java.awt.Rectangle(15, 135, 140, 20));
342 jLabelDefaultValue = new JLabel();
343 jLabelDefaultValue.setText("Default Value");
344 jLabelDefaultValue.setBounds(new java.awt.Rectangle(15, 85, 140, 20));
345 jLabelToken = new JLabel();
346 jLabelToken.setText("Token");
347 jLabelToken.setBounds(new java.awt.Rectangle(15, 35, 140, 20));
348 jLabelItemType = new JLabel();
349 jLabelItemType.setText("Item Type");
350 jLabelItemType.setBounds(new java.awt.Rectangle(15, 110, 140, 20));
351 jContentPane = new JPanel();
352 jContentPane.setLayout(null);
353 jContentPane.setSize(new java.awt.Dimension(480,336));
354 jContentPane.add(jLabelItemType, null);
355 jContentPane.add(jLabelC_Name, null);
356 jContentPane.add(getJTextFieldC_Name(), null);
357 jContentPane.add(jLabelToken, null);
358 jContentPane.add(getJTextFieldToken(), null);
359 jContentPane.add(jLabelDefaultValue, null);
360 jContentPane.add(getJTextFieldDefaultValue(), null);
361 jContentPane.add(jLabelUsage, null);
362 jContentPane.add(getJComboBoxUsage(), null);
363 jContentPane.add(getJButtonOk(), null);
364 jContentPane.add(getJButtonCancel(), null);
365 jContentPane.add(getJComboBoxItemType(), null);
366 jContentPane.add(jLabelDatumType, null);
367 jContentPane.add(getJComboBoxDatumType(), null);
368
369 jStarLabel1 = new StarLabel();
370 jStarLabel1.setLocation(new java.awt.Point(0, 10));
371 jStarLabel2 = new StarLabel();
372 jStarLabel2.setLocation(new java.awt.Point(0, 35));
373 jStarLabel3 = new StarLabel();
374 jStarLabel3.setLocation(new java.awt.Point(0, 60));
375 jStarLabel4 = new StarLabel();
376 jStarLabel4.setLocation(new java.awt.Point(0, 110));
377
378 jContentPane.add(jStarLabel1, null);
379 jContentPane.add(jStarLabel2, null);
380 jContentPane.add(jStarLabel3, null);
381 jContentPane.add(jStarLabel4, null);
382 }
383 return jContentPane;
384 }
385
386 /**
387 This method initializes Usage type, Item type and Datum type
388
389 **/
390 private void initFrame() {
391 jComboBoxUsage.addItem("ALWAYS_CONSUMED");
392 jComboBoxUsage.addItem("SOMETIMES_CONSUMED");
393 jComboBoxUsage.addItem("ALWAYS_PRODUCED");
394 jComboBoxUsage.addItem("SOMETIMES_PRODUCED");
395 jComboBoxUsage.addItem("DEFAULT");
396
397 jComboBoxItemType.addItem("FEATURE_FLAG");
398 jComboBoxItemType.addItem("FIXED_AT_BUILD");
399 jComboBoxItemType.addItem("PATCHABLE_IN_MODULE");
400 jComboBoxItemType.addItem("DYNAMIC");
401 jComboBoxItemType.addItem("DYNAMIC_EX");
402
403 jComboBoxDatumType.addItem("UINT8");
404 jComboBoxDatumType.addItem("UINT16");
405 jComboBoxDatumType.addItem("UINT32");
406 jComboBoxDatumType.addItem("UINT64");
407 jComboBoxDatumType.addItem("VOID*");
408 jComboBoxDatumType.addItem("BOOLEAN");
409 }
410
411 /* (non-Javadoc)
412 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
413 *
414 * Override actionPerformed to listen all actions
415 *
416 */
417 public void actionPerformed(ActionEvent arg0) {
418 if (arg0.getSource() == jButtonOk) {
419 this.setEdited(true);
420 this.save();
421 this.dispose();
422 }
423 if (arg0.getSource() == jButtonCancel) {
424 this.dispose();
425 }
426 }
427
428 /**
429 Get PCDsDocument.PCDs
430
431 @return PCDsDocument.PCDs
432
433 **/
434 public PCDsDocument.PCDs getPcds() {
435 return pcds;
436 }
437
438 /**
439 Set PCDsDocument.PCDs
440
441 @param pcds The input data of PCDsDocument.PCDs
442
443 **/
444 public void setPcds(PCDsDocument.PCDs pcds) {
445 this.pcds = pcds;
446 }
447
448 /**
449 Data validation for all fields
450
451 @retval true - All datas are valid
452 @retval false - At least one data is invalid
453
454 **/
455 public boolean check() {
456 //
457 // Check if all required fields are not empty
458 //
459 if (isEmpty(this.jTextFieldC_Name.getText())) {
460 Log.err("C_Name couldn't be empty");
461 return false;
462 }
463 if (isEmpty(this.jTextFieldToken.getText())) {
464 Log.err("Token couldn't be empty");
465 return false;
466 }
467
468 //
469 // Check if all fields have correct data types
470 //
471 if (!isEmpty(this.jTextFieldC_Name.getText()) && !DataValidation.isCName(this.jTextFieldC_Name.getText())) {
472 Log.err("Incorrect data type for C_Name");
473 return false;
474 }
475 if (!isEmpty(this.jTextFieldToken.getText()) && !DataValidation.isToken(this.jTextFieldToken.getText())) {
476 Log.err("Incorrect data type for Token");
477 return false;
478 }
479
480 return true;
481 }
482
483 /**
484 Save all components of PCDs
485 if exists pcds, set the value directly
486 if not exists pcds, new an instance first
487
488 **/
489 public void save() {
490 try {
491 if (this.pcds == null) {
492 pcds = PCDsDocument.PCDs.Factory.newInstance();
493 }
494 PCDsDocument.PCDs.PcdData pcdData = PCDsDocument.PCDs.PcdData.Factory.newInstance();
495 if (!isEmpty(this.jTextFieldC_Name.getText())) {
496 pcdData.setCName(this.jTextFieldC_Name.getText());
497 }
498 if (!isEmpty(this.jTextFieldToken.getText())) {
499 pcdData.setToken(this.jTextFieldToken.getText());
500 }
501 pcdData.setDatumType(PcdDataTypes.Enum.forString(this.jComboBoxDatumType.getSelectedItem().toString()));
502 if (!isEmpty(this.jTextFieldDefaultValue.getText())) {
503 pcdData.setDefaultValue(this.jTextFieldDefaultValue.getText());
504 }
505 pcdData.setItemType(PcdItemTypes.Enum.forString(this.jComboBoxItemType.getSelectedItem().toString()));
506 pcdData.setPcdUsage(PcdUsage.Enum.forString(this.jComboBoxUsage.getSelectedItem().toString()));
507
508
509 if (location > -1) {
510 pcds.setPcdDataArray(location, pcdData);
511 } else {
512 pcds.addNewPcdData();
513 pcds.setPcdDataArray(pcds.getPcdDataList().size() - 1, pcdData);
514 }
515 } catch (Exception e) {
516 Log.err("Update Hobs", e.getMessage());
517 }
518 }
519 }