9176407277fa9955a2c858ee001c0a29e17e3453
[mirror_edk2.git] / Tools / Source / ModuleEditor / src / org / tianocore / packaging / module / ui / MbdHeader.java
1 /** @file
2
3 This file is used to create, update MbdHeader of a 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
16 package org.tianocore.packaging.module.ui;
17
18 import java.awt.event.ActionEvent;
19
20 import javax.swing.JButton;
21 import javax.swing.JLabel;
22 import javax.swing.JPanel;
23 import javax.swing.JScrollPane;
24 import javax.swing.JTextArea;
25 import javax.swing.JTextField;
26
27 import org.tianocore.BaseNameDocument;
28 import org.tianocore.GuidDocument;
29 import org.tianocore.LicenseDocument;
30 import org.tianocore.MbdHeaderDocument;
31 import org.tianocore.common.DataValidation;
32 import org.tianocore.common.Log;
33 import org.tianocore.common.Tools;
34 import org.tianocore.packaging.common.ui.IInternalFrame;
35 import org.tianocore.packaging.common.ui.StarLabel;
36
37 /**
38 This class is used to create, update MbdHeader of a MBD file
39 It extends IInternalFrame
40
41 @since ModuleEditor 1.0
42
43 **/
44 public class MbdHeader extends IInternalFrame {
45 ///
46 /// Define class Serial Version UID
47 ///
48 private static final long serialVersionUID = -2015726615436197378L;
49
50 //
51 // Define class members
52 //
53 private JPanel jContentPane = null;
54
55 private JLabel jLabelBaseName = null;
56
57 private JTextField jTextFieldBaseName = null;
58
59 private JLabel jLabelGuid = null;
60
61 private JTextField jTextFieldGuid = null;
62
63 private JLabel jLabelVersion = null;
64
65 private JTextField jTextFieldVersion = null;
66
67 private JButton jButtonGenerateGuid = null;
68
69 private JLabel jLabelLicense = null;
70
71 private JTextArea jTextAreaLicense = null;
72
73 private JLabel jLabelCopyright = null;
74
75 private JTextArea jTextAreaCopyright = null;
76
77 private JLabel jLabelDescription = null;
78
79 private JTextArea jTextAreaDescription = null;
80
81 private JButton jButtonOk = null;
82
83 private JButton jButtonCancel = null;
84
85 private JScrollPane jScrollPaneLicense = null;
86
87 private JScrollPane jScrollPaneCopyright = null;
88
89 private JScrollPane jScrollPaneDescription = null;
90
91 private StarLabel jStarLabel1 = null;
92
93 private StarLabel jStarLabel2 = null;
94
95 private StarLabel jStarLabel3 = null;
96
97 private StarLabel jStarLabel4 = null;
98
99 private StarLabel jStarLabel5 = null;
100
101 private StarLabel jStarLabel6 = null;
102
103 private MbdHeaderDocument.MbdHeader mbdHeader = null;
104
105 /**
106 This method initializes jTextFieldBaseName
107
108 @return javax.swing.JTextField jTextFieldBaseName
109
110 **/
111 private JTextField getJTextFieldBaseName() {
112 if (jTextFieldBaseName == null) {
113 jTextFieldBaseName = new JTextField();
114 jTextFieldBaseName.setBounds(new java.awt.Rectangle(160, 10, 320, 20));
115 }
116 return jTextFieldBaseName;
117 }
118
119 /**
120 This method initializes jTextFieldGuid
121
122 @return javax.swing.JTextField jTextFieldGuid
123
124 **/
125 private JTextField getJTextFieldGuid() {
126 if (jTextFieldGuid == null) {
127 jTextFieldGuid = new JTextField();
128 jTextFieldGuid.setBounds(new java.awt.Rectangle(160, 35, 240, 20));
129 }
130 return jTextFieldGuid;
131 }
132
133 /**
134 This method initializes jTextFieldVersion
135
136 @return javax.swing.JTextField jTextFieldVersion
137
138 **/
139 private JTextField getJTextFieldVersion() {
140 if (jTextFieldVersion == null) {
141 jTextFieldVersion = new JTextField();
142 jTextFieldVersion.setBounds(new java.awt.Rectangle(160, 60, 320, 20));
143 }
144 return jTextFieldVersion;
145 }
146
147 /**
148 This method initializes jButtonGenerateGuid
149
150 @return javax.swing.JButton jButtonGenerateGuid
151
152 **/
153 private JButton getJButtonGenerateGuid() {
154 if (jButtonGenerateGuid == null) {
155 jButtonGenerateGuid = new JButton();
156 jButtonGenerateGuid.setBounds(new java.awt.Rectangle(405, 35, 75, 20));
157 jButtonGenerateGuid.setText("GEN");
158 jButtonGenerateGuid.addActionListener(this);
159 }
160 return jButtonGenerateGuid;
161 }
162
163 /**
164 This method initializes jTextAreaLicense
165
166 @return javax.swing.JTextArea jTextAreaLicense
167
168 **/
169 private JTextArea getJTextAreaLicense() {
170 if (jTextAreaLicense == null) {
171 jTextAreaLicense = new JTextArea();
172 jTextAreaLicense.setText("");
173 jTextAreaLicense.setLineWrap(true);
174 }
175 return jTextAreaLicense;
176 }
177
178 /**
179 This method initializes jTextAreaCopyright
180
181 @return javax.swing.JTextArea jTextAreaCopyright
182
183 **/
184 private JTextArea getJTextAreaCopyright() {
185 if (jTextAreaCopyright == null) {
186 jTextAreaCopyright = new JTextArea();
187 jTextAreaCopyright.setLineWrap(true);
188 }
189 return jTextAreaCopyright;
190 }
191
192 /**
193 This method initializes jTextAreaDescription
194
195 @return javax.swing.JTextArea jTextAreaDescription
196
197 **/
198 private JTextArea getJTextAreaDescription() {
199 if (jTextAreaDescription == null) {
200 jTextAreaDescription = new JTextArea();
201 jTextAreaDescription.setLineWrap(true);
202 }
203 return jTextAreaDescription;
204 }
205
206 /**
207 This method initializes jButtonOk
208
209 @return javax.swing.JButton jButtonOk
210
211 **/
212 private JButton getJButtonOk() {
213 if (jButtonOk == null) {
214 jButtonOk = new JButton();
215 jButtonOk.setText("OK");
216 jButtonOk.setBounds(new java.awt.Rectangle(290, 345, 90, 20));
217 jButtonOk.addActionListener(this);
218 }
219 return jButtonOk;
220 }
221
222 /**
223 This method initializes jButtonCancel
224
225 @return javax.swing.JButton jButtonCancel
226
227 **/
228 private JButton getJButtonCancel() {
229 if (jButtonCancel == null) {
230 jButtonCancel = new JButton();
231 jButtonCancel.setText("Cancel");
232 jButtonCancel.setBounds(new java.awt.Rectangle(390, 345, 90, 20));
233 jButtonCancel.addActionListener(this);
234 }
235 return jButtonCancel;
236 }
237
238 /**
239 This method initializes jScrollPaneLicense
240
241 @return javax.swing.JScrollPane jScrollPaneLicense
242
243 **/
244 private JScrollPane getJScrollPaneLicense() {
245 if (jScrollPaneLicense == null) {
246 jScrollPaneLicense = new JScrollPane();
247 jScrollPaneLicense.setBounds(new java.awt.Rectangle(160, 85, 320, 80));
248 jScrollPaneLicense.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
249 jScrollPaneLicense.setViewportView(getJTextAreaLicense());
250 }
251 return jScrollPaneLicense;
252 }
253
254 /**
255 This method initializes jScrollPaneCopyright
256
257 @return javax.swing.JScrollPane jScrollPaneCopyright
258
259 **/
260 private JScrollPane getJScrollPaneCopyright() {
261 if (jScrollPaneCopyright == null) {
262 jScrollPaneCopyright = new JScrollPane();
263 jScrollPaneCopyright.setBounds(new java.awt.Rectangle(160, 170, 320, 80));
264 jScrollPaneCopyright.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
265 jScrollPaneCopyright.setViewportView(getJTextAreaCopyright());
266 }
267 return jScrollPaneCopyright;
268 }
269
270 /**
271 This method initializes jScrollPaneDescription
272
273 @return javax.swing.JScrollPane jScrollPaneDescription
274
275 **/
276 private JScrollPane getJScrollPaneDescription() {
277 if (jScrollPaneDescription == null) {
278 jScrollPaneDescription = new JScrollPane();
279 jScrollPaneDescription.setBounds(new java.awt.Rectangle(160, 255, 320, 80));
280 jScrollPaneDescription.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
281 jScrollPaneDescription.setViewportView(getJTextAreaDescription());
282 }
283 return jScrollPaneDescription;
284 }
285
286 public static void main(String[] args) {
287
288 }
289
290 /**
291 This is the default constructor
292
293 **/
294 public MbdHeader() {
295 super();
296 init();
297 this.setVisible(true);
298 }
299
300 /**
301 This is the override edit constructor
302
303 **/
304 public MbdHeader(MbdHeaderDocument.MbdHeader inMbdHeader) {
305 super();
306 init(inMbdHeader);
307 this.setVisible(true);
308 this.setViewMode(false);
309 }
310
311 /**
312 This method initializes this
313
314 **/
315 private void init() {
316 this.setSize(500, 515);
317 this.setContentPane(getJContentPane());
318 this.setTitle("Module Build Description Header");
319 initFrame();
320 }
321
322 /**
323 This method initializes this
324 Fill values to all fields if these values are not empty
325
326 @param inMbdHeader The input MbdHeaderDocument.MbdHeader
327
328 **/
329 private void init(MbdHeaderDocument.MbdHeader inMbdHeader) {
330 init();
331 setMbdHeader(inMbdHeader);
332 if (inMbdHeader != null) {
333 if (this.mbdHeader.getBaseName() != null) {
334 this.jTextFieldBaseName.setText(this.mbdHeader.getBaseName().getStringValue());
335 }
336 if (this.mbdHeader.getGuid() != null) {
337 this.jTextFieldGuid.setText(this.mbdHeader.getGuid().getStringValue());
338 }
339 if (this.mbdHeader.getVersion() != null) {
340 this.jTextFieldVersion.setText(this.mbdHeader.getVersion());
341 }
342 if (this.mbdHeader.getLicense() != null) {
343 this.jTextAreaLicense.setText(this.mbdHeader.getLicense().getStringValue());
344 }
345 if (this.mbdHeader.getCopyright() != null) {
346 this.jTextAreaCopyright.setText(this.mbdHeader.getCopyright());
347 }
348 if (this.mbdHeader.getDescription() != null) {
349 this.jTextAreaDescription.setText(this.mbdHeader.getDescription());
350 }
351 }
352 }
353
354 /**
355 Disable all components when the mode is view
356
357 @param isView true - The view mode; false - The non-view mode
358
359 **/
360 public void setViewMode(boolean isView) {
361 this.jButtonOk.setVisible(false);
362 this.jButtonCancel.setVisible(false);
363 if (isView) {
364 this.jTextFieldBaseName.setEnabled(!isView);
365 this.jTextFieldGuid.setEnabled(!isView);
366 this.jTextFieldVersion.setEnabled(!isView);
367 this.jTextAreaLicense.setEnabled(!isView);
368 this.jTextAreaCopyright.setEnabled(!isView);
369 this.jTextAreaDescription.setEnabled(!isView);
370 this.jButtonCancel.setEnabled(!isView);
371 this.jButtonGenerateGuid.setEnabled(!isView);
372 this.jButtonOk.setEnabled(!isView);
373 }
374 }
375
376 /**
377 This method initializes jContentPane
378
379 @return javax.swing.JPanel jContentPane
380
381 **/
382 private JPanel getJContentPane() {
383 if (jContentPane == null) {
384 jLabelDescription = new JLabel();
385 jLabelDescription.setText("Description");
386 jLabelDescription.setBounds(new java.awt.Rectangle(15, 255, 140, 20));
387 jLabelCopyright = new JLabel();
388 jLabelCopyright.setText("Copyright");
389 jLabelCopyright.setBounds(new java.awt.Rectangle(15, 170, 140, 20));
390 jLabelLicense = new JLabel();
391 jLabelLicense.setText("License");
392 jLabelLicense.setBounds(new java.awt.Rectangle(15, 85, 140, 20));
393 jLabelVersion = new JLabel();
394 jLabelVersion.setText("Version");
395 jLabelVersion.setBounds(new java.awt.Rectangle(15, 60, 140, 20));
396 jLabelGuid = new JLabel();
397 jLabelGuid.setPreferredSize(new java.awt.Dimension(25, 15));
398 jLabelGuid.setBounds(new java.awt.Rectangle(15, 35, 140, 20));
399 jLabelGuid.setText("Guid");
400 jLabelBaseName = new JLabel();
401 jLabelBaseName.setText("Base Name");
402 jLabelBaseName.setBounds(new java.awt.Rectangle(15, 10, 140, 20));
403 jContentPane = new JPanel();
404 jContentPane.setLayout(null);
405 jContentPane.setLocation(new java.awt.Point(0, 0));
406 jContentPane.setSize(new java.awt.Dimension(500, 524));
407 jContentPane.add(jLabelBaseName, null);
408 jContentPane.add(getJTextFieldBaseName(), null);
409 jContentPane.add(jLabelGuid, null);
410 jContentPane.add(getJTextFieldGuid(), null);
411 jContentPane.add(jLabelVersion, null);
412 jContentPane.add(getJTextFieldVersion(), null);
413 jContentPane.add(getJButtonGenerateGuid(), null);
414 jContentPane.add(jLabelLicense, null);
415 jContentPane.add(jLabelCopyright, null);
416 jContentPane.add(jLabelDescription, null);
417 jContentPane.add(getJButtonOk(), null);
418 jContentPane.add(getJButtonCancel(), null);
419 jContentPane.add(getJScrollPaneLicense(), null);
420 jContentPane.add(getJScrollPaneCopyright(), null);
421 jContentPane.add(getJScrollPaneDescription(), null);
422
423 jStarLabel1 = new StarLabel();
424 jStarLabel1.setLocation(new java.awt.Point(0, 10));
425 jStarLabel2 = new StarLabel();
426 jStarLabel2.setLocation(new java.awt.Point(0, 35));
427 jStarLabel3 = new StarLabel();
428 jStarLabel3.setLocation(new java.awt.Point(0, 60));
429 jStarLabel4 = new StarLabel();
430 jStarLabel4.setLocation(new java.awt.Point(0, 85));
431 jStarLabel5 = new StarLabel();
432 jStarLabel5.setLocation(new java.awt.Point(0, 170));
433 jStarLabel6 = new StarLabel();
434 jStarLabel6.setLocation(new java.awt.Point(0, 255));
435
436 jContentPane.add(jStarLabel1, null);
437 jContentPane.add(jStarLabel2, null);
438 jContentPane.add(jStarLabel3, null);
439 jContentPane.add(jStarLabel4, null);
440 jContentPane.add(jStarLabel5, null);
441 jContentPane.add(jStarLabel6, null);
442 }
443 return jContentPane;
444 }
445
446 /* (non-Javadoc)
447 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
448 *
449 * Override actionPerformed to listen all actions
450 *
451 */
452 public void actionPerformed(ActionEvent arg0) {
453 if (arg0.getSource() == jButtonOk) {
454 this.dispose();
455 this.save();
456 this.setEdited(true);
457 }
458 if (arg0.getSource() == jButtonCancel) {
459 this.dispose();
460 this.setEdited(false);
461 }
462 //
463 // Generate GUID
464 //
465 if (arg0.getSource() == jButtonGenerateGuid) {
466 jTextFieldGuid.setText(Tools.generateUuidString());
467 }
468 }
469
470 /**
471 Data validation for all fields
472
473 @retval true - All datas are valid
474 @retval false - At least one data is invalid
475
476 **/
477 public boolean check() {
478 //
479 // Check if all required fields are not empty
480 //
481 if (isEmpty(this.jTextFieldBaseName.getText())) {
482 Log.err("Base Name couldn't be empty");
483 return false;
484 }
485 if (isEmpty(this.jTextFieldGuid.getText())) {
486 Log.err("Guid couldn't be empty");
487 return false;
488 }
489 if (isEmpty(this.jTextFieldVersion.getText())) {
490 Log.err("Version couldn't be empty");
491 return false;
492 }
493 if (isEmpty(this.jTextAreaLicense.getText())) {
494 Log.err("License couldn't be empty");
495 return false;
496 }
497 if (isEmpty(this.jTextAreaCopyright.getText())) {
498 Log.err("Copyright couldn't be empty");
499 return false;
500 }
501 if (isEmpty(this.jTextAreaDescription.getText())) {
502 Log.err("Description couldn't be empty");
503 return false;
504 }
505
506 //
507 // Check if all fields have correct data types
508 //
509 if (!DataValidation.isBaseName(this.jTextFieldBaseName.getText())) {
510 Log.err("Incorrect data type for Base Name");
511 return false;
512 }
513 if (!DataValidation.isGuid((this.jTextFieldGuid).getText())) {
514 Log.err("Incorrect data type for Guid");
515 return false;
516 }
517 if (!DataValidation.isCopyright(this.jTextAreaCopyright.getText())) {
518 Log.err("Incorrect data type for Copyright");
519 return false;
520 }
521 return true;
522 }
523
524 /**
525 Save all components of Mbd Header
526 if exists mbdHeader, set the value directly
527 if not exists mbdHeader, new an instance first
528
529 **/
530 public void save() {
531 try {
532 if (this.mbdHeader == null) {
533 mbdHeader = MbdHeaderDocument.MbdHeader.Factory.newInstance();
534 }
535 if (this.mbdHeader.getBaseName() != null) {
536 this.mbdHeader.getBaseName().setStringValue(this.jTextFieldBaseName.getText());
537 } else {
538 BaseNameDocument.BaseName mBaseName = BaseNameDocument.BaseName.Factory.newInstance();
539 mBaseName.setStringValue(this.jTextFieldBaseName.getText());
540 this.mbdHeader.setBaseName(mBaseName);
541 }
542
543 if (this.mbdHeader.getGuid() != null) {
544 this.mbdHeader.getGuid().setStringValue(this.jTextFieldGuid.getText());
545 } else {
546 GuidDocument.Guid mGuid = GuidDocument.Guid.Factory.newInstance();
547 mGuid.setStringValue(this.jTextFieldGuid.getText());
548 this.mbdHeader.setGuid(mGuid);
549 }
550
551 this.mbdHeader.setVersion(this.jTextFieldVersion.getText());
552
553 if (this.mbdHeader.getLicense() != null) {
554 this.mbdHeader.getLicense().setStringValue(this.jTextAreaLicense.getText());
555 } else {
556 LicenseDocument.License mLicense = LicenseDocument.License.Factory.newInstance();
557 mLicense.setStringValue(this.jTextAreaLicense.getText());
558 this.mbdHeader.setLicense(mLicense);
559 }
560
561 this.mbdHeader.setCopyright(this.jTextAreaCopyright.getText());
562 this.mbdHeader.setDescription(this.jTextAreaDescription.getText());
563
564 if (this.mbdHeader.getCreated() == null) {
565 this.mbdHeader.setCreated(Tools.getCurrentDateTime());
566 } else {
567 this.mbdHeader.setModified(Tools.getCurrentDateTime());
568 }
569
570 } catch (Exception e) {
571 Log.err("Save Module Buid Description", e.getMessage());
572 }
573 }
574
575 /**
576 This method initializes module type and compontent type
577
578 **/
579 private void initFrame() {
580
581 }
582
583 /**
584 Get MbdHeaderDocument.MbdHeader
585
586 @return MbdHeaderDocument.MbdHeader mbdHeader
587
588 **/
589 public MbdHeaderDocument.MbdHeader getMbdHeader() {
590 return mbdHeader;
591 }
592
593 /**
594 Set MbdHeaderDocument.MbdHeader
595
596 @param mbdHeader The input MbdHeaderDocument.MbdHeader
597
598 **/
599 public void setMbdHeader(MbdHeaderDocument.MbdHeader mbdHeader) {
600 this.mbdHeader = mbdHeader;
601 }
602 }