style="push">\r
</command>\r
-->\r
+ <command\r
+ commandId="org.simantics.sysdyn.ui.newSCLModule"\r
+ icon="platform:/plugin/com.famfamfam.silk/icons/script.png"\r
+ id="org.simantics.sysdyn.ui.newSCLModule"\r
+ label="SCL Module"\r
+ style="push">\r
+ <visibleWhen\r
+ checkEnabled="true">\r
+ <with\r
+ variable="selection">\r
+ <test\r
+ args="org.simantics.sysdyn.ui.browser.nodes.SCLModulesFolder"\r
+ property="org.simantics.sysdyn.ui.nodeClass">\r
+ </test>\r
+ </with>\r
+ </visibleWhen>\r
+ </command>\r
<command\r
commandId="org.simantics.sysdyn.ui.newModuleNode"\r
id="org.simantics.sysdyn.ui.browser.newModule"\r
<menu\r
id="org.simantics.export"\r
label="Export">\r
+ <command\r
+ commandId="org.simantics.sysdyn.ui.exportSharedOntology"\r
+ icon="platform:/plugin/com.famfamfam.silk/icons/application_form.png"\r
+ id="org.simantics.sysdyn.ui.exportSharedOntology"\r
+ label="Shared Library"\r
+ style="push">\r
+ <visibleWhen\r
+ checkEnabled="true">\r
+ <with\r
+ variable="selection">\r
+ <or>\r
+ <test\r
+ args="org.simantics.sysdyn.ui.browser.contribution.SharedOntologyNode"\r
+ property="org.simantics.sysdyn.ui.nodeClass">\r
+ </test>\r
+ </or>\r
+ </with>\r
+ </visibleWhen>\r
+ </command>\r
<command\r
commandId="org.simantics.sysdyn.ui.exportModel"\r
label="Model"\r
property="org.simantics.graph.resourceType"\r
value="true">\r
</test>\r
+ <test\r
+ args="http://www.simantics.org/Layer0-0.0/SCLModule"\r
+ property="org.simantics.graph.resourceType"\r
+ value="true">\r
+ </test>\r
</or>\r
</with>\r
</visibleWhen>\r
property="org.simantics.graph.resourceType"\r
value="true">\r
</test>\r
+ <test\r
+ args="http://www.simantics.org/Layer0-0.0/SCLModule"\r
+ property="org.simantics.graph.resourceType"\r
+ value="true">\r
+ </test>\r
</or>\r
</with>\r
</visibleWhen>\r
</extension>\r
<extension\r
point="org.eclipse.ui.commands">\r
+ <command\r
+ id="org.simantics.sysdyn.ui.newSCLModule"\r
+ name="New SCL Module">\r
+ </command>\r
+ <command\r
+ id="org.simantics.sysdyn.ui.exportSharedOntology"\r
+ name="Export Shared Library">\r
+ </command>\r
<command\r
id="org.simantics.sysdyn.ui.trend.view.pin"\r
name="Pin Trend">\r
class="org.simantics.sysdyn.ui.trend.TrendToSvg"\r
commandId="org.simantics.sysdyn.ui.trend.view.svg">\r
</handler>\r
+ <handler\r
+ class="org.simantics.sysdyn.ui.handlers.NewSCLModuleHandler"\r
+ commandId="org.simantics.sysdyn.ui.newSCLModule">\r
+ <activeWhen>\r
+ <with\r
+ variable="selection">\r
+ <or>\r
+ <test\r
+ args="org.simantics.sysdyn.ui.browser.nodes.SCLModulesFolder"\r
+ property="org.simantics.sysdyn.ui.nodeClass">\r
+ </test>\r
+ </or>\r
+ </with>\r
+ </activeWhen>\r
+ </handler>\r
<handler\r
class="org.simantics.sysdyn.ui.handlers.ShowModuleHandler"\r
commandId="org.simantics.sysdyn.ui.showModule">\r
args="org.simantics.sysdyn.ui.browser.nodes.AbstractChartNode"\r
property="org.simantics.sysdyn.ui.nodeClass">\r
</test>\r
+ <test\r
+ args="org.simantics.sysdyn.ui.browser.nodes.SCLModule"\r
+ property="org.simantics.sysdyn.ui.nodeClass">\r
+ </test>\r
<!--\r
<test\r
args="org.simantics.document.workbench.browser_old.DocumentationNode"\r
args="org.simantics.sysdyn.ui.browser.nodes.ModuleNode"\r
property="org.simantics.sysdyn.ui.nodeClass">\r
</test>\r
+ <test\r
+ args="org.simantics.sysdyn.ui.browser.nodes.SCLModule"\r
+ property="org.simantics.sysdyn.ui.nodeClass">\r
+ </test>\r
<!--\r
<test\r
args="org.simantics.document.workbench.browser_old.DocumentationNode"\r
</with>\r
</activeWhen>\r
</handler>\r
+ <handler\r
+ class="org.simantics.sysdyn.ui.handlers.ExportSharedOntologyHandler"\r
+ commandId="org.simantics.sysdyn.ui.exportSharedOntology">\r
+ <activeWhen>\r
+ <with\r
+ variable="selection">\r
+ <or>\r
+ <test\r
+ args="org.simantics.sysdyn.ui.browser.contribution.SharedOntologyNode"\r
+ property="org.simantics.sysdyn.ui.nodeClass">\r
+ </test>\r
+ </or>\r
+ </with>\r
+ </activeWhen>\r
+ </handler> \r
</extension>\r
<extension\r
point="org.eclipse.ui.importWizards">\r
class="org.simantics.sysdyn.ui.browser.contributions.Model"\r
preference="2.0">\r
</implementation>\r
+ <implementation\r
+ class="org.simantics.sysdyn.ui.browser.contributions.SharedOntology"\r
+ preference="2.0">\r
+ </implementation>\r
<implementation\r
class="org.simantics.sysdyn.ui.browser.contributions.Experiment"\r
preference="1.0">\r
point="org.simantics.browsing.ui.common.labelerBinding">\r
<binding\r
browseContext="http://www.simantics.org/Sysdyn-0.0/Browser">\r
+ <implementation\r
+ class="org.simantics.sysdyn.ui.browser.contributions.SharedOntologyLabeler"\r
+ preference="3.0">\r
+ </implementation>\r
<implementation\r
class="org.simantics.sysdyn.ui.browser.contributions.ConfigurationLabeler"\r
preference="2.0">\r
point="org.simantics.browsing.ui.common.imagerBinding">\r
<binding\r
browseContext="http://www.simantics.org/Sysdyn-0.0/Browser">\r
+ <implementation\r
+ class="org.simantics.sysdyn.ui.browser.contributions.SharedOntologyImager"\r
+ preference="3.0">\r
+ </implementation>\r
<implementation\r
class="org.simantics.browsing.ui.swt.ImageDescriptorProviderAdapter"\r
preference="1.0">\r
\r
import java.util.ArrayList;\r
import java.util.Collection;\r
+import java.util.Collections;\r
\r
+import org.simantics.Simantics;\r
import org.simantics.browsing.ui.common.node.AbstractNode;\r
import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.common.request.ObjectsWithType;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.layer0.Layer0;\r
+import org.simantics.project.ontology.ProjectResource;\r
import org.simantics.sysdyn.SysdynResource;\r
\r
public class Project extends ViewpointContributor<Resource> {\r
e.printStackTrace();\r
}\r
}\r
+ \r
+ ProjectResource PROJ = ProjectResource.getInstance(graph);\r
+ if(!graph.isInstanceOf(project, PROJ.Project)) return Collections.emptyList();\r
+ Collection<Resource> ontologies = Simantics.applySCL("Simantics/SharedOntologies", "traverseSharedOntologies", graph, graph.getRootLibrary());\r
+ for(Resource o : ontologies) result.add(new SharedOntologyNode(o));\r
+\r
return result;\r
\r
}\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2010, 2011 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.ui.browser.contributions;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+\r
+import org.simantics.browsing.ui.common.node.AbstractNode;\r
+import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.sysdyn.ui.browser.nodes.SCLModulesFolder;\r
+\r
+public class SharedOntology extends ViewpointContributor<SharedOntologyNode> {\r
+\r
+ @Override\r
+ public Collection<?> getContribution(ReadGraph graph, SharedOntologyNode model)\r
+ throws DatabaseException {\r
+ ArrayList<AbstractNode<Resource>> result = new ArrayList<AbstractNode<Resource>>();\r
+ result.add(new SCLModulesFolder(model.data));\r
+ return result;\r
+ }\r
+\r
+ @Override\r
+ public String getViewpointId() {\r
+ return "Standard";\r
+ }\r
+}\r
--- /dev/null
+package org.simantics.sysdyn.ui.browser.contributions;\r
+\r
+import java.net.MalformedURLException;\r
+import java.net.URL;\r
+\r
+import org.eclipse.jface.resource.ImageDescriptor;\r
+import org.simantics.browsing.ui.swt.ImagerContributor;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+\r
+public class SharedOntologyImager extends ImagerContributor<SharedOntologyNode> {\r
+\r
+ @Override\r
+ public ImageDescriptor getDescriptor(ReadGraph graph, SharedOntologyNode node) throws DatabaseException {\r
+ \r
+ try {\r
+ return ImageDescriptor.createFromURL(new URL("platform:/plugin/com.famfamfam.silk/icons/folder.png"));\r
+ } catch (MalformedURLException e) {\r
+ e.printStackTrace();\r
+ }\r
+ return null;\r
+ \r
+ }\r
+}\r
--- /dev/null
+package org.simantics.sysdyn.ui.browser.contributions;\r
+\r
+import org.simantics.browsing.ui.graph.contributor.labeler.LabelerContributor;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+\r
+public class SharedOntologyLabeler extends LabelerContributor<SharedOntologyNode> {\r
+\r
+ @Override\r
+ public String getLabel(ReadGraph graph, SharedOntologyNode node) throws DatabaseException {\r
+ return graph.getURI(node.data);\r
+ }\r
+ \r
+ @Override\r
+ public int getCategory(ReadGraph graph, SharedOntologyNode node) throws DatabaseException {\r
+ return -1;\r
+ }\r
+\r
+}\r
--- /dev/null
+package org.simantics.sysdyn.ui.browser.contributions;\r
+\r
+import org.simantics.browsing.ui.common.node.AbstractNode;\r
+import org.simantics.browsing.ui.common.node.DeleteException;\r
+import org.simantics.browsing.ui.common.node.IDeletableNode;\r
+import org.simantics.browsing.ui.common.node.IModifiableNode;\r
+import org.simantics.browsing.ui.content.Labeler.Modifier;\r
+import org.simantics.db.Resource;\r
+\r
+public class SharedOntologyNode extends AbstractNode<Resource> implements IDeletableNode, IModifiableNode {\r
+\r
+ public SharedOntologyNode(Resource data) {\r
+ super(data);\r
+ }\r
+ \r
+ @Override\r
+ public void delete() throws DeleteException {\r
+ }\r
+\r
+ @Override\r
+ public Modifier getModifier(String columnId) {\r
+ return null;\r
+ }\r
+\r
+}\r
package org.simantics.sysdyn.ui.browser.nodes;\r
\r
import org.simantics.browsing.ui.common.node.AbstractNode;\r
+import org.simantics.browsing.ui.common.node.DeleteException;\r
+import org.simantics.browsing.ui.common.node.IDeletableNode;\r
+import org.simantics.browsing.ui.common.node.IModifiableNode;\r
+import org.simantics.browsing.ui.content.Labeler.Modifier;\r
+import org.simantics.browsing.ui.graph.impl.LabelModifier;\r
import org.simantics.db.Resource;\r
+import org.simantics.db.Session;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.exception.CancelTransactionException;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.util.RemoverUtil;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.ui.SimanticsUI;\r
+import org.simantics.utils.ui.ExceptionUtils;\r
\r
-public class SCLModule extends AbstractNode<Resource> {\r
+public class SCLModule extends AbstractNode<Resource> implements IDeletableNode, IModifiableNode {\r
\r
public SCLModule(Resource resource) {\r
super(resource);\r
}\r
\r
+ @Override\r
+ public void delete() throws DeleteException {\r
+ try {\r
+ SimanticsUI.getSession().syncRequest(new WriteRequest() {\r
+ @Override\r
+ public void perform(WriteGraph graph) throws DatabaseException, CancelTransactionException {\r
+ RemoverUtil.remove(graph, data);\r
+ }\r
+ });\r
+ } catch (DatabaseException e) {\r
+ ExceptionUtils.logAndShowError(e);\r
+ } \r
+\r
+ }\r
+\r
+ @Override\r
+ public Modifier getModifier(String columnId) {\r
+ Session session = SimanticsUI.getSession();\r
+ return new LabelModifier(session, data, session.getService(Layer0.class).HasName);\r
+ }\r
+ \r
}\r
--- /dev/null
+package org.simantics.sysdyn.ui.handlers;\r
+\r
+import org.eclipse.core.commands.AbstractHandler;\r
+import org.eclipse.core.commands.ExecutionEvent;\r
+import org.eclipse.core.commands.ExecutionException;\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.ui.handlers.HandlerUtil;\r
+import org.simantics.modeling.ModelingUtils;\r
+import org.simantics.sysdyn.ui.browser.contributions.SharedOntologyNode;\r
+import org.simantics.utils.ui.AdaptionUtils;\r
+\r
+public class ExportSharedOntologyHandler extends AbstractHandler {\r
+\r
+ /**\r
+ * Assumes to be called from a node with SysdynModel, Library or SysdynModelicaFunction as its resource\r
+ */\r
+ @Override\r
+ public Object execute(ExecutionEvent event) throws ExecutionException {\r
+\r
+ ISelection sel = HandlerUtil.getCurrentSelection(event);\r
+ \r
+ @SuppressWarnings("unchecked")\r
+ SharedOntologyNode node = AdaptionUtils.adaptToSingle(sel, SharedOntologyNode.class);\r
+ if (node == null)\r
+ return null;\r
+\r
+ ModelingUtils.exportSharedOntologyWithUI(node.data);\r
+\r
+ return null;\r
+ \r
+ }\r
+\r
+}\r
--- /dev/null
+package org.simantics.sysdyn.ui.handlers;\r
+\r
+import org.eclipse.core.commands.AbstractHandler;\r
+import org.eclipse.core.commands.ExecutionEvent;\r
+import org.eclipse.core.commands.ExecutionException;\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.ui.handlers.HandlerUtil;\r
+import org.simantics.browsing.ui.common.node.AbstractNode;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.modeling.ModelingUtils;\r
+import org.simantics.ui.SimanticsUI;\r
+import org.simantics.utils.ui.AdaptionUtils;\r
+\r
+public class NewSCLModuleHandler extends AbstractHandler {\r
+\r
+ /**\r
+ * Assumes to be called from a node with SysdynModel, Library or SysdynModelicaFunction as its resource\r
+ */\r
+ @Override\r
+ public Object execute(ExecutionEvent event) throws ExecutionException {\r
+\r
+ ISelection sel = HandlerUtil.getCurrentSelection(event);\r
+ \r
+ @SuppressWarnings("unchecked")\r
+ AbstractNode<Resource> node = AdaptionUtils.adaptToSingle(sel, AbstractNode.class);\r
+ if (node == null)\r
+ return null;\r
+\r
+ final Resource parent = node.data;\r
+ \r
+ SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
+ \r
+ @Override\r
+ public void perform(WriteGraph graph) throws DatabaseException {\r
+ ModelingUtils.createSCLModule(graph, parent);\r
+ }\r
+ \r
+ });\r
+ \r
+ return null;\r
+ \r
+ }\r
+\r
+}\r