]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Added prints to console to tell that mapping has failed. This does not fix the fact...
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 31 Jul 2012 06:58:45 +0000 (06:58 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 31 Jul 2012 06:58:45 +0000 (06:58 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@25372 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynConsole.java [new file with mode: 0644]
org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynModel.java
org.simantics.sysdyn/src/org/simantics/sysdyn/representation/LoadRepresentation.java
org.simantics.sysdyn/src/org/simantics/sysdyn/simulation/SimulationJob.java

diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynConsole.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynConsole.java
new file mode 100644 (file)
index 0000000..90d7305
--- /dev/null
@@ -0,0 +1,206 @@
+package org.simantics.sysdyn.manager;\r
+\r
+import java.text.SimpleDateFormat;\r
+import java.util.Calendar;\r
+\r
+import org.eclipse.jface.text.BadLocationException;\r
+import org.eclipse.ui.PartInitException;\r
+import org.eclipse.ui.PlatformUI;\r
+import org.eclipse.ui.console.ConsolePlugin;\r
+import org.eclipse.ui.console.IConsole;\r
+import org.eclipse.ui.console.IConsoleManager;\r
+import org.eclipse.ui.console.IHyperlink;\r
+import org.eclipse.ui.console.IPatternMatchListener;\r
+import org.eclipse.ui.console.MessageConsole;\r
+import org.eclipse.ui.console.MessageConsoleStream;\r
+import org.eclipse.ui.console.PatternMatchEvent;\r
+import org.eclipse.ui.console.TextConsole;\r
+import org.simantics.modelica.IModelicaMonitor;\r
+\r
+public class SysdynConsole  implements IModelicaMonitor {\r
+\r
+    private static String SYSDYN_CONSOLE = "Sysyn modelica console";\r
+    private MessageConsole console;\r
+\r
+    public static SysdynConsole INSTANCE = new SysdynConsole();\r
+    \r
+    public SysdynConsole() {\r
+        ConsolePlugin plugin = ConsolePlugin.getDefault();\r
+        IConsoleManager conMan = plugin.getConsoleManager();\r
+        IConsole[] existing = conMan.getConsoles();\r
+        for (int i = 0; i < existing.length; i++)\r
+            if (existing[i].getName().equals(SYSDYN_CONSOLE))\r
+                console =  (MessageConsole) existing[i];\r
+        if(console == null) {\r
+            MessageConsole myConsole = new MessageConsole(SYSDYN_CONSOLE, null);\r
+            conMan.addConsoles(new IConsole[]{myConsole});\r
+            console = myConsole;\r
+            console.addPatternMatchListener(new IPatternMatchListener() {\r
+\r
+                @Override\r
+                public void matchFound(PatternMatchEvent event) {\r
+                    try {\r
+                        console.addHyperlink(new IssueLink(), event.getOffset(), event.getLength());\r
+                    } catch (BadLocationException e) {\r
+                        e.printStackTrace();\r
+                    }\r
+                }\r
+\r
+                @Override\r
+                public void disconnect() {\r
+                }\r
+\r
+                @Override\r
+                public void connect(TextConsole console) {\r
+                }\r
+\r
+                @Override\r
+                public String getPattern() {\r
+                    \r
+                    return "Issues view";\r
+                }\r
+\r
+                @Override\r
+                public String getLineQualifier() {\r
+                    return null;\r
+                }\r
+\r
+                @Override\r
+                public int getCompilerFlags() {\r
+                    return 0;\r
+                }\r
+            });\r
+            \r
+            /* Link to the modelica document: to be opened to a modelica code viewer.\r
+            console.addPatternMatchListener(new IPatternMatchListener() {\r
+\r
+                @Override\r
+                public void matchFound(PatternMatchEvent event) {\r
+                    try {\r
+                        if(event.getSource() instanceof MessageConsole) {\r
+                            MessageConsole console = (MessageConsole) event.getSource();\r
+                            IDocument document = console.getDocument();\r
+                            String s = document.get(event.getOffset(), event.getLength());\r
+                            s = s.substring(s.indexOf(":") + 1, s.lastIndexOf(":"));\r
+                            String[] split = s.split(":|-");\r
+                            \r
+                            //TODO: Find the modelica document and its locations\r
+                            int startOffset = modelicaDocument.getLineOffset(Integer.parseInt(split[0])) + Integer.parseInt(split[1]);\r
+                            int endOffset = modelicaDocument.getLineOffset(Integer.parseInt(split[2])) + Integer.parseInt(split[3]);\r
+                            System.out.println("Open modelica editor for model at: " + startOffset + ", " + (endOffset - startOffset));\r
+                            \r
+                        }\r
+                        \r
+                        console.addHyperlink(new ModelicaLink(), event.getOffset(), event.getLength());\r
+                    } catch (BadLocationException e) {\r
+                        e.printStackTrace();\r
+                    }\r
+                }\r
+\r
+                @Override\r
+                public void disconnect() {\r
+                }\r
+\r
+                @Override\r
+                public void connect(TextConsole console) {\r
+                }\r
+\r
+                @Override\r
+                public String getPattern() {\r
+                    return "\\[[^\\[]*:[\\d]*:[\\d]*\\-[\\d]*:[\\d]*:writable\\]";\r
+\r
+                }\r
+\r
+                @Override\r
+                public String getLineQualifier() {\r
+                    return null;\r
+                }\r
+\r
+                @Override\r
+                public int getCompilerFlags() {\r
+                    return 0;\r
+                }\r
+            });\r
+            */\r
+\r
+\r
+        }\r
+    }\r
+\r
+    @Override\r
+    public void message(String message) {\r
+        message(message, "hh:mm:ss");\r
+    }\r
+\r
+    /**\r
+     * Print message to a console with a specified time stamp format\r
+     * \r
+     * @param message the message to be printed\r
+     * @param timeStampFormat simpledateformat timestamp format. null if no timestamp wanted\r
+     */\r
+    public void message(String message, String timeStampFormat) {\r
+        Calendar cal = Calendar.getInstance();\r
+        SimpleDateFormat sdf = new SimpleDateFormat(timeStampFormat);\r
+        String time = sdf.format(cal.getTime());\r
+\r
+        MessageConsoleStream out = this.console.newMessageStream();\r
+        if(message.length() > 1)\r
+            out.println("[" + time +"] " + message);\r
+\r
+\r
+\r
+        if(message.contains("Error")) {\r
+            showConsole();\r
+            out.println("See Issues view");\r
+        }\r
+    }\r
+\r
+    public void clearConsole() {\r
+        this.console.clearConsole();\r
+    }\r
+\r
+    public void showConsole() {\r
+        ConsolePlugin plugin = ConsolePlugin.getDefault();\r
+        IConsoleManager conMan = plugin.getConsoleManager();\r
+        conMan.showConsoleView(console);\r
+    }\r
+    \r
+\r
+    class IssueLink implements IHyperlink {\r
+\r
+        @Override\r
+        public void linkEntered() {\r
+        }\r
+\r
+        @Override\r
+        public void linkExited() {\r
+        }\r
+\r
+        @Override\r
+        public void linkActivated() {\r
+            try {\r
+                PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView("org.simantics.issues.ui.issueview");\r
+            } catch (PartInitException e) {\r
+                e.printStackTrace();\r
+            }            \r
+        }\r
+    }\r
+    \r
+    class ModelicaLink implements IHyperlink {\r
+\r
+        @Override\r
+        public void linkEntered() {\r
+        }\r
+\r
+        @Override\r
+        public void linkExited() {\r
+        }\r
+\r
+        @Override\r
+        public void linkActivated() {\r
+            System.out.println("MODELICA LINK");           \r
+        }\r
+\r
+    }\r
+\r
+}\r
index 00379a9c11359dae8499420086473f4b5eb975b3..b5aebdae25291ea90d941860f52e2ad95a678736 100644 (file)
@@ -36,6 +36,7 @@ import org.simantics.db.service.VirtualGraphSupport;
 import org.simantics.layer0.Layer0;\r
 import org.simantics.objmap.IMapping;\r
 import org.simantics.objmap.IMappingListener;\r
+import org.simantics.objmap.MappingException;\r
 import org.simantics.objmap.Mappings;\r
 import org.simantics.project.IProject;\r
 import org.simantics.simulation.experiment.IDynamicExperiment;\r
@@ -139,7 +140,16 @@ public class SysdynModel implements IMappingListener, IModel, VariableSubscripti
         SysdynSchema schema = new SysdynSchema(g);\r
         mapping = Mappings.createWithListening(schema);\r
         mapping.addMappingListener(SysdynModel.this);\r
-        configuration = (Configuration)mapping.map(g, configurationResource);\r
+        try {\r
+            configuration = (Configuration)mapping.map(g, configurationResource);                \r
+        } catch (MappingException e) {\r
+            SysdynConsole.INSTANCE.message(\r
+                    "Error: Mapping is broken! Find the problem, " +\r
+                    "fix it and restart the program." +\r
+                    "\nJava error message:\n" + \r
+                            e.getMessage());\r
+            throw e;\r
+        }\r
         for(Resource config : readModules(g, configurationResource)) {\r
             modules.add((Configuration)mapping.map(g, config));\r
         }\r
@@ -256,7 +266,17 @@ public class SysdynModel implements IMappingListener, IModel, VariableSubscripti
      */\r
     public synchronized boolean update(ReadGraph graph) throws DatabaseException {\r
         if(mapping.isDomainModified()) {\r
-            mapping.updateRange(graph);\r
+            \r
+            try {\r
+                mapping.updateRange(graph);\r
+            } catch (MappingException e) {\r
+                SysdynConsole.INSTANCE.message(\r
+                        "Error: Mapping is broken! Find the problem, " +\r
+                        "fix it and restart the program." +\r
+                        "\nJava error message:\n" + \r
+                                e.getMessage());\r
+                throw e;\r
+            }\r
 \r
             // Remove all unnecessary module configurations from modules \r
             Set<Resource> configs = readModules(graph, configurationResource); \r
index 912f2e9ba21f999544538e44822677a4f5c7e3f4..fd5aac59482c4f4a3021518d4a70c62192f14034 100644 (file)
@@ -17,7 +17,9 @@ import org.simantics.db.Session;
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.db.request.Read;\r
 import org.simantics.objmap.IMapping;\r
+import org.simantics.objmap.MappingException;\r
 import org.simantics.objmap.Mappings;\r
+import org.simantics.sysdyn.manager.SysdynConsole;\r
 \r
 public class LoadRepresentation {\r
     \r
@@ -29,7 +31,18 @@ public class LoadRepresentation {
                     throws DatabaseException {\r
                 SysdynSchema schema = new SysdynSchema(graph);\r
                 IMapping mapping = Mappings.createWithoutListening(schema);\r
-                mapping.map(graph, configuration);\r
+                \r
+                try {\r
+                    mapping.map(graph, configuration);\r
+                } catch (MappingException e) {\r
+                    SysdynConsole.INSTANCE.message(\r
+                            "Error: Mapping is broken! Find the problem, " +\r
+                            "fix it and restart the program." +\r
+                            "\nJava error message:\n" + \r
+                                    e.getMessage());\r
+                    throw e;\r
+                }\r
+                \r
                 return mapping;\r
             }\r
             \r
@@ -44,7 +57,18 @@ public class LoadRepresentation {
                     throws DatabaseException {\r
                 SysdynSchema schema = new SysdynSchema(graph);\r
                 IMapping mapping = Mappings.createWithoutListening(schema);\r
-                return (Configuration)mapping.map(graph, configuration);                \r
+                \r
+                try {\r
+                    return (Configuration)mapping.map(graph, configuration);                \r
+                } catch (MappingException e) {\r
+                    SysdynConsole.INSTANCE.message(\r
+                            "Error: Mapping is broken! Find the problem, " +\r
+                            "fix it and restart the program." +\r
+                            "\nJava error message:\n" + \r
+                                    e.getMessage());\r
+                    throw e;\r
+                }\r
+                \r
             }\r
             \r
         });\r
@@ -58,7 +82,18 @@ public class LoadRepresentation {
                     throws DatabaseException {\r
                 SysdynSchema schema = new SysdynSchema(graph);\r
                 IMapping mapping = Mappings.createWithoutListening(schema);\r
-                return (IElement)mapping.map(graph, element);                \r
+                \r
+                try {\r
+                    return (IElement)mapping.map(graph, element);                \r
+                } catch (MappingException e) {\r
+                    SysdynConsole.INSTANCE.message(\r
+                            "Error: Mapping is broken! Find the problem, " +\r
+                            "fix it and restart the program." +\r
+                            "\nJava error message:\n" + \r
+                                    e.getMessage());\r
+                    throw e;\r
+                }\r
+                \r
             }\r
             \r
         });\r
index ccb4d92e92821d9d05b1a563824976979458591d..f61c40c1fe0daf84f189a24ef5eb63a822f1f952 100644 (file)
@@ -18,35 +18,25 @@ import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;\r
 import org.eclipse.core.runtime.Status;\r
 import org.eclipse.core.runtime.jobs.Job;\r
-import org.eclipse.jface.text.BadLocationException;\r
-import org.eclipse.ui.PartInitException;\r
 import org.eclipse.ui.PlatformUI;\r
-import org.eclipse.ui.console.ConsolePlugin;\r
-import org.eclipse.ui.console.IConsole;\r
-import org.eclipse.ui.console.IConsoleManager;\r
-import org.eclipse.ui.console.IHyperlink;\r
-import org.eclipse.ui.console.IPatternMatchListener;\r
-import org.eclipse.ui.console.MessageConsole;\r
-import org.eclipse.ui.console.MessageConsoleStream;\r
-import org.eclipse.ui.console.PatternMatchEvent;\r
-import org.eclipse.ui.console.TextConsole;\r
 import org.simantics.modelica.IModelicaMonitor;\r
 import org.simantics.simulation.experiment.Experiment;\r
+import org.simantics.sysdyn.manager.SysdynConsole;\r
 import org.simantics.sysdyn.manager.SysdynExperiment;\r
 import org.simantics.sysdyn.manager.SysdynModel;\r
 \r
 public class SimulationJob extends Job {\r
 \r
-    SysdynModel model;\r
-    Experiment experiment;\r
-    IModelicaMonitor monitor;\r
-\r
+    private SysdynModel model;\r
+    private Experiment experiment;\r
+    private IModelicaMonitor monitor;\r
+    \r
     public SimulationJob(SysdynModel model, Experiment experiment) {\r
         super("Simulate " + model.getConfiguration().getLabel());\r
         this.model = model;\r
         this.experiment = experiment;\r
         if(PlatformUI.isWorkbenchRunning()) {\r
-            this.monitor = new ModelicaMonitor();\r
+            this.monitor = SysdynConsole.INSTANCE;\r
         } else {\r
             // Fallback to headless\r
             this.monitor = new HeadlessModelicaMonitor();\r
@@ -109,153 +99,6 @@ public class SimulationJob extends Job {
         public void showConsole() {\r
         }\r
 \r
-    }\r
-    //org.simantics.sysdyn.ui.modelicaEditor\r
-    private class ModelicaMonitor implements IModelicaMonitor {\r
-\r
-        MessageConsole console;\r
-\r
-        public ModelicaMonitor() {\r
-            ConsolePlugin plugin = ConsolePlugin.getDefault();\r
-            IConsoleManager conMan = plugin.getConsoleManager();\r
-            IConsole[] existing = conMan.getConsoles();\r
-            for (int i = 0; i < existing.length; i++)\r
-                if (existing[i].getName().equals("Simulation"))\r
-                    console =  (MessageConsole) existing[i];\r
-            if(console == null) {\r
-                MessageConsole myConsole = new MessageConsole("Simulation", null);\r
-                conMan.addConsoles(new IConsole[]{myConsole});\r
-                console = myConsole;\r
-                console.addPatternMatchListener(new IPatternMatchListener() {\r
-\r
-                    @Override\r
-                    public void matchFound(PatternMatchEvent event) {\r
-                        try {\r
-                            console.addHyperlink(new IssueLink(), event.getOffset(), event.getLength());\r
-                        } catch (BadLocationException e) {\r
-                            e.printStackTrace();\r
-                        }\r
-                    }\r
-\r
-                    @Override\r
-                    public void disconnect() {\r
-                    }\r
-\r
-                    @Override\r
-                    public void connect(TextConsole console) {\r
-                    }\r
-\r
-                    @Override\r
-                    public String getPattern() {\r
-                        \r
-                        return "Issues view";\r
-                    }\r
-\r
-                    @Override\r
-                    public String getLineQualifier() {\r
-                        return null;\r
-                    }\r
-\r
-                    @Override\r
-                    public int getCompilerFlags() {\r
-                        return 0;\r
-                    }\r
-                });\r
-                \r
-                /* Link to the modelica document: to be opened to a modelica code viewer.\r
-                console.addPatternMatchListener(new IPatternMatchListener() {\r
-\r
-                    @Override\r
-                    public void matchFound(PatternMatchEvent event) {\r
-                        try {\r
-                            if(event.getSource() instanceof MessageConsole) {\r
-                                MessageConsole console = (MessageConsole) event.getSource();\r
-                                IDocument document = console.getDocument();\r
-                                String s = document.get(event.getOffset(), event.getLength());\r
-                                s = s.substring(s.indexOf(":") + 1, s.lastIndexOf(":"));\r
-                                String[] split = s.split(":|-");\r
-                                \r
-                                //TODO: Find the modelica document and its locations\r
-                                int startOffset = modelicaDocument.getLineOffset(Integer.parseInt(split[0])) + Integer.parseInt(split[1]);\r
-                                int endOffset = modelicaDocument.getLineOffset(Integer.parseInt(split[2])) + Integer.parseInt(split[3]);\r
-                                System.out.println("Open modelica editor for model at: " + startOffset + ", " + (endOffset - startOffset));\r
-                                \r
-                            }\r
-                            \r
-                            console.addHyperlink(new ModelicaLink(), event.getOffset(), event.getLength());\r
-                        } catch (BadLocationException e) {\r
-                            e.printStackTrace();\r
-                        }\r
-                    }\r
-\r
-                    @Override\r
-                    public void disconnect() {\r
-                    }\r
-\r
-                    @Override\r
-                    public void connect(TextConsole console) {\r
-                    }\r
-\r
-                    @Override\r
-                    public String getPattern() {\r
-                        return "\\[[^\\[]*:[\\d]*:[\\d]*\\-[\\d]*:[\\d]*:writable\\]";\r
-\r
-                    }\r
-\r
-                    @Override\r
-                    public String getLineQualifier() {\r
-                        return null;\r
-                    }\r
-\r
-                    @Override\r
-                    public int getCompilerFlags() {\r
-                        return 0;\r
-                    }\r
-                });\r
-                */\r
-\r
-\r
-            }\r
-        }\r
-\r
-        @Override\r
-        public void message(String message) {\r
-            message(message, "hh:mm:ss");\r
-        }\r
-\r
-        /**\r
-         * Print message to a console with a specified time stamp format\r
-         * \r
-         * @param message the message to be printed\r
-         * @param timeStampFormat simpledateformat timestamp format. null if no timestamp wanted\r
-         */\r
-        public void message(String message, String timeStampFormat) {\r
-            Calendar cal = Calendar.getInstance();\r
-            SimpleDateFormat sdf = new SimpleDateFormat(timeStampFormat);\r
-            String time = sdf.format(cal.getTime());\r
-\r
-            MessageConsoleStream out = this.console.newMessageStream();\r
-            if(message.length() > 1)\r
-                out.println("[" + time +"] " + message);\r
-\r
-\r
-\r
-            if(message.contains("Error")) {\r
-                showConsole();\r
-                out.println("See Issues view");\r
-            }\r
-        }\r
-\r
-        public void clearConsole() {\r
-            this.console.clearConsole();\r
-        }\r
-\r
-        public void showConsole() {\r
-            ConsolePlugin plugin = ConsolePlugin.getDefault();\r
-            IConsoleManager conMan = plugin.getConsoleManager();\r
-            conMan.showConsoleView(console);\r
-        }\r
-\r
     }\r
 \r
     @Override\r
@@ -263,42 +106,4 @@ public class SimulationJob extends Job {
 \r
     }\r
 \r
-\r
-    class IssueLink implements IHyperlink {\r
-\r
-        @Override\r
-        public void linkEntered() {\r
-        }\r
-\r
-        @Override\r
-        public void linkExited() {\r
-        }\r
-\r
-        @Override\r
-        public void linkActivated() {\r
-            try {\r
-                PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView("org.simantics.issues.ui.issueview");\r
-            } catch (PartInitException e) {\r
-                e.printStackTrace();\r
-            }            \r
-        }\r
-    }\r
-    \r
-    class ModelicaLink implements IHyperlink {\r
-\r
-        @Override\r
-        public void linkEntered() {\r
-        }\r
-\r
-        @Override\r
-        public void linkExited() {\r
-        }\r
-\r
-        @Override\r
-        public void linkActivated() {\r
-            System.out.println("MODELICA LINK");           \r
-        }\r
-\r
-    }\r
-\r
 }\r