]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/ModuleEditor/src/org/tianocore/packaging/module/ui/MbdLibraries.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 / MbdLibraries.java
1 /** @file
2
3 The file is used to create, update MbdLibraries 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 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.JCheckBox;
24 import javax.swing.JComboBox;
25 import javax.swing.JLabel;
26 import javax.swing.JPanel;
27 import javax.swing.JTextField;
28
29 import org.tianocore.LibrariesDocument;
30 import org.tianocore.LibraryUsage;
31 import org.tianocore.SupportedArchitectures;
32 import org.tianocore.common.DataValidation;
33 import org.tianocore.common.Log;
34 import org.tianocore.common.Tools;
35 import org.tianocore.packaging.common.ui.IDefaultMutableTreeNode;
36 import org.tianocore.packaging.common.ui.IInternalFrame;
37 import org.tianocore.packaging.common.ui.StarLabel;
38
39 /**
40 The class is used to create, update MbdLibraries of a MBD file
41 It extends IInternalFrame
42
43 @since ModuleEditor 1.0
44
45 **/
46 public class MbdLibraries extends IInternalFrame implements ItemListener {
47
48 ///
49 /// Define class Serial Version UID
50 ///
51 private static final long serialVersionUID = 8042998899875417568L;
52
53 //
54 //Define class members
55 //
56 private LibrariesDocument.Libraries libraries = null;
57
58 private int location = -1;
59
60 private int intSelectedItemId = 0;
61
62 //
63 //1 - Add; 2 - Update
64 //
65 private int operation = -1;
66
67 private Vector<String> vName = new Vector<String>();
68
69 private Vector<String> vGuid = new Vector<String>();
70
71 private Vector<String> vLibraryClass = new Vector<String>();
72
73 private Vector<String> vClassGuid = new Vector<String>();
74
75 private Vector<String> vVersion = new Vector<String>();
76
77 private Vector<String> vUsage = new Vector<String>();
78
79 private Vector<String> vOverrideID = new Vector<String>();
80
81 private JPanel jContentPane = null;
82
83 private JButton jButtonOk = null;
84
85 private JButton jButtonCancel = null;
86
87 private JLabel jLabelName = null;
88
89 private JTextField jTextFieldFileName = null;
90
91 private JLabel jLabelGuid = null;
92
93 private JTextField jTextFieldGuid = null;
94
95 private JButton jButtonGenerateGuid = null;
96
97 private JComboBox jComboBoxArch = null;
98
99 private JLabel jLabelLibraryClass = null;
100
101 private JTextField jTextFieldLibraryClass = null;
102
103 private JLabel jLabelUsage = null;
104
105 private JLabel jLabelClassGuid = null;
106
107 private JTextField jTextFieldClassGuid = null;
108
109 private JLabel jLabelOverrideID = null;
110
111 private JTextField jTextFieldOverrideID = null;
112
113 private JComboBox jComboBoxUsage = null;
114
115 private StarLabel jStarLabel1 = null;
116
117 private JComboBox jComboBoxFileList = null;
118
119 private JButton jButtonAdd = null;
120
121 private JButton jButtonRemove = null;
122
123 private JButton jButtonUpdate = null;
124
125 private JCheckBox jCheckBoxArch = null;
126
127 private JButton jButtonGenerateGuid2 = null;
128
129 private JLabel jLabelVersion = null;
130
131 private JTextField jTextFieldVersion = null;
132
133 /**
134 This method initializes jButtonOk
135
136 @return javax.swing.JButton jButtonOk
137
138 **/
139 private JButton getJButton() {
140 if (jButtonOk == null) {
141 jButtonOk = new JButton();
142 jButtonOk.setText("OK");
143 jButtonOk.setBounds(new java.awt.Rectangle(290, 240, 90, 20));
144 jButtonOk.addActionListener(this);
145 }
146 return jButtonOk;
147 }
148
149 /**
150 *This method initializes jButtonCancel
151
152 @return javax.swing.JButton jButtonCancel
153
154 **/
155 private JButton getJButtonCancel() {
156 if (jButtonCancel == null) {
157 jButtonCancel = new JButton();
158 jButtonCancel.setText("Cancel");
159 jButtonCancel.setBounds(new java.awt.Rectangle(390, 240, 90, 20));
160 jButtonCancel.setPreferredSize(new java.awt.Dimension(90, 20));
161 jButtonCancel.addActionListener(this);
162 }
163 return jButtonCancel;
164 }
165
166 /**
167 This method initializes jTextFieldFileName
168
169 @return javax.swing.JTextField jTextFieldFileName
170
171 **/
172 private JTextField getJTextFieldSourceFilesDirectory() {
173 if (jTextFieldFileName == null) {
174 jTextFieldFileName = new JTextField();
175 jTextFieldFileName.setBounds(new java.awt.Rectangle(160, 10, 320, 20));
176 }
177 return jTextFieldFileName;
178 }
179
180 /**
181 This method initializes jTextFieldGuid
182
183 @return javax.swing.JTextField jTextFieldGuid
184
185 **/
186 private JTextField getJTextFieldGuid() {
187 if (jTextFieldGuid == null) {
188 jTextFieldGuid = new JTextField();
189 jTextFieldGuid.setBounds(new java.awt.Rectangle(160, 35, 250, 20));
190 }
191 return jTextFieldGuid;
192 }
193
194 /**
195 This method initializes jButtonGenerateGuid
196
197 @return javax.swing.JButton jButtonGenerateGuid
198
199 **/
200 private JButton getJButtonGenerateGuid() {
201 if (jButtonGenerateGuid == null) {
202 jButtonGenerateGuid = new JButton();
203 jButtonGenerateGuid.setBounds(new java.awt.Rectangle(415, 35, 65, 20));
204 jButtonGenerateGuid.setText("GEN");
205 jButtonGenerateGuid.addActionListener(this);
206 }
207 return jButtonGenerateGuid;
208 }
209
210 /**
211 This method initializes jComboBoxArch
212
213 @return javax.swing.JComboBox jComboBoxArch
214
215 **/
216 private JComboBox getJComboBoxArch() {
217 if (jComboBoxArch == null) {
218 jComboBoxArch = new JComboBox();
219 jComboBoxArch.setBounds(new java.awt.Rectangle(140, 210, 340, 20));
220 jComboBoxArch.setEnabled(false);
221 }
222 return jComboBoxArch;
223 }
224
225 /**
226 This method initializes jTextFieldLibraryClass
227
228 @return javax.swing.JTextField jTextFieldLibraryClass
229
230 **/
231 private JTextField getJTextFieldLibraryClass() {
232 if (jTextFieldLibraryClass == null) {
233 jTextFieldLibraryClass = new JTextField();
234 jTextFieldLibraryClass.setBounds(new java.awt.Rectangle(160, 60, 320, 20));
235 }
236 return jTextFieldLibraryClass;
237 }
238
239 /**
240 This method initializes jTextFieldClassGuid
241
242 @return javax.swing.JTextField jTextFieldClassGuid
243
244 **/
245 private JTextField getJTextFieldClassGuid() {
246 if (jTextFieldClassGuid == null) {
247 jTextFieldClassGuid = new JTextField();
248 jTextFieldClassGuid.setBounds(new java.awt.Rectangle(160, 85, 250, 20));
249 }
250 return jTextFieldClassGuid;
251 }
252
253 /**
254 This method initializes jTextFieldOverrideID
255
256 @return javax.swing.JTextField jTextFieldOverrideID
257
258 **/
259 private JTextField getJTextFieldOverrideID() {
260 if (jTextFieldOverrideID == null) {
261 jTextFieldOverrideID = new JTextField();
262 jTextFieldOverrideID.setBounds(new java.awt.Rectangle(160, 160, 50, 20));
263 }
264 return jTextFieldOverrideID;
265 }
266
267 /**
268 This method initializes jComboBoxUsage
269
270 @return javax.swing.JComboBox jComboBoxUsage
271
272 **/
273 private JComboBox getJComboBoxUsage() {
274 if (jComboBoxUsage == null) {
275 jComboBoxUsage = new JComboBox();
276 jComboBoxUsage.setBounds(new java.awt.Rectangle(160, 135, 320, 20));
277 }
278 return jComboBoxUsage;
279 }
280
281 /**
282 This method initializes jComboBoxFileList
283
284 @return javax.swing.JComboBox jComboBoxFileList
285
286 **/
287 private JComboBox getJComboBoxFileList() {
288 if (jComboBoxFileList == null) {
289 jComboBoxFileList = new JComboBox();
290 jComboBoxFileList.setBounds(new java.awt.Rectangle(15, 185, 210, 20));
291 jComboBoxFileList.addItemListener(this);
292 jComboBoxFileList.addActionListener(this);
293 }
294 return jComboBoxFileList;
295 }
296
297 /**
298 This method initializes jButtonAdd
299
300 @return javax.swing.JButton jButtonAdd
301
302 **/
303 private JButton getJButtonAdd() {
304 if (jButtonAdd == null) {
305 jButtonAdd = new JButton();
306 jButtonAdd.setBounds(new java.awt.Rectangle(230, 185, 80, 20));
307 jButtonAdd.setText("Add");
308 jButtonAdd.addActionListener(this);
309 }
310 return jButtonAdd;
311 }
312
313 /**
314 This method initializes jButtonRemove
315
316 @return javax.swing.JButton jButtonRemove
317
318 **/
319 private JButton getJButtonRemove() {
320 if (jButtonRemove == null) {
321 jButtonRemove = new JButton();
322 jButtonRemove.setBounds(new java.awt.Rectangle(400, 185, 80, 20));
323 jButtonRemove.setText("Remove");
324 jButtonRemove.addActionListener(this);
325 }
326 return jButtonRemove;
327 }
328
329 /**
330 This method initializes jButtonUpdate
331
332 @return javax.swing.JButton jButtonUpdate
333
334 **/
335 private JButton getJButtonUpdate() {
336 if (jButtonUpdate == null) {
337 jButtonUpdate = new JButton();
338 jButtonUpdate.setBounds(new java.awt.Rectangle(315, 185, 80, 20));
339 jButtonUpdate.setText("Update");
340 jButtonUpdate.addActionListener(this);
341 }
342 return jButtonUpdate;
343 }
344
345 /**
346 This method initializes jCheckBoxArch
347
348 @return javax.swing.JCheckBox jCheckBoxArch
349
350 **/
351 private JCheckBox getJCheckBoxArch() {
352 if (jCheckBoxArch == null) {
353 jCheckBoxArch = new JCheckBox();
354 jCheckBoxArch.setBounds(new java.awt.Rectangle(10, 210, 119, 20));
355 jCheckBoxArch.setText("Specific Arch");
356 jCheckBoxArch.addActionListener(this);
357 }
358 return jCheckBoxArch;
359 }
360
361 /**
362 This method initializes jButtonGenerateGuid2
363
364 @return javax.swing.JButton jButtonGenerateGuid2
365
366 **/
367 private JButton getJButtonGenerateGuid2() {
368 if (jButtonGenerateGuid2 == null) {
369 jButtonGenerateGuid2 = new JButton();
370 jButtonGenerateGuid2.setBounds(new java.awt.Rectangle(415, 85, 65, 20));
371 jButtonGenerateGuid2.setText("GEN");
372 jButtonGenerateGuid2.addActionListener(this);
373 }
374 return jButtonGenerateGuid2;
375 }
376
377 /**
378 This method initializes jTextFieldVersion
379
380 @return javax.swing.JTextField jTextFieldVersion
381
382 **/
383 private JTextField getJTextFieldVersion() {
384 if (jTextFieldVersion == null) {
385 jTextFieldVersion = new JTextField();
386 jTextFieldVersion.setBounds(new java.awt.Rectangle(160, 110, 320, 20));
387 }
388 return jTextFieldVersion;
389 }
390
391 public static void main(String[] args) {
392
393 }
394
395 /**
396 This is the default constructor
397
398 **/
399 public MbdLibraries() {
400 super();
401 init();
402 this.setVisible(true);
403 }
404
405 /**
406 This is the override edit constructor
407
408 @param inLibraries The input LibrariesDocument.Libraries
409
410 **/
411 public MbdLibraries(LibrariesDocument.Libraries inLibraries) {
412 super();
413 init(inLibraries);
414 this.setVisible(true);
415 }
416
417 /**
418 This is the override edit constructor
419
420 @param inLibraries The input LibrariesDocument.Libraries
421 @param type The input data of node type
422 @param index The input data of node index
423
424 **/
425 public MbdLibraries(LibrariesDocument.Libraries inLibraries, int type, int index) {
426 super();
427 init(inLibraries);
428 this.setVisible(true);
429 }
430
431 /**
432 This is the override edit constructor
433
434 @param inLibraries The input LibrariesDocument.Libraries
435 @param type The input data of node type
436 @param index The input data of node index
437 @param inOperation The input data of operation type
438
439 **/
440 public MbdLibraries(LibrariesDocument.Libraries inLibraries, int type, int index, int inOperation) {
441 super();
442 init(inLibraries, type, index, inOperation);
443 this.operation = inOperation;
444 this.setVisible(true);
445 }
446
447 /**
448 This method initializes this
449
450 @param inLibraries LibrariesDocument.Libraries
451
452 **/
453 private void init(LibrariesDocument.Libraries inLibraries) {
454 init();
455 this.setLibraries(inLibraries);
456 }
457
458 /**
459 This method initializes this
460 Fill values to all fields if these values are not empty
461
462 @param inLibraries LibrariesDocument.Libraries
463 @param type The input data of node type
464 @param index The input data of node index
465 @param inOperation The input data of operation type
466
467 **/
468 private void init(LibrariesDocument.Libraries inLibraries, int type, int index, int inOperation) {
469 init(inLibraries);
470 this.location = index;
471 this.operation = inOperation;
472
473 if (operation == 2) {
474 this.jCheckBoxArch.setEnabled(false);
475 this.jComboBoxArch.setEnabled(false);
476
477 if (type == IDefaultMutableTreeNode.LIBRARIES_LIBRARY) {
478 if (this.libraries.getLibraryList().size() > 0) {
479 for (int indexI = 0; indexI < this.libraries.getLibraryList().size(); indexI++) {
480 if (this.libraries.getLibraryArray(indexI).getStringValue() != null) {
481 vName.addElement(this.libraries.getLibraryArray(indexI).getStringValue());
482 } else {
483 vName.addElement("");
484 }
485 if (this.libraries.getLibraryArray(indexI).getGuid() != null) {
486 vGuid.addElement(this.libraries.getLibraryArray(indexI).getGuid());
487 } else {
488 vGuid.addElement("");
489 }
490 if (this.libraries.getLibraryArray(indexI).getLibraryClass() != null) {
491 vLibraryClass.addElement(this.libraries.getLibraryArray(indexI).getLibraryClass());
492 } else {
493 vLibraryClass.addElement("");
494 }
495 if (this.libraries.getLibraryArray(indexI).getClassGuid() != null) {
496 vClassGuid.addElement(this.libraries.getLibraryArray(indexI).getClassGuid());
497 } else {
498 vClassGuid.addElement("");
499 }
500 if (this.libraries.getLibraryArray(indexI).getVersion() != null) {
501 vVersion.addElement(this.libraries.getLibraryArray(indexI).getVersion());
502 } else {
503 vVersion.addElement("");
504 }
505 if (this.libraries.getLibraryArray(indexI).getUsage() != null) {
506 vUsage.addElement(this.libraries.getLibraryArray(indexI).getUsage().toString());
507 } else {
508 vUsage.addElement("ALWAYS_CONSUMED");
509 }
510 vOverrideID.addElement(String.valueOf(this.libraries.getLibraryArray(indexI).getOverrideID()));
511 jComboBoxFileList.addItem(this.libraries.getLibraryArray(indexI).getStringValue());
512 }
513 }
514 }
515 if (type == IDefaultMutableTreeNode.LIBRARIES_ARCH_ITEM) {
516 this.jCheckBoxArch.setSelected(true);
517 this.jComboBoxArch.setSelectedItem(this.libraries.getArchArray(index).getArchType().toString());
518 for (int indexI = 0; indexI < this.libraries.getArchArray(index).getLibraryList().size(); indexI++) {
519 if (this.libraries.getArchArray(index).getLibraryArray(indexI).getStringValue() != null) {
520 vName.addElement(this.libraries.getArchArray(index).getLibraryArray(indexI).getStringValue());
521 } else {
522 vName.addElement("");
523 }
524 if (this.libraries.getArchArray(index).getLibraryArray(indexI).getGuid() != null) {
525 vGuid.addElement(this.libraries.getArchArray(index).getLibraryArray(indexI).getGuid());
526 } else {
527 vGuid.addElement("");
528 }
529 if (this.libraries.getArchArray(index).getLibraryArray(indexI).getLibraryClass() != null) {
530 vLibraryClass.addElement(this.libraries.getArchArray(index).getLibraryArray(indexI)
531 .getLibraryClass());
532 } else {
533 vLibraryClass.addElement("");
534 }
535 if (this.libraries.getArchArray(index).getLibraryArray(indexI).getClassGuid() != null) {
536 vClassGuid
537 .addElement(this.libraries.getArchArray(index).getLibraryArray(indexI).getClassGuid());
538 } else {
539 vClassGuid.addElement("");
540 }
541 if (this.libraries.getArchArray(index).getLibraryArray(indexI).getVersion() != null) {
542 vVersion.addElement(this.libraries.getArchArray(index).getLibraryArray(indexI).getVersion());
543 } else {
544 vVersion.addElement("");
545 }
546 if (this.libraries.getArchArray(index).getLibraryArray(indexI).getUsage() != null) {
547 vUsage.addElement(this.libraries.getArchArray(index).getLibraryArray(indexI).getUsage()
548 .toString());
549 } else {
550 vUsage.addElement("");
551 }
552 vOverrideID.addElement(String.valueOf(this.libraries.getArchArray(index).getLibraryArray(indexI).getOverrideID()));
553 jComboBoxFileList.addItem(this.libraries.getArchArray(index).getLibraryArray(indexI)
554 .getStringValue());
555 }
556 }
557 }
558 }
559
560 /**
561 This method initializes this
562
563 **/
564 private void init() {
565 this.setSize(500, 515);
566 this.setName("JFrame");
567 this.setContentPane(getJContentPane());
568 this.setTitle("Source Files");
569 initFrame();
570 this.setViewMode(false);
571 }
572
573 /**
574 Disable all components when the mode is view
575
576 @param isView true - The view mode; false - The non-view mode
577
578 **/
579 public void setViewMode(boolean isView) {
580 this.jButtonOk.setVisible(false);
581 this.jButtonCancel.setVisible(false);
582 if (isView) {
583 this.jTextFieldFileName.setEnabled(!isView);
584 this.jTextFieldGuid.setEnabled(!isView);
585 this.jButtonGenerateGuid.setEnabled(!isView);
586 this.jComboBoxArch.setEnabled(!isView);
587 this.jTextFieldLibraryClass.setEnabled(!isView);
588 this.jTextFieldClassGuid.setEnabled(!isView);
589 this.jTextFieldOverrideID.setEnabled(!isView);
590 this.jComboBoxUsage.setEnabled(!isView);
591 this.jButtonAdd.setEnabled(!isView);
592 this.jButtonRemove.setEnabled(!isView);
593 this.jButtonUpdate.setEnabled(!isView);
594 this.jCheckBoxArch.setEnabled(!isView);
595 this.jTextFieldVersion.setEnabled(!isView);
596
597 this.jButtonOk.setEnabled(!isView);
598 this.jButtonCancel.setEnabled(!isView);
599 this.jButtonGenerateGuid.setEnabled(!isView);
600 this.jButtonGenerateGuid2.setEnabled(!isView);
601 }
602 }
603
604 /**
605 This method initializes jContentPane
606
607 @return javax.swing.JPanel jContentPane
608
609 **/
610 private JPanel getJContentPane() {
611 if (jContentPane == null) {
612 jLabelVersion = new JLabel();
613 jLabelVersion.setBounds(new java.awt.Rectangle(15, 110, 140, 20));
614 jLabelVersion.setText("Version");
615 jLabelOverrideID = new JLabel();
616 jLabelOverrideID.setBounds(new java.awt.Rectangle(15, 160, 140, 20));
617 jLabelOverrideID.setText("Override ID");
618 jLabelClassGuid = new JLabel();
619 jLabelClassGuid.setBounds(new java.awt.Rectangle(15, 85, 140, 20));
620 jLabelClassGuid.setText("Class Guid");
621 jLabelUsage = new JLabel();
622 jLabelUsage.setBounds(new java.awt.Rectangle(15, 135, 140, 20));
623 jLabelUsage.setText("Usage");
624 jLabelLibraryClass = new JLabel();
625 jLabelLibraryClass.setBounds(new java.awt.Rectangle(15, 60, 140, 20));
626 jLabelLibraryClass.setText("Library Class");
627 jLabelGuid = new JLabel();
628 jLabelGuid.setBounds(new java.awt.Rectangle(15, 35, 140, 20));
629 jLabelGuid.setText("Guid");
630 jLabelName = new JLabel();
631 jLabelName.setText("Name");
632 jLabelName.setBounds(new java.awt.Rectangle(15, 10, 140, 20));
633 jContentPane = new JPanel();
634 jContentPane.setLayout(null);
635 jContentPane.add(getJButton(), null);
636 jContentPane.add(getJButtonCancel(), null);
637 jContentPane.add(jLabelName, null);
638 jContentPane.add(getJTextFieldSourceFilesDirectory(), null);
639 jContentPane.add(jLabelGuid, null);
640 jContentPane.add(getJTextFieldGuid(), null);
641 jContentPane.add(getJButtonGenerateGuid(), null);
642 jContentPane.add(getJComboBoxArch(), null);
643 jContentPane.add(jLabelLibraryClass, null);
644 jContentPane.add(getJTextFieldLibraryClass(), null);
645 jContentPane.add(jLabelUsage, null);
646 jContentPane.add(jLabelClassGuid, null);
647 jContentPane.add(getJTextFieldClassGuid(), null);
648 jContentPane.add(getJButtonGenerateGuid2(), null);
649 jContentPane.add(jLabelVersion, null);
650 jContentPane.add(getJTextFieldVersion(), null);
651 jContentPane.add(jLabelOverrideID, null);
652 jContentPane.add(getJTextFieldOverrideID(), null);
653 jContentPane.add(getJComboBoxUsage(), null);
654
655 jStarLabel1 = new StarLabel();
656 jStarLabel1.setLocation(new java.awt.Point(0, 10));
657
658 jContentPane.add(jStarLabel1, null);
659 jContentPane.add(getJComboBoxFileList(), null);
660 jContentPane.add(getJButtonAdd(), null);
661 jContentPane.add(getJButtonRemove(), null);
662 jContentPane.add(getJButtonUpdate(), null);
663 jContentPane.add(getJCheckBoxArch(), null);
664
665 }
666 return jContentPane;
667 }
668
669 /* (non-Javadoc)
670 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
671 *
672 * Override actionPerformed to listen all actions
673 *
674 */
675 public void actionPerformed(ActionEvent arg0) {
676 if (arg0.getSource() == jButtonOk) {
677 this.setEdited(true);
678 this.save();
679 this.dispose();
680 }
681 if (arg0.getSource() == jButtonCancel) {
682 this.dispose();
683 }
684 if (arg0.getSource() == jButtonGenerateGuid) {
685 jTextFieldGuid.setText(Tools.generateUuidString());
686 }
687 if (arg0.getSource() == jButtonGenerateGuid2) {
688 jTextFieldClassGuid.setText(Tools.generateUuidString());
689 }
690 if (arg0.getSource() == jButtonAdd) {
691 if (!checkAdd()) {
692 return;
693 }
694 addToList();
695 }
696 if (arg0.getSource() == jButtonRemove) {
697 removeFromList();
698 }
699 if (arg0.getSource() == jButtonUpdate) {
700 if (!checkAdd()) {
701 return;
702 }
703 updateForList();
704 }
705 if (arg0.getSource() == jCheckBoxArch) {
706 if (this.jCheckBoxArch.isSelected()) {
707 this.jComboBoxArch.setEnabled(true);
708 } else {
709 this.jComboBoxArch.setEnabled(false);
710 }
711 }
712 }
713
714 /**
715 Init the items of Usage and Arch
716
717 **/
718 private void initFrame() {
719 jComboBoxUsage.addItem("ALWAYS_CONSUMED");
720 jComboBoxUsage.addItem("SOMETIMES_CONSUMED");
721 jComboBoxUsage.addItem("ALWAYS_PRODUCED");
722 jComboBoxUsage.addItem("SOMETIMES_PRODUCED");
723 jComboBoxUsage.addItem("DEFAULT");
724 jComboBoxUsage.addItem("PRIVATE");
725
726 jComboBoxArch.addItem("ALL");
727 jComboBoxArch.addItem("EBC");
728 jComboBoxArch.addItem("ARM");
729 jComboBoxArch.addItem("IA32");
730 jComboBoxArch.addItem("X64");
731 jComboBoxArch.addItem("IPF");
732 jComboBoxArch.addItem("PPC");
733 }
734
735 /**
736 Add current item to Vector
737
738 **/
739 private void addToList() {
740 intSelectedItemId = vName.size();
741 vName.addElement(this.jTextFieldFileName.getText());
742 vGuid.addElement(this.jTextFieldGuid.getText());
743 vLibraryClass.addElement(this.jTextFieldLibraryClass.getText());
744 vClassGuid.addElement(this.jTextFieldClassGuid.getText());
745 vVersion.addElement(this.jTextFieldVersion.getText());
746 vUsage.addElement(this.jComboBoxUsage.getSelectedItem().toString());
747 vOverrideID.addElement(this.jTextFieldOverrideID.getText());
748 jComboBoxFileList.addItem(this.jTextFieldFileName.getText());
749 jComboBoxFileList.setSelectedItem(this.jTextFieldFileName.getText());
750
751 //
752 // Reset select item index
753 //
754 intSelectedItemId = vName.size();
755
756 //
757 // Reload all fields of selected item
758 //
759 reloadFromList();
760 }
761
762 /**
763 Remove current item from Vector
764
765 **/
766 private void removeFromList() {
767 int intTempIndex = intSelectedItemId;
768 if (vName.size() < 1) {
769 return;
770 }
771
772 jComboBoxFileList.removeItemAt(intSelectedItemId);
773
774 vName.removeElementAt(intTempIndex);
775 vGuid.removeElementAt(intTempIndex);
776 vLibraryClass.removeElementAt(intTempIndex);
777 vClassGuid.removeElementAt(intTempIndex);
778 vVersion.removeElementAt(intTempIndex);
779 vUsage.removeElementAt(intTempIndex);
780 vOverrideID.removeElementAt(intTempIndex);
781
782 //
783 // Reload all fields of selected item
784 //
785 reloadFromList();
786 }
787
788 /**
789 Update current item of Vector
790
791 **/
792 private void updateForList() {
793 //
794 // Backup selected item index
795 //
796 int intTempIndex = intSelectedItemId;
797 vName.setElementAt(this.jTextFieldFileName.getText(), intSelectedItemId);
798 vGuid.setElementAt(this.jTextFieldGuid.getText(), intSelectedItemId);
799 vLibraryClass.setElementAt(this.jTextFieldLibraryClass.getText(), intSelectedItemId);
800 vClassGuid.setElementAt(this.jTextFieldClassGuid.getText(), intSelectedItemId);
801 vVersion.setElementAt(this.jTextFieldVersion.getText(), intSelectedItemId);
802 vUsage.setElementAt(this.jComboBoxUsage.getSelectedItem().toString(), intSelectedItemId);
803 vOverrideID.setElementAt(this.jTextFieldOverrideID.getText(), intSelectedItemId);
804
805 jComboBoxFileList.removeAllItems();
806 for (int index = 0; index < vName.size(); index++) {
807 jComboBoxFileList.addItem(vName.elementAt(index));
808 }
809
810 //
811 // Restore selected item index
812 //
813 intSelectedItemId = intTempIndex;
814
815 //
816 // Reset select item index
817 //
818 jComboBoxFileList.setSelectedIndex(intSelectedItemId);
819
820 //
821 // Reload all fields of selected item
822 //
823 reloadFromList();
824 }
825
826 /**
827 Refresh all fields' values of selected item of Vector
828
829 **/
830 private void reloadFromList() {
831 if (vName.size() > 0) {
832 //
833 // Get selected item index
834 //
835 intSelectedItemId = jComboBoxFileList.getSelectedIndex();
836
837 this.jTextFieldFileName.setText(vName.elementAt(intSelectedItemId).toString());
838 this.jComboBoxUsage.setSelectedItem(vUsage.elementAt(intSelectedItemId).toString());
839 this.jTextFieldGuid.setText(vGuid.elementAt(intSelectedItemId).toString());
840 this.jTextFieldLibraryClass.setText(vLibraryClass.elementAt(intSelectedItemId).toString());
841 this.jTextFieldClassGuid.setText(vClassGuid.elementAt(intSelectedItemId).toString());
842 this.jTextFieldVersion.setText(vVersion.elementAt(intSelectedItemId).toString());
843 this.jTextFieldOverrideID.setText(vOverrideID.elementAt(intSelectedItemId).toString());
844 } else {
845 this.jTextFieldFileName.setText("");
846 this.jComboBoxUsage.setSelectedIndex(0);
847 this.jTextFieldGuid.setText("");
848 this.jTextFieldLibraryClass.setText("");
849 this.jTextFieldClassGuid.setText("");
850 this.jTextFieldVersion.setText("");
851 this.jTextFieldOverrideID.setText("");
852 }
853 }
854
855 /* (non-Javadoc)
856 * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
857 *
858 * Reflesh the frame when selected item changed
859 */
860 public void itemStateChanged(ItemEvent arg0) {
861 if (arg0.getStateChange() == ItemEvent.SELECTED) {
862 reloadFromList();
863 }
864 }
865
866 /**
867 Data validation for all fields before save
868
869 @retval true - All datas are valid
870 @retval false - At least one data is invalid
871
872 **/
873 public boolean check() {
874 if (this.jComboBoxFileList.getItemCount() < 1) {
875 Log.err("Must have one Library at least!");
876 return false;
877 }
878 return true;
879 }
880
881 /**
882 Data validation for all fields before add current item to Vector
883
884 @retval true - All datas are valid
885 @retval false - At least one data is invalid
886
887 **/
888 public boolean checkAdd() {
889 //
890 // Check if all required fields are not empty
891 //
892 if (isEmpty(this.jTextFieldFileName.getText())) {
893 Log.err("File Name couldn't be empty");
894 return false;
895 }
896
897 //
898 // Check if all fields have correct data types
899 //
900 if (!DataValidation.isBaseName(this.jTextFieldFileName.getText())) {
901 Log.err("Incorrect data type for Name");
902 return false;
903 }
904 if (!isEmpty(this.jTextFieldGuid.getText()) && !DataValidation.isGuid(this.jTextFieldGuid.getText())) {
905 Log.err("Incorrect data type for Guid");
906 return false;
907 }
908 if (!isEmpty(this.jTextFieldLibraryClass.getText())
909 && !DataValidation.isPath(this.jTextFieldLibraryClass.getText())) {
910 Log.err("Incorrect data type for Path");
911 return false;
912 }
913 if (!isEmpty(this.jTextFieldClassGuid.getText()) && !DataValidation.isGuid(this.jTextFieldClassGuid.getText())) {
914 Log.err("Incorrect data type for Guid");
915 return false;
916 }
917 if (!isEmpty(this.jTextFieldOverrideID.getText())
918 && !DataValidation.isOverrideID(this.jTextFieldOverrideID.getText())) {
919 Log.err("Incorrect data type for Override ID");
920 return false;
921 }
922
923 return true;
924 }
925
926 /**
927 Save all components of Mbd Libraries
928 if exists libraries, set the value directly
929 if not exists libraries, new an instance first
930
931 **/
932 public void save() {
933 try {
934 if (this.libraries == null) {
935 libraries = LibrariesDocument.Libraries.Factory.newInstance();
936 }
937 //
938 //Save as file name
939 //
940 if (!this.jCheckBoxArch.isSelected()) {
941 if (this.operation == 2) { //Add new filename
942 //
943 //First remove all existed filename
944 //
945 if (libraries.getLibraryList().size() > 0) {
946 for (int index = libraries.getLibraryList().size() - 1; index >= 0; index--) {
947 libraries.removeLibrary(index);
948 }
949 }
950 }
951 LibrariesDocument.Libraries.Library library = LibrariesDocument.Libraries.Library.Factory.newInstance();
952 for (int index = 0; index < vName.size(); index++) {
953 if (!isEmpty(vName.elementAt(index).toString())) {
954 library.setStringValue(vName.elementAt(index).toString());
955 }
956 if (!isEmpty(vGuid.elementAt(index).toString())) {
957 library.setGuid(vGuid.elementAt(index).toString());
958 }
959 if (!isEmpty(vLibraryClass.elementAt(index).toString())) {
960 library.setLibraryClass(vLibraryClass.elementAt(index).toString());
961 }
962 if (!isEmpty(vClassGuid.elementAt(index).toString())) {
963 library.setClassGuid(vClassGuid.elementAt(index).toString());
964 }
965 if (!isEmpty(vVersion.elementAt(index).toString())) {
966 library.setVersion(vVersion.elementAt(index).toString());
967 }
968 if (!isEmpty(vUsage.elementAt(index).toString())) {
969 library.setUsage(LibraryUsage.Enum.forString(vUsage.elementAt(index).toString()));
970 }
971 if (!isEmpty(vOverrideID.elementAt(index).toString())) {
972 library.setOverrideID(Integer.parseInt(vOverrideID.elementAt(index).toString()));
973 }
974 libraries.addNewLibrary();
975 libraries.setLibraryArray(libraries.getLibraryList().size() - 1, library);
976 }
977 }
978 //
979 //Save as Arch
980 //
981 if (this.jCheckBoxArch.isSelected()) {
982 LibrariesDocument.Libraries.Arch arch = LibrariesDocument.Libraries.Arch.Factory.newInstance();
983 if (this.operation == 2) {
984 //First remove all existed filename
985 for (int index = libraries.getArchArray(location).getLibraryList().size() - 1; index >= 0; index--) {
986 libraries.getArchArray(location).removeLibrary(index);
987 }
988 }
989 for (int index = 0; index < vName.size(); index++) {
990 LibrariesDocument.Libraries.Arch.Library library = LibrariesDocument.Libraries.Arch.Library.Factory.newInstance();
991 if (!isEmpty(vName.elementAt(index).toString())) {
992 library.setStringValue(vName.elementAt(index).toString());
993 }
994 if (!isEmpty(vGuid.elementAt(index).toString())) {
995 library.setGuid(vGuid.elementAt(index).toString());
996 }
997 if (!isEmpty(vLibraryClass.elementAt(index).toString())) {
998 library.setLibraryClass(vLibraryClass.elementAt(index).toString());
999 }
1000 if (!isEmpty(vClassGuid.elementAt(index).toString())) {
1001 library.setClassGuid(vClassGuid.elementAt(index).toString());
1002 }
1003 if (!isEmpty(vVersion.elementAt(index).toString())) {
1004 library.setVersion(vVersion.elementAt(index).toString());
1005 }
1006 if (!isEmpty(vUsage.elementAt(index).toString())) {
1007 library.setUsage(LibraryUsage.Enum.forString(vUsage.elementAt(index).toString()));
1008 }
1009 if (!isEmpty(vOverrideID.elementAt(index).toString())) {
1010 library.setOverrideID(Integer.parseInt(vOverrideID.elementAt(index).toString()));
1011 }
1012 arch.addNewLibrary();
1013 arch.setLibraryArray(arch.getLibraryList().size() - 1, library);
1014 }
1015 arch
1016 .setArchType(SupportedArchitectures.Enum.forString(this.jComboBoxArch.getSelectedItem().toString()));
1017 if (location > -1) {
1018 libraries.setArchArray(location, arch);
1019 } else {
1020 libraries.addNewArch();
1021 libraries.setArchArray(libraries.getArchList().size() - 1, arch);
1022 }
1023 }
1024 } catch (Exception e) {
1025 Log.err("Update Source Files", e.getMessage());
1026 }
1027 }
1028
1029 /**
1030 Get LibrariesDocument.Libraries
1031
1032 @return LibrariesDocument.Libraries
1033
1034 **/
1035 public LibrariesDocument.Libraries getLibraries() {
1036 return libraries;
1037 }
1038
1039 /**
1040 Set LibrariesDocument.Libraries
1041
1042 @param libraries The input LibrariesDocument.Libraries
1043
1044 **/
1045 public void setLibraries(LibrariesDocument.Libraries libraries) {
1046 this.libraries = libraries;
1047 }
1048 }