<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
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
\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
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
\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
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
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
--- /dev/null
+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
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
@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
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
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
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
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
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
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
\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
\r
support.resume("experiments");\r
\r
+\r
+\r
+\r
+\r
} catch (DatabaseException e) {\r
\r
e.printStackTrace();\r
}\r
\r
\r
-\r
+ cleanProjectFolder(project.get());\r
context.setHint(INITIALIZED, Boolean.TRUE);\r
\r
}\r
\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
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
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
\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
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
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