]> 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 102dd3dc4669da5d056bf252d5da0f1f49767b89..b97e0d77e64ac4445d1d86a04fb924b5bd44e84c 100644 (file)
@@ -96,7 +96,6 @@ public class FpdModuleSA extends JDialog implements ActionListener {
     private FpdFileContents ffc = null;\r
     private String moduleKey = null;\r
     private ModuleIdentification moduleId = null;\r
-    private int moduleSaNum = -1;\r
     private HashMap<LibraryClassDescriptor, ArrayList<String>> classInstanceMap = null;\r
     //\r
     // map of <{libName, supArch, supMod}, list of Module information>\r
@@ -154,13 +153,12 @@ 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
+        initPcdBuildDefinition(moduleKey);\r
         moduleId = WorkspaceProfile.getModuleId(moduleKey);\r
         if (moduleId == null) {\r
             return;\r
@@ -178,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
@@ -187,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
@@ -236,6 +234,9 @@ public class FpdModuleSA extends JDialog implements ActionListener {
         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
@@ -575,12 +576,41 @@ public class FpdModuleSA extends JDialog implements ActionListener {
         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
@@ -600,7 +630,25 @@ 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
     }\r
@@ -738,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
@@ -1124,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
@@ -1335,12 +1388,31 @@ 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