]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Better handling for result files (e.g. automatic remove when project activated) and...
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Fri, 11 Jun 2010 12:26:58 +0000 (12:26 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Fri, 11 Jun 2010 12:26:58 +0000 (12:26 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@16140 ac1ea38d-2e2b-0410-8846-a27921b304fc

14 files changed:
org.simantics.sysdyn.ui/icons/chart_bar_blackAndWhite.png [new file with mode: 0644]
org.simantics.sysdyn.ui/icons/tick.png [new file with mode: 0644]
org.simantics.sysdyn.ui/plugin.xml
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/Activator.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/SysdynBrowser.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ExperimentImager.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ExperimentLabelDecorator.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SimulationResult.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SimulationResultDecorator.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/SimulationResultImager.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/UnlinkNodeHandler.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynProjectLifeCycle.java
org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynExperiment.java
sysdyn_ontologies/sysdyn.graph

diff --git a/org.simantics.sysdyn.ui/icons/chart_bar_blackAndWhite.png b/org.simantics.sysdyn.ui/icons/chart_bar_blackAndWhite.png
new file mode 100644 (file)
index 0000000..087f88c
Binary files /dev/null and b/org.simantics.sysdyn.ui/icons/chart_bar_blackAndWhite.png differ
diff --git a/org.simantics.sysdyn.ui/icons/tick.png b/org.simantics.sysdyn.ui/icons/tick.png
new file mode 100644 (file)
index 0000000..a9925a0
Binary files /dev/null and b/org.simantics.sysdyn.ui/icons/tick.png differ
index 40eb7ca1819e36ff571d9e2b1e6e379f46cd30a0..fedd9c93b7437fab1cd76f6b4120c1dbe6d2c5d2 100644 (file)
          <command\r
                commandId="org.simantics.sysdyn.ui.activateResult"\r
                id="org.simantics.sysdyn.ui.browser.activateResult"\r
-               label="Activate"\r
+               label="Show in charts"\r
                style="push">\r
             <visibleWhen\r
                   checkEnabled="true">\r
       <command\r
             defaultHandler="org.simantics.sysdyn.ui.handlers.ToggleResultActivation"\r
             id="org.simantics.sysdyn.ui.activateResult"\r
-            name="Activate Result">\r
+            name="Show in charts">\r
       </command>\r
       <command\r
             defaultHandler="org.simantics.sysdyn.ui.handlers.NewExperimentNodeHandler"\r
          <activeWhen>\r
             <with\r
                   variable="selection">\r
-               <test\r
-                     args="org.simantics.sysdyn.ui.browser.nodes.ModelNode"\r
-                     property="org.simantics.sysdyn.ui.nodeClass">\r
-               </test>\r
+               <or>\r
+                  <test\r
+                        args="org.simantics.sysdyn.ui.browser.nodes.ModelNode"\r
+                        property="org.simantics.sysdyn.ui.nodeClass">\r
+                  </test>\r
+                  <test\r
+                        args="org.simantics.sysdyn.ui.browser.nodes.ExperimentNode"\r
+                        property="org.simantics.sysdyn.ui.nodeClass">\r
+                  </test>\r
+                  <test\r
+                        args="org.simantics.sysdyn.ui.browser.nodes.SimulationResultNode"\r
+                        property="org.simantics.sysdyn.ui.nodeClass">\r
+                  </test>\r
+               </or>\r
             </with>\r
          </activeWhen>\r
       </handler>\r
                class="org.simantics.sysdyn.ui.browser.contributions.SimulationResultDecorator"\r
                preference="2.0">\r
          </implementation>\r
+         <implementation\r
+               class="org.simantics.sysdyn.ui.browser.contributions.ExperimentLabelDecorator"\r
+               preference="2.0">\r
+         </implementation>\r
       </binding>\r
    </extension>\r
    <extension\r
index 54140cc4541d7b9f8eb01d13f27f0e8690532298..988e479d4d030901f60e8926732e4a7613274f7b 100644 (file)
@@ -16,6 +16,10 @@ import org.apache.log4j.ConsoleAppender;
 import org.apache.log4j.Level;\r
 import org.apache.log4j.Logger;\r
 import org.apache.log4j.SimpleLayout;\r
+import org.eclipse.jface.resource.JFaceResources;\r
+import org.eclipse.jface.resource.LocalResourceManager;\r
+import org.eclipse.jface.resource.ResourceManager;\r
+import org.eclipse.swt.widgets.Display;\r
 import org.eclipse.ui.plugin.AbstractUIPlugin;\r
 import org.osgi.framework.BundleContext;\r
 \r
@@ -26,6 +30,8 @@ public class Activator extends AbstractUIPlugin {
     \r
     // The shared instance\r
     private static Activator plugin;\r
+    \r
+    private static LocalResourceManager resourceManager;\r
 \r
     @Override\r
     public void start(BundleContext context) throws Exception {\r
@@ -46,4 +52,17 @@ public class Activator extends AbstractUIPlugin {
     public static Activator getDefault() {\r
         return plugin;\r
     }\r
+    \r
+    public static ResourceManager initializeResourceManager(Display display) {\r
+        if (resourceManager == null) {\r
+            resourceManager = new LocalResourceManager(JFaceResources.getResources(display));\r
+        }\r
+        return resourceManager;\r
+    }\r
+\r
+    public static ResourceManager getResources() {\r
+        if (resourceManager == null)\r
+            throw new IllegalStateException("ResourceManager of bundle '" + PLUGIN_ID + "' is not initialized.");\r
+        return resourceManager;\r
+    }\r
 }\r
index aa546cde92c92888163b0645a616ff66e05123cb..bc107306027ab7963e248261d6ce72c64d776c25 100644 (file)
@@ -13,9 +13,12 @@ package org.simantics.sysdyn.ui.browser;
 \r
 import java.util.Collections;\r
 import java.util.Set;\r
+\r
+import org.eclipse.swt.widgets.Composite;\r
 import org.simantics.browsing.ui.swt.ContextMenuInitializer;\r
 import org.simantics.browsing.ui.swt.GraphExplorerView;\r
 import org.simantics.browsing.ui.swt.IContextMenuInitializer;\r
+import org.simantics.sysdyn.ui.Activator;\r
 \r
 \r
 public class SysdynBrowser extends GraphExplorerView {\r
@@ -31,4 +34,15 @@ public class SysdynBrowser extends GraphExplorerView {
     protected Set<String> getBrowseContexts() {\r
         return browseContexts;\r
     }\r
+    \r
+    @Override\r
+    protected void createControls(Composite parent) {\r
+        // Make sure the resource manager of this plug-in is initialized\r
+        // properly before using it in this browser.\r
+        Activator.initializeResourceManager(parent.getDisplay());\r
+\r
+        super.createControls(parent);\r
+        //IToolBarManager toolBar = getViewSite().getActionBars().getToolBarManager();\r
+        //toolBar.add(new HomeAction());\r
+    }\r
 }\r
index a4262231e19249310212b0779906ad743a06dd83..0f607d5dbe4d08d2a78c793afa7d3aa8ae8d16b1 100644 (file)
@@ -4,13 +4,19 @@ import org.eclipse.jface.resource.ImageDescriptor;
 import org.simantics.browsing.ui.swt.ImagerContributor;\r
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.project.IProject;\r
+import org.simantics.simulation.project.IExperimentManager;\r
 import org.simantics.sysdyn.ui.Activator;\r
 import org.simantics.sysdyn.ui.browser.nodes.ExperimentNode;\r
+import org.simantics.ui.SimanticsUI;\r
 \r
 public class ExperimentImager extends ImagerContributor<ExperimentNode> {\r
     \r
     @Override\r
     public ImageDescriptor getDescriptor(ReadGraph graph, ExperimentNode experiment) throws DatabaseException {\r
+        IProject project = SimanticsUI.getProject();\r
+        IExperimentManager experimentManager = project.getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);\r
+        System.out.println(experimentManager.getActiveExperiment());\r
         return ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/time.png"));\r
     }\r
 \r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ExperimentLabelDecorator.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ExperimentLabelDecorator.java
new file mode 100644 (file)
index 0000000..f0e0361
--- /dev/null
@@ -0,0 +1,43 @@
+package org.simantics.sysdyn.ui.browser.contributions;\r
+\r
+import org.eclipse.jface.resource.FontDescriptor;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.graphics.Font;\r
+import org.simantics.browsing.ui.content.LabelDecorator;\r
+import org.simantics.browsing.ui.graph.contributor.labeler.LabelDecoratorContributor;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.simulation.experiment.IExperiment;\r
+import org.simantics.simulation.project.IExperimentManager;\r
+import org.simantics.sysdyn.manager.SysdynExperiment;\r
+import org.simantics.sysdyn.ui.Activator;\r
+import org.simantics.sysdyn.ui.browser.nodes.ExperimentNode;\r
+import org.simantics.ui.SimanticsUI;\r
+\r
+public class ExperimentLabelDecorator extends LabelDecoratorContributor<ExperimentNode> {\r
+\r
+    @Override\r
+    public LabelDecorator getDecorator(ReadGraph graph, ExperimentNode experimentNode) throws DatabaseException {\r
+        IExperimentManager manager = \r
+            SimanticsUI.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);\r
+        IExperiment exp = manager.getActiveExperiment();\r
+        if(exp instanceof SysdynExperiment) {\r
+            SysdynExperiment experiment = (SysdynExperiment) exp;\r
+            if(experiment.getResource().equals(experimentNode.resource))\r
+                return new LabelDecorator.Stub() {\r
+                @Override\r
+                public String decorateLabel(String label, String column, int itemIndex) {\r
+                    return label + " [ACTIVE]";\r
+                }\r
+\r
+                @SuppressWarnings("unchecked")\r
+                @Override\r
+                public <F> F decorateFont(F font, String column, int itemIndex) {\r
+                    return (F) Activator.getResources().get(FontDescriptor.createFrom((Font) font).withStyle(SWT.BOLD));\r
+                }\r
+            };\r
+        }\r
+        return null;\r
+    }\r
+\r
+}\r
index 7133bd17f95d9ba0ebaead3da509f9effe7ed3e6..cf5bfb1dec5dfadde99c14e98a1626a160cfe146 100644 (file)
@@ -1,13 +1,15 @@
 package org.simantics.sysdyn.ui.browser.contributions;\r
 \r
+import java.io.File;\r
 import java.util.ArrayList;\r
 import java.util.Collection;\r
 \r
 import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor;\r
-import org.simantics.db.Builtins;\r
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
 import org.simantics.db.common.request.ObjectsWithType;\r
+import org.simantics.db.common.request.WriteRequest;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.sysdyn.ui.browser.nodes.AbstractNode;\r
@@ -18,13 +20,26 @@ public class SimulationResult  extends ViewpointContributor<ExperimentNode> {
     @Override\r
     public Collection<?> getContribution(ReadGraph graph, ExperimentNode experiment) throws DatabaseException {\r
         ArrayList<AbstractNode> result = new ArrayList<AbstractNode>();\r
-        Builtins b = graph.getBuiltins();\r
         SysdynResource sr = SysdynResource.getInstance(graph);\r
-        for(Resource r : graph.syncRequest(new ObjectsWithType(experiment.resource, sr.HasResult, sr.Result))) {\r
-            try {\r
-                result.add(graph.adapt(r, AbstractNode.class));\r
-            } catch(DatabaseException e) {\r
-                e.printStackTrace();\r
+        for(final Resource r : graph.syncRequest(new ObjectsWithType(experiment.resource, sr.HasResult, sr.Result))) {\r
+            String resultPath = (String)graph.getPossibleRelatedValue(r, sr.HasResultFile);\r
+            File file = new File(resultPath);\r
+            if(file.exists()) {\r
+                try {\r
+                    result.add(graph.adapt(r, AbstractNode.class));\r
+                } catch(DatabaseException e) {\r
+                    e.printStackTrace();\r
+                }\r
+            } else {\r
+                graph.asyncRequest(new WriteRequest() {\r
+                    \r
+                    @Override\r
+                    public void perform(WriteGraph graph) throws DatabaseException {\r
+                        graph.deny(r, b.PartOf);\r
+                        graph.deny(r, graph.getInverse(SysdynResource.getInstance(graph).HasResult));\r
+                        \r
+                    }\r
+                });\r
             }\r
         }\r
         return result;\r
index 78333c56d8ccc1cd721f251ac22c78b61700934c..7b2400f43b49e3eeb302bc1fade86375f3103422 100644 (file)
@@ -1,10 +1,14 @@
 package org.simantics.sysdyn.ui.browser.contributions;\r
 \r
+import org.eclipse.jface.resource.FontDescriptor;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.graphics.Font;\r
 import org.simantics.browsing.ui.content.LabelDecorator;\r
 import org.simantics.browsing.ui.graph.contributor.labeler.LabelDecoratorContributor;\r
 import org.simantics.db.Builtins;\r
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.sysdyn.ui.Activator;\r
 import org.simantics.sysdyn.ui.browser.nodes.SimulationResultNode;\r
 \r
 public class SimulationResultDecorator extends LabelDecoratorContributor<SimulationResultNode>{\r
@@ -14,9 +18,11 @@ public class SimulationResultDecorator extends LabelDecoratorContributor<Simulat
         Builtins b = graph.getBuiltins();\r
         if (graph.hasStatement(result.resource, b.IsActive)) {\r
             return new LabelDecorator.Stub() {\r
+                \r
+                @SuppressWarnings("unchecked")\r
                 @Override\r
-                public String decorateLabel(String label, String column, int itemIndex) {\r
-                    return label + " [ACTIVE]";\r
+                public <F> F decorateFont(F font, String column, int itemIndex) {\r
+                    return (F) Activator.getResources().get(FontDescriptor.createFrom((Font) font).withStyle(SWT.BOLD));\r
                 }\r
             };\r
         }\r
index 1aef4422a30d7943ad98b15fe55681d6fbc7cdd0..1bc94307423f64a68a7e3f22a66641c1318e525d 100644 (file)
@@ -10,8 +10,11 @@ import org.simantics.sysdyn.ui.browser.nodes.SimulationResultNode;
 public class SimulationResultImager extends ImagerContributor<SimulationResultNode>{\r
 \r
     @Override\r
-    public ImageDescriptor getDescriptor(ReadGraph graph, SimulationResultNode input) throws DatabaseException {\r
-        return ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/chart_bar.png"));\r
+    public ImageDescriptor getDescriptor(ReadGraph graph, SimulationResultNode result) throws DatabaseException {\r
+        if(graph.hasStatement(result.resource, graph.getBuiltins().IsActive))\r
+            return ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/chart_bar.png"));\r
+        else\r
+            return ImageDescriptor.createFromURL(Activator.getDefault().getBundle().getResource("icons/chart_bar_blackAndWhite.png"));\r
     }\r
 \r
 }\r
index 52666750714e3ead447bbb818c215b1644672377..171007aa9a7e08d4cad65601acaab7371f7214d9 100644 (file)
@@ -129,6 +129,9 @@ public class UnlinkNodeHandler extends AbstractHandler {
         if(path != null) {\r
             File file = new File(path);\r
             file.delete();\r
+            File parent = file.getParentFile();\r
+            if(parent.listFiles().length == 0)\r
+                parent.delete();\r
         }\r
     }\r
 \r
index 85c9d6e7bda8532c03ab46e418b0f20f41830547..2136673d43209c6859d97f991ff8ef72cbd45eb3 100644 (file)
@@ -1,9 +1,13 @@
 package org.simantics.sysdyn.ui.project;\r
 \r
+import java.io.File;\r
+import java.util.HashMap;\r
 import java.util.Timer;\r
 \r
+import org.eclipse.core.runtime.Platform;\r
 import org.simantics.databoard.accessor.Accessor;\r
 import org.simantics.db.Builtins;\r
+import org.simantics.db.ReadGraph;\r
 import org.simantics.db.RequestProcessor;\r
 import org.simantics.db.Resource;\r
 import org.simantics.db.Session;\r
@@ -11,18 +15,24 @@ import org.simantics.db.VirtualGraph;
 import org.simantics.db.WriteGraph;\r
 import org.simantics.db.common.procedure.single.SingleSetListener;\r
 import org.simantics.db.common.request.ObjectsWithType;\r
+import org.simantics.db.common.request.WriteRequest;\r
 import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.exception.ServiceException;\r
+import org.simantics.db.exception.ValidationException;\r
 import org.simantics.db.layer0.adapter.ActivationManager;\r
 import org.simantics.db.layer0.adapter.RuntimeValuations;\r
 import org.simantics.db.layer0.adapter.TrendVariable;\r
 import org.simantics.db.layer0.adapter.ValuationVirtualGraph;\r
 import org.simantics.db.layer0.util.Simantics;\r
 import org.simantics.db.management.ISessionContext;\r
+import org.simantics.db.request.Read;\r
 import org.simantics.db.service.VirtualGraphSupport;\r
+import org.simantics.layer0.utils.direct.GraphUtils;\r
 import org.simantics.project.IProject;\r
 import org.simantics.project.IProjectLifeCycle;\r
 import org.simantics.simulation.experiment.IExperiment;\r
 import org.simantics.simulation.project.IExperimentManager;\r
+import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.ui.SimanticsUI;\r
 import org.simantics.utils.datastructures.hints.IHintContext.Key;\r
 import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;\r
@@ -35,18 +45,24 @@ public class SysdynProjectLifeCycle implements IProjectLifeCycle{
 \r
     @Override\r
     public void onCreate(WriteGraph g, Resource project) {\r
-//        System.out.println("onCreate Apros Project: " + GraphUtils.getReadableName(g, project));\r
+//        System.out.println("onCreate Sysdyn Project: " + GraphUtils.getReadableName(g, project));\r
     }\r
 \r
     @Override\r
     public void onDestroy(WriteGraph g, Resource project) {\r
-//        System.out.println("onDestroy Apros Project: " + GraphUtils.getReadableName(g, project));\r
+        try {\r
+            System.out.println("onDestroy Sysdyn Project: " + GraphUtils.getReadableName(g, project));\r
+        } catch (ValidationException e) {\r
+            e.printStackTrace();\r
+        } catch (ServiceException e) {\r
+            e.printStackTrace();\r
+        }\r
     }\r
 \r
     @Override\r
     public void onActivated(RequestProcessor processor, final IProject project) {\r
 \r
-//      System.out.println("onActivated DEVS Project");\r
+        System.out.println("onActivated Sysdyn Project");\r
 \r
         ISessionContext context = SimanticsUI.getSessionContext();\r
         if (context.getHint(INITIALIZED) == null) {\r
@@ -135,6 +151,10 @@ public class SysdynProjectLifeCycle implements IProjectLifeCycle{
 \r
                 support.resume("experiments");\r
 \r
+\r
+\r
+\r
+\r
             } catch (DatabaseException e) {\r
 \r
                 e.printStackTrace();\r
@@ -142,7 +162,7 @@ public class SysdynProjectLifeCycle implements IProjectLifeCycle{
             }\r
 \r
 \r
-\r
+            cleanProjectFolder(project.get());\r
             context.setHint(INITIALIZED, Boolean.TRUE);\r
 \r
         }\r
@@ -151,6 +171,76 @@ public class SysdynProjectLifeCycle implements IProjectLifeCycle{
 \r
     @Override\r
     public void onDeactivated(IProject project) {\r
-//        System.out.println("onDeactivated Apros Project: " + project.getName());\r
+//        System.out.println("onDeactivated Sysdyn Project: " + project.getName());\r
+    }\r
+\r
+    public void cleanProjectFolder(final Resource projectResource) {\r
+        System.out.println("cleaning up project folder");\r
+        ISessionContext context = SimanticsUI.getSessionContext();\r
+        final Session session = context.getSession();\r
+        String projectName = null;\r
+        final HashMap<String, Resource> resultPaths = new HashMap<String, Resource>();\r
+        try {\r
+            projectName = session.syncRequest(new Read<String>() {\r
+\r
+                @Override\r
+                public String perform(ReadGraph graph) throws DatabaseException {\r
+                    Builtins b = graph.getBuiltins();\r
+                    SysdynResource sr = SysdynResource.getInstance(graph);\r
+                    for(Resource model : graph.getObjects(projectResource, b.ConsistsOf)) {\r
+                        if(graph.isInstanceOf(model, sr.SysdynModel)){\r
+                            for(Resource experiment : graph.getObjects(model, b.ConsistsOf)) {\r
+                                if(graph.isInstanceOf(experiment, b.Experiment)) {\r
+                                    for(Resource result : graph.getObjects(experiment, sr.HasResult)) {\r
+                                        String resultFile = (String)graph.getPossibleRelatedValue(result, sr.HasResultFile);\r
+                                        if(result != null) resultPaths.put(resultFile, result);\r
+                                    }\r
+                                }\r
+                            }\r
+                        }\r
+                    }\r
+                    return graph.getPossibleRelatedValue(projectResource, b.HasName);\r
+\r
+                }\r
+            });\r
+        } catch (DatabaseException e) {\r
+            e.printStackTrace();\r
+        }\r
+\r
+        if(projectName != null) {\r
+            File root = new File(Platform.getLocation().toOSString(), "www.simantics.org");\r
+            if(!root.isDirectory()) return;\r
+            File projectRoot = new File(root, projectName);\r
+            if(!projectRoot.isDirectory()) return;\r
+            File[] files = projectRoot.listFiles();\r
+            \r
+            for(File file : files) {\r
+                if(resultPaths.get(file.getAbsolutePath()) == null) {\r
+                    file.delete();\r
+                } else {\r
+                    resultPaths.remove(file.getAbsolutePath());\r
+                }\r
+            }\r
+            \r
+            if (!resultPaths.keySet().isEmpty()) {\r
+                session.asyncRequest(new WriteRequest() {\r
+                    \r
+                    @Override\r
+                    public void perform(WriteGraph graph) throws DatabaseException {\r
+                        Builtins b = graph.getBuiltins();\r
+                        for(String key : resultPaths.keySet()) {\r
+                            Resource result = resultPaths.get(key);\r
+                            graph.deny(result, b.PartOf);\r
+                            graph.deny(result, graph.getInverse(SysdynResource.getInstance(graph).HasResult));\r
+                        }\r
+                    }\r
+                }) ;\r
+\r
+\r
+            }\r
+            \r
+            \r
+                \r
+        }\r
     }\r
 }\r
index a2a2e88f8d05c4a07dc34dcd7c193e2c04d7f5fd..a4ec1791b8b19ab6f8215b1dc938f4a0196b0c72 100644 (file)
@@ -16,6 +16,7 @@ import org.simantics.db.WriteGraph;
 import org.simantics.db.common.request.ReadRequest;\r
 import org.simantics.db.common.request.WriteRequest;\r
 import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.service.LifecycleSupport;\r
 import org.simantics.layer0.utils.direct.GraphUtils;\r
 import org.simantics.simulation.experiment.Experiment;\r
 import org.simantics.simulation.experiment.ExperimentState;\r
@@ -36,6 +37,10 @@ public class SysdynExperiment extends Experiment implements IDynamicExperiment {
         this.experiment = experiment;\r
         // TODO Auto-generated constructor stub\r
     }\r
+    \r
+    public Resource getResource() {\r
+        return this.experiment;\r
+    }\r
 \r
     @Override\r
     public void rewindTo(double time) {\r
@@ -54,11 +59,15 @@ public class SysdynExperiment extends Experiment implements IDynamicExperiment {
 \r
                 @Override\r
                 public void perform(WriteGraph graph) throws DatabaseException {\r
-                    File root = new File(Platform.getLocation().toOSString(), "www.simantics.org");\r
-                    if(!root.isDirectory())\r
-                        root.mkdir();\r
-                    File file = new File( root, UUID.randomUUID().toString() + ".dbb");\r
                     Builtins b = graph.getBuiltins();\r
+                    Resource model = graph.getSingleObject(experiment, b.PartOf);\r
+                    Resource project = graph.getSingleObject(model, b.PartOf);\r
+                    String projectName = graph.getPossibleRelatedValue(project, b.HasName);\r
+                    File root = new File(Platform.getLocation().toOSString(), "www.simantics.org");\r
+                    if(!root.isDirectory()) root.mkdir();\r
+                    File projectRoot = new File(root, projectName);\r
+                    if(!projectRoot.isDirectory()) projectRoot.mkdir();\r
+                    File file = new File( projectRoot, UUID.randomUUID().toString() + ".dbb");\r
                     SysdynResource sr = SysdynResource.getInstance(graph);\r
                     Resource res = GraphUtils.create2(graph, sr.Result,\r
                             b.HasLabel, "Result x",\r
@@ -67,9 +76,9 @@ public class SysdynExperiment extends Experiment implements IDynamicExperiment {
                             sr.HasResultFile, file.getAbsolutePath());\r
                     graph.claim(experiment, sr.HasResult, res);\r
                     result.saveToFile(file);\r
-\r
                 }\r
             });\r
+            session.getService(LifecycleSupport.class).save();\r
         } catch (DatabaseException e) {\r
             e.printStackTrace();\r
         }\r
index 326a0f44beb3cc5e9d64a9a04564f2b981324c83..9f37766af66a746e7b4b7ddd92bc81ed6d919d9e 100644 (file)
@@ -166,13 +166,13 @@ IsTailOf <R ST.IsConnectedTo
     L0.HasRange Dependency\r
     L0.InverseOf HasTail \r
     ST.AllowsConnectionType SysdynConnectionType\r
-    ST.HasAttachmentRelation DIA.HasInput\r
+    ST.HasAttachmentRelation DIA.HasArrowConnector\r
 IsHeadOf <R ST.IsConnectedTo\r
     L0.HasDomain Variable\r
     L0.HasRange Dependency\r
     L0.InverseOf HasHead\r
     ST.AllowsConnectionType SysdynConnectionType\r
-    ST.HasAttachmentRelation DIA.HasOutput\r
+    ST.HasAttachmentRelation DIA.HasPlainConnector\r
 \r
 Dependency <T ST.Connection\r
     [HasAngle card "1"]\r