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