summaryrefslogtreecommitdiff
path: root/Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdModuleSA.java
blob: d6b13238af13981be568b6af641fb66cdbbbbfe5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
package org.tianocore.frameworkwizard.platform.ui;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;

import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JDialog;
import javax.swing.JTabbedPane;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JSplitPane;
import javax.swing.JButton;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
import javax.swing.table.TableModel;

import org.tianocore.frameworkwizard.FrameworkWizardUI;
import org.tianocore.frameworkwizard.common.DataValidation;
import org.tianocore.frameworkwizard.common.GlobalData;
import org.tianocore.frameworkwizard.common.IDefaultTableModel;
import org.tianocore.frameworkwizard.common.Identifications.OpeningPlatformType;
import org.tianocore.frameworkwizard.platform.ui.global.LibraryClassDescriptor;
import org.tianocore.frameworkwizard.platform.ui.global.WorkspaceProfile;
import org.tianocore.frameworkwizard.platform.ui.global.SurfaceAreaQuery;
import org.tianocore.frameworkwizard.module.Identifications.ModuleIdentification;
import org.tianocore.frameworkwizard.packaging.PackageIdentification;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.ListIterator;
import java.util.Stack;
import java.util.Vector;

import javax.swing.JTextField;
import java.awt.GridLayout;
import javax.swing.JComboBox;

public class FpdModuleSA extends JDialog implements ActionListener {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    private JPanel jContentPane = null;
    private JTabbedPane jTabbedPane = null;
    private JPanel jPanelPcd = null;
    private JPanel jPanelLibrary = null;
    private JLabel jLabelPcdData = null;
    private JScrollPane jScrollPaneTablePcd = null;
    private JTable jTablePcd = null;
    private JPanel jPanelPcdSouth = null;
    private JScrollPane jScrollPanePcdHelp = null;
    private JTextArea jTextAreaPcdHelp = null;
    private JPanel jPanelContentPaneSouth = null;
    private JSplitPane jSplitPane = null;
    private JPanel jPanelLibraryLeft = null;
    private JPanel jPanelLibraryRight = null;
    private JLabel jLabelLibClass = null;
    private JLabel jLabelQualifiedInstance = null;
    private JScrollPane jScrollPaneSelectedInstances = null;
    private JTable jTableSelectedInstances = null;
    private JScrollPane jScrollPaneLibClass = null;
    private JTable jTableLibClass = null;
    private JScrollPane jScrollPaneQualifiedInstance = null;
    private JTable jTableLibInstances = null;
    private JPanel jPanelLibrarySouth = null;
    private JPanel jPanelLibraryCenter = null;
    private JScrollPane jScrollPaneInstanceHelp = null;
    private JTextArea jTextAreaInstanceHelp = null;
    private JLabel jLabelSelectedInstances = null;
    private JLabel jLabelInstanceHelp = null;
    private JButton jButtonAdd = null;
    private JButton jButtonDeleteInstance = null;
    private JLabel jLabelPcdHelp = null;
    private JButton jButtonOk = null;
    private JButton jButtonCancel = null;
    private IDefaultTableModel model = null;
    private IDefaultTableModel selectedInstancesTableModel = null;
    private IDefaultTableModel libClassTableModel = null;
    private IDefaultTableModel libInstanceTableModel = null;
    private DefaultTableModel optionsTableModel = null;
    private FpdFileContents ffc = null;
    private String moduleKey = null;
    private ModuleIdentification moduleId = null;
    private int moduleSaNum = -1;
    private HashMap<LibraryClassDescriptor, ArrayList<String>> classInstanceMap = null;
    //
    // map of <{libName, supArch, supMod}, list of Module information>
    //
    private HashMap<LibraryClassDescriptor, ArrayList<String>> classConsumed = null;
    private HashMap<LibraryClassDescriptor, ArrayList<String>> classProduced = null;
    
    private JPanel jPanelModuleSaOpts = null;
    private JLabel jLabelFvBinding = null;
    private JTextField jTextFieldFvBinding = null;
    private JLabel jLabelFfsFileGuid = null;
    private JTextField jTextFieldFileGuid = null;
    private JLabel jLabelFfsFormatKey = null;
    private JTextField jTextFieldFfsKey = null;
    private JScrollPane jScrollPaneModuleSaOptions = null;
    private JTable jTableModuleSaOptions = null;
    private JButton jButtonNew = null;
    private JButton jButtonDeleteOption = null;
    private JPanel jPanelPcdFields = null;
    private JPanel jPanelPcdFieldsSecondRow = null;
    private JPanel jPanelPcdFieldsThirdRow = null;
    private JPanel jPanelPcdFieldsFirstRow = null;
    private JLabel jLabelItemType = null;
    private JComboBox jComboBoxItemType = null;
    private JLabel jLabelMaxDatumSize = null;
    private JTextField jTextFieldMaxDatumSize = null;
    private JLabel jLabelPcdDefaultValue = null;
    private JTextField jTextFieldPcdDefault = null;
    private JButton jButtonUpdatePcd = null;
    private JComboBox jComboBoxFeatureFlagValue = null;
    private OpeningPlatformType docConsole = null;
    private JPanel jPanelCustomToolChain = null;
    private JPanel jPanelToolchainS = null;
    private JPanel jPanelLibraryCenterN = null;
    private JPanel jPanelLibraryCenterC = null;  //  @jve:decl-index=0:visual-constraint="20,224"
    
    private final int buildTargetWidth = 150;
    private final int toolChainFamilyWidth = 150;
    private final int supportArchWidth = 150;
    private final int toolCmdCodeWidth = 200;
    private final int tagNameWidth = 150;
    private final int argWidth = 400;
    
    /**
     * This is the default constructor
     */
    public FpdModuleSA() {
        super(FrameworkWizardUI.getInstance());
        initialize();
    }
    public FpdModuleSA(FpdFileContents ffc) {
        this();
        this.ffc = ffc;
    }
    
    public void setKey(String k, int i, OpeningPlatformType dc){
        this.moduleKey = k;
        moduleSaNum = i;
        this.docConsole = dc;
        classInstanceMap = null;
        classProduced = null;
        classConsumed = null;
        jTabbedPane.setSelectedIndex(0);
        initPcdBuildDefinition(i);
        moduleId = WorkspaceProfile.getModuleId(moduleKey);
        if (moduleId == null) {
            return;
        }
        int tabIndex = jTabbedPane.indexOfTab("Libraries");
        if (moduleId.isLibrary()) {
            jTabbedPane.setEnabledAt(tabIndex, false);
        }
        else {
            jTabbedPane.setEnabledAt(tabIndex, true);
        }
    }

    /**
      init will be called each time FpdModuleSA object is to be shown.
      @param key Module information.
     **/
    public void initPcdBuildDefinition(int i) {
        //
        // display pcd for key.
        //
        model.setRowCount(0);
        jTextAreaPcdHelp.setText("");
        jComboBoxItemType.setSelectedIndex(-1);
        jTextFieldMaxDatumSize.setText("");
        jTextFieldPcdDefault.setText("");
        int pcdCount = ffc.getPcdDataCount(i);
        if (pcdCount != 0) {
            String[][] saa = new String[pcdCount][7];
            ffc.getPcdData(i, saa);
            for (int j = 0; j < saa.length; ++j) {
                model.addRow(saa[j]);
            }
        }
    }
    
    public void initLibraries(String key) {
        libClassTableModel.setRowCount(0);
        libInstanceTableModel.setRowCount(0);
        selectedInstancesTableModel.setRowCount(0);
        Vector<String> errorMsg = new Vector<String>();
        try {
            //
            // display library classes that need to be resolved. also potential instances for them.
            //
            resolveLibraryInstances(moduleKey, true, errorMsg);
        } catch (Exception e) {
            String exceptionMsg = e.getCause() + " " + e.getMessage();
            errorMsg.add(exceptionMsg);
            JOptionPane.showMessageDialog(FrameworkWizardUI.getInstance(), exceptionMsg);
        }
        //
        // display lib instances already selected for key
        //
        
        int instanceCount = ffc.getLibraryInstancesCount(key);
        if (instanceCount != 0) {
            String[][] saa = new String[instanceCount][5];
            ffc.getLibraryInstances(key, saa);
            for (int i = 0; i < saa.length; ++i) {
                ModuleIdentification mi = WorkspaceProfile.getModuleId(saa[i][1] + " " + saa[i][2] + " " + saa[i][3]
                                                                       + " " + saa[i][4]);
                if (mi != null) {
                    //
                    // ToDo: verify this instance first.
                    //
                    saa[i][0] = mi.getName();
                    saa[i][2] = mi.getVersion();
                    saa[i][4] = mi.getPackageId().getVersion();
                    //
                    // re-evaluate lib instance usage when adding a already-selected lib instance.
                    //
                    try {
                        resolveLibraryInstances(saa[i][1] + " " + saa[i][2] + " " + saa[i][3] + " " + saa[i][4], true, errorMsg);
                    } catch (Exception e) {
                        String exceptionMsg = e.getCause() + " " + e.getMessage();
                        if (!errorMsg.contains(exceptionMsg)) {
                            JOptionPane.showMessageDialog(FrameworkWizardUI.getInstance(), e.getCause() + " " + e.getMessage());
                        }
                    }
                    selectedInstancesTableModel.addRow(saa[i]);
                }
            }
        }

        if (errorMsg.size() > 0) {
            String errors = "";
            for (int i = 0; i < errorMsg.size(); ++i) {
                errors += " " + errorMsg.get(i) + "\n";
            }
            JOptionPane.showMessageDialog(FrameworkWizardUI.getInstance(), errors);
        }
    }
    
    public void initFvInfo (String key) {
        //
        // display module SA options
        //
        jTextFieldFvBinding.setText("");
        String fvBinding = ffc.getFvBinding(key);
        if (fvBinding != null) {
            jTextFieldFvBinding.setText(fvBinding);
        }
        jTextFieldFileGuid.setText("");
        String fileGuid = ffc.getFfsFileNameGuid(key);
        if (fileGuid != null) {
            jTextFieldFileGuid.setText(fileGuid);
        }
        jTextFieldFfsKey.setText("");
        String ffsKey = ffc.getFfsFormatKey(key);
        if (ffsKey != null) {
            jTextFieldFfsKey.setText(ffsKey);
        }
    }
    
    public void initToolChainOptions(String key) {
        
        optionsTableModel.setRowCount(0);
        String[][] saa = new String[ffc.getModuleSAOptionsCount(key)][6];
        ffc.getModuleSAOptions(key, saa);
        for (int i = 0; i < saa.length; ++i) {
            optionsTableModel.addRow(saa[i]);
        }
    }
    
    private void filterClassConsumedByArch (Vector<LibraryClassDescriptor> v) {
        String[] moduleInfo = moduleKey.split(" ");
        Vector<String> vModuleArchs = new Vector<String>();
        //
        // Skip guid, version information, get archs to check.
        //
        for (int i = 4; i < moduleInfo.length; ++i) {
            vModuleArchs.add(moduleInfo[i]);
        }
        //
        // if module will be built on all platforms, no filter needed for lib classes.
        //
        if (vModuleArchs.size() == 0) {
            return;
        }
        
        Iterator<LibraryClassDescriptor> iter = v.iterator();
        while (iter.hasNext()) {
            LibraryClassDescriptor libInfo = iter.next();

            Vector<String> vSupArchs = libInfo.getVectorFromString(libInfo.supArchs);
            
            if (vSupArchs.size() == 0 || (vSupArchs.size() == 1 && vSupArchs.get(0).equalsIgnoreCase(""))) {
                //
                // update lib info to module archs only.
                //
                libInfo.supArchs = "";
                for (int i = 0; i < vModuleArchs.size(); ++i) {
                    libInfo.supArchs += vModuleArchs.get(i);
                    libInfo.supArchs += " ";
                }
                libInfo.supArchs.trim();
                continue;
            }
            //
            // only retain those lib class used by module archs.
            //
            vSupArchs.retainAll(vModuleArchs);
            if (vSupArchs.size() > 0) {
                //
                // update lib info to reflect which kind of arch need to select instance.
                //
                libInfo.supArchs = "";
                for (int i = 0; i < vSupArchs.size(); ++i) {
                    libInfo.supArchs += vSupArchs.get(i);
                    libInfo.supArchs += " ";
                }
                libInfo.supArchs.trim();
                continue;
            }
            //
            // remove this lib definition if it supports no archs module will be built under.
            //
            iter.remove();
        }
    }
    
    private void addProducedClassFromModule (String key) {
        ModuleIdentification mi = WorkspaceProfile.getModuleId(key);
        Vector<LibraryClassDescriptor> vClassProduced = SurfaceAreaQuery.getLibraryClasses("ALWAYS_PRODUCED", mi);
        if (this.classProduced == null) {
            this.classProduced = new HashMap<LibraryClassDescriptor, ArrayList<String>>();
        }
        for (int i = 0; i < vClassProduced.size(); ++i) {
            ArrayList<String> producedBy = this.classProduced.get(vClassProduced.get(i));
            if (producedBy == null) {
                producedBy = new ArrayList<String>();
            }
            //
            // class already produced by previous module (lib instance).
            /*
            if (producedBy.size() == 1) {
                String instanceKey = producedBy.get(0);
                ModuleIdentification libMi = WorkspaceProfile.getModuleId(instanceKey);
                throw new MultipleInstanceException (vClassProduced.get(i).className, libMi.getName(), mi.getName());
            }
            Iterator<LibraryClassDescriptor> lcdi = this.classProduced.keySet().iterator();
            while (lcdi.hasNext()) {
                LibraryClassDescriptor lcd = lcdi.next();
                if (vClassProduced.get(i).hasInterSectionWith(lcd)) {
                    ArrayList<String> alreadyProducedBy = this.classProduced.get(lcd);
                    String instanceKey = alreadyProducedBy.get(0);
                    ModuleIdentification libMi = WorkspaceProfile.getModuleId(instanceKey);
                    throw new MultipleInstanceException (vClassProduced.get(i).className, libMi.getName(), mi.getName());
                }
            }
            */
            // normal case.
            //
            producedBy.add(key);
            this.classProduced.put(vClassProduced.get(i), producedBy);
            
        }
    }
    
    private Vector<LibraryClassDescriptor> addConsumedClassFromModule (String key) {
        ModuleIdentification mi = WorkspaceProfile.getModuleId(key);
//        PackageIdentification[] depPkgList = null;

        //
        // Get dependency pkg list into which we will search lib instances.
        //
        //depPkgList = SurfaceAreaQuery.getDependencePkg(null, mi);
        //
        // Get the lib class consumed, produced by this module itself.
        //
        Vector<LibraryClassDescriptor> vClassConsumed = SurfaceAreaQuery.getLibraryClasses("ALWAYS_CONSUMED", mi);
        for (int i = 0; i < vClassConsumed.size(); ++i) {
            vClassConsumed.get(i).supModTypes = WorkspaceProfile.getModuleType(moduleId);
        }
        filterClassConsumedByArch(vClassConsumed);
        if (this.classConsumed == null) {
            this.classConsumed = new HashMap<LibraryClassDescriptor, ArrayList<String>>();
        }

        for (int i = 0; i < vClassConsumed.size(); ++i) {
            ArrayList<String> consumedBy = this.classConsumed.get(vClassConsumed.get(i));
            if (consumedBy == null) {
                consumedBy = new ArrayList<String>();
            }
            consumedBy.add(key);
            this.classConsumed.put(vClassConsumed.get(i), consumedBy);
        }

        return vClassConsumed;
    }
    
    private void resolveLibraryInstances(String key, boolean autoSelectSingleInstance, Vector<String> errorMsg) throws MultipleInstanceException, NoInstanceException{
                
        Vector<LibraryClassDescriptor> vLcd = addConsumedClassFromModule (key);
        addProducedClassFromModule (key);
        
        Stack<LibraryClassDescriptor> lcdStack = new Stack<LibraryClassDescriptor>();
        for (int i = 0; i < vLcd.size(); ++i) {
            LibraryClassDescriptor cls = vLcd.get(i);
            lcdStack.push(cls);
        }
        
        if (classInstanceMap == null) {
            classInstanceMap = new HashMap<LibraryClassDescriptor, ArrayList<String>>();
        }
        while (!lcdStack.empty()) {
            LibraryClassDescriptor cls = lcdStack.pop();
            if (isBoundedClass(cls, errorMsg)) {
                continue;
            }
            ArrayList<String> instances = getInstancesForClass(cls, null);
            if (instances.size() == 0) {
//                throw new NoInstanceException (cls.className);
                String exceptionMsg = new NoInstanceException (cls.className).getMessage();
                if (!errorMsg.contains(exceptionMsg)) {
                    errorMsg.add(exceptionMsg);    
                }
                
            }
            classInstanceMap.put(cls, instances);
            if (instances.size() == 1 && autoSelectSingleInstance) {
                String instanceInfo = instances.get(0);
                ModuleIdentification libMi = WorkspaceProfile.getModuleId(instanceInfo);
                try {
                    Object[] row = {libMi.getName(), libMi.getGuid(), libMi.getVersion(), 
                                    libMi.getPackageId().getGuid(), libMi.getPackageId().getVersion()};
                    if (!ffc.instanceExistsInModuleSA(moduleKey, row[1]+"", row[2]+"", row[3]+"", row[4]+"")) {
                        addLibInstance(libMi);
                        docConsole.setSaved(false);
                        selectedInstancesTableModel.addRow(row);
                        addProducedClassFromModule (instanceInfo);
                        vLcd = addConsumedClassFromModule(instanceInfo);
                        for (int i = 0; i < vLcd.size(); ++i) {
                            LibraryClassDescriptor lcd = vLcd.get(i);
                            lcdStack.push(lcd);
                        }
                    }
                }
                catch (Exception e) {
                    if (!errorMsg.contains(e.getMessage())) {
                        errorMsg.add(e.getMessage());
                    }
                }
            }
        }

        showClassToResolved();
        }
//            

    /**Search classProduced map to see if this class has been produced by some instance (module).
     * @param cls
     * @return
     */
    private boolean isBoundedClass (LibraryClassDescriptor cls, Vector<String> errorMsg) {
//        if (this.classProduced.containsKey(cls)) {
//            return true;
//        }
        Iterator<LibraryClassDescriptor> lcdi = this.classProduced.keySet().iterator();
        while (lcdi.hasNext()) {
            LibraryClassDescriptor lcd = lcdi.next();
            if (cls.className.equals(lcd.className)) {
                if (cls.isSubSetByArchs(lcd) && cls.isSubSetByModTypes(lcd)) {
                    return true;
                }
                else {
                    ArrayList<String> producedBy = this.classProduced.get(lcd);
                    String instancesName = "";
                    for (int i = 0; i < producedBy.size(); ++i) {
                        ModuleIdentification mi = WorkspaceProfile.getModuleId(producedBy.get(i));
                        instancesName += mi.getName();
                        instancesName += " ";
                    }
                    String msg = new ImproperInstanceException(lcd.className, instancesName, lcd.supArchs, lcd.supModTypes).getMessage();
                    if (!errorMsg.contains(msg)) {
                        errorMsg.add(msg);
                    }
                }
            }
        }
        
        return false;
    }
    
    private ArrayList<String> getInstancesForClass(LibraryClassDescriptor cls, PackageIdentification[] depPkgList){
        ArrayList<String> al = new ArrayList<String>();
        
//        for (int i = 0; i < depPkgList.length; ++i) {
            Iterator ismi = GlobalData.vModuleList.iterator();
            while(ismi.hasNext()) {
                ModuleIdentification mi = (ModuleIdentification)ismi.next();
//                if (!mi.getPackageId().getGuid().equalsIgnoreCase(depPkgList[i].getGuid())) {
//                    continue;
//                }
                Vector<LibraryClassDescriptor> clsProduced = SurfaceAreaQuery.getLibraryClasses("ALWAYS_PRODUCED", mi);
                
                boolean isPotential = false;
                Iterator<LibraryClassDescriptor> lcdi = clsProduced.iterator();
                while (lcdi.hasNext()) {
                    LibraryClassDescriptor lcd = lcdi.next();
                    if (cls.isSubSetByArchs(lcd) && cls.isSubSetByModTypes(lcd)){
                        isPotential = true;
                    }
                    
                    if (isPotential && hasBeenProduced(lcd)) {
                        isPotential = false;
                        break;
                    }
                }
                if (isPotential) {
                    al.add(mi.getGuid() + " " + mi.getVersion() + " " + 
                           mi.getPackageId().getGuid() + " " + mi.getPackageId().getVersion());
                }
            }
//        }
        
        return al;
    }
    
    private boolean hasBeenProduced (LibraryClassDescriptor cls) {
        Iterator<LibraryClassDescriptor> lcdi = this.classProduced.keySet().iterator();
        while (lcdi.hasNext()) {
            LibraryClassDescriptor lcd = lcdi.next();
            if (cls.isSubSetByArchs(lcd) && cls.isSubSetByModTypes(lcd)) {
                return true;
            }
        }
        return false;
    }
    
    private ArrayList<String> getConsumedBy (String className) {
        Iterator<LibraryClassDescriptor> lcdi = this.classConsumed.keySet().iterator();
        while (lcdi.hasNext()) {
            LibraryClassDescriptor lcd = lcdi.next();
            if ((lcd.className != null) && lcd.className.equals(className)) {
                return this.classConsumed.get(lcd);
            }
        }
        return null;
    }
    
    private void removeInstance(String key) {
        ModuleIdentification mi = WorkspaceProfile.getModuleId(key); 
        //
        // remove pcd information of instance from current ModuleSA
        //
        ffc.removePcdData(moduleKey, mi);
        //
        // remove class produced by this instance and add back these produced class to be bound.
        //
        Vector<LibraryClassDescriptor> clsProduced = getClassProduced(mi);
        for (int i = 0; i < clsProduced.size(); ++i) {
            
            classProduced.remove(clsProduced.get(i));
        }
        //
        // remove class consumed by this instance. we do not need to bound it now.
        //
        String[] clsConsumed = getClassConsumed(mi);
        for (int i = 0; i < clsConsumed.length; ++i) {
            ArrayList<String> al = getConsumedBy (clsConsumed[i]);
            
            if (al == null ) {
                continue;
            }
            al.remove(key);
            
        }
        
        showClassToResolved();
        
    }
    
    
    private Vector<LibraryClassDescriptor> getClassProduced(ModuleIdentification mi){
        
        Vector<LibraryClassDescriptor> clsProduced = SurfaceAreaQuery.getLibraryClasses("ALWAYS_PRODUCED", mi);
        return clsProduced;
//        String[] sClassProduced = new String[clsProduced.size()];
//        for (int i = 0; i < clsProduced.size(); ++i) {
//            sClassProduced[i] = clsProduced.get(i).className;
//        }
//        return sClassProduced;
    }
    
    private String[] getClassConsumed(ModuleIdentification mi){
        
        Vector<LibraryClassDescriptor> clsConsumed = SurfaceAreaQuery.getLibraryClasses("ALWAYS_CONSUMED", mi);
        String[] sClassConsumed = new String[clsConsumed.size()];
        for (int i = 0; i < clsConsumed.size(); ++i) {
            sClassConsumed[i] = clsConsumed.get(i).className;
        }
        return sClassConsumed;
    }
    
    private void showClassToResolved(){
        Vector<String> errorMsg = new Vector<String>();
        libClassTableModel.setRowCount(0);
        libInstanceTableModel.setRowCount(0);
        if (classConsumed == null || classConsumed.size() == 0) {
            return;
        }

        Iterator<LibraryClassDescriptor> li = classConsumed.keySet().iterator();
        while(li.hasNext()){
            LibraryClassDescriptor lcd = li.next();
            if (classConsumed.get(lcd) == null || classConsumed.get(lcd).size() == 0) {
                continue;
            }
            
            if (!isBoundedClass(lcd, errorMsg)){
     
                String[] s = { lcd.className, lcd.supArchs, lcd.supModTypes };
                libClassTableModel.addRow(s);
            }
        }
        
        if (errorMsg.size() > 0) {
            String errors = "";
            for (int i = 0; i < errorMsg.size(); ++i) {
                errors += " " + errorMsg.get(i) + "\n";
            }
            JOptionPane.showMessageDialog(FrameworkWizardUI.getInstance(), errors);
        }
    }
    
    private String getModuleArch () {
    	String arch = "";
    	String[] moduleInfo = moduleKey.split(" ");
    	for (int i = 4; i < moduleInfo.length; ++i) {
    		arch += moduleInfo[i];
    		arch += " ";
    	}
    	return arch.trim();
    }
    private void addLibInstance (ModuleIdentification libMi) throws Exception{
        
        //
        // Add pcd information of selected instance to current moduleSA
        //
        ffc.addFrameworkModulesPcdBuildDefs(libMi, getModuleArch(), ffc.getModuleSA(moduleKey));
        
        ffc.genLibraryInstance(libMi, moduleKey);
    }
    /**
     * This method initializes this
     * 
     * @return void
     */
    private void initialize() {
        this.setSize(877, 555);
        this.setResizable(false);
        this.centerWindow();
        this.setModal(true);
        this.setTitle("Module Settings");
        this.setContentPane(getJContentPane());
    }

    /**
     * This method initializes jContentPane
     * 
     * @return javax.swing.JPanel
     */
    private JPanel getJContentPane() {
        if (jContentPane == null) {
            jContentPane = new JPanel();
            jContentPane.setLayout(new BorderLayout());
            jContentPane.add(getJTabbedPane(), java.awt.BorderLayout.CENTER);
            jContentPane.add(getJPanelContentPaneSouth(), java.awt.BorderLayout.SOUTH);
        }
        return jContentPane;
    }

    /**
     * This method initializes jTabbedPane	
     * 	
     * @return javax.swing.JTabbedPane	
     */
    private JTabbedPane getJTabbedPane() {
        if (jTabbedPane == null) {
            jTabbedPane = new JTabbedPane();
            jTabbedPane.addTab("PCD Build Definition", null, getJPanelPcd(), null);
            jTabbedPane.addTab("Libraries", null, getJPanelLibrary(), null);
            jTabbedPane.addTab("FV Info", null, getJPanelModuleSaOpts(), null);
            jTabbedPane.addTab("Custom Toolchain", null, getJPanelCustomToolChain(), null);
            
        }
        return jTabbedPane;
    }

    /**
     * This method initializes jPanelPcd
     * 	
     * @return javax.swing.JPanel	
     */
    private JPanel getJPanelPcd() {
        if (jPanelPcd == null) {
            jLabelPcdData = new JLabel();
            jLabelPcdData.setText(" PCD Data");
            jPanelPcd = new JPanel();
            jPanelPcd.setLayout(new BorderLayout());
            jPanelPcd.add(jLabelPcdData, java.awt.BorderLayout.NORTH);
            jPanelPcd.add(getJScrollPaneTablePcd(), java.awt.BorderLayout.CENTER);
            jPanelPcd.add(getJPanelPcdSouth(), java.awt.BorderLayout.SOUTH);
            jPanelPcd.addComponentListener(new java.awt.event.ComponentAdapter() {
                public void componentShown(java.awt.event.ComponentEvent e) {
                    initPcdBuildDefinition(moduleSaNum);
                }
            });
            
        }
        return jPanelPcd;
    }

    /**
     * This method initializes jPanelLibrary
     * 	
     * @return javax.swing.JPanel	
     */
    private JPanel getJPanelLibrary() {
        if (jPanelLibrary == null) {
            jPanelLibrary = new JPanel();
            jPanelLibrary.setLayout(new BorderLayout());
            jPanelLibrary.add(getJSplitPane(), java.awt.BorderLayout.NORTH);
            jPanelLibrary.add(getJPanelLibrarySouth(), java.awt.BorderLayout.SOUTH);
            jPanelLibrary.add(getJPanelLibraryCenter(), java.awt.BorderLayout.CENTER);
            jPanelLibrary.addComponentListener(new java.awt.event.ComponentAdapter() {
                public void componentShown(java.awt.event.ComponentEvent e) {
                    initLibraries(moduleKey);
                }
            });
        }
        return jPanelLibrary;
    }

    /**
     * This method initializes jScrollPaneTablePcd
     * 	
     * @return javax.swing.JScrollPane	
     */
    private JScrollPane getJScrollPaneTablePcd() {
        if (jScrollPaneTablePcd == null) {
            jScrollPaneTablePcd = new JScrollPane();
            jScrollPaneTablePcd.setViewportView(getJTablePcd());
        }
        return jScrollPaneTablePcd;
    }

    /**
     * This method initializes jTable	
     * 	
     * @return javax.swing.JTable	
     */
    private JTable getJTablePcd() {
        if (jTablePcd == null) {
            model = new IDefaultTableModel();
            jTablePcd = new JTable(model);
            jTablePcd.setRowHeight(20);
            jTablePcd.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_ALL_COLUMNS);
            model.addColumn("CName");
            model.addColumn("TokenSpaceGUID");
            model.addColumn("ItemType");
            model.addColumn("Token");
            model.addColumn("MaxDatumSize");
            model.addColumn("DataType");
            model.addColumn("DefaultValue");
            
            jTablePcd.getColumnModel().getColumn(0).setMinWidth(250);
            
            TableColumn tokenColumn = jTablePcd.getColumnModel().getColumn(3);
            jTablePcd.removeColumn(tokenColumn);
                        
            jTablePcd.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            jTablePcd.getSelectionModel().addListSelectionListener(new ListSelectionListener(){
                public void valueChanged(ListSelectionEvent e) {
                    
                    if (e.getValueIsAdjusting()){
                        return;
                    }
                    ListSelectionModel lsm = (ListSelectionModel)e.getSource();
                    if (lsm.isSelectionEmpty()) {
                        return;
                    }
                    else{
                        int selectedRow = lsm.getMinSelectionIndex();
                        String cName = model.getValueAt(selectedRow, 0)+"";
                        String tsGuid = model.getValueAt(selectedRow, 1)+"";
                        String itemType = model.getValueAt(selectedRow, 2)+"";
                        //
                        // array for pcd related information: helpText, itemType, moduleType.
                        //
                        String[] pcdInfo = {"", "", ""};
                        Vector<String> validPcdTypes = new Vector<String>();
                        getPcdInfo(moduleKey, cName, tsGuid, pcdInfo, validPcdTypes);
                        jTextAreaPcdHelp.setText(pcdInfo[0]);
                        initComboBox(pcdInfo[1], pcdInfo[2], validPcdTypes);
                        jComboBoxItemType.setSelectedItem(itemType);
                        jTextFieldMaxDatumSize.setEnabled(true);
                        jTextFieldMaxDatumSize.setVisible(true);
                        jTextFieldMaxDatumSize.setText(model.getValueAt(selectedRow, 4)+"");
                        jTextFieldPcdDefault.setEnabled(true);
                        jTextFieldPcdDefault.setText(model.getValueAt(selectedRow, 6)+"");
                        if ((model.getValueAt(selectedRow, 5) != null) && model.getValueAt(selectedRow, 5).equals("VOID*")) {
                            if (pcdInfo[1].equals("FEATURE_FLAG")) {
                                jTextFieldMaxDatumSize.setVisible(false);
                            }
                            else if (pcdInfo[1].equals("FIXED_AT_BUILD")) {
                                try{
                                    jTextFieldMaxDatumSize.setEnabled(false);
                                    jTextFieldMaxDatumSize.setText(ffc.setMaxSizeForPointer(model.getValueAt(selectedRow, 6)+"")+"");
                                }
                                catch(Exception except){
                                    JOptionPane.showMessageDialog(FpdModuleSA.this, "Unacceptable PCD Value: " + except.getMessage());
                                }
                            }
                            else{
                                jTextFieldMaxDatumSize.setText(model.getValueAt(selectedRow, 4)+"");
                            }
                        }
                        else {
                            jTextFieldMaxDatumSize.setEnabled(false);
                        }
                        
                        if (!model.getValueAt(selectedRow, 2).equals("DYNAMIC") && !model.getValueAt(selectedRow, 2).equals("DYNAMIC_EX")) {
                            jTextFieldPcdDefault.setText(model.getValueAt(selectedRow, 6)+"");
                            if (model.getValueAt(selectedRow, 2).equals("FEATURE_FLAG")){
                                jTextFieldPcdDefault.setVisible(false);
                                jComboBoxFeatureFlagValue.setVisible(true);
                                jComboBoxFeatureFlagValue.setSelectedItem(model.getValueAt(selectedRow, 6)+"");
                            }
                            else{
                                jTextFieldPcdDefault.setVisible(true);
                                jTextFieldPcdDefault.setEnabled(true);
                                jComboBoxFeatureFlagValue.setVisible(false);
                            }
                        }
                        else{
                            jTextFieldPcdDefault.setEnabled(false);
                        }
                    }
                    
                    
                }
            });
            
        }
        return jTablePcd;
    }
    
    private void initComboBox(String originalType, String mType, Vector<String> validPcdTypes) {
        jComboBoxItemType.removeAllItems();

        if (originalType.equals("DYNAMIC")) {
            for (int i = 0; i < validPcdTypes.size(); ++i) {
                jComboBoxItemType.addItem(validPcdTypes.get(i));
            }
        }
        else {
            jComboBoxItemType.addItem(originalType);
        }
    }
    
    /**
     * @param cName
     * @param tsGuid
     * @param sa sa[0]: HelpText; sa[1]: itemType in Msa; sa[2]: isBinary;
     */
    private void getPcdInfo(String moduleKey, String cName, String tsGuid, String[] sa, Vector<String> validPcdTypes) {
        String[][] saa = new String[ffc.getLibraryInstancesCount(moduleKey)][5];
        ffc.getLibraryInstances(moduleKey, saa);
        
        try{
            if (ffc.getPcdBuildDataInfo(WorkspaceProfile.getModuleId(moduleKey), cName, tsGuid, sa, validPcdTypes)) {
                return;
            }
            for (int j = 0; j < saa.length; ++j) {
                if (ffc.getPcdBuildDataInfo(WorkspaceProfile.getModuleId(saa[j][1] + " " + saa[j][2] + " " + saa[j][3] + " " + saa[j][4]),
                                            cName, tsGuid, sa, validPcdTypes)) {
                    return;
                }
            }
        }
        catch(Exception e) {
            JOptionPane.showMessageDialog(this, "Get PCD details fail: " + e.getMessage());
        }
    }

    /**
     * This method initializes jPanelPcdSouth
     * 	
     * @return javax.swing.JPanel	
     */
    private JPanel getJPanelPcdSouth() {
        if (jPanelPcdSouth == null) {
            jLabelPcdHelp = new JLabel();
            jLabelPcdHelp.setText("PCD Description");
            jPanelPcdSouth = new JPanel();
            jPanelPcdSouth.setPreferredSize(new java.awt.Dimension(607,200));
            jPanelPcdSouth.add(jLabelPcdHelp, null);
            jPanelPcdSouth.add(getJScrollPanePcdHelp(), null);
            jPanelPcdSouth.add(getJPanelPcdFields(), null);
        }
        return jPanelPcdSouth;
    }

    /**
     * This method initializes jScrollPanePcdHelp
     * 	
     * @return javax.swing.JScrollPane	
     */
    private JScrollPane getJScrollPanePcdHelp() {
        if (jScrollPanePcdHelp == null) {
            jScrollPanePcdHelp = new JScrollPane();
            jScrollPanePcdHelp.setPreferredSize(new java.awt.Dimension(500,100));
            jScrollPanePcdHelp.setViewportView(getJTextAreaPcdHelp());
        }
        return jScrollPanePcdHelp;
    }

    /**
     * This method initializes jTextAreaPcdHelp
     * 	
     * @return javax.swing.JTextArea	
     */
    private JTextArea getJTextAreaPcdHelp() {
        if (jTextAreaPcdHelp == null) {
            jTextAreaPcdHelp = new JTextArea();
            jTextAreaPcdHelp.setEditable(false);
        }
        return jTextAreaPcdHelp;
    }

    /**
     * This method initializes jPanelContentPaneSouth
     * 	
     * @return javax.swing.JPanel	
     */
    private JPanel getJPanelContentPaneSouth() {
        if (jPanelContentPaneSouth == null) {
            FlowLayout flowLayout = new FlowLayout();
            flowLayout.setAlignment(java.awt.FlowLayout.RIGHT);
            jPanelContentPaneSouth = new JPanel();
            jPanelContentPaneSouth.setLayout(flowLayout);
            jPanelContentPaneSouth.add(getJButtonOk(), null);
            jPanelContentPaneSouth.add(getJButtonCancel(), null);
        }
        return jPanelContentPaneSouth;
    }

    /**
     * This method initializes jSplitPane	
     * 	
     * @return javax.swing.JSplitPane	
     */
    private JSplitPane getJSplitPane() {
        if (jSplitPane == null) {
            jSplitPane = new JSplitPane();
            jSplitPane.setDividerLocation(200);
            jSplitPane.setLeftComponent(getJPanelLibraryLeft());
            jSplitPane.setRightComponent(getJPanelLibraryRight());
            jSplitPane.setPreferredSize(new java.awt.Dimension(202,200));
        }
        return jSplitPane;
    }

    /**
     * This method initializes jPanelLibraryLeft
     * 	
     * @return javax.swing.JPanel	
     */
    private JPanel getJPanelLibraryLeft() {
        if (jPanelLibraryLeft == null) {
            jLabelLibClass = new JLabel();
            jLabelLibClass.setText("Library Classes Uninstantiated");
            jPanelLibraryLeft = new JPanel();
            jPanelLibraryLeft.add(jLabelLibClass, null);
            jPanelLibraryLeft.add(getJScrollPaneLibClass(), null);
        }
        return jPanelLibraryLeft;
    }

    /**
     * This method initializes jPanelLibraryRight
     * 	
     * @return javax.swing.JPanel	
     */
    private JPanel getJPanelLibraryRight() {
        if (jPanelLibraryRight == null) {
            jLabelQualifiedInstance = new JLabel();
            jLabelQualifiedInstance.setText("Instances Available");
            jPanelLibraryRight = new JPanel();
            jPanelLibraryRight.add(jLabelQualifiedInstance, null);
            jPanelLibraryRight.add(getJScrollPaneQualifiedInstance(), null);
        }
        return jPanelLibraryRight;
    }

    /**
     * This method initializes jScrollPaneSelectedInstances
     * 	
     * @return javax.swing.JScrollPane	
     */
    private JScrollPane getJScrollPaneSelectedInstances() {
        if (jScrollPaneSelectedInstances == null) {
            jScrollPaneSelectedInstances = new JScrollPane();
            jScrollPaneSelectedInstances.setPreferredSize(new java.awt.Dimension(600,150));
            jScrollPaneSelectedInstances.setViewportView(getJTableSelectedInstances());
        }
        return jScrollPaneSelectedInstances;
    }

    /**
     * This method initializes jTableSelectedInstances
     * 	
     * @return javax.swing.JTable	
     */
    private JTable getJTableSelectedInstances() {
        if (jTableSelectedInstances == null) {
            selectedInstancesTableModel = new IDefaultTableModel();
            selectedInstancesTableModel.addColumn("Name");
            selectedInstancesTableModel.addColumn("ModuleGUID");
            selectedInstancesTableModel.addColumn("ModuleVersion");
            selectedInstancesTableModel.addColumn("PackageGUID");
            selectedInstancesTableModel.addColumn("PackageVersion");
            jTableSelectedInstances = new JTable(selectedInstancesTableModel);
            jTableSelectedInstances.setRowHeight(20);
            
            jTableSelectedInstances.getColumnModel().getColumn(0).setMinWidth(250);
            
            jTableSelectedInstances.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
            jTableSelectedInstances.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            
        }
        return jTableSelectedInstances;
    }

    /**
     * This method initializes jScrollPaneLibClass
     * 	
     * @return javax.swing.JScrollPane	
     */
    private JScrollPane getJScrollPaneLibClass() {
        if (jScrollPaneLibClass == null) {
            jScrollPaneLibClass = new JScrollPane();
            jScrollPaneLibClass.setPreferredSize(new java.awt.Dimension(200,170));
            jScrollPaneLibClass.setViewportView(getJTableLibClass());
        }
        return jScrollPaneLibClass;
    }

    /**
     * This method initializes jTableLibClass
     * 	
     * @return javax.swing.JTable	
     */
    private JTable getJTableLibClass() {
        if (jTableLibClass == null) {
            libClassTableModel = new IDefaultTableModel();
            libClassTableModel.addColumn("LibraryClass");
            libClassTableModel.addColumn("Arch");
            libClassTableModel.addColumn("ModType");
            jTableLibClass = new JTable(libClassTableModel);
            jTableLibClass.setRowHeight(20);
            jTableLibClass.setShowGrid(false);
            jTableLibClass.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            
            TableColumn column = jTableLibClass.getColumnModel().getColumn(1);
            jTableLibClass.getColumnModel().removeColumn(column);
            column = jTableLibClass.getColumnModel().getColumn(1);
            jTableLibClass.getColumnModel().removeColumn(column);
            
            jTableLibClass.getSelectionModel().addListSelectionListener(new ListSelectionListener(){
                public void valueChanged(ListSelectionEvent e) {
                    if (e.getValueIsAdjusting()){
                        return;
                    }
                    ListSelectionModel lsm = (ListSelectionModel)e.getSource();
                    if (lsm.isSelectionEmpty()) {
                        return;
                    }
                    else{
                        int selectedRow2 = lsm.getMinSelectionIndex();
                        if (selectedRow2 < 0) {
                            return;
                        }
                        //
                        // display potential lib instances according to class selection
                        //
                        libInstanceTableModel.setRowCount(0);
                        String cls = libClassTableModel.getValueAt(selectedRow2, 0).toString();
                        String arch = libClassTableModel.getValueAt(selectedRow2, 1).toString();
                        String modType = libClassTableModel.getValueAt(selectedRow2, 2).toString();
                        ArrayList<String> al = classInstanceMap.get(new LibraryClassDescriptor(cls, arch, modType));
                        if (al == null) {
                            return;
                        }
                        ListIterator<String> li = al.listIterator();
                        while(li.hasNext()) {
                            String instance = li.next();
                            String[] s = {"", "", "", "", ""};
                            if (WorkspaceProfile.getModuleId(instance) != null) {
                                s[0] = WorkspaceProfile.getModuleId(instance).getName();
                            }
                            
                            String[] instancePart = instance.split(" ");
                            for (int i = 0; i < instancePart.length; ++i){
                                s[i+1] = instancePart[i];
                            }
                            libInstanceTableModel.addRow(s);
                        }
                        
                    }
                }
            });
        }
        return jTableLibClass;
    }

    /**
     * This method initializes jScrollPaneQualifiedInstance
     * 	
     * @return javax.swing.JScrollPane	
     */
    private JScrollPane getJScrollPaneQualifiedInstance() {
        if (jScrollPaneQualifiedInstance == null) {
            jScrollPaneQualifiedInstance = new JScrollPane();
            jScrollPaneQualifiedInstance.setPreferredSize(new java.awt.Dimension(600,170));
            jScrollPaneQualifiedInstance.setViewportView(getJTableLibInstances());
        }
        return jScrollPaneQualifiedInstance;
    }

    /**
     * This method initializes jTableLibInstances
     * 	
     * @return javax.swing.JTable	
     */
    private JTable getJTableLibInstances() {
        if (jTableLibInstances == null) {
            libInstanceTableModel = new IDefaultTableModel();
            libInstanceTableModel.addColumn("Name");
            libInstanceTableModel.addColumn("ModuleGUID");
            libInstanceTableModel.addColumn("ModuleVersion");
            libInstanceTableModel.addColumn("PackageGUID");
            libInstanceTableModel.addColumn("PackageVersion");
            jTableLibInstances = new JTable(libInstanceTableModel);
            jTableLibInstances.setRowHeight(20);
            
            jTableLibInstances.getColumnModel().getColumn(0).setMinWidth(250);
            
            jTableLibInstances.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
            jTableLibInstances.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            
        }
        return jTableLibInstances;
    }

    /**
     * This method initializes jPanelLibrarySouth
     * 	
     * @return javax.swing.JPanel	
     */
    private JPanel getJPanelLibrarySouth() {
        if (jPanelLibrarySouth == null) {
            jPanelLibrarySouth = new JPanel();
        }
        return jPanelLibrarySouth;
    }

    /**
     * This method initializes jPanelLibraryCenter
     * 	
     * @return javax.swing.JPanel	
     */
    private JPanel getJPanelLibraryCenter() {
        if (jPanelLibraryCenter == null) {
            jLabelInstanceHelp = new JLabel();
            jLabelInstanceHelp.setText("Instance Description");
            jLabelSelectedInstances = new JLabel();
            jLabelSelectedInstances.setText("Selected Instances");
            jPanelLibraryCenter = new JPanel();
            jPanelLibraryCenter.setLayout(new BorderLayout());

            jPanelLibraryCenter.add(getJPanelLibraryCenterC(), java.awt.BorderLayout.CENTER);
            jPanelLibraryCenter.add(getJPanelLibraryCenterN(), java.awt.BorderLayout.NORTH);

        }
        return jPanelLibraryCenter;
    }

    /**
     * This method initializes jScrollPaneInstanceHelp
     * 	
     * @return javax.swing.JScrollPane	
     */
    private JScrollPane getJScrollPaneInstanceHelp() {
        if (jScrollPaneInstanceHelp == null) {
            jScrollPaneInstanceHelp = new JScrollPane();
            jScrollPaneInstanceHelp.setPreferredSize(new java.awt.Dimension(400,50));
            jScrollPaneInstanceHelp.setViewportView(getJTextAreaInstanceHelp());
        }
        return jScrollPaneInstanceHelp;
    }

    /**
     * This method initializes jTextAreaInstanceHelp
     * 	
     * @return javax.swing.JTextArea	
     */
    private JTextArea getJTextAreaInstanceHelp() {
        if (jTextAreaInstanceHelp == null) {
            jTextAreaInstanceHelp = new JTextArea();
            jTextAreaInstanceHelp.setEditable(false);
        }
        return jTextAreaInstanceHelp;
    }

    /**
     * This method initializes jButtonAdd
     * 	
     * @return javax.swing.JButton	
     */
    private JButton getJButtonAdd() {
        if (jButtonAdd == null) {
            jButtonAdd = new JButton();
            jButtonAdd.setPreferredSize(new java.awt.Dimension(80,20));
            jButtonAdd.setText("Add");
            jButtonAdd.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent e) {
                    int row = jTableLibInstances.getSelectedRow();
                    if (row < 0) {
                        return;
                    }
                    
                    String instanceValue = libInstanceTableModel.getValueAt(row, 1) + " " +
                    libInstanceTableModel.getValueAt(row, 2) + " " +
                    libInstanceTableModel.getValueAt(row, 3) + " " +
                    libInstanceTableModel.getValueAt(row, 4);
                    ModuleIdentification libMi = WorkspaceProfile.getModuleId(instanceValue);
                    try {
                        addLibInstance (libMi);
                    }
                    catch (Exception exception) {
                        JOptionPane.showMessageDialog(FpdModuleSA.this, "Adding Instance " + libMi.getName() + " : \n"+ exception.getMessage());
                        return;
                    }
                    docConsole.setSaved(false);
                    Object[] s = {libInstanceTableModel.getValueAt(row, 0), libInstanceTableModel.getValueAt(row, 1),
                                  libInstanceTableModel.getValueAt(row, 2), libInstanceTableModel.getValueAt(row, 3),
                                  libInstanceTableModel.getValueAt(row, 4)};
                    selectedInstancesTableModel.addRow(s);
                    
                    Vector<String> errorMsg = new Vector<String>();
                    try {
                        resolveLibraryInstances(instanceValue, true, errorMsg);
                    }
                    catch (Exception exp) {
                        JOptionPane.showMessageDialog(FpdModuleSA.this, exp.getMessage());
                    }
                    
                    if (errorMsg.size() > 0) {
                        String errors = "";
                        for (int i = 0; i < errorMsg.size(); ++i) {
                            errors += " " + errorMsg.get(i) + "\n";
                        }
                        JOptionPane.showMessageDialog(FpdModuleSA.this, errors);
                    }
                }
            });
        }
        return jButtonAdd;
    }

    /**
     * This method initializes jButton1
     * 	
     * @return javax.swing.JButton	
     */
    private JButton getJButtonDeleteInstance() {
        if (jButtonDeleteInstance == null) {
            jButtonDeleteInstance = new JButton();
            jButtonDeleteInstance.setPreferredSize(new java.awt.Dimension(80,20));
            jButtonDeleteInstance.setText("Delete");
            jButtonDeleteInstance.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent e) {
                    int row = jTableSelectedInstances.getSelectedRow();
                    if (row < 0) {
                        return;
                    }
                    docConsole.setSaved(false);
                    removeInstance(selectedInstancesTableModel.getValueAt(row, 1) + " " +
                                   selectedInstancesTableModel.getValueAt(row, 2) + " " +
                                   selectedInstancesTableModel.getValueAt(row, 3) + " " +
                                   selectedInstancesTableModel.getValueAt(row, 4));
                    ffc.removeLibraryInstance(moduleKey, row);
                    selectedInstancesTableModel.removeRow(row);
                    
                }
            });
        }
        return jButtonDeleteInstance;
    }

    /**
     * This method initializes jButton2	
     * 	
     * @return javax.swing.JButton	
     */
    private JButton getJButtonOk() {
        if (jButtonOk == null) {
            jButtonOk = new JButton();
            jButtonOk.setPreferredSize(new java.awt.Dimension(80,20));
            jButtonOk.setText("Close");
            jButtonOk.addActionListener(this);
        }
        return jButtonOk;
    }

    /**
     * This method initializes jButton3	
     * 	
     * @return javax.swing.JButton	
     */
    private JButton getJButtonCancel() {
        if (jButtonCancel == null) {
            jButtonCancel = new JButton();
            jButtonCancel.setPreferredSize(new java.awt.Dimension(80,20));
            jButtonCancel.setText("Cancel");
            jButtonCancel.setVisible(false);
        }
        return jButtonCancel;
    }
    public void actionPerformed(ActionEvent arg0) {

        if (arg0.getSource() == jButtonOk) {
            if (jTableModuleSaOptions.isEditing()) {
                jTableModuleSaOptions.getCellEditor().stopCellEditing();
            }
            this.setVisible(false);
        }
    }
    /**
     * This method initializes jPanelModuleSaOpts
     * 	
     * @return javax.swing.JPanel	
     */
    private JPanel getJPanelModuleSaOpts() {
        if (jPanelModuleSaOpts == null) {
            FlowLayout flowLayout4 = new FlowLayout();
            flowLayout4.setAlignment(java.awt.FlowLayout.LEFT);
            jLabelFfsFormatKey = new JLabel();
            jLabelFfsFormatKey.setText("FFS Format Key");
            jLabelFfsFormatKey.setPreferredSize(new java.awt.Dimension(90,16));
            jLabelFfsFileGuid = new JLabel();
            jLabelFfsFileGuid.setText("FFS File GUID");
            jLabelFfsFileGuid.setPreferredSize(new java.awt.Dimension(90,16));
            jLabelFfsFileGuid.setVisible(false);
            jLabelFvBinding = new JLabel();
            jLabelFvBinding.setText("FV Binding");
            jLabelFvBinding.setPreferredSize(new java.awt.Dimension(90,16));
            jPanelModuleSaOpts = new JPanel();
            jPanelModuleSaOpts.setLayout(flowLayout4);
            jPanelModuleSaOpts.add(jLabelFvBinding, null);
            jPanelModuleSaOpts.add(getJTextFieldFvBinding(), null);
            jPanelModuleSaOpts.add(jLabelFfsFileGuid, null);
            jPanelModuleSaOpts.add(getJTextFieldFileGuid(), null);
            jPanelModuleSaOpts.add(jLabelFfsFormatKey, null);
            jPanelModuleSaOpts.add(getJTextFieldFfsKey(), null);
            jPanelModuleSaOpts.addComponentListener(new java.awt.event.ComponentAdapter() {
                public void componentShown(java.awt.event.ComponentEvent e) {
                    initFvInfo(moduleKey);
                }
            });
        }
        return jPanelModuleSaOpts;
    }
    
    private Vector<String> getVectorFromString (String s) {
        if (s == null || s.equals("null")) {
            s = "";
        }
        String[] sa1 = s.split(" ");
        Vector<String> v = new Vector<String>();
        for (int i = 0; i < sa1.length; ++i) {
            v.add(sa1[i]);
        }
        return v;
    }
    
    /**
     * This method initializes jTextField	
     * 	
     * @return javax.swing.JTextField	
     */
    private JTextField getJTextFieldFvBinding() {
        if (jTextFieldFvBinding == null) {
            jTextFieldFvBinding = new JTextField();
            jTextFieldFvBinding.setPreferredSize(new java.awt.Dimension(400,20));
            jTextFieldFvBinding.setEditable(true);
            jTextFieldFvBinding.addFocusListener(new java.awt.event.FocusAdapter() {
                public void focusLost(java.awt.event.FocusEvent e) {
                    String originalFvBinding = ffc.getFvBinding(moduleKey);
                    String newFvBinding = jTextFieldFvBinding.getText();
                    if (newFvBinding.equals(originalFvBinding)) {
                        return;
                    }
                    if (newFvBinding.length() == 0 && originalFvBinding == null) {
                        return;
                    }
                    
                    Vector<String> oldFvList = getVectorFromString (originalFvBinding);
                    Vector<String> newFvList = getVectorFromString (newFvBinding);
                    String moduleInfo[] = moduleKey.split(" ");
                    ffc.setFvBinding(moduleKey, newFvBinding);
                    //
                    // remove module from Fvs that not in newFvList now.
                    //
                    oldFvList.removeAll(newFvList);
                    for (int j = 0; j < oldFvList.size(); ++j) {
                        ffc.removeModuleInBuildOptionsUserExtensions(oldFvList.get(j), "IMAGES", "1", moduleInfo[0], moduleInfo[1], moduleInfo[2], moduleInfo[3], moduleInfo[4]);    
                    }
                    //
                    // add module to Fvs that were not in oldFvList.
                    //
                    oldFvList = getVectorFromString (originalFvBinding);
                    newFvList.removeAll(oldFvList);
                    for (int i = 0; i < newFvList.size(); ++i) {
                        ffc.addModuleIntoBuildOptionsUserExtensions(newFvList.get(i), "IMAGES", "1", moduleInfo[0], moduleInfo[1], moduleInfo[2], moduleInfo[3], moduleInfo[4]);
                    }
                    docConsole.setSaved(false);
                }
            });
            
        }
        return jTextFieldFvBinding;
    }
    /**
     * This method initializes jTextField1	
     * 	
     * @return javax.swing.JTextField	
     */
    private JTextField getJTextFieldFileGuid() {
        if (jTextFieldFileGuid == null) {
            jTextFieldFileGuid = new JTextField();
            jTextFieldFileGuid.setPreferredSize(new java.awt.Dimension(300,20));
            jTextFieldFileGuid.setVisible(false);
            jTextFieldFileGuid.addFocusListener(new java.awt.event.FocusAdapter() {
                public void focusLost(java.awt.event.FocusEvent e) {
                    String originalFileGuid = ffc.getFfsFileNameGuid(moduleKey);
                    String newFileGuid = jTextFieldFileGuid.getText();
                    if (newFileGuid.equals(originalFileGuid)) {
                        return;
                    }
                    if (newFileGuid.length() == 0 && originalFileGuid == null) {
                        return;
                    }
                    if (newFileGuid.length() > 0) {
                        if (!DataValidation.isGuid(newFileGuid)) {
                            JOptionPane.showMessageDialog(FpdModuleSA.this, "FFS File Guid is NOT GUID Type.");
                            return;
                        }
                    }
                    
                    docConsole.setSaved(false);
                    if (newFileGuid.length() == 0) {
                        newFileGuid = null;
                    }
                    ffc.setFfsFileNameGuid(moduleKey, newFileGuid);
                }
            });
            
        }
        return jTextFieldFileGuid;
    }
    /**
     * This method initializes jTextFieldFfsKey	
     * 	
     * @return javax.swing.JTextField	
     */
    private JTextField getJTextFieldFfsKey() {
        if (jTextFieldFfsKey == null) {
            jTextFieldFfsKey = new JTextField();
            jTextFieldFfsKey.setPreferredSize(new java.awt.Dimension(250,20));
            jTextFieldFfsKey.addFocusListener(new java.awt.event.FocusAdapter() {
                public void focusLost(java.awt.event.FocusEvent e) {
                    String originalFfsKey = ffc.getFfsFormatKey(moduleKey);
                    String newFfsKey = jTextFieldFfsKey.getText();
                    if (newFfsKey.equals(originalFfsKey)) {
                        return;
                    }
                    if (newFfsKey.length() == 0 && originalFfsKey == null) {
                        return;
                    }
                    docConsole.setSaved(false);
                    ffc.setFfsFormatKey(moduleKey, newFfsKey);
                }
            });
            
        }
        return jTextFieldFfsKey;
    }
    /**
     * This method initializes jScrollPaneModuleSaOptions
     * 	
     * @return javax.swing.JScrollPane	
     */
    private JScrollPane getJScrollPaneModuleSaOptions() {
        if (jScrollPaneModuleSaOptions == null) {
            jScrollPaneModuleSaOptions = new JScrollPane();
            jScrollPaneModuleSaOptions.setPreferredSize(new java.awt.Dimension(600,350));
            jScrollPaneModuleSaOptions.setViewportView(getJTableModuleSaOptions());
        }
        return jScrollPaneModuleSaOptions;
    }
    /**
     * This method initializes jTableModuleSaOptions
     * 	
     * @return javax.swing.JTable	
     */
    private JTable getJTableModuleSaOptions() {
        if (jTableModuleSaOptions == null) {
            optionsTableModel = new DefaultTableModel();
            optionsTableModel.addColumn("BuildTargets");
            optionsTableModel.addColumn("ToolChainFamily");
            optionsTableModel.addColumn("TagName");
            optionsTableModel.addColumn("ToolCode");
            optionsTableModel.addColumn("SupportedArchs");
            optionsTableModel.addColumn("Contents");
            jTableModuleSaOptions = new JTable(optionsTableModel);
            jTableModuleSaOptions.setRowHeight(20);
            
            jTableModuleSaOptions.getColumnModel().getColumn(0).setMinWidth(buildTargetWidth);
            jTableModuleSaOptions.getColumnModel().getColumn(1).setMinWidth(toolChainFamilyWidth);
            jTableModuleSaOptions.getColumnModel().getColumn(2).setMinWidth(tagNameWidth);
            jTableModuleSaOptions.getColumnModel().getColumn(3).setMinWidth(toolCmdCodeWidth);
            jTableModuleSaOptions.getColumnModel().getColumn(4).setMinWidth(supportArchWidth);
            jTableModuleSaOptions.getColumnModel().getColumn(5).setMinWidth(argWidth);
//            javax.swing.table.TableColumn toolFamilyCol = jTableModuleSaOptions.getColumnModel().getColumn(1);
//            JComboBox cb = new JComboBox();
//            cb.addItem("MSFT");
//            cb.addItem("GCC");
//            cb.addItem("CYGWIN");
//            cb.addItem("INTEL");
//            cb.addItem("USER_DEFINED");
//            toolFamilyCol.setCellEditor(new DefaultCellEditor(cb));
            
            Vector<String> vArch = new Vector<String>();
            vArch.add("IA32");
            vArch.add("X64");
            vArch.add("IPF");
            vArch.add("EBC");
            vArch.add("ARM");
            vArch.add("PPC");
            jTableModuleSaOptions.getColumnModel().getColumn(4).setCellEditor(new ListEditor(vArch, FrameworkWizardUI.getInstance()));
            
            jTableModuleSaOptions.getColumnModel().getColumn(5).setCellEditor(new LongTextEditor(FrameworkWizardUI.getInstance()));
            
            jTableModuleSaOptions.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
			jTableModuleSaOptions.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
            jTableModuleSaOptions.getModel().addTableModelListener(new TableModelListener() {
                public void tableChanged(TableModelEvent arg0) {
                    // TODO Auto-generated method stub
                    int row = arg0.getFirstRow();
                    TableModel m = (TableModel)arg0.getSource();
                    
                    if (arg0.getType() == TableModelEvent.UPDATE){
                        //ToDo Data Validition check.
                        String targets = m.getValueAt(row, 0) + "";
                        Vector<Object> targetName = null;
                        if (targets.length() > 0) {
                            targetName = new Vector<Object>();
                            String[] sArray = targets.split(" ");
                            for (int i = 0; i < sArray.length; ++i) {
                                targetName.add(sArray[i]);
                            }
                        }
                        
                        String toolChain = m.getValueAt(row, 1) + "";
                        String tagName = m.getValueAt(row, 2) + "";
                        String toolCode = m.getValueAt(row, 3) + "";
                        String archs = m.getValueAt(row, 4) + "";
                        Vector<Object> supArch = null;
                        if (archs.length() > 0) {
                            supArch = new Vector<Object>();
                            String[] sArray1 = archs.split(" ");
                            for (int i = 0; i < sArray1.length; ++i) {
                                supArch.add(sArray1[i]);
                            }
                        }
                        
                        String contents = m.getValueAt(row, 5) + "";
                        docConsole.setSaved(false);
                        ffc.updateModuleSAOptionsOpt(moduleKey, row, targetName, toolChain, tagName, toolCode, supArch, contents);
                    }
                }
            });
        }
        return jTableModuleSaOptions;
    }
    /**
     * This method initializes jButtonNew
     * 	
     * @return javax.swing.JButton	
     */
    private JButton getJButtonNew() {
        if (jButtonNew == null) {
            jButtonNew = new JButton();
            jButtonNew.setPreferredSize(new java.awt.Dimension(80,20));
            jButtonNew.setText("New");
            jButtonNew.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent e) {
                    String[] row = {"", "", "", "", "", ""};
                    optionsTableModel.addRow(row);
                    Vector<Object> v = null;
                    Vector<Object> v1 = null;
                    docConsole.setSaved(false);
                    ffc.genModuleSAOptionsOpt(moduleKey, v, "", "", "", v1, "");
                }
            });
        }
        return jButtonNew;
    }
    /**
     * This method initializes jButtonDelete
     * 	
     * @return javax.swing.JButton	
     */
    private JButton getJButtonDeleteOption() {
        if (jButtonDeleteOption == null) {
            jButtonDeleteOption = new JButton();
            jButtonDeleteOption.setPreferredSize(new java.awt.Dimension(80,20));
            jButtonDeleteOption.setText("Delete");
            jButtonDeleteOption.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent e) {
                    if (jTableModuleSaOptions.getSelectedRow() < 0) {
                        return;
                    }
                    docConsole.setSaved(false);
                    ffc.removeModuleSAOptionsOpt(moduleKey, jTableModuleSaOptions.getSelectedRow());
                    optionsTableModel.removeRow(jTableModuleSaOptions.getSelectedRow());
                }
            });
        }
        return jButtonDeleteOption;
    }
    
    /**
    Start the window at the center of screen
    
    **/
   protected void centerWindow(int intWidth, int intHeight) {
       Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
       this.setLocation((d.width - intWidth) / 2, (d.height - intHeight) / 2);
   }

   /**
    Start the window at the center of screen
    
    **/
   protected void centerWindow() {
       centerWindow(this.getSize().width, this.getSize().height);
   }
/**
 * This method initializes jPanelPcdFields
 * 	
 * @return javax.swing.JPanel	
 */
private JPanel getJPanelPcdFields() {
    if (jPanelPcdFields == null) {
        GridLayout gridLayout = new GridLayout();
        gridLayout.setRows(3);
        gridLayout.setColumns(2);
        jPanelPcdFields = new JPanel();
        jPanelPcdFields.setLayout(gridLayout);
        jPanelPcdFields.setPreferredSize(new java.awt.Dimension(600,90));
        jPanelPcdFields.add(getJPanelPcdFieldsFirstRow(), null);
        jPanelPcdFields.add(getJPanelPcdFieldsSecondRow(), null);
        jPanelPcdFields.add(getJPanelPcdFieldsThirdRow(), null);
    }
    return jPanelPcdFields;
}
/**
 * This method initializes jPanelPcdFieldsSecondRow
 * 	
 * @return javax.swing.JPanel	
 */
private JPanel getJPanelPcdFieldsSecondRow() {
    if (jPanelPcdFieldsSecondRow == null) {
        FlowLayout flowLayout2 = new FlowLayout();
        flowLayout2.setAlignment(java.awt.FlowLayout.LEFT);
        jLabelMaxDatumSize = new JLabel();
        jLabelMaxDatumSize.setText("Max Datum Size");
        jPanelPcdFieldsSecondRow = new JPanel();
        jPanelPcdFieldsSecondRow.setLayout(flowLayout2);
        jPanelPcdFieldsSecondRow.add(jLabelMaxDatumSize, null);
        jPanelPcdFieldsSecondRow.add(getJTextFieldMaxDatumSize(), null);
    }
    return jPanelPcdFieldsSecondRow;
}
/**
 * This method initializes jPanelPcdFieldsThirdRow
 * 	
 * @return javax.swing.JPanel	
 */
private JPanel getJPanelPcdFieldsThirdRow() {
    if (jPanelPcdFieldsThirdRow == null) {
        FlowLayout flowLayout3 = new FlowLayout();
        flowLayout3.setAlignment(java.awt.FlowLayout.LEFT);
        jLabelPcdDefaultValue = new JLabel();
        jLabelPcdDefaultValue.setText("Default Value");
        jLabelPcdDefaultValue.setPreferredSize(new java.awt.Dimension(91,16));
        jPanelPcdFieldsThirdRow = new JPanel();
        jPanelPcdFieldsThirdRow.setLayout(flowLayout3);
        jPanelPcdFieldsThirdRow.add(jLabelPcdDefaultValue, null);
        jPanelPcdFieldsThirdRow.add(getJTextFieldPcdDefault(), null);
        jPanelPcdFieldsThirdRow.add(getJComboBoxFeatureFlagValue(), null);
        jPanelPcdFieldsThirdRow.add(getJButtonUpdatePcd(), null);
    }
    return jPanelPcdFieldsThirdRow;
}
/**
 * This method initializes jPanelPcdFieldsFirstRow
 * 	
 * @return javax.swing.JPanel	
 */
private JPanel getJPanelPcdFieldsFirstRow() {
    if (jPanelPcdFieldsFirstRow == null) {
        FlowLayout flowLayout1 = new FlowLayout();
        flowLayout1.setAlignment(java.awt.FlowLayout.LEFT);
        jLabelItemType = new JLabel();
        jLabelItemType.setText("Item Type");
        jLabelItemType.setPreferredSize(new java.awt.Dimension(91,16));
        jPanelPcdFieldsFirstRow = new JPanel();
        jPanelPcdFieldsFirstRow.setLayout(flowLayout1);
        jPanelPcdFieldsFirstRow.add(jLabelItemType, null);
        jPanelPcdFieldsFirstRow.add(getJComboBoxItemType(), null);
    }
    return jPanelPcdFieldsFirstRow;
}
/**
 * This method initializes jComboBoxItemType
 * 	
 * @return javax.swing.JComboBox	
 */
private JComboBox getJComboBoxItemType() {
    if (jComboBoxItemType == null) {
        jComboBoxItemType = new JComboBox();
        jComboBoxItemType.setPreferredSize(new java.awt.Dimension(200,20));
        jComboBoxItemType.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent e) {
                
                int row = jTablePcd.getSelectedRow();
                if (row < 0) {
                    return;
                }
                        
                if (jComboBoxItemType.getSelectedItem() != null && jComboBoxItemType.getSelectedItem().equals("FIXED_AT_BUILD")) {
				    jTextFieldPcdDefault.setEnabled(true);
                }
                else {
                	jTextFieldPcdDefault.setEnabled(false);
                }
            }        
        });
    }
    return jComboBoxItemType;
}

private void pcdDynamicToNonDynamic(String cName, String tsGuid) {
    String[][] saa = new String[ffc.getDynamicPcdBuildDataCount()][5];
    ffc.getDynamicPcdBuildData(saa);
    String maxSize = "";
    String value = "";
    for (int i = 0; i < saa.length; ++i) {
        if (saa[i][0].equals(cName) && saa[i][2].equals(tsGuid)) {
            maxSize = saa[i][3];
            value = ffc.getDynamicPcdBuildDataValue(i);
            break;
        }
    }
    
    ArrayList<String> al = ffc.getDynPcdMapValue(cName + " " + tsGuid);
    for (int i = 0; i < al.size(); ++i) {
        String mKey = moduleInfo (al.get(i));
        value = null;
        String itemType = jComboBoxItemType.getSelectedItem()+"";
        ffc.updatePcdData(mKey, cName, tsGuid, itemType, maxSize, value);
        al.set(i, mKey + " " + itemType);
    }
    
    ffc.removeDynamicPcdBuildData(cName, tsGuid);
}

private void pcdNonDynamicToDynamic(String cName, String tsGuid) {
    ArrayList<String> al = ffc.getDynPcdMapValue(cName + " " + tsGuid);
    for (int i = 0; i < al.size(); ++i) {
        String mKey = moduleInfo (al.get(i));
        String itemType = jComboBoxItemType.getSelectedItem()+"";
        ffc.updatePcdData(mKey, cName, tsGuid, itemType, jTextFieldMaxDatumSize.getText(), jTextFieldPcdDefault.isVisible() ? jTextFieldPcdDefault.getText() : jComboBoxFeatureFlagValue.getSelectedItem()+"");
        al.set(i, mKey + " " + itemType);
    }
    try{
        ffc.addDynamicPcdBuildData(cName, model.getValueAt(jTablePcd.getSelectedRow(), 3), tsGuid, "DYNAMIC", model.getValueAt(jTablePcd.getSelectedRow(), 5)+"", jTextFieldPcdDefault.isVisible() ? jTextFieldPcdDefault.getText() : jComboBoxFeatureFlagValue.getSelectedItem()+"");
    }
    catch(Exception e){
        JOptionPane.showMessageDialog(FpdModuleSA.this, "PCD value format: " + e.getMessage());
    }
}

private void changePcdTypeWithinSameCategory (String cName, String tsGuid) {
    ArrayList<String> al = ffc.getDynPcdMapValue(cName + " " + tsGuid);
    for (int i = 0; i < al.size(); ++i) {
        String mKey = moduleInfo (al.get(i));
        String itemType = jComboBoxItemType.getSelectedItem()+"";
        ffc.updatePcdData(mKey, cName, tsGuid, itemType, null, null);
        al.set(i, mKey + " " + itemType);
    }
}

private String moduleInfo (String pcdInfo) {
    
    return pcdInfo.substring(0, pcdInfo.lastIndexOf(" "));
}

/**
 * This method initializes jTextFieldMaxDatumSize
 * 	
 * @return javax.swing.JTextField	
 */
private JTextField getJTextFieldMaxDatumSize() {
    if (jTextFieldMaxDatumSize == null) {
        jTextFieldMaxDatumSize = new JTextField();
        jTextFieldMaxDatumSize.setPreferredSize(new java.awt.Dimension(200,20));
    }
    return jTextFieldMaxDatumSize;
}
/**
 * This method initializes jTextField4	
 * 	
 * @return javax.swing.JTextField	
 */
private JTextField getJTextFieldPcdDefault() {
    if (jTextFieldPcdDefault == null) {
        jTextFieldPcdDefault = new JTextField();
        jTextFieldPcdDefault.setPreferredSize(new java.awt.Dimension(200,20));
    }
    return jTextFieldPcdDefault;
}
/**
 * This method initializes jButton6	
 * 	
 * @return javax.swing.JButton	
 */
private JButton getJButtonUpdatePcd() {
    if (jButtonUpdatePcd == null) {
        jButtonUpdatePcd = new JButton();
        jButtonUpdatePcd.setPreferredSize(new java.awt.Dimension(150,20));
        jButtonUpdatePcd.setText("Update PCD Data");
        jButtonUpdatePcd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent e) {
                int row = jTablePcd.getSelectedRow();
                if (row < 0) {
                    return;
                }
                
                String cName = model.getValueAt(row, 0)+"";
                String tsGuid = model.getValueAt(row, 1)+"";
                String oldItemType = model.getValueAt(row, 2)+"";
                String dataType = model.getValueAt(row, 5)+"";
                String newItemType = jComboBoxItemType.getSelectedItem()+"";
                String newValue = jTextFieldPcdDefault.isVisible()? jTextFieldPcdDefault.getText():jComboBoxFeatureFlagValue.getSelectedItem()+""; 
                if (newValue.length() == 0){
                
                    if (dataType.equals("UINT8") || dataType.equals("UINT16") || dataType.equals("UINT32") || dataType.equals("UINT64")) {
                        newValue = "0";
                    }
                    if (dataType.equals("BOOLEAN")){
                        newValue = "FALSE";
                    }
                    if (dataType.equals("VOID*")) {
                        newValue = "L\"\"";
                    }
                }
                
                String[] pcdInfo = {"", "", ""};
                Vector<String> validPcdTypes = new Vector<String>();
                getPcdInfo (moduleKey, cName, tsGuid, pcdInfo, validPcdTypes);
                if (pcdInfo[1].equals("FIXED_AT_BUILD") && model.getValueAt(row, 5).equals("VOID*")) {
                    try {
                        jTextFieldMaxDatumSize.setText(ffc.setMaxSizeForPointer(newValue)+"");
                    }
                    catch (Exception exp) {
                        JOptionPane.showMessageDialog(FpdModuleSA.this, "PCD Value MalFormed: " + exp.getMessage());
                        return;
                    }
                }
                String newMaxDatumSize = jTextFieldMaxDatumSize.getText();
                
                if (!newItemType.equals(oldItemType)) {
                    Vector<ModuleIdentification> moduleInfo = new Vector<ModuleIdentification>();
                    try {
                        boolean changable = itemTypeCouldBeChanged (cName, tsGuid, newItemType, moduleInfo);
                        if (!changable) {
                            JOptionPane.showMessageDialog(FpdModuleSA.this, "Can NOT Change Pcd Type in: " + moduleInfo.get(0).getName() + " contained in package " + moduleInfo.get(0).getPackageId().getName());
                            return;
                        }
                    }
                    catch (Exception exp) {
                        JOptionPane.showMessageDialog(FpdModuleSA.this, "Can NOT Change Pcd Type in: " + moduleInfo.get(0).getName() + " contained in package " + moduleInfo.get(0).getPackageId().getName() + " " + exp.getMessage());
                        return;
                    }
                    
                    if ((oldItemType.equals("DYNAMIC") || oldItemType.equals("DYNAMIC_EX")) && !newItemType.equals("DYNAMIC") && !newItemType.equals("DYNAMIC_EX")) {
                        pcdDynamicToNonDynamic(cName, tsGuid);
                    }
                    if (!oldItemType.equals("DYNAMIC") && !oldItemType.equals("DYNAMIC_EX") && (newItemType.equals("DYNAMIC") || newItemType.equals("DYNAMIC_EX"))) {
                        pcdNonDynamicToDynamic(cName, tsGuid);
                    }
                    else {
                        changePcdTypeWithinSameCategory (cName, tsGuid);
                    }
                    model.setValueAt(newItemType, row, 2);
                }
                
                ffc.updatePcdData(moduleKey, cName, tsGuid, model.getValueAt(row, 2)+"", newMaxDatumSize, newValue);
                docConsole.setSaved(false);
                model.setValueAt(newValue, row, 6);
                model.setValueAt(newMaxDatumSize, row, 4);
                
            }
        });
    }
    return jButtonUpdatePcd;
}

private boolean itemTypeCouldBeChanged (String cName, String tsGuid, String newItemType, Vector<ModuleIdentification> mi) throws Exception{
    ArrayList<String> pcdConsumers = ffc.getDynPcdMapValue(cName + " " + tsGuid);
    for (int i = 0; i < pcdConsumers.size(); ++i) {
        String consumerInfo = moduleInfo (pcdConsumers.get(i));
        mi.removeAllElements();
        mi.add(WorkspaceProfile.getModuleId(consumerInfo));
        String[] sa = {"", "", ""};
        Vector<String> validPcdTypes = new Vector<String>();
        getPcdInfo (consumerInfo, cName, tsGuid, sa, validPcdTypes);
        if (validPcdTypes.size() == 0) {
            return false;
        }
        if (!sa[1].equals("DYNAMIC")) {
            return false;
        }
        if (!validPcdTypes.contains(newItemType)) {
            return false;
        }
    }
    return true;
}

/**
 * This method initializes jComboBoxFeatureFlagValue
 * 	
 * @return javax.swing.JComboBox	
 */
private JComboBox getJComboBoxFeatureFlagValue() {
    if (jComboBoxFeatureFlagValue == null) {
        jComboBoxFeatureFlagValue = new JComboBox();
        jComboBoxFeatureFlagValue.setPreferredSize(new java.awt.Dimension(100,20));
        jComboBoxFeatureFlagValue.setVisible(false);
        jComboBoxFeatureFlagValue.addItem("TRUE");
        jComboBoxFeatureFlagValue.addItem("FALSE");
    }
    return jComboBoxFeatureFlagValue;
}
/**
 * This method initializes jPanelCustomToolChain	
 * 	
 * @return javax.swing.JPanel	
 */
private JPanel getJPanelCustomToolChain() {
    if (jPanelCustomToolChain == null) {
        jPanelCustomToolChain = new JPanel();
        jPanelCustomToolChain.setLayout(new BorderLayout());
        jPanelCustomToolChain.add(getJPanelToolchainS(), java.awt.BorderLayout.SOUTH);
        jPanelCustomToolChain.add(getJScrollPaneModuleSaOptions(), java.awt.BorderLayout.CENTER);
        jPanelCustomToolChain.addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentShown(java.awt.event.ComponentEvent e) {
                initToolChainOptions(moduleKey);
            }
        });
    }
    return jPanelCustomToolChain;
}
/**
 * This method initializes jPanelToolchainS	
 * 	
 * @return javax.swing.JPanel	
 */
private JPanel getJPanelToolchainS() {
    if (jPanelToolchainS == null) {
        jPanelToolchainS = new JPanel();
        jPanelToolchainS.add(getJButtonNew(), null);
        jPanelToolchainS.add(getJButtonDeleteOption(), null);
    }
    return jPanelToolchainS;
}

/**
 * This method initializes jPanelLibraryCenterN	
 * 	
 * @return javax.swing.JPanel	
 */
private JPanel getJPanelLibraryCenterN() {
    if (jPanelLibraryCenterN == null) {
        FlowLayout flowLayout5 = new FlowLayout();
        flowLayout5.setAlignment(java.awt.FlowLayout.CENTER);
        flowLayout5.setHgap(10);
        jPanelLibraryCenterN = new JPanel();
        jPanelLibraryCenterN.setLayout(flowLayout5);
        jPanelLibraryCenterN.add(jLabelInstanceHelp, null);
        jPanelLibraryCenterN.add(getJScrollPaneInstanceHelp(), null);
        jPanelLibraryCenterN.add(getJButtonAdd(), null);
        jPanelLibraryCenterN.add(getJButtonDeleteInstance(), null);
    }
    return jPanelLibraryCenterN;
}
/**
 * This method initializes jPanelLibraryCenterC	
 * 	
 * @return javax.swing.JPanel	
 */
private JPanel getJPanelLibraryCenterC() {
    if (jPanelLibraryCenterC == null) {
        jPanelLibraryCenterC = new JPanel();
        jPanelLibraryCenterC.add(jLabelSelectedInstances, null);
        jPanelLibraryCenterC.add(getJScrollPaneSelectedInstances(), null);
    }
    return jPanelLibraryCenterC;
}


}  //  @jve:decl-index=0:visual-constraint="10,10"

class MultipleInstanceException extends Exception {

    /**
     * 
     */
    private static final long serialVersionUID = -9148463005930920297L;
    private String className = null;
    private String libInstance1 = null;
    private String libInstance2 = null;
    
    MultipleInstanceException (String libClass, String instance1, String instance2) {
        super();
        className = libClass;
        libInstance1 = instance1;
        libInstance2 = instance2;
    }

    /* (non-Javadoc)
     * @see java.lang.Throwable#getMessage()
     */
    @Override
    public String getMessage() {
        // TODO Auto-generated method stub
        return " Library Class " + className + "is Produced by Two Instances: " 
            + libInstance1 + " and " + libInstance2 + ". Platform Build will Fail.";
    }
    
}

class ImproperInstanceException extends Exception {

    /**
     * 
     */
    private static final long serialVersionUID = -5279700566993277033L;
    private String className = null;
    private String libInstance = null;
    private String instanceSupArch = null;
    private String instanceSupModType = null;
    
    ImproperInstanceException (String libClass, String instance1, String arch, String type) {
        super();
        className = libClass;
        libInstance = instance1;
        instanceSupArch = arch;
        instanceSupModType = type;
    }

    /* (non-Javadoc)
     * @see java.lang.Throwable#getMessage()
     */
    @Override
    public String getMessage() {
        // TODO Auto-generated method stub
        return " Library Class " + className + " Produced by Library Instance: " 
            + libInstance + "\nOnly Supports " + instanceSupArch + " and Module Type " + instanceSupModType + ".\n This instance should be removed.\n";
    }
    
}

class NoInstanceException extends Exception {

    /**
     * 
     */
    private static final long serialVersionUID = 1987122786598970598L;
    
    private String className = null;
    
    NoInstanceException (String libClass) {
        className = libClass;
    }
    
    public String getMessage() {
        return "No Applicable Instance for Library Class " + className
            + ", Platform Build will Fail.";
    }
}