2923a441534525cd7e31fd7c957b11b040b541c8
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / platform / ui / FpdModuleSA.java
1 package org.tianocore.frameworkwizard.platform.ui;
2
3 import java.awt.BorderLayout;
4 import java.awt.Dimension;
5 import java.awt.Toolkit;
6
7 import javax.swing.JFrame;
8 import javax.swing.JOptionPane;
9 import javax.swing.JPanel;
10 import javax.swing.JDialog;
11 import javax.swing.JTabbedPane;
12 import javax.swing.JLabel;
13 import javax.swing.JScrollPane;
14 import javax.swing.JTable;
15 import javax.swing.JTextArea;
16 import javax.swing.JSplitPane;
17 import javax.swing.JButton;
18 import javax.swing.ListSelectionModel;
19 import javax.swing.event.ListSelectionEvent;
20 import javax.swing.event.ListSelectionListener;
21 import javax.swing.event.TableModelEvent;
22 import javax.swing.event.TableModelListener;
23 import javax.swing.table.DefaultTableModel;
24 import javax.swing.table.TableModel;
25
26 import org.apache.xmlbeans.XmlObject;
27 import org.tianocore.frameworkwizard.platform.ui.global.GlobalData;
28 import org.tianocore.frameworkwizard.platform.ui.global.SurfaceAreaQuery;
29 import org.tianocore.frameworkwizard.platform.ui.id.ModuleIdentification;
30 import org.tianocore.frameworkwizard.platform.ui.id.PackageIdentification;
31
32 import java.awt.FlowLayout;
33 import java.awt.event.ActionEvent;
34 import java.awt.event.ActionListener;
35 import java.util.ArrayList;
36 import java.util.HashMap;
37 import java.util.Iterator;
38 import java.util.ListIterator;
39 import java.util.Map;
40 import java.util.Set;
41 import java.util.Vector;
42
43 import javax.swing.JTextField;
44
45 public class FpdModuleSA extends JDialog implements ActionListener {
46
47 /**
48 *
49 */
50 private static final long serialVersionUID = 1L;
51 static JFrame frame;
52 private JPanel jContentPane = null;
53 private JTabbedPane jTabbedPane = null;
54 private JPanel jPanel = null;
55 private JPanel jPanel1 = null;
56 private JLabel jLabel = null;
57 private JScrollPane jScrollPane = null;
58 private JTable jTable = null;
59 private JPanel jPanel2 = null;
60 private JScrollPane jScrollPane1 = null;
61 private JTextArea jTextArea = null;
62 private JPanel jPanel3 = null;
63 private JSplitPane jSplitPane = null;
64 private JPanel jPanel4 = null;
65 private JPanel jPanel5 = null;
66 private JLabel jLabel1 = null;
67 private JLabel jLabel2 = null;
68 private JScrollPane jScrollPane2 = null;
69 private JTable jTable1 = null;
70 private JScrollPane jScrollPane3 = null;
71 private JTable jTable2 = null;
72 private JScrollPane jScrollPane4 = null;
73 private JTable jTable3 = null;
74 private JPanel jPanel6 = null;
75 private JPanel jPanel7 = null;
76 private JScrollPane jScrollPane5 = null;
77 private JTextArea jTextArea1 = null;
78 private JLabel jLabel3 = null;
79 private JLabel jLabel4 = null;
80 private JButton jButton = null;
81 private JButton jButton1 = null;
82 private JLabel jLabel5 = null;
83 private JButton jButton2 = null;
84 private JButton jButton3 = null;
85 private PartialEditableTableModel model = null;
86 private LibraryTableModel model1 = null;
87 private LibraryTableModel model2 = null;
88 private LibraryTableModel model3 = null;
89 private DefaultTableModel optionsTableModel = null;
90 private FpdFileContents ffc = null;
91 private String moduleKey = null;
92 private HashMap<String, ArrayList<String>> classInstanceMap = null;
93 private ArrayList<String> classProduced = null;
94 private HashMap<String, ArrayList<String>> classConsumed = null;
95 private JPanel jPanel8 = null;
96 private JLabel jLabel6 = null;
97 private JTextField jTextField = null;
98 private JLabel jLabel7 = null;
99 private JTextField jTextField1 = null;
100 private JLabel jLabel8 = null;
101 private JTextField jTextField2 = null;
102 private JScrollPane jScrollPane6 = null;
103 private JTable jTable4 = null;
104 private JButton jButton4 = null;
105 private JButton jButton5 = null;
106 /**
107 * This is the default constructor
108 */
109 public FpdModuleSA() {
110 super();
111 initialize();
112 }
113 public FpdModuleSA(FpdFileContents ffc) {
114 this();
115 this.ffc = ffc;
116 }
117
118 public void setKey(String k){
119 this.moduleKey = k;
120 }
121
122 /**
123 init will be called each time FpdModuleSA object is to be shown.
124 @param key Module information.
125 **/
126 public void init(String key) {
127 //
128 // display pcd for key.
129 //
130 model.setRowCount(0);
131 int pcdCount = ffc.getPcdDataCount(key);
132 if (pcdCount != 0) {
133 String[][] saa = new String[pcdCount][7];
134 ffc.getPcdData(key, saa);
135 for (int i = 0; i < saa.length; ++i) {
136 model.addRow(saa[i]);
137 }
138 }
139 //
140 // display library classes that need to be resolved. also potential instances for them.
141 //
142 resolveLibraryInstances(key);
143 //
144 // display lib instances already selected for key
145 //
146 model1.setRowCount(0);
147 int instanceCount = ffc.getLibraryInstancesCount(key);
148 if (instanceCount != 0) {
149 String[][] saa = new String[instanceCount][5];
150 ffc.getLibraryInstances(key, saa);
151 for (int i = 0; i < saa.length; ++i) {
152 ModuleIdentification mi = getModuleId(saa[i][1] + " " + saa[i][2] + " " + saa[i][3] + " " + saa[i][4]);
153 if (mi != null) {
154 saa[i][0] = mi.getName();
155 saa[i][2] = mi.getVersion();
156 saa[i][4] = mi.getPackage().getVersion();
157 //
158 // re-evaluate lib instance usage when adding a already-selected lib instance.
159 //
160 resolveLibraryInstances(saa[i][1] + " " + saa[i][2] + " " + saa[i][3] + " " + saa[i][4]);
161 model1.addRow(saa[i]);
162 }
163
164
165 }
166 }
167
168 //
169 // display module SA options
170 //
171 String fvBinding = ffc.getFvBinding(key);
172 if (fvBinding != null) {
173 jTextField.setText(fvBinding);
174 }
175 String fileGuid = ffc.getFfsFileNameGuid(key);
176 if (fileGuid != null) {
177 jTextField1.setText(fileGuid);
178 }
179 String ffsKey = ffc.getFfsFormatKey(key);
180 if (ffsKey != null) {
181 jTextField2.setText(ffsKey);
182 }
183 }
184
185 private void resolveLibraryInstances(String key) {
186 ModuleIdentification mi = getModuleId(key);
187 PackageIdentification[] depPkgList = null;
188 try{
189 Map<String, XmlObject> m = GlobalData.getNativeMsa(mi);
190 SurfaceAreaQuery.setDoc(m);
191 //
192 // Get dependency pkg list into which we will search lib instances.
193 //
194 depPkgList = SurfaceAreaQuery.getDependencePkg(null);
195 //
196 // Get the lib class consumed, produced by this module itself.
197 //
198 String[] classConsumed = SurfaceAreaQuery.getLibraryClasses("ALWAYS_CONSUMED");
199
200 if (this.classConsumed == null) {
201 this.classConsumed = new HashMap<String, ArrayList<String>>();
202 }
203
204 for(int i = 0; i < classConsumed.length; ++i){
205 ArrayList<String> consumedBy = this.classConsumed.get(classConsumed[i]);
206 if (consumedBy == null) {
207 consumedBy = new ArrayList<String>();
208 }
209 consumedBy.add(key);
210 this.classConsumed.put(classConsumed[i], consumedBy);
211 }
212
213 String[] classProduced = SurfaceAreaQuery.getLibraryClasses("ALWAYS_PRODUCED");
214 if (this.classProduced == null) {
215 this.classProduced = new ArrayList<String>();
216 }
217 for(int i = 0; i < classProduced.length; ++i){
218 if (!this.classProduced.contains(classProduced[i])){
219 this.classProduced.add(classProduced[i]);
220 }
221 }
222 //
223 // Get classes unresolved
224 //
225 // Iterator<String> lip = this.classProduced.listIterator();
226 // while(lip.hasNext()){
227 // String clsProduced = lip.next();
228 // this.classConsumed.remove(clsProduced);
229 //
230 // }
231 //
232 // find potential instances in all dependency pkgs for classes still in classConsumed.
233 //
234 if (classInstanceMap == null){
235 classInstanceMap = new HashMap<String, ArrayList<String>>();
236 }
237 Iterator<String> lic = this.classConsumed.keySet().iterator();
238 while(lic.hasNext()){
239 String cls = lic.next();
240 if (this.classProduced.contains(cls) || classInstanceMap.containsKey(cls)) {
241 continue;
242 }
243 ArrayList<String> instances = getInstancesForClass(cls, depPkgList);
244 if (instances.size() == 0){
245 JOptionPane.showMessageDialog(frame, "No Applicable Instance for Library Class " +
246 cls + ", Platform Build will Fail.");
247 }
248 classInstanceMap.put(cls, instances);
249
250 }
251
252 showClassToResolved();
253 }
254 catch(Exception e) {
255 e.printStackTrace();
256 }
257 }
258
259 private ArrayList<String> getInstancesForClass(String cls, PackageIdentification[] depPkgList) throws Exception{
260 ArrayList<String> al = new ArrayList<String>();
261
262 for (int i = 0; i < depPkgList.length; ++i) {
263 Set<ModuleIdentification> smi = GlobalData.getModules(depPkgList[i]);
264 Iterator ismi = smi.iterator();
265 while(ismi.hasNext()) {
266 ModuleIdentification mi = (ModuleIdentification)ismi.next();
267
268 String[] clsProduced = getClassProduced(mi);
269
270 boolean isPotential = false;
271 for (int j = 0; j < clsProduced.length; ++j) {
272 if (clsProduced[j] == null) {
273 continue;
274 }
275 if (clsProduced[j].equals(cls)){
276 isPotential = true;
277 }
278 if (classProduced.contains(clsProduced[j])) {
279 isPotential = false;
280 break;
281 }
282 }
283 if (isPotential) {
284 al.add(mi.getGuid() + " " + mi.getVersion() + " " +
285 depPkgList[i].getGuid() + " " + depPkgList[i].getVersion());
286 }
287 }
288 }
289
290 return al;
291 }
292
293 private void removeInstance(String key) {
294 ModuleIdentification mi = getModuleId(key);
295 //
296 // remove pcd information of instance from current ModuleSA
297 //
298 ffc.removePcdDataFromLibraryInstance(moduleKey, key);
299 //
300 // remove class produced by this instance and add back these produced class to be bound.
301 //
302 String[] clsProduced = getClassProduced(mi);
303 for (int i = 0; i < clsProduced.length; ++i) {
304
305 classProduced.remove(clsProduced[i]);
306 }
307 //
308 // remove class consumed by this instance. we do not need to bound it now.
309 //
310 String[] clsConsumed = getClassConsumed(mi);
311 for (int i = 0; i < clsConsumed.length; ++i) {
312 ArrayList<String> al = classConsumed.get(clsConsumed[i]);
313
314 if (al == null ) {
315 classConsumed.remove(clsConsumed[i]);
316 continue;
317 }
318 al.remove(key);
319 if (al.size() == 0) {
320 classConsumed.remove(clsConsumed[i]);
321 }
322
323 }
324
325 showClassToResolved();
326
327 }
328
329 private ModuleIdentification getModuleId(String key){
330 //
331 // Get ModuleGuid, ModuleVersion, PackageGuid, PackageVersion into string array.
332 //
333 String[] keyPart = key.split(" ");
334 Set<PackageIdentification> spi = GlobalData.getPackageList();
335 Iterator ispi = spi.iterator();
336
337 while(ispi.hasNext()) {
338 PackageIdentification pi = (PackageIdentification)ispi.next();
339 if ( !pi.getGuid().equals(keyPart[2])){
340 // || !pi.getVersion().equals(keyPart[3])){
341 continue;
342 }
343 Set<ModuleIdentification> smi = GlobalData.getModules(pi);
344 Iterator ismi = smi.iterator();
345 while(ismi.hasNext()) {
346 ModuleIdentification mi = (ModuleIdentification)ismi.next();
347 if (mi.getGuid().equals(keyPart[0])){
348 // && mi.getVersion().equals(keyPart[1])){
349 return mi;
350 }
351 }
352 }
353 return null;
354 }
355
356 private String[] getClassProduced(ModuleIdentification mi){
357
358 try{
359 Map<String, XmlObject> m = GlobalData.getNativeMsa(mi);
360 SurfaceAreaQuery.setDoc(m);
361 String[] clsProduced = SurfaceAreaQuery.getLibraryClasses("ALWAYS_PRODUCED");
362 return clsProduced;
363
364 }catch (Exception e) {
365 e.printStackTrace();
366 }
367 return new String[0];
368
369 }
370
371 private String[] getClassConsumed(ModuleIdentification mi){
372
373 String[] clsConsumed = null;
374 try{
375 Map<String, XmlObject> m = GlobalData.getNativeMsa(mi);
376 SurfaceAreaQuery.setDoc(m);
377 clsConsumed = SurfaceAreaQuery.getLibraryClasses("ALWAYS_CONSUMED");
378
379 }catch (Exception e) {
380 e.printStackTrace();
381 }
382 return clsConsumed;
383 }
384
385 private void showClassToResolved(){
386 model2.setRowCount(0);
387 if (classConsumed.size() == 0) {
388 return;
389 }
390 Iterator<String> li = classConsumed.keySet().iterator();
391 while(li.hasNext()){
392
393 String[] s = {li.next()};
394 if (classConsumed.get(s[0]) == null) {
395 continue;
396 }
397 if (classConsumed.get(s[0]).size() == 0) {
398 continue;
399 }
400 if (!classProduced.contains(s[0])){
401 model2.addRow(s);
402 }
403 }
404 model3.setRowCount(0);
405 }
406 /**
407 * This method initializes this
408 *
409 * @return void
410 */
411 private void initialize() {
412 this.setSize(664, 515);
413 this.centerWindow();
414 this.setModal(true);
415 this.setTitle("Module Settings");
416 this.setContentPane(getJContentPane());
417 }
418
419 /**
420 * This method initializes jContentPane
421 *
422 * @return javax.swing.JPanel
423 */
424 private JPanel getJContentPane() {
425 if (jContentPane == null) {
426 jContentPane = new JPanel();
427 jContentPane.setLayout(new BorderLayout());
428 jContentPane.add(getJTabbedPane(), java.awt.BorderLayout.CENTER);
429 jContentPane.add(getJPanel3(), java.awt.BorderLayout.SOUTH);
430 }
431 return jContentPane;
432 }
433
434 /**
435 * This method initializes jTabbedPane
436 *
437 * @return javax.swing.JTabbedPane
438 */
439 private JTabbedPane getJTabbedPane() {
440 if (jTabbedPane == null) {
441 jTabbedPane = new JTabbedPane();
442 jTabbedPane.addTab("PCD Build Definition", null, getJPanel(), null);
443 jTabbedPane.addTab("Module SA Options", null, getJPanel8(), null);
444 jTabbedPane.addTab("Libraries", null, getJPanel1(), null);
445 }
446 return jTabbedPane;
447 }
448
449 /**
450 * This method initializes jPanel
451 *
452 * @return javax.swing.JPanel
453 */
454 private JPanel getJPanel() {
455 if (jPanel == null) {
456 jLabel = new JLabel();
457 jLabel.setText("PcdData");
458 jPanel = new JPanel();
459 jPanel.setLayout(new BorderLayout());
460 jPanel.add(jLabel, java.awt.BorderLayout.NORTH);
461 jPanel.add(getJScrollPane(), java.awt.BorderLayout.CENTER);
462 jPanel.add(getJPanel2(), java.awt.BorderLayout.SOUTH);
463 jPanel.addComponentListener(new java.awt.event.ComponentAdapter() {
464 public void componentShown(java.awt.event.ComponentEvent e) {
465 init(moduleKey);
466 }
467 });
468
469 }
470 return jPanel;
471 }
472
473 /**
474 * This method initializes jPanel1
475 *
476 * @return javax.swing.JPanel
477 */
478 private JPanel getJPanel1() {
479 if (jPanel1 == null) {
480 jPanel1 = new JPanel();
481 jPanel1.setLayout(new BorderLayout());
482 jPanel1.add(getJSplitPane(), java.awt.BorderLayout.NORTH);
483 jPanel1.add(getJPanel6(), java.awt.BorderLayout.SOUTH);
484 jPanel1.add(getJPanel7(), java.awt.BorderLayout.CENTER);
485 jPanel1.addComponentListener(new java.awt.event.ComponentAdapter() {
486 public void componentShown(java.awt.event.ComponentEvent e) {
487 init(moduleKey);
488 }
489 });
490 }
491 return jPanel1;
492 }
493
494 /**
495 * This method initializes jScrollPane
496 *
497 * @return javax.swing.JScrollPane
498 */
499 private JScrollPane getJScrollPane() {
500 if (jScrollPane == null) {
501 jScrollPane = new JScrollPane();
502 jScrollPane.setViewportView(getJTable());
503 }
504 return jScrollPane;
505 }
506
507 /**
508 * This method initializes jTable
509 *
510 * @return javax.swing.JTable
511 */
512 private JTable getJTable() {
513 if (jTable == null) {
514 model = new PartialEditableTableModel();
515 jTable = new JTable(model);
516 jTable.setRowHeight(20);
517 jTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
518 model.addColumn("CName");
519 model.addColumn("TokenSpaceGUID");
520 model.addColumn("ItemType");
521 model.addColumn("Token");
522 model.addColumn("MaxDatumSize");
523 model.addColumn("DataType");
524 model.addColumn("DefaultValue");
525
526 jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
527 jTable.getSelectionModel().addListSelectionListener(new ListSelectionListener(){
528 public void valueChanged(ListSelectionEvent e) {
529
530 if (e.getValueIsAdjusting()){
531 return;
532 }
533 ListSelectionModel lsm = (ListSelectionModel)e.getSource();
534 if (lsm.isSelectionEmpty()) {
535 return;
536 }
537 else{
538 // int selectedRow = lsm.getMinSelectionIndex();
539
540
541 }
542 }
543 });
544
545 jTable.getModel().addTableModelListener(new TableModelListener() {
546 public void tableChanged(TableModelEvent arg0) {
547 // TODO Auto-generated method stub
548 int row = arg0.getFirstRow();
549 TableModel m = (TableModel)arg0.getSource();
550 if (arg0.getType() == TableModelEvent.INSERT) {
551 //
552 // Set combo box values for item type according to pcd values added.
553 //
554
555 }
556 if (arg0.getType() == TableModelEvent.UPDATE){
557 //ToDo Data Validition check.
558
559 }
560 }
561 });
562 }
563 return jTable;
564 }
565
566 /**
567 * This method initializes jPanel2
568 *
569 * @return javax.swing.JPanel
570 */
571 private JPanel getJPanel2() {
572 if (jPanel2 == null) {
573 jLabel5 = new JLabel();
574 jLabel5.setText("PCD Description");
575 jPanel2 = new JPanel();
576 jPanel2.add(jLabel5, null);
577 jPanel2.add(getJScrollPane1(), null);
578 }
579 return jPanel2;
580 }
581
582 /**
583 * This method initializes jScrollPane1
584 *
585 * @return javax.swing.JScrollPane
586 */
587 private JScrollPane getJScrollPane1() {
588 if (jScrollPane1 == null) {
589 jScrollPane1 = new JScrollPane();
590 jScrollPane1.setPreferredSize(new java.awt.Dimension(500,100));
591 jScrollPane1.setViewportView(getJTextArea());
592 }
593 return jScrollPane1;
594 }
595
596 /**
597 * This method initializes jTextArea
598 *
599 * @return javax.swing.JTextArea
600 */
601 private JTextArea getJTextArea() {
602 if (jTextArea == null) {
603 jTextArea = new JTextArea();
604 jTextArea.setEditable(false);
605 }
606 return jTextArea;
607 }
608
609 /**
610 * This method initializes jPanel3
611 *
612 * @return javax.swing.JPanel
613 */
614 private JPanel getJPanel3() {
615 if (jPanel3 == null) {
616 FlowLayout flowLayout = new FlowLayout();
617 flowLayout.setAlignment(java.awt.FlowLayout.RIGHT);
618 jPanel3 = new JPanel();
619 jPanel3.setLayout(flowLayout);
620 jPanel3.add(getJButton2(), null);
621 jPanel3.add(getJButton3(), null);
622 }
623 return jPanel3;
624 }
625
626 /**
627 * This method initializes jSplitPane
628 *
629 * @return javax.swing.JSplitPane
630 */
631 private JSplitPane getJSplitPane() {
632 if (jSplitPane == null) {
633 jSplitPane = new JSplitPane();
634 jSplitPane.setDividerLocation(200);
635 jSplitPane.setLeftComponent(getJPanel4());
636 jSplitPane.setRightComponent(getJPanel5());
637 jSplitPane.setPreferredSize(new java.awt.Dimension(202,200));
638 }
639 return jSplitPane;
640 }
641
642 /**
643 * This method initializes jPanel4
644 *
645 * @return javax.swing.JPanel
646 */
647 private JPanel getJPanel4() {
648 if (jPanel4 == null) {
649 jLabel1 = new JLabel();
650 jLabel1.setText("Library Classes Consumed");
651 jPanel4 = new JPanel();
652 jPanel4.add(jLabel1, null);
653 jPanel4.add(getJScrollPane3(), null);
654 }
655 return jPanel4;
656 }
657
658 /**
659 * This method initializes jPanel5
660 *
661 * @return javax.swing.JPanel
662 */
663 private JPanel getJPanel5() {
664 if (jPanel5 == null) {
665 jLabel2 = new JLabel();
666 jLabel2.setText("Instances Available");
667 jPanel5 = new JPanel();
668 jPanel5.add(jLabel2, null);
669 jPanel5.add(getJScrollPane4(), null);
670 }
671 return jPanel5;
672 }
673
674 /**
675 * This method initializes jScrollPane2
676 *
677 * @return javax.swing.JScrollPane
678 */
679 private JScrollPane getJScrollPane2() {
680 if (jScrollPane2 == null) {
681 jScrollPane2 = new JScrollPane();
682 jScrollPane2.setPreferredSize(new java.awt.Dimension(453,150));
683 jScrollPane2.setViewportView(getJTable1());
684 }
685 return jScrollPane2;
686 }
687
688 /**
689 * This method initializes jTable1
690 *
691 * @return javax.swing.JTable
692 */
693 private JTable getJTable1() {
694 if (jTable1 == null) {
695 model1 = new LibraryTableModel();
696 model1.addColumn("Name");
697 model1.addColumn("ModuleGUID");
698 model1.addColumn("ModuleVersion");
699 model1.addColumn("PackageGUID");
700 model1.addColumn("PackageVersion");
701 jTable1 = new JTable(model1);
702 jTable1.setRowHeight(20);
703 jTable1.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
704 jTable1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
705 jTable1.getSelectionModel().addListSelectionListener(new ListSelectionListener(){
706 public void valueChanged(ListSelectionEvent e) {
707 int selectedRow1 = -1;
708 if (e.getValueIsAdjusting()){
709 return;
710 }
711 ListSelectionModel lsm = (ListSelectionModel)e.getSource();
712 if (lsm.isSelectionEmpty()) {
713 return;
714 }
715 else{
716 selectedRow1 = lsm.getMinSelectionIndex();
717
718
719 }
720 }
721 });
722
723
724 }
725 return jTable1;
726 }
727
728 /**
729 * This method initializes jScrollPane3
730 *
731 * @return javax.swing.JScrollPane
732 */
733 private JScrollPane getJScrollPane3() {
734 if (jScrollPane3 == null) {
735 jScrollPane3 = new JScrollPane();
736 jScrollPane3.setPreferredSize(new java.awt.Dimension(200,170));
737 jScrollPane3.setViewportView(getJTable2());
738 }
739 return jScrollPane3;
740 }
741
742 /**
743 * This method initializes jTable2
744 *
745 * @return javax.swing.JTable
746 */
747 private JTable getJTable2() {
748 if (jTable2 == null) {
749 model2 = new LibraryTableModel();
750 model2.addColumn("LibraryClass");
751 jTable2 = new JTable(model2);
752 jTable2.setRowHeight(20);
753 jTable2.setShowGrid(false);
754 jTable2.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
755 jTable2.getSelectionModel().addListSelectionListener(new ListSelectionListener(){
756 public void valueChanged(ListSelectionEvent e) {
757 if (e.getValueIsAdjusting()){
758 return;
759 }
760 ListSelectionModel lsm = (ListSelectionModel)e.getSource();
761 if (lsm.isSelectionEmpty()) {
762 return;
763 }
764 else{
765 int selectedRow2 = lsm.getMinSelectionIndex();
766 if (selectedRow2 < 0) {
767 return;
768 }
769 //
770 // display potential lib instances according to class selection
771 //
772 model3.setRowCount(0);
773 String cls = model2.getValueAt(selectedRow2, 0).toString();
774 ArrayList<String> al = classInstanceMap.get(cls);
775 ListIterator<String> li = al.listIterator();
776 while(li.hasNext()) {
777 String instance = li.next();
778 String[] s = {"", "", "", "", ""};
779 if (getModuleId(instance) != null) {
780 s[0] = getModuleId(instance).getName();
781 }
782
783 String[] instancePart = instance.split(" ");
784 for (int i = 0; i < instancePart.length; ++i){
785 s[i+1] = instancePart[i];
786 }
787 model3.addRow(s);
788 }
789
790 }
791 }
792 });
793 }
794 return jTable2;
795 }
796
797 /**
798 * This method initializes jScrollPane4
799 *
800 * @return javax.swing.JScrollPane
801 */
802 private JScrollPane getJScrollPane4() {
803 if (jScrollPane4 == null) {
804 jScrollPane4 = new JScrollPane();
805 jScrollPane4.setPreferredSize(new java.awt.Dimension(450,170));
806 jScrollPane4.setViewportView(getJTable3());
807 }
808 return jScrollPane4;
809 }
810
811 /**
812 * This method initializes jTable3
813 *
814 * @return javax.swing.JTable
815 */
816 private JTable getJTable3() {
817 if (jTable3 == null) {
818 model3 = new LibraryTableModel();
819 model3.addColumn("Name");
820 model3.addColumn("ModuleGUID");
821 model3.addColumn("ModuleVersion");
822 model3.addColumn("PackageGUID");
823 model3.addColumn("PackageVersion");
824 jTable3 = new JTable(model3);
825 jTable3.setRowHeight(20);
826 jTable3.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
827 jTable3.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
828 jTable3.getSelectionModel().addListSelectionListener(new ListSelectionListener(){
829 public void valueChanged(ListSelectionEvent e) {
830 int selectedRow3 = -1;
831 if (e.getValueIsAdjusting()){
832 return;
833 }
834 ListSelectionModel lsm = (ListSelectionModel)e.getSource();
835 if (lsm.isSelectionEmpty()) {
836 return;
837 }
838 else{
839 selectedRow3 = lsm.getMinSelectionIndex();
840
841
842 }
843 }
844 });
845 }
846 return jTable3;
847 }
848
849 /**
850 * This method initializes jPanel6
851 *
852 * @return javax.swing.JPanel
853 */
854 private JPanel getJPanel6() {
855 if (jPanel6 == null) {
856 jPanel6 = new JPanel();
857 }
858 return jPanel6;
859 }
860
861 /**
862 * This method initializes jPanel7
863 *
864 * @return javax.swing.JPanel
865 */
866 private JPanel getJPanel7() {
867 if (jPanel7 == null) {
868 jLabel4 = new JLabel();
869 jLabel4.setText("Instance Description");
870 jLabel3 = new JLabel();
871 jLabel3.setText("Selected Instances");
872 jPanel7 = new JPanel();
873 jPanel7.add(jLabel4, null);
874 jPanel7.add(getJScrollPane5(), null);
875 jPanel7.add(getJButton(), null);
876 jPanel7.add(getJButton1(), null);
877 jPanel7.add(jLabel3, null);
878 jPanel7.add(getJScrollPane2(), null);
879 }
880 return jPanel7;
881 }
882
883 /**
884 * This method initializes jScrollPane5
885 *
886 * @return javax.swing.JScrollPane
887 */
888 private JScrollPane getJScrollPane5() {
889 if (jScrollPane5 == null) {
890 jScrollPane5 = new JScrollPane();
891 jScrollPane5.setPreferredSize(new java.awt.Dimension(300,50));
892 jScrollPane5.setViewportView(getJTextArea1());
893 }
894 return jScrollPane5;
895 }
896
897 /**
898 * This method initializes jTextArea1
899 *
900 * @return javax.swing.JTextArea
901 */
902 private JTextArea getJTextArea1() {
903 if (jTextArea1 == null) {
904 jTextArea1 = new JTextArea();
905 jTextArea1.setEditable(false);
906 }
907 return jTextArea1;
908 }
909
910 /**
911 * This method initializes jButton
912 *
913 * @return javax.swing.JButton
914 */
915 private JButton getJButton() {
916 if (jButton == null) {
917 jButton = new JButton();
918 jButton.setPreferredSize(new java.awt.Dimension(80,20));
919 jButton.setText("Add");
920 jButton.addActionListener(new java.awt.event.ActionListener() {
921 public void actionPerformed(java.awt.event.ActionEvent e) {
922 int row = jTable3.getSelectedRow();
923 if (row < 0) {
924 return;
925 }
926 Object[] s = {model3.getValueAt(row, 0), model3.getValueAt(row, 1),
927 model3.getValueAt(row, 2), model3.getValueAt(row, 3),
928 model3.getValueAt(row, 4)};
929 model1.addRow(s);
930 String instanceValue = model3.getValueAt(row, 1) + " " +
931 model3.getValueAt(row, 2) + " " +
932 model3.getValueAt(row, 3) + " " +
933 model3.getValueAt(row, 4);
934 //
935 // Add pcd information of selected instance to current moduleSA
936 //
937 try{
938 ffc.addFrameworkModulesPcdBuildDefs(getModuleId(instanceValue), ffc.getModuleSA(moduleKey));
939 }
940 catch (Exception exception) {
941 JOptionPane.showMessageDialog(frame, "PCD Insertion Fail. " + exception.getMessage());
942 }
943 resolveLibraryInstances(instanceValue);
944 }
945 });
946 }
947 return jButton;
948 }
949
950 /**
951 * This method initializes jButton1
952 *
953 * @return javax.swing.JButton
954 */
955 private JButton getJButton1() {
956 if (jButton1 == null) {
957 jButton1 = new JButton();
958 jButton1.setPreferredSize(new java.awt.Dimension(80,20));
959 jButton1.setText("Delete");
960 jButton1.addActionListener(new java.awt.event.ActionListener() {
961 public void actionPerformed(java.awt.event.ActionEvent e) {
962 int row = jTable1.getSelectedRow();
963 if (row < 0) {
964 return;
965 }
966 removeInstance(model1.getValueAt(row, 1) + " " +
967 model1.getValueAt(row, 2) + " " +
968 model1.getValueAt(row, 3) + " " +
969 model1.getValueAt(row, 4));
970 model1.removeRow(row);
971
972 }
973 });
974 }
975 return jButton1;
976 }
977
978 /**
979 * This method initializes jButton2
980 *
981 * @return javax.swing.JButton
982 */
983 private JButton getJButton2() {
984 if (jButton2 == null) {
985 jButton2 = new JButton();
986 jButton2.setPreferredSize(new java.awt.Dimension(80,20));
987 jButton2.setText("Ok");
988 jButton2.addActionListener(this);
989 }
990 return jButton2;
991 }
992
993 /**
994 * This method initializes jButton3
995 *
996 * @return javax.swing.JButton
997 */
998 private JButton getJButton3() {
999 if (jButton3 == null) {
1000 jButton3 = new JButton();
1001 jButton3.setPreferredSize(new java.awt.Dimension(80,20));
1002 jButton3.setText("Cancel");
1003 jButton3.setVisible(false);
1004 }
1005 return jButton3;
1006 }
1007 public void actionPerformed(ActionEvent arg0) {
1008
1009 if (arg0.getSource() == jButton2) {
1010 ffc.removeLibraryInstances(moduleKey);
1011 for (int i = 0; i < model1.getRowCount(); ++i) {
1012 String mg = model1.getValueAt(i, 1)+"";
1013 String mv = model1.getValueAt(i, 2)+"";
1014 String pg = model1.getValueAt(i, 3)+"";
1015 String pv = model1.getValueAt(i, 4)+"";
1016 ffc.genLibraryInstance(mg, mv, pg, pv, moduleKey);
1017 }
1018 this.setVisible(false);
1019 }
1020 }
1021 /**
1022 * This method initializes jPanel8
1023 *
1024 * @return javax.swing.JPanel
1025 */
1026 private JPanel getJPanel8() {
1027 if (jPanel8 == null) {
1028 jLabel8 = new JLabel();
1029 jLabel8.setText("FFS Format Key");
1030 jLabel7 = new JLabel();
1031 jLabel7.setText("FFS File GUID");
1032 jLabel6 = new JLabel();
1033 jLabel6.setText("FV Binding");
1034 jPanel8 = new JPanel();
1035 jPanel8.add(jLabel6, null);
1036 jPanel8.add(getJTextField(), null);
1037 jPanel8.add(jLabel7, null);
1038 jPanel8.add(getJTextField1(), null);
1039 jPanel8.add(jLabel8, null);
1040 jPanel8.add(getJTextField2(), null);
1041 jPanel8.add(getJScrollPane6(), null);
1042 jPanel8.add(getJButton4(), null);
1043 jPanel8.add(getJButton5(), null);
1044 jPanel8.addComponentListener(new java.awt.event.ComponentAdapter() {
1045 public void componentShown(java.awt.event.ComponentEvent e) {
1046 init(moduleKey);
1047 }
1048 });
1049 }
1050 return jPanel8;
1051 }
1052 /**
1053 * This method initializes jTextField
1054 *
1055 * @return javax.swing.JTextField
1056 */
1057 private JTextField getJTextField() {
1058 if (jTextField == null) {
1059 jTextField = new JTextField();
1060 jTextField.setPreferredSize(new java.awt.Dimension(100,20));
1061 jTextField.addFocusListener(new java.awt.event.FocusAdapter() {
1062 public void focusLost(java.awt.event.FocusEvent e) {
1063 ffc.setFvBinding(moduleKey, jTextField.getText());
1064 }
1065 });
1066 }
1067 return jTextField;
1068 }
1069 /**
1070 * This method initializes jTextField1
1071 *
1072 * @return javax.swing.JTextField
1073 */
1074 private JTextField getJTextField1() {
1075 if (jTextField1 == null) {
1076 jTextField1 = new JTextField();
1077 jTextField1.setPreferredSize(new java.awt.Dimension(100,20));
1078 jTextField1.addFocusListener(new java.awt.event.FocusAdapter() {
1079 public void focusLost(java.awt.event.FocusEvent e) {
1080 ffc.setFfsFileNameGuid(moduleKey, jTextField1.getText());
1081 }
1082 });
1083 }
1084 return jTextField1;
1085 }
1086 /**
1087 * This method initializes jTextField2
1088 *
1089 * @return javax.swing.JTextField
1090 */
1091 private JTextField getJTextField2() {
1092 if (jTextField2 == null) {
1093 jTextField2 = new JTextField();
1094 jTextField2.setPreferredSize(new java.awt.Dimension(100,20));
1095 jTextField2.addFocusListener(new java.awt.event.FocusAdapter() {
1096 public void focusLost(java.awt.event.FocusEvent e) {
1097 ffc.setFfsFormatKey(moduleKey, jTextField2.getText());
1098 }
1099 });
1100 }
1101 return jTextField2;
1102 }
1103 /**
1104 * This method initializes jScrollPane6
1105 *
1106 * @return javax.swing.JScrollPane
1107 */
1108 private JScrollPane getJScrollPane6() {
1109 if (jScrollPane6 == null) {
1110 jScrollPane6 = new JScrollPane();
1111 jScrollPane6.setPreferredSize(new java.awt.Dimension(600,200));
1112 jScrollPane6.setViewportView(getJTable4());
1113 }
1114 return jScrollPane6;
1115 }
1116 /**
1117 * This method initializes jTable4
1118 *
1119 * @return javax.swing.JTable
1120 */
1121 private JTable getJTable4() {
1122 if (jTable4 == null) {
1123 optionsTableModel = new DefaultTableModel();
1124 optionsTableModel.addColumn("BuildTargets");
1125 optionsTableModel.addColumn("ToolChainFamily");
1126 optionsTableModel.addColumn("TagName");
1127 optionsTableModel.addColumn("ToolCode");
1128 optionsTableModel.addColumn("SupportedArchs");
1129 optionsTableModel.addColumn("Contents");
1130 jTable4 = new JTable(optionsTableModel);
1131 jTable4.setRowHeight(20);
1132 Vector<String> vArch = new Vector<String>();
1133 vArch.add("IA32");
1134 vArch.add("X64");
1135 vArch.add("IPF");
1136 vArch.add("EBC");
1137 vArch.add("ARM");
1138 vArch.add("PPC");
1139 jTable4.getColumnModel().getColumn(4).setCellEditor(new ListEditor(vArch));
1140 jTable4.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
1141 jTable4.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
1142 jTable4.getModel().addTableModelListener(new TableModelListener() {
1143 public void tableChanged(TableModelEvent arg0) {
1144 // TODO Auto-generated method stub
1145 int row = arg0.getFirstRow();
1146 TableModel m = (TableModel)arg0.getSource();
1147
1148 if (arg0.getType() == TableModelEvent.UPDATE){
1149 //ToDo Data Validition check.
1150 String targets = m.getValueAt(row, 0) + "";
1151 Vector<Object> targetName = null;
1152 if (targets.length() > 0) {
1153 targetName = new Vector<Object>();
1154 String[] sArray = targets.split(" ");
1155 for (int i = 0; i < sArray.length; ++i) {
1156 targetName.add(sArray[i]);
1157 }
1158 }
1159
1160 String toolChain = m.getValueAt(row, 1) + "";
1161 String tagName = m.getValueAt(row, 2) + "";
1162 String toolCode = m.getValueAt(row, 3) + "";
1163 String archs = m.getValueAt(row, 4) + "";
1164 Vector<Object> supArch = null;
1165 if (archs.length() > 0) {
1166 supArch = new Vector<Object>();
1167 String[] sArray1 = archs.split(" ");
1168 for (int i = 0; i < sArray1.length; ++i) {
1169 supArch.add(sArray1[i]);
1170 }
1171 }
1172
1173 String contents = m.getValueAt(row, 5) + "";
1174
1175 ffc.updateModuleSAOptionsOpt(moduleKey, row, targetName, toolChain, tagName, toolCode, supArch, contents);
1176 }
1177 }
1178 });
1179 }
1180 return jTable4;
1181 }
1182 /**
1183 * This method initializes jButton4
1184 *
1185 * @return javax.swing.JButton
1186 */
1187 private JButton getJButton4() {
1188 if (jButton4 == null) {
1189 jButton4 = new JButton();
1190 jButton4.setPreferredSize(new java.awt.Dimension(80,20));
1191 jButton4.setText("New");
1192 jButton4.addActionListener(new java.awt.event.ActionListener() {
1193 public void actionPerformed(java.awt.event.ActionEvent e) {
1194 String[] row = {"", "", "", "", "IA32", ""};
1195 optionsTableModel.addRow(row);
1196 Vector<Object> v = new Vector<Object>();
1197 Vector<Object> v1 = new Vector<Object>();
1198 v1.add("IA32");
1199 ffc.genModuleSAOptionsOpt(moduleKey, v, "", "", "", v1, "");
1200 }
1201 });
1202 }
1203 return jButton4;
1204 }
1205 /**
1206 * This method initializes jButton5
1207 *
1208 * @return javax.swing.JButton
1209 */
1210 private JButton getJButton5() {
1211 if (jButton5 == null) {
1212 jButton5 = new JButton();
1213 jButton5.setPreferredSize(new java.awt.Dimension(80,20));
1214 jButton5.setText("Delete");
1215 jButton5.addActionListener(new java.awt.event.ActionListener() {
1216 public void actionPerformed(java.awt.event.ActionEvent e) {
1217 if (jTable4.getSelectedRow() < 0) {
1218 return;
1219 }
1220
1221 ffc.removeModuleSAOptionsOpt(moduleKey, jTable4.getSelectedRow());
1222 optionsTableModel.removeRow(jTable4.getSelectedRow());
1223 }
1224 });
1225 }
1226 return jButton5;
1227 }
1228
1229 /**
1230 Start the window at the center of screen
1231
1232 **/
1233 protected void centerWindow(int intWidth, int intHeight) {
1234 Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
1235 this.setLocation((d.width - intWidth) / 2, (d.height - intHeight) / 2);
1236 }
1237
1238 /**
1239 Start the window at the center of screen
1240
1241 **/
1242 protected void centerWindow() {
1243 centerWindow(this.getSize().width, this.getSize().height);
1244 }
1245
1246
1247 } // @jve:decl-index=0:visual-constraint="10,10"
1248
1249 class PartialEditableTableModel extends DefaultTableModel {
1250 /**
1251 *
1252 */
1253 private static final long serialVersionUID = 1L;
1254
1255 public boolean isCellEditable(int row, int col) {
1256 switch (col){
1257 case 2:
1258 return false;
1259 default:
1260 return false;
1261 }
1262
1263 }
1264 }
1265
1266 class LibraryTableModel extends DefaultTableModel {
1267 /**
1268 *
1269 */
1270 private static final long serialVersionUID = 1L;
1271
1272 public boolean isCellEditable(int row, int col) {
1273 return false;
1274 }
1275 }