]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Java/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdModuleSA.java
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@2297 6f19259b...
[mirror_edk2.git] / Tools / Java / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / platform / ui / FpdModuleSA.java
index 22bcf498acdfa1edc8e1c702840e0bafe5e46726..9b5ec73b6565684e9d5f4a31a141d1191bc36438 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
@@ -53,7 +53,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,6 +93,7 @@ public class FpdModuleSA extends JDialog implements ActionListener {
     private DefaultTableModel optionsTableModel = null;\r
     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
@@ -142,7 +142,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
@@ -159,12 +159,12 @@ public class FpdModuleSA extends JDialog implements ActionListener {
         classConsumed = null;\r
         jTabbedPane.setSelectedIndex(0);\r
         initPcdBuildDefinition(i);\r
-        ModuleIdentification mi = WorkspaceProfile.getModuleId(moduleKey);\r
-        if (mi == null) {\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
@@ -208,7 +208,7 @@ public class FpdModuleSA extends JDialog implements ActionListener {
         } catch (Exception e) {\r
             String exceptionMsg = e.getCause() + " " + e.getMessage();\r
             errorMsg.add(exceptionMsg);\r
-            JOptionPane.showMessageDialog(frame, exceptionMsg);\r
+            JOptionPane.showMessageDialog(FrameworkWizardUI.getInstance(), exceptionMsg);\r
         }\r
         //\r
         // display lib instances already selected for key\r
@@ -236,7 +236,7 @@ public class FpdModuleSA extends JDialog implements ActionListener {
                     } catch (Exception e) {\r
                         String exceptionMsg = e.getCause() + " " + e.getMessage();\r
                         if (!errorMsg.contains(exceptionMsg)) {\r
-                            JOptionPane.showMessageDialog(frame, e.getCause() + " " + e.getMessage());\r
+                            JOptionPane.showMessageDialog(FrameworkWizardUI.getInstance(), e.getCause() + " " + e.getMessage());\r
                         }\r
                     }\r
                     selectedInstancesTableModel.addRow(saa[i]);\r
@@ -249,7 +249,7 @@ public class FpdModuleSA extends JDialog implements ActionListener {
             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
@@ -349,11 +349,14 @@ public class FpdModuleSA extends JDialog implements ActionListener {
         //\r
         // Get dependency pkg list into which we will search lib instances.\r
         //\r
-        depPkgList = SurfaceAreaQuery.getDependencePkg(null, mi);\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
+        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
@@ -412,7 +415,7 @@ public class FpdModuleSA extends JDialog implements ActionListener {
         Iterator<LibraryClassDescriptor> lic = this.classConsumed.keySet().iterator();\r
         while (lic.hasNext()) {\r
             LibraryClassDescriptor cls = lic.next();\r
-            if (isBoundedClass(cls)) {\r
+            if (isBoundedClass(cls, errorMsg)) {\r
                 continue;\r
             }\r
             ArrayList<String> instances = getInstancesForClass(cls, depPkgList);\r
@@ -434,15 +437,30 @@ public class FpdModuleSA extends JDialog implements ActionListener {
      * @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 +487,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 +506,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
@@ -561,6 +579,7 @@ 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
@@ -574,19 +593,35 @@ public class FpdModuleSA extends JDialog implements ActionListener {
                 continue;\r
             }\r
             \r
-            if (!isBoundedClass(lcd)){\r
+            if (!isBoundedClass(lcd, errorMsg)){\r
                 libClassTableModel.addRow(s);\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
@@ -758,7 +793,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
@@ -1189,7 +1224,7 @@ public class FpdModuleSA extends JDialog implements ActionListener {
                         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
@@ -1203,7 +1238,7 @@ public class FpdModuleSA extends JDialog implements ActionListener {
                         resolveLibraryInstances(instanceValue, errorMsg);\r
                     }\r
                     catch (Exception exp) {\r
-                        JOptionPane.showMessageDialog(frame, exp.getMessage());\r
+                        JOptionPane.showMessageDialog(FpdModuleSA.this, exp.getMessage());\r
                     }\r
                     \r
                     if (errorMsg.size() > 0) {\r
@@ -1211,7 +1246,7 @@ public class FpdModuleSA extends JDialog implements ActionListener {
                         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
@@ -1405,7 +1440,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 +1535,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
@@ -1752,7 +1787,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 +1874,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 +1885,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 +2052,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