7f355c1e4d8f870751a305b894fc109884116eed
[mirror_edk2.git] / Tools / Source / ModuleEditor / src / org / tianocore / packaging / module / ui / MbdLibHeader.java
1 /** @file
2
3 The file is used to create, update MbdLibHeader 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 package org.tianocore.packaging.module.ui;
16
17 import java.awt.event.ActionEvent;
18
19 import javax.swing.JButton;
20 import javax.swing.JLabel;
21 import javax.swing.JPanel;
22 import javax.swing.JScrollPane;
23 import javax.swing.JTextArea;
24 import javax.swing.JTextField;
25
26 import org.tianocore.BaseNameDocument;
27 import org.tianocore.GuidDocument;
28 import org.tianocore.LicenseDocument;
29 import org.tianocore.MbdLibHeaderDocument;
30 import org.tianocore.common.DataValidation;
31 import org.tianocore.common.Log;
32 import org.tianocore.common.Tools;
33 import org.tianocore.packaging.common.ui.IInternalFrame;
34 import org.tianocore.packaging.common.ui.StarLabel;
35
36 /**
37 The class is used to create, update MbdLibHeader of a MBD file
38 It extends IInternalFrame
39
40 @since ModuleEditor 1.0
41
42 **/
43 public class MbdLibHeader extends IInternalFrame {
44
45 ///
46 /// Define class Serial Version UID
47 ///
48 private static final long serialVersionUID = -4881447351274201866L;
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 MbdLibHeaderDocument.MbdLibHeader mbdLibHeader = 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 MbdLibHeader() {
295 super();
296 init();
297 this.setVisible(true);
298 }
299
300 /**
301 This is the override edit constructor
302
303 @param inMbdLibHeader The input MbdLibHeaderDocument.MbdLibHeader
304
305 **/
306 public MbdLibHeader(MbdLibHeaderDocument.MbdLibHeader inMbdLibHeader) {
307 super();
308 init(inMbdLibHeader);
309 this.setVisible(true);
310 this.setViewMode(false);
311 }
312
313 /**
314 This method initializes this
315
316 **/
317 private void init() {
318 this.setSize(500, 515);
319 this.setContentPane(getJContentPane());
320 this.setTitle("Library Module Build Description Header");
321 initFrame();
322 }
323
324 /**
325 This method initializes this
326 Fill values to all fields if these values are not empty
327
328 @param inMbdLibHeader The input MbdLibHeaderDocument.MbdLibHeader
329
330 **/
331 private void init(MbdLibHeaderDocument.MbdLibHeader inMbdLibHeader) {
332 init();
333 setMbdLibHeader(inMbdLibHeader);
334 if (inMbdLibHeader != null) {
335 if (this.mbdLibHeader.getBaseName() != null) {
336 this.jTextFieldBaseName.setText(this.mbdLibHeader.getBaseName().getStringValue());
337 }
338 if (this.mbdLibHeader.getGuid() != null) {
339 this.jTextFieldGuid.setText(this.mbdLibHeader.getGuid().getStringValue());
340 }
341 if (this.mbdLibHeader.getVersion() != null) {
342 this.jTextFieldVersion.setText(this.mbdLibHeader.getVersion());
343 }
344 if (this.mbdLibHeader.getLicense() != null) {
345 this.jTextAreaLicense.setText(this.mbdLibHeader.getLicense().getStringValue());
346 }
347 if (this.mbdLibHeader.getCopyright() != null) {
348 this.jTextAreaCopyright.setText(this.mbdLibHeader.getCopyright());
349 }
350 if (this.mbdLibHeader.getDescription() != null) {
351 this.jTextAreaDescription.setText(this.mbdLibHeader.getDescription());
352 }
353 }
354 }
355
356 /**
357 Disable all components when the mode is view
358
359 @param isView true - The view mode; false - The non-view mode
360
361 **/
362 public void setViewMode(boolean isView) {
363 this.jButtonOk.setVisible(false);
364 this.jButtonCancel.setVisible(false);
365 if (isView) {
366 this.jTextFieldBaseName.setEnabled(!isView);
367 this.jTextFieldGuid.setEnabled(!isView);
368 this.jTextFieldVersion.setEnabled(!isView);
369 this.jTextAreaLicense.setEnabled(!isView);
370 this.jTextAreaCopyright.setEnabled(!isView);
371 this.jTextAreaDescription.setEnabled(!isView);
372 this.jButtonCancel.setEnabled(!isView);
373 this.jButtonGenerateGuid.setEnabled(!isView);
374 this.jButtonOk.setEnabled(!isView);
375 }
376 }
377
378 /**
379 This method initializes jContentPane
380
381 @return javax.swing.JPanel jContentPane
382
383 **/
384 private JPanel getJContentPane() {
385 if (jContentPane == null) {
386 jLabelDescription = new JLabel();
387 jLabelDescription.setText("Description");
388 jLabelDescription.setBounds(new java.awt.Rectangle(15, 255, 140, 20));
389 jLabelCopyright = new JLabel();
390 jLabelCopyright.setText("Copyright");
391 jLabelCopyright.setBounds(new java.awt.Rectangle(15, 170, 140, 20));
392 jLabelLicense = new JLabel();
393 jLabelLicense.setText("License");
394 jLabelLicense.setBounds(new java.awt.Rectangle(15, 85, 140, 20));
395 jLabelVersion = new JLabel();
396 jLabelVersion.setText("Version");
397 jLabelVersion.setBounds(new java.awt.Rectangle(15, 60, 140, 20));
398 jLabelGuid = new JLabel();
399 jLabelGuid.setPreferredSize(new java.awt.Dimension(25, 15));
400 jLabelGuid.setBounds(new java.awt.Rectangle(15, 35, 140, 20));
401 jLabelGuid.setText("Guid");
402 jLabelBaseName = new JLabel();
403 jLabelBaseName.setText("Base Name");
404 jLabelBaseName.setBounds(new java.awt.Rectangle(15, 10, 140, 20));
405 jContentPane = new JPanel();
406 jContentPane.setLayout(null);
407 jContentPane.setLocation(new java.awt.Point(0, 0));
408 jContentPane.setSize(new java.awt.Dimension(500, 524));
409 jContentPane.add(jLabelBaseName, null);
410 jContentPane.add(getJTextFieldBaseName(), null);
411 jContentPane.add(jLabelGuid, null);
412 jContentPane.add(getJTextFieldGuid(), null);
413 jContentPane.add(jLabelVersion, null);
414 jContentPane.add(getJTextFieldVersion(), null);
415 jContentPane.add(getJButtonGenerateGuid(), null);
416 jContentPane.add(jLabelLicense, null);
417 jContentPane.add(jLabelCopyright, null);
418 jContentPane.add(jLabelDescription, null);
419 jContentPane.add(getJButtonOk(), null);
420 jContentPane.add(getJButtonCancel(), null);
421 jContentPane.add(getJScrollPaneLicense(), null);
422 jContentPane.add(getJScrollPaneCopyright(), null);
423 jContentPane.add(getJScrollPaneDescription(), null);
424
425 jStarLabel1 = new StarLabel();
426 jStarLabel1.setLocation(new java.awt.Point(0, 10));
427 jStarLabel2 = new StarLabel();
428 jStarLabel2.setLocation(new java.awt.Point(0, 35));
429 jStarLabel3 = new StarLabel();
430 jStarLabel3.setLocation(new java.awt.Point(0, 60));
431 jStarLabel4 = new StarLabel();
432 jStarLabel4.setLocation(new java.awt.Point(0, 85));
433 jStarLabel5 = new StarLabel();
434 jStarLabel5.setLocation(new java.awt.Point(0, 170));
435 jStarLabel6 = new StarLabel();
436 jStarLabel6.setLocation(new java.awt.Point(0, 255));
437
438 jContentPane.add(jStarLabel1, null);
439 jContentPane.add(jStarLabel2, null);
440 jContentPane.add(jStarLabel3, null);
441 jContentPane.add(jStarLabel4, null);
442 jContentPane.add(jStarLabel5, null);
443 jContentPane.add(jStarLabel6, null);
444 }
445 return jContentPane;
446 }
447
448 /* (non-Javadoc)
449 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
450 *
451 * Override actionPerformed to listen all actions
452 *
453 */
454 public void actionPerformed(ActionEvent arg0) {
455 if (arg0.getSource() == jButtonOk) {
456 this.dispose();
457 this.save();
458 this.setEdited(true);
459 }
460 if (arg0.getSource() == jButtonCancel) {
461 this.dispose();
462 this.setEdited(false);
463 }
464 if (arg0.getSource() == jButtonGenerateGuid) {
465 jTextFieldGuid.setText(Tools.generateUuidString());
466 }
467 }
468
469 /**
470 Data validation for all fields
471
472 @retval true - All datas are valid
473 @retval false - At least one data is invalid
474
475 **/
476 public boolean check() {
477 //
478 // Check if all required fields are not empty
479 //
480 if (isEmpty(this.jTextFieldBaseName.getText())) {
481 Log.err("Base Name couldn't be empty");
482 return false;
483 }
484 if (isEmpty(this.jTextFieldGuid.getText())) {
485 Log.err("Guid couldn't be empty");
486 return false;
487 }
488 if (isEmpty(this.jTextFieldVersion.getText())) {
489 Log.err("Version couldn't be empty");
490 return false;
491 }
492 if (isEmpty(this.jTextAreaLicense.getText())) {
493 Log.err("License couldn't be empty");
494 return false;
495 }
496 if (isEmpty(this.jTextAreaCopyright.getText())) {
497 Log.err("Copyright couldn't be empty");
498 return false;
499 }
500 if (isEmpty(this.jTextAreaDescription.getText())) {
501 Log.err("Description couldn't be empty");
502 return false;
503 }
504
505 //
506 // Check if all fields have correct data types
507 //
508 if (!DataValidation.isBaseName(this.jTextFieldBaseName.getText())) {
509 Log.err("Incorrect data type for Base Name");
510 return false;
511 }
512 if (!DataValidation.isGuid((this.jTextFieldGuid).getText())) {
513 Log.err("Incorrect data type for Guid");
514 return false;
515 }
516 if (!DataValidation.isCopyright(this.jTextAreaCopyright.getText())) {
517 Log.err("Incorrect data type for Copyright");
518 return false;
519 }
520 return true;
521 }
522
523 /**
524 Save all components of Mbd Lib Header
525 if exists mbdLibHeader, set the value directly
526 if not exists mbdLibHeader, new an instance first
527
528 **/
529 public void save() {
530 try {
531 if (this.mbdLibHeader == null) {
532 mbdLibHeader = MbdLibHeaderDocument.MbdLibHeader.Factory.newInstance();
533 }
534 if (this.mbdLibHeader.getBaseName() != null) {
535 this.mbdLibHeader.getBaseName().setStringValue(this.jTextFieldBaseName.getText());
536 } else {
537 BaseNameDocument.BaseName mBaseName = BaseNameDocument.BaseName.Factory.newInstance();
538 mBaseName.setStringValue(this.jTextFieldBaseName.getText());
539 this.mbdLibHeader.setBaseName(mBaseName);
540 }
541
542 if (this.mbdLibHeader.getGuid() != null) {
543 this.mbdLibHeader.getGuid().setStringValue(this.jTextFieldGuid.getText());
544 } else {
545 GuidDocument.Guid mGuid = GuidDocument.Guid.Factory.newInstance();
546 mGuid.setStringValue(this.jTextFieldGuid.getText());
547 this.mbdLibHeader.setGuid(mGuid);
548 }
549
550 this.mbdLibHeader.setVersion(this.jTextFieldVersion.getText());
551
552 if (this.mbdLibHeader.getLicense() != null) {
553 this.mbdLibHeader.getLicense().setStringValue(this.jTextAreaLicense.getText());
554 } else {
555 LicenseDocument.License mLicense = LicenseDocument.License.Factory.newInstance();
556 mLicense.setStringValue(this.jTextAreaLicense.getText());
557 this.mbdLibHeader.setLicense(mLicense);
558 }
559
560 this.mbdLibHeader.setCopyright(this.jTextAreaCopyright.getText());
561 this.mbdLibHeader.setDescription(this.jTextAreaDescription.getText());
562
563 if (this.mbdLibHeader.getCreated() == null) {
564 this.mbdLibHeader.setCreated(Tools.getCurrentDateTime());
565 } else {
566 this.mbdLibHeader.setModified(Tools.getCurrentDateTime());
567 }
568 } catch (Exception e) {
569 Log.err("Save Module Buid Description", e.getMessage());
570 }
571 }
572
573 /**
574 This method initializes module type and compontent type
575
576 **/
577 private void initFrame() {
578 }
579
580 /**
581 Get MbdLibHeaderDocument.MbdLibHeader
582
583 @return MbdLibHeaderDocument.MbdLibHeader
584
585 **/
586 public MbdLibHeaderDocument.MbdLibHeader getMbdLibHeader() {
587 return mbdLibHeader;
588 }
589
590 /**
591 Set MbdLibHeaderDocument.MbdLibHeader
592
593 @param mbdLibHeader The input MbdLibHeaderDocument.MbdLibHeader
594
595 **/
596 public void setMbdLibHeader(MbdLibHeaderDocument.MbdLibHeader mbdLibHeader) {
597 this.mbdLibHeader = mbdLibHeader;
598 }
599 }