]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdModuleSA.java
1. Refresh applicable library instances after one illegal library instance is removed.
[mirror_edk2.git] / Tools / Java / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / platform / ui / FpdModuleSA.java
index 380a702eb4d0216c2608dcb52181966f1b0e4f0f..b97e0d77e64ac4445d1d86a04fb924b5bd44e84c 100644 (file)
@@ -4,7 +4,6 @@ import java.awt.BorderLayout;
 import java.awt.Dimension;\r
 import java.awt.Toolkit;\r
 \r
-import javax.swing.JFrame;\r
 import javax.swing.JOptionPane;\r
 import javax.swing.JPanel;\r
 import javax.swing.JDialog;\r
@@ -24,6 +23,7 @@ import javax.swing.table.DefaultTableModel;
 import javax.swing.table.TableColumn;\r
 import javax.swing.table.TableModel;\r
 \r
+import org.tianocore.frameworkwizard.FrameworkWizardUI;\r
 import org.tianocore.frameworkwizard.common.DataValidation;\r
 import org.tianocore.frameworkwizard.common.GlobalData;\r
 import org.tianocore.frameworkwizard.common.IDefaultTableModel;\r
@@ -41,6 +41,8 @@ import java.util.ArrayList;
 import java.util.HashMap;\r
 import java.util.Iterator;\r
 import java.util.ListIterator;\r
+import java.util.Set;\r
+import java.util.Stack;\r
 import java.util.Vector;\r
 \r
 import javax.swing.JTextField;\r
@@ -53,7 +55,6 @@ public class FpdModuleSA extends JDialog implements ActionListener {
      * \r
      */\r
     private static final long serialVersionUID = 1L;\r
-    static JFrame frame;\r
     private JPanel jContentPane = null;\r
     private JTabbedPane jTabbedPane = null;\r
     private JPanel jPanelPcd = null;\r
@@ -94,7 +95,7 @@ public class FpdModuleSA extends JDialog implements ActionListener {
     private DefaultTableModel optionsTableModel = null;\r
     private FpdFileContents ffc = null;\r
     private String moduleKey = null;\r
-    private int moduleSaNum = -1;\r
+    private ModuleIdentification moduleId = null;\r
     private HashMap<LibraryClassDescriptor, ArrayList<String>> classInstanceMap = null;\r
     //\r
     // map of <{libName, supArch, supMod}, list of Module information>\r
@@ -142,7 +143,7 @@ public class FpdModuleSA extends JDialog implements ActionListener {
      * This is the default constructor\r
      */\r
     public FpdModuleSA() {\r
-        super();\r
+        super(FrameworkWizardUI.getInstance());\r
         initialize();\r
     }\r
     public FpdModuleSA(FpdFileContents ffc) {\r
@@ -152,19 +153,18 @@ public class FpdModuleSA extends JDialog implements ActionListener {
     \r
     public void setKey(String k, int i, OpeningPlatformType dc){\r
         this.moduleKey = k;\r
-        moduleSaNum = i;\r
         this.docConsole = dc;\r
         classInstanceMap = null;\r
         classProduced = null;\r
         classConsumed = null;\r
         jTabbedPane.setSelectedIndex(0);\r
-        initPcdBuildDefinition(i);\r
-        ModuleIdentification mi = WorkspaceProfile.getModuleId(moduleKey);\r
-        if (mi == null) {\r
+        initPcdBuildDefinition(moduleKey);\r
+        moduleId = WorkspaceProfile.getModuleId(moduleKey);\r
+        if (moduleId == null) {\r
             return;\r
         }\r
         int tabIndex = jTabbedPane.indexOfTab("Libraries");\r
-        if (mi.isLibrary()) {\r
+        if (moduleId.isLibrary()) {\r
             jTabbedPane.setEnabledAt(tabIndex, false);\r
         }\r
         else {\r
@@ -176,7 +176,7 @@ public class FpdModuleSA extends JDialog implements ActionListener {
       init will be called each time FpdModuleSA object is to be shown.\r
       @param key Module information.\r
      **/\r
-    public void initPcdBuildDefinition(int i) {\r
+    public void initPcdBuildDefinition(String key) {\r
         //\r
         // display pcd for key.\r
         //\r
@@ -185,10 +185,10 @@ public class FpdModuleSA extends JDialog implements ActionListener {
         jComboBoxItemType.setSelectedIndex(-1);\r
         jTextFieldMaxDatumSize.setText("");\r
         jTextFieldPcdDefault.setText("");\r
-        int pcdCount = ffc.getPcdDataCount(i);\r
+        int pcdCount = ffc.getPcdDataCount(key);\r
         if (pcdCount != 0) {\r
             String[][] saa = new String[pcdCount][7];\r
-            ffc.getPcdData(i, saa);\r
+            ffc.getPcdData(key, saa);\r
             for (int j = 0; j < saa.length; ++j) {\r
                 model.addRow(saa[j]);\r
             }\r
@@ -200,27 +200,18 @@ public class FpdModuleSA extends JDialog implements ActionListener {
         libInstanceTableModel.setRowCount(0);\r
         selectedInstancesTableModel.setRowCount(0);\r
         Vector<String> errorMsg = new Vector<String>();\r
-        try {\r
-            //\r
-            // display library classes that need to be resolved. also potential instances for them.\r
-            //\r
-            resolveLibraryInstances(moduleKey, errorMsg);\r
-        } catch (Exception e) {\r
-            String exceptionMsg = e.getCause() + " " + e.getMessage();\r
-            errorMsg.add(exceptionMsg);\r
-            JOptionPane.showMessageDialog(frame, exceptionMsg);\r
-        }\r
-        //\r
-        // display lib instances already selected for key\r
-        //\r
+        Vector<ModuleIdentification> newInstances = new Vector<ModuleIdentification>();\r
+        \r
+        addConsumedClassFromModule (key);\r
+        addProducedClassFromModule (key);\r
         \r
         int instanceCount = ffc.getLibraryInstancesCount(key);\r
         if (instanceCount != 0) {\r
             String[][] saa = new String[instanceCount][5];\r
             ffc.getLibraryInstances(key, saa);\r
             for (int i = 0; i < saa.length; ++i) {\r
-                ModuleIdentification mi = WorkspaceProfile.getModuleId(saa[i][1] + " " + saa[i][2] + " " + saa[i][3]\r
-                                                                       + " " + saa[i][4]);\r
+                String libInstanceKey = saa[i][1] + " " + saa[i][2] + " " + saa[i][3] + " " + saa[i][4];\r
+                ModuleIdentification mi = WorkspaceProfile.getModuleId(libInstanceKey);\r
                 if (mi != null) {\r
                     //\r
                     // ToDo: verify this instance first.\r
@@ -231,27 +222,58 @@ public class FpdModuleSA extends JDialog implements ActionListener {
                     //\r
                     // re-evaluate lib instance usage when adding a already-selected lib instance.\r
                     //\r
-                    try {\r
-                        resolveLibraryInstances(saa[i][1] + " " + saa[i][2] + " " + saa[i][3] + " " + saa[i][4], errorMsg);\r
-                    } catch (Exception e) {\r
-                        String exceptionMsg = e.getCause() + " " + e.getMessage();\r
-                        if (!errorMsg.contains(exceptionMsg)) {\r
-                            JOptionPane.showMessageDialog(frame, e.getCause() + " " + e.getMessage());\r
-                        }\r
-                    }\r
+                    addConsumedClassFromModule (libInstanceKey);\r
+                    addProducedClassFromModule (libInstanceKey);\r
                     selectedInstancesTableModel.addRow(saa[i]);\r
                 }\r
             }\r
         }\r
-\r
+        \r
+        Set<LibraryClassDescriptor> sLcd = this.classConsumed.keySet();\r
+        Iterator<LibraryClassDescriptor> iter = sLcd.iterator(); \r
+        Stack<LibraryClassDescriptor> lcdStack = new Stack<LibraryClassDescriptor>();\r
+        while (iter.hasNext()) {\r
+            LibraryClassDescriptor lcd = iter.next();\r
+            if (this.classConsumed.get(lcd) == null || this.classConsumed.get(lcd).size() == 0) {\r
+                continue;\r
+            }\r
+            if (isBoundedClass(lcd, errorMsg)) {\r
+                continue;\r
+            }\r
+            \r
+            if (!lcdStack.contains(lcd)) {\r
+                lcdStack.push(lcd);\r
+            }\r
+        }\r
+        \r
+        try {\r
+            resolveLibraryInstances(lcdStack, true, errorMsg, newInstances);\r
+        } catch (Exception e) {\r
+            String exceptionMsg = e.getCause() + " " + e.getMessage();\r
+            if (!errorMsg.contains(exceptionMsg)) {\r
+                JOptionPane.showMessageDialog(FrameworkWizardUI.getInstance(), e.getCause() + " " + e.getMessage());\r
+            }\r
+        }\r
+        \r
+        String newInstancesAddedMsg = "Library instance automatically added to this module :\n";\r
+        for (int i = 0; i < newInstances.size(); ++i) {\r
+            ModuleIdentification libMi = newInstances.get(i);\r
+            newInstancesAddedMsg += libMi.getName();\r
+            newInstancesAddedMsg += " ";\r
+        }\r
+        if (newInstances.size() > 0) {\r
+            JOptionPane.showMessageDialog(FrameworkWizardUI.getInstance(), newInstancesAddedMsg);\r
+        }\r
+        \r
+        showClassToResolved();\r
+        \r
         if (errorMsg.size() > 0) {\r
             String errors = "";\r
             for (int i = 0; i < errorMsg.size(); ++i) {\r
                 errors += " " + errorMsg.get(i) + "\n";\r
             }\r
-            JOptionPane.showMessageDialog(frame, errors);\r
+            JOptionPane.showMessageDialog(FrameworkWizardUI.getInstance(), errors);\r
         }\r
-        showClassToResolved();\r
     }\r
     \r
     public void initFvInfo (String key) {\r
@@ -342,32 +364,8 @@ public class FpdModuleSA extends JDialog implements ActionListener {
         }\r
     }\r
     \r
-    private void resolveLibraryInstances(String key, Vector<String> errorMsg) throws MultipleInstanceException, NoInstanceException{\r
+    private void addProducedClassFromModule (String key) {\r
         ModuleIdentification mi = WorkspaceProfile.getModuleId(key);\r
-        PackageIdentification[] depPkgList = null;\r
-        \r
-        //\r
-        // Get dependency pkg list into which we will search lib instances.\r
-        //\r
-        depPkgList = SurfaceAreaQuery.getDependencePkg(null, mi);\r
-        //\r
-        // Get the lib class consumed, produced by this module itself.\r
-        //\r
-        Vector<LibraryClassDescriptor> vClassConsumed = SurfaceAreaQuery.getLibraryClasses("ALWAYS_CONSUMED", mi);\r
-        filterClassConsumedByArch(vClassConsumed);\r
-        if (this.classConsumed == null) {\r
-            this.classConsumed = new HashMap<LibraryClassDescriptor, ArrayList<String>>();\r
-        }\r
-\r
-        for (int i = 0; i < vClassConsumed.size(); ++i) {\r
-            ArrayList<String> consumedBy = this.classConsumed.get(vClassConsumed.get(i));\r
-            if (consumedBy == null) {\r
-                consumedBy = new ArrayList<String>();\r
-            }\r
-            consumedBy.add(key);\r
-            this.classConsumed.put(vClassConsumed.get(i), consumedBy);\r
-        }\r
-\r
         Vector<LibraryClassDescriptor> vClassProduced = SurfaceAreaQuery.getLibraryClasses("ALWAYS_PRODUCED", mi);\r
         if (this.classProduced == null) {\r
             this.classProduced = new HashMap<LibraryClassDescriptor, ArrayList<String>>();\r
@@ -402,20 +400,51 @@ public class FpdModuleSA extends JDialog implements ActionListener {
             this.classProduced.put(vClassProduced.get(i), producedBy);\r
             \r
         }\r
-\r
+    }\r
+    \r
+    private Vector<LibraryClassDescriptor> addConsumedClassFromModule (String key) {\r
+        ModuleIdentification mi = WorkspaceProfile.getModuleId(key);\r
+//        PackageIdentification[] depPkgList = null;\r
+        \r
+        //\r
+        // Get dependency pkg list into which we will search lib instances.\r
+        //\r
+        //depPkgList = SurfaceAreaQuery.getDependencePkg(null, mi);\r
         //\r
-        // find potential instances in all pkgs for classes still in classConsumed.\r
+        // Get the lib class consumed, produced by this module itself.\r
         //\r
+        Vector<LibraryClassDescriptor> vClassConsumed = SurfaceAreaQuery.getLibraryClasses("ALWAYS_CONSUMED", mi);\r
+        for (int i = 0; i < vClassConsumed.size(); ++i) {\r
+            vClassConsumed.get(i).supModTypes = WorkspaceProfile.getModuleType(moduleId);\r
+        }\r
+        filterClassConsumedByArch(vClassConsumed);\r
+        if (this.classConsumed == null) {\r
+            this.classConsumed = new HashMap<LibraryClassDescriptor, ArrayList<String>>();\r
+        }\r
+\r
+        for (int i = 0; i < vClassConsumed.size(); ++i) {\r
+            ArrayList<String> consumedBy = this.classConsumed.get(vClassConsumed.get(i));\r
+            if (consumedBy == null) {\r
+                consumedBy = new ArrayList<String>();\r
+            }\r
+            consumedBy.add(key);\r
+            this.classConsumed.put(vClassConsumed.get(i), consumedBy);\r
+        }\r
+\r
+        return vClassConsumed;\r
+    }\r
+    \r
+    private void resolveLibraryInstances(Stack<LibraryClassDescriptor> lcdStack, boolean autoSelectSingleInstance, Vector<String> errorMsg, Vector<ModuleIdentification> newInstances) throws MultipleInstanceException, NoInstanceException{\r
+        \r
         if (classInstanceMap == null) {\r
             classInstanceMap = new HashMap<LibraryClassDescriptor, ArrayList<String>>();\r
-        }\r
-        Iterator<LibraryClassDescriptor> lic = this.classConsumed.keySet().iterator();\r
-        while (lic.hasNext()) {\r
-            LibraryClassDescriptor cls = lic.next();\r
-            if (isBoundedClass(cls)) {\r
+        }        \r
+        while (!lcdStack.empty()) {\r
+            LibraryClassDescriptor cls = lcdStack.pop();\r
+            if (isBoundedClass(cls, errorMsg)) {\r
                 continue;\r
             }\r
-            ArrayList<String> instances = getInstancesForClass(cls, depPkgList);\r
+            ArrayList<String> instances = getInstancesForClass(cls, null);\r
             if (instances.size() == 0) {\r
 //                throw new NoInstanceException (cls.className);\r
                 String exceptionMsg = new NoInstanceException (cls.className).getMessage();\r
@@ -425,24 +454,65 @@ public class FpdModuleSA extends JDialog implements ActionListener {
                 \r
             }\r
             classInstanceMap.put(cls, instances);\r
-\r
+            if (instances.size() == 1 && autoSelectSingleInstance) {\r
+                String instanceInfo = instances.get(0);\r
+                ModuleIdentification libMi = WorkspaceProfile.getModuleId(instanceInfo);\r
+                try {\r
+                    Object[] row = {libMi.getName(), libMi.getGuid(), libMi.getVersion(), \r
+                                    libMi.getPackageId().getGuid(), libMi.getPackageId().getVersion()};\r
+                    if (!ffc.instanceExistsInModuleSA(moduleKey, row[1]+"", row[2]+"", row[3]+"", row[4]+"")) {\r
+                        addLibInstance(libMi);\r
+                        newInstances.add(libMi);\r
+                        docConsole.setSaved(false);\r
+                        selectedInstancesTableModel.addRow(row);\r
+                        addProducedClassFromModule (instanceInfo);\r
+                        Vector<LibraryClassDescriptor> vLcd = addConsumedClassFromModule(instanceInfo);\r
+                        for (int i = 0; i < vLcd.size(); ++i) {\r
+                            LibraryClassDescriptor lcd = vLcd.get(i);\r
+                            if (!lcdStack.contains(lcd)) {\r
+                                lcdStack.push(lcd);\r
+                            }\r
+                        }\r
+                    }\r
+                }\r
+                catch (Exception e) {\r
+                    if (!errorMsg.contains(e.getMessage())) {\r
+                        errorMsg.add(e.getMessage());\r
+                    }\r
+                }\r
+            }\r
         }\r
-//            showClassToResolved();\r
     }\r
+//            \r
 \r
     /**Search classProduced map to see if this class has been produced by some instance (module).\r
      * @param cls\r
      * @return\r
      */\r
-    private boolean isBoundedClass (LibraryClassDescriptor cls) {\r
-        if (this.classProduced.containsKey(cls)) {\r
-            return true;\r
-        }\r
+    private boolean isBoundedClass (LibraryClassDescriptor cls, Vector<String> errorMsg) {\r
+//        if (this.classProduced.containsKey(cls)) {\r
+//            return true;\r
+//        }\r
         Iterator<LibraryClassDescriptor> lcdi = this.classProduced.keySet().iterator();\r
         while (lcdi.hasNext()) {\r
             LibraryClassDescriptor lcd = lcdi.next();\r
-            if (cls.isSubSetByArchs(lcd) && cls.isSubSetByModTypes(lcd)) {\r
-                return true;\r
+            if (cls.className.equals(lcd.className)) {\r
+                if (cls.isSubSetByArchs(lcd) && cls.isSubSetByModTypes(lcd)) {\r
+                    return true;\r
+                }\r
+                else {\r
+                    ArrayList<String> producedBy = this.classProduced.get(lcd);\r
+                    String instancesName = "";\r
+                    for (int i = 0; i < producedBy.size(); ++i) {\r
+                        ModuleIdentification mi = WorkspaceProfile.getModuleId(producedBy.get(i));\r
+                        instancesName += mi.getName();\r
+                        instancesName += " ";\r
+                    }\r
+                    String msg = new ImproperInstanceException(lcd.className, instancesName, lcd.supArchs, lcd.supModTypes).getMessage();\r
+                    if (!errorMsg.contains(msg)) {\r
+                        errorMsg.add(msg);\r
+                    }\r
+                }\r
             }\r
         }\r
         \r
@@ -469,7 +539,7 @@ public class FpdModuleSA extends JDialog implements ActionListener {
                         isPotential = true;\r
                     }\r
                     \r
-                    if (hasBeenProduced(lcd)) {\r
+                    if (isPotential && hasBeenProduced(lcd)) {\r
                         isPotential = false;\r
                         break;\r
                     }\r
@@ -488,7 +558,7 @@ public class FpdModuleSA extends JDialog implements ActionListener {
         Iterator<LibraryClassDescriptor> lcdi = this.classProduced.keySet().iterator();\r
         while (lcdi.hasNext()) {\r
             LibraryClassDescriptor lcd = lcdi.next();\r
-            if (cls.hasInterSectionWith(lcd)) {\r
+            if (cls.isSubSetByArchs(lcd) && cls.isSubSetByModTypes(lcd)) {\r
                 return true;\r
             }\r
         }\r
@@ -499,19 +569,48 @@ public class FpdModuleSA extends JDialog implements ActionListener {
         Iterator<LibraryClassDescriptor> lcdi = this.classConsumed.keySet().iterator();\r
         while (lcdi.hasNext()) {\r
             LibraryClassDescriptor lcd = lcdi.next();\r
-            if (lcd.className.equals(className)) {\r
+            if ((lcd.className != null) && lcd.className.equals(className)) {\r
                 return this.classConsumed.get(lcd);\r
             }\r
         }\r
         return null;\r
     }\r
     \r
+    private ArrayList<String> getProducedBy (String className) {\r
+        Iterator<LibraryClassDescriptor> lcdi = this.classProduced.keySet().iterator();\r
+        while (lcdi.hasNext()) {\r
+            LibraryClassDescriptor lcd = lcdi.next();\r
+            if ((lcd.className != null) && lcd.className.equals(className)) {\r
+                return this.classProduced.get(lcd);\r
+            }\r
+        }\r
+        return null;\r
+    }\r
+    //\r
+    // Get class name list related with instanceKey from HashMap m<LibraryClass, ArrayList<instanceKey>>.\r
+    //\r
+    private ArrayList<String> getLibraryClassList (String instanceKey, HashMap<LibraryClassDescriptor, ArrayList<String>> m) {\r
+        ArrayList<String> libraryClass = new ArrayList<String>();\r
+        Iterator<LibraryClassDescriptor> lcdi = m.keySet().iterator();\r
+        while (lcdi.hasNext()) {\r
+            LibraryClassDescriptor lcd = lcdi.next();\r
+            if ((m.get(lcd) != null) && m.get(lcd).contains(instanceKey)) {\r
+                libraryClass.add(lcd.className);\r
+            }\r
+        }\r
+        return libraryClass;\r
+    }\r
+    \r
     private void removeInstance(String key) {\r
         ModuleIdentification mi = WorkspaceProfile.getModuleId(key); \r
         //\r
         // remove pcd information of instance from current ModuleSA\r
+        // Note that Pcd data SHOULD be removed prior to library instance\r
+        // because Multi-Sourced PCD could not be removed, if we remove library instance first,\r
+        // it will impact the judgement of whether a PCD entry is Multi-Sourced.\r
         //\r
         ffc.removePcdData(moduleKey, mi);\r
+        ffc.removeLibraryInstance(moduleKey, key);\r
         //\r
         // remove class produced by this instance and add back these produced class to be bound.\r
         //\r
@@ -531,11 +630,27 @@ public class FpdModuleSA extends JDialog implements ActionListener {
                 continue;\r
             }\r
             al.remove(key);\r
-            \r
+            if (al.size() == 0) {\r
+                ArrayList<String> from = getProducedBy (clsConsumed[i]);\r
+                if (from == null) {\r
+                    continue;\r
+                }\r
+                boolean noUse = true;\r
+                for (int j = 0; j < from.size(); ++j) {\r
+                    ArrayList<String> libClasses = getLibraryClassList(from.get(j), classProduced);\r
+                    for (int k = 0; k < libClasses.size(); ++k) {\r
+                        if (getConsumedBy (libClasses.get(k)) != null && getConsumedBy (libClasses.get(k)).size() > 0) {\r
+                            noUse = false;\r
+                        }\r
+                    }\r
+                    if (noUse) {\r
+                        removeInstance(from.get(j));\r
+                    }\r
+                    noUse = true;\r
+                }\r
+            }\r
         }\r
         \r
-        showClassToResolved();\r
-        \r
     }\r
     \r
     \r
@@ -561,32 +676,51 @@ public class FpdModuleSA extends JDialog implements ActionListener {
     }\r
     \r
     private void showClassToResolved(){\r
+        Vector<String> errorMsg = new Vector<String>();\r
         libClassTableModel.setRowCount(0);\r
         libInstanceTableModel.setRowCount(0);\r
         if (classConsumed == null || classConsumed.size() == 0) {\r
             return;\r
         }\r
+\r
         Iterator<LibraryClassDescriptor> li = classConsumed.keySet().iterator();\r
         while(li.hasNext()){\r
             LibraryClassDescriptor lcd = li.next();\r
-            String[] s = {lcd.className, lcd.supArchs, lcd.supModTypes};\r
             if (classConsumed.get(lcd) == null || classConsumed.get(lcd).size() == 0) {\r
                 continue;\r
             }\r
             \r
-            if (!isBoundedClass(lcd)){\r
+            if (!isBoundedClass(lcd, errorMsg)){\r
+     \r
+                String[] s = { lcd.className, lcd.supArchs, lcd.supModTypes };\r
                 libClassTableModel.addRow(s);\r
             }\r
         }\r
-        \r
+\r
+        if (errorMsg.size() > 0) {\r
+            String errors = "";\r
+            for (int i = 0; i < errorMsg.size(); ++i) {\r
+                errors += " " + errorMsg.get(i) + "\n";\r
+            }\r
+            JOptionPane.showMessageDialog(FrameworkWizardUI.getInstance(), errors);\r
+        }\r
     }\r
     \r
+    private String getModuleArch () {\r
+       String arch = "";\r
+       String[] moduleInfo = moduleKey.split(" ");\r
+       for (int i = 4; i < moduleInfo.length; ++i) {\r
+               arch += moduleInfo[i];\r
+               arch += " ";\r
+       }\r
+       return arch.trim();\r
+    }\r
     private void addLibInstance (ModuleIdentification libMi) throws Exception{\r
         \r
         //\r
         // Add pcd information of selected instance to current moduleSA\r
         //\r
-        ffc.addFrameworkModulesPcdBuildDefs(libMi, null, ffc.getModuleSA(moduleKey));\r
+        ffc.addFrameworkModulesPcdBuildDefs(libMi, getModuleArch(), ffc.getModuleSA(moduleKey));\r
         \r
         ffc.genLibraryInstance(libMi, moduleKey);\r
     }\r
@@ -652,7 +786,7 @@ public class FpdModuleSA extends JDialog implements ActionListener {
             jPanelPcd.add(getJPanelPcdSouth(), java.awt.BorderLayout.SOUTH);\r
             jPanelPcd.addComponentListener(new java.awt.event.ComponentAdapter() {\r
                 public void componentShown(java.awt.event.ComponentEvent e) {\r
-                    initPcdBuildDefinition(moduleSaNum);\r
+                    initPcdBuildDefinition(moduleKey);\r
                 }\r
             });\r
             \r
@@ -748,7 +882,7 @@ public class FpdModuleSA extends JDialog implements ActionListener {
                         jTextFieldMaxDatumSize.setText(model.getValueAt(selectedRow, 4)+"");\r
                         jTextFieldPcdDefault.setEnabled(true);\r
                         jTextFieldPcdDefault.setText(model.getValueAt(selectedRow, 6)+"");\r
-                        if (model.getValueAt(selectedRow, 5).equals("VOID*")) {\r
+                        if ((model.getValueAt(selectedRow, 5) != null) && model.getValueAt(selectedRow, 5).equals("VOID*")) {\r
                             if (pcdInfo[1].equals("FEATURE_FLAG")) {\r
                                 jTextFieldMaxDatumSize.setVisible(false);\r
                             }\r
@@ -758,7 +892,7 @@ public class FpdModuleSA extends JDialog implements ActionListener {
                                     jTextFieldMaxDatumSize.setText(ffc.setMaxSizeForPointer(model.getValueAt(selectedRow, 6)+"")+"");\r
                                 }\r
                                 catch(Exception except){\r
-                                    JOptionPane.showMessageDialog(frame, "Unacceptable PCD Value: " + except.getMessage());\r
+                                    JOptionPane.showMessageDialog(FpdModuleSA.this, "Unacceptable PCD Value: " + except.getMessage());\r
                                 }\r
                             }\r
                             else{\r
@@ -1038,9 +1172,14 @@ public class FpdModuleSA extends JDialog implements ActionListener {
                         String cls = libClassTableModel.getValueAt(selectedRow2, 0).toString();\r
                         String arch = libClassTableModel.getValueAt(selectedRow2, 1).toString();\r
                         String modType = libClassTableModel.getValueAt(selectedRow2, 2).toString();\r
-                        ArrayList<String> al = classInstanceMap.get(new LibraryClassDescriptor(cls, arch, modType));\r
+                        LibraryClassDescriptor lcd = new LibraryClassDescriptor(cls, arch, modType);\r
+                        ArrayList<String> al = classInstanceMap.get(lcd);\r
                         if (al == null) {\r
-                            return;\r
+                            al = getInstancesForClass(lcd, null);\r
+                            if (al.size() != 0) {\r
+                                classInstanceMap.put(lcd, al);\r
+                            }\r
+                            \r
                         }\r
                         ListIterator<String> li = al.listIterator();\r
                         while(li.hasNext()) {\r
@@ -1180,16 +1319,16 @@ public class FpdModuleSA extends JDialog implements ActionListener {
                         return;\r
                     }\r
                     \r
-                    String instanceValue = libInstanceTableModel.getValueAt(row, 1) + " " +\r
+                    String libInstanceKey = libInstanceTableModel.getValueAt(row, 1) + " " +\r
                     libInstanceTableModel.getValueAt(row, 2) + " " +\r
                     libInstanceTableModel.getValueAt(row, 3) + " " +\r
                     libInstanceTableModel.getValueAt(row, 4);\r
-                    ModuleIdentification libMi = WorkspaceProfile.getModuleId(instanceValue);\r
+                    ModuleIdentification libMi = WorkspaceProfile.getModuleId(libInstanceKey);\r
                     try {\r
                         addLibInstance (libMi);\r
                     }\r
                     catch (Exception exception) {\r
-                        JOptionPane.showMessageDialog(frame, "Adding Instance " + libMi.getName() + " : \n"+ exception.getMessage());\r
+                        JOptionPane.showMessageDialog(FpdModuleSA.this, "Adding Instance " + libMi.getName() + " : \n"+ exception.getMessage());\r
                         return;\r
                     }\r
                     docConsole.setSaved(false);\r
@@ -1198,22 +1337,34 @@ public class FpdModuleSA extends JDialog implements ActionListener {
                                   libInstanceTableModel.getValueAt(row, 4)};\r
                     selectedInstancesTableModel.addRow(s);\r
                     \r
+                    Vector<LibraryClassDescriptor> vLcd = addConsumedClassFromModule (libInstanceKey);\r
+                    addProducedClassFromModule (libInstanceKey);\r
+                    \r
                     Vector<String> errorMsg = new Vector<String>();\r
+                    Vector<ModuleIdentification> newInstances = new Vector<ModuleIdentification>();\r
+                    Stack<LibraryClassDescriptor> lcdStack = new Stack<LibraryClassDescriptor>();\r
+                    for (int i = 0; i < vLcd.size(); ++i) {\r
+                        LibraryClassDescriptor lcd = vLcd.get(i);\r
+                        if (!lcdStack.contains(lcd)) {\r
+                            lcdStack.push(lcd);\r
+                        }\r
+                    }\r
                     try {\r
-                        resolveLibraryInstances(instanceValue, errorMsg);\r
+                        resolveLibraryInstances(lcdStack, true, errorMsg, newInstances);\r
                     }\r
                     catch (Exception exp) {\r
-                        JOptionPane.showMessageDialog(frame, exp.getMessage());\r
+                        JOptionPane.showMessageDialog(FpdModuleSA.this, exp.getMessage());\r
                     }\r
                     \r
+                    showClassToResolved();\r
+                    \r
                     if (errorMsg.size() > 0) {\r
                         String errors = "";\r
                         for (int i = 0; i < errorMsg.size(); ++i) {\r
                             errors += " " + errorMsg.get(i) + "\n";\r
                         }\r
-                        JOptionPane.showMessageDialog(frame, errors);\r
+                        JOptionPane.showMessageDialog(FpdModuleSA.this, errors);\r
                     }\r
-                    showClassToResolved();\r
                 }\r
             });\r
         }\r
@@ -1237,13 +1388,32 @@ public class FpdModuleSA extends JDialog implements ActionListener {
                         return;\r
                     }\r
                     docConsole.setSaved(false);\r
-                    removeInstance(selectedInstancesTableModel.getValueAt(row, 1) + " " +\r
-                                   selectedInstancesTableModel.getValueAt(row, 2) + " " +\r
-                                   selectedInstancesTableModel.getValueAt(row, 3) + " " +\r
-                                   selectedInstancesTableModel.getValueAt(row, 4));\r
-                    ffc.removeLibraryInstance(moduleKey, row);\r
-                    selectedInstancesTableModel.removeRow(row);\r
+                    String instanceKey = selectedInstancesTableModel.getValueAt(row, 1) + " "\r
+                                         + selectedInstancesTableModel.getValueAt(row, 2) + " "\r
+                                         + selectedInstancesTableModel.getValueAt(row, 3) + " "\r
+                                         + selectedInstancesTableModel.getValueAt(row, 4);\r
+                    removeInstance(instanceKey);\r
                     \r
+                    selectedInstancesTableModel.setRowCount(0);\r
+                    int instanceCount = ffc.getLibraryInstancesCount(moduleKey);\r
+                    if (instanceCount != 0) {\r
+                        String[][] saa = new String[instanceCount][5];\r
+                        ffc.getLibraryInstances(moduleKey, saa);\r
+                        for (int i = 0; i < saa.length; ++i) {\r
+                            String libInstanceKey = saa[i][1] + " " + saa[i][2] + " " + saa[i][3] + " " + saa[i][4];\r
+                            ModuleIdentification mi = WorkspaceProfile.getModuleId(libInstanceKey);\r
+                            if (mi != null) {\r
+                                //\r
+                                // ToDo: verify this instance first.\r
+                                //\r
+                                saa[i][0] = mi.getName();\r
+                                saa[i][2] = mi.getVersion();\r
+                                saa[i][4] = mi.getPackageId().getVersion();\r
+                                selectedInstancesTableModel.addRow(saa[i]);\r
+                            }\r
+                        }\r
+                    }\r
+                    showClassToResolved();\r
                 }\r
             });\r
         }\r
@@ -1366,7 +1536,7 @@ public class FpdModuleSA extends JDialog implements ActionListener {
                     //\r
                     oldFvList.removeAll(newFvList);\r
                     for (int j = 0; j < oldFvList.size(); ++j) {\r
-                        ffc.removeModuleInBuildOptionsUserExtensions(oldFvList.get(j), "IMAGES", 1, moduleInfo[0], moduleInfo[1], moduleInfo[2], moduleInfo[3], moduleInfo[4]);    \r
+                        ffc.removeModuleInBuildOptionsUserExtensions(oldFvList.get(j), "IMAGES", "1", moduleInfo[0], moduleInfo[1], moduleInfo[2], moduleInfo[3], moduleInfo[4]);    \r
                     }\r
                     //\r
                     // add module to Fvs that were not in oldFvList.\r
@@ -1374,7 +1544,7 @@ public class FpdModuleSA extends JDialog implements ActionListener {
                     oldFvList = getVectorFromString (originalFvBinding);\r
                     newFvList.removeAll(oldFvList);\r
                     for (int i = 0; i < newFvList.size(); ++i) {\r
-                        ffc.addModuleIntoBuildOptionsUserExtensions(newFvList.get(i), "IMAGES", 1, moduleInfo[0], moduleInfo[1], moduleInfo[2], moduleInfo[3], moduleInfo[4]);\r
+                        ffc.addModuleIntoBuildOptionsUserExtensions(newFvList.get(i), "IMAGES", "1", moduleInfo[0], moduleInfo[1], moduleInfo[2], moduleInfo[3], moduleInfo[4]);\r
                     }\r
                     docConsole.setSaved(false);\r
                 }\r
@@ -1405,7 +1575,7 @@ public class FpdModuleSA extends JDialog implements ActionListener {
                     }\r
                     if (newFileGuid.length() > 0) {\r
                         if (!DataValidation.isGuid(newFileGuid)) {\r
-                            JOptionPane.showMessageDialog(frame, "FFS File Guid is NOT GUID Type.");\r
+                            JOptionPane.showMessageDialog(FpdModuleSA.this, "FFS File Guid is NOT GUID Type.");\r
                             return;\r
                         }\r
                     }\r
@@ -1500,9 +1670,9 @@ public class FpdModuleSA extends JDialog implements ActionListener {
             vArch.add("EBC");\r
             vArch.add("ARM");\r
             vArch.add("PPC");\r
-            jTableModuleSaOptions.getColumnModel().getColumn(4).setCellEditor(new ListEditor(vArch));\r
+            jTableModuleSaOptions.getColumnModel().getColumn(4).setCellEditor(new ListEditor(vArch, FrameworkWizardUI.getInstance()));\r
             \r
-            jTableModuleSaOptions.getColumnModel().getColumn(5).setCellEditor(new LongTextEditor());\r
+            jTableModuleSaOptions.getColumnModel().getColumn(5).setCellEditor(new LongTextEditor(FrameworkWizardUI.getInstance()));\r
             \r
             jTableModuleSaOptions.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);\r
                        jTableModuleSaOptions.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);\r
@@ -1699,11 +1869,11 @@ private JComboBox getJComboBoxItemType() {
             public void itemStateChanged(java.awt.event.ItemEvent e) {\r
                 \r
                 int row = jTablePcd.getSelectedRow();\r
-                if (row < 0 || model.getValueAt(row, 2).equals(jComboBoxItemType.getSelectedItem())) {\r
+                if (row < 0) {\r
                     return;\r
                 }\r
                         \r
-                if (jComboBoxItemType.getSelectedItem().equals("FIXED_AT_BUILD")) {\r
+                if (jComboBoxItemType.getSelectedItem() != null && jComboBoxItemType.getSelectedItem().equals("FIXED_AT_BUILD")) {\r
                                    jTextFieldPcdDefault.setEnabled(true);\r
                 }\r
                 else {\r
@@ -1752,7 +1922,7 @@ private void pcdNonDynamicToDynamic(String cName, String tsGuid) {
         ffc.addDynamicPcdBuildData(cName, model.getValueAt(jTablePcd.getSelectedRow(), 3), tsGuid, "DYNAMIC", model.getValueAt(jTablePcd.getSelectedRow(), 5)+"", jTextFieldPcdDefault.isVisible() ? jTextFieldPcdDefault.getText() : jComboBoxFeatureFlagValue.getSelectedItem()+"");\r
     }\r
     catch(Exception e){\r
-        JOptionPane.showMessageDialog(frame, "PCD value format: " + e.getMessage());\r
+        JOptionPane.showMessageDialog(FpdModuleSA.this, "PCD value format: " + e.getMessage());\r
     }\r
 }\r
 \r
@@ -1839,7 +2009,7 @@ private JButton getJButtonUpdatePcd() {
                         jTextFieldMaxDatumSize.setText(ffc.setMaxSizeForPointer(newValue)+"");\r
                     }\r
                     catch (Exception exp) {\r
-                        JOptionPane.showMessageDialog(frame, "PCD Value MalFormed: " + exp.getMessage());\r
+                        JOptionPane.showMessageDialog(FpdModuleSA.this, "PCD Value MalFormed: " + exp.getMessage());\r
                         return;\r
                     }\r
                 }\r
@@ -1850,12 +2020,12 @@ private JButton getJButtonUpdatePcd() {
                     try {\r
                         boolean changable = itemTypeCouldBeChanged (cName, tsGuid, newItemType, moduleInfo);\r
                         if (!changable) {\r
-                            JOptionPane.showMessageDialog(frame, "Can NOT Change Pcd Type in: " + moduleInfo.get(0).getName() + " contained in package " + moduleInfo.get(0).getPackageId().getName());\r
+                            JOptionPane.showMessageDialog(FpdModuleSA.this, "Can NOT Change Pcd Type in: " + moduleInfo.get(0).getName() + " contained in package " + moduleInfo.get(0).getPackageId().getName());\r
                             return;\r
                         }\r
                     }\r
                     catch (Exception exp) {\r
-                        JOptionPane.showMessageDialog(frame, "Can NOT Change Pcd Type in: " + moduleInfo.get(0).getName() + " contained in package " + moduleInfo.get(0).getPackageId().getName() + " " + exp.getMessage());\r
+                        JOptionPane.showMessageDialog(FpdModuleSA.this, "Can NOT Change Pcd Type in: " + moduleInfo.get(0).getName() + " contained in package " + moduleInfo.get(0).getPackageId().getName() + " " + exp.getMessage());\r
                         return;\r
                     }\r
                     \r
@@ -2017,6 +2187,37 @@ class MultipleInstanceException extends Exception {
     \r
 }\r
 \r
+class ImproperInstanceException extends Exception {\r
+\r
+    /**\r
+     * \r
+     */\r
+    private static final long serialVersionUID = -5279700566993277033L;\r
+    private String className = null;\r
+    private String libInstance = null;\r
+    private String instanceSupArch = null;\r
+    private String instanceSupModType = null;\r
+    \r
+    ImproperInstanceException (String libClass, String instance1, String arch, String type) {\r
+        super();\r
+        className = libClass;\r
+        libInstance = instance1;\r
+        instanceSupArch = arch;\r
+        instanceSupModType = type;\r
+    }\r
+\r
+    /* (non-Javadoc)\r
+     * @see java.lang.Throwable#getMessage()\r
+     */\r
+    @Override\r
+    public String getMessage() {\r
+        // TODO Auto-generated method stub\r
+        return " Library Class " + className + " Produced by Library Instance: " \r
+            + libInstance + "\nOnly Supports " + instanceSupArch + " and Module Type " + instanceSupModType + ".\n This instance should be removed.\n";\r
+    }\r
+    \r
+}\r
+\r
 class NoInstanceException extends Exception {\r
 \r
     /**\r