Difference between revisions of "Check list: Model browser contributions"
(6 intermediate revisions by the same user not shown) | |||
Line 2: | Line 2: | ||
== Step 1: Ontology Plug-in == | == Step 1: Ontology Plug-in == | ||
− | Define | + | Define an ontology plugin (org.mylib.ontology) |
+ | |||
+ | Define dependencies from Simantics plugins in MANIFEST.MF/Dependencies/Required Plug-ins | ||
+ | <nowiki>org.simantics.layer0 | ||
+ | org.simantics.modeling.ontology | ||
+ | org.simantics.viewpoint.ontology | ||
+ | org.simantics.action.ontology</nowiki> | ||
Include the following definitions into your ontology file (*.pgraph) | Include the following definitions into your ontology file (*.pgraph) | ||
<nowiki>L0 = <http://www.simantics.org/Layer0-1.1> | <nowiki>L0 = <http://www.simantics.org/Layer0-1.1> | ||
VP = <http://www.simantics.org/Viewpoint-1.2> | VP = <http://www.simantics.org/Viewpoint-1.2> | ||
− | ACT = <http://www.simantics.org/Action-1.1></nowiki> | + | ACT = <http://www.simantics.org/Action-1.1> |
+ | MOD = <http://www.simantics.org/Modeling-1.2></nowiki> | ||
− | Define a new library (www.mylib. | + | Define a new library (www.mylib.org) for your ontology under Simantics root (''http://''): |
<nowiki>MY_LIB = <http://www.mylib.org> : L0.Library | <nowiki>MY_LIB = <http://www.mylib.org> : L0.Library | ||
@L0.new</nowiki> | @L0.new</nowiki> | ||
Line 16: | Line 23: | ||
<nowiki>MY_ONTOLOGY = <http://www.mylib.org/MyOntology-1.0> : L0.Ontology | <nowiki>MY_ONTOLOGY = <http://www.mylib.org/MyOntology-1.0> : L0.Ontology | ||
@L0.new | @L0.new | ||
− | L0.HasResourceClass "org.mylib. | + | L0.HasResourceClass "org.mylib.MyOntologyResource" : L0.String</nowiki> |
Check the Name property of ontology plugin in MANIFEST.MF/Overview/General Information. It has to match with URI (without version number) of your ontology. | Check the Name property of ontology plugin in MANIFEST.MF/Overview/General Information. It has to match with URI (without version number) of your ontology. | ||
Line 31: | Line 38: | ||
VP.BrowseContext.HasActionContribution _ : VP.ActionContribution | VP.BrowseContext.HasActionContribution _ : VP.ActionContribution | ||
L0.HasLabel "My action..." | L0.HasLabel "My action..." | ||
− | VP.ActionContribution.HasAction | + | VP.ActionContribution.HasAction MY_ONTOLOGY.MyAction : ACT.Action |
VP.ActionContribution.HasNodeType | VP.ActionContribution.HasNodeType | ||
− | L0.Entity | + | L0.Entity</nowiki> |
+ | |||
+ | == Step 2: Implementation Plug-in == | ||
+ | Define a plugin for implementation (org.mylib). Options: Generate an activator=checked, This plug-in will make contributions to the UI=checked. | ||
+ | |||
+ | Define dependencies from Simantics plugins in MANIFEST.MF/Dependencies/Required Plug-ins | ||
+ | <nowiki>org.simantics.db.layer0</nowiki> | ||
+ | |||
+ | Define a new package src/org.mylib.actions | ||
+ | |||
+ | Define a new Java class MyAction.java under org.mylib.actions package | ||
+ | <nowiki>package org.mylib.actions; | ||
+ | import org.simantics.db.layer0.adapter.ActionFactory; | ||
+ | import org.simantics.db.Resource; | ||
+ | |||
+ | public class MyAction implements ActionFactory { | ||
+ | @Override | ||
+ | public Runnable create(Object target) { | ||
+ | if (!(target instanceof Resource)) | ||
+ | return null; | ||
+ | final Resource res = (Resource) target; | ||
+ | return new Runnable() { | ||
+ | @Override | ||
+ | public void run() { | ||
+ | // TODO: put your code here | ||
+ | } | ||
+ | }; | ||
+ | } | ||
+ | } </nowiki> | ||
+ | |||
+ | Create a new file (adapters.xml) under implementation plugin to map URI (unversioned) of your action to Java class implementation. The content of the file is as follows: | ||
+ | <nowiki><?xml version="1.0" encoding="UTF-8"?> | ||
+ | <adapters> | ||
+ | <target interface="org.simantics.db.layer0.adapter.ActionFactory"> | ||
+ | <resource | ||
+ | uri="http://www.mylib.org/MyOntology-0.0/MyAction" | ||
+ | class="org.mylib.actions.MyAction" /> | ||
+ | </target> | ||
+ | </adapters></nowiki> | ||
+ | |||
+ | You can check correctness of URI by Graph debugger to search a resource: | ||
+ | <pre>http://www.mylib.org/MyOntology-1.0/MyAction</pre> | ||
+ | Note! Use versioned URI (0.0 -> 1.0) while searching. | ||
+ | |||
+ | Include adapters.xml into build configuration in MANIFEST.MF/Build/Binary Build. Also, include SCL packages and SCL modules if your use them in your implementation. | ||
+ | |||
+ | Export the implementation package (org.mylib.actions) of MyAction.java in MANIFEST.MF/Runtime/Exported Packages. | ||
+ | |||
+ | == Step 3: Product == | ||
+ | Include the ontology and the implementation plugins into your product configuration (Debug Configurations/Plug-ins) and validate Plug-ins dependencies before running the product. |
Latest revision as of 13:18, 3 July 2017
To avoid typical errors while defining ontology contributions to model browser follow the following check list:
Step 1: Ontology Plug-in
Define an ontology plugin (org.mylib.ontology)
Define dependencies from Simantics plugins in MANIFEST.MF/Dependencies/Required Plug-ins
org.simantics.layer0 org.simantics.modeling.ontology org.simantics.viewpoint.ontology org.simantics.action.ontology
Include the following definitions into your ontology file (*.pgraph)
L0 = <http://www.simantics.org/Layer0-1.1> VP = <http://www.simantics.org/Viewpoint-1.2> ACT = <http://www.simantics.org/Action-1.1> MOD = <http://www.simantics.org/Modeling-1.2>
Define a new library (www.mylib.org) for your ontology under Simantics root (http://):
MY_LIB = <http://www.mylib.org> : L0.Library @L0.new
Define your ontology under the library and specify its ResourceClass
MY_ONTOLOGY = <http://www.mylib.org/MyOntology-1.0> : L0.Ontology @L0.new L0.HasResourceClass "org.mylib.MyOntologyResource" : L0.String
Check the Name property of ontology plugin in MANIFEST.MF/Overview/General Information. It has to match with URI (without version number) of your ontology.
Name: http://www.mylib.org/MyOntology
Export the package (org.mylib) of ResourceClass in MANIFEST.MF/Runtime/Exported Packages.
Define a new context and include it into MOD.ModelingActionContext
MY_AC = MY_ONTOLOGY.MyActionContext : VP.BrowseContext VP.BrowseContext.IsIncludedIn MOD.ModelingActionContext
Define a new ActionContribution for each action in this context
MY_AC VP.BrowseContext.HasActionContribution _ : VP.ActionContribution L0.HasLabel "My action..." VP.ActionContribution.HasAction MY_ONTOLOGY.MyAction : ACT.Action VP.ActionContribution.HasNodeType L0.Entity
Step 2: Implementation Plug-in
Define a plugin for implementation (org.mylib). Options: Generate an activator=checked, This plug-in will make contributions to the UI=checked.
Define dependencies from Simantics plugins in MANIFEST.MF/Dependencies/Required Plug-ins
org.simantics.db.layer0
Define a new package src/org.mylib.actions
Define a new Java class MyAction.java under org.mylib.actions package
package org.mylib.actions; import org.simantics.db.layer0.adapter.ActionFactory; import org.simantics.db.Resource; public class MyAction implements ActionFactory { @Override public Runnable create(Object target) { if (!(target instanceof Resource)) return null; final Resource res = (Resource) target; return new Runnable() { @Override public void run() { // TODO: put your code here } }; } }
Create a new file (adapters.xml) under implementation plugin to map URI (unversioned) of your action to Java class implementation. The content of the file is as follows:
<?xml version="1.0" encoding="UTF-8"?> <adapters> <target interface="org.simantics.db.layer0.adapter.ActionFactory"> <resource uri="http://www.mylib.org/MyOntology-0.0/MyAction" class="org.mylib.actions.MyAction" /> </target> </adapters>
You can check correctness of URI by Graph debugger to search a resource:
http://www.mylib.org/MyOntology-1.0/MyAction
Note! Use versioned URI (0.0 -> 1.0) while searching.
Include adapters.xml into build configuration in MANIFEST.MF/Build/Binary Build. Also, include SCL packages and SCL modules if your use them in your implementation.
Export the implementation package (org.mylib.actions) of MyAction.java in MANIFEST.MF/Runtime/Exported Packages.
Step 3: Product
Include the ontology and the implementation plugins into your product configuration (Debug Configurations/Plug-ins) and validate Plug-ins dependencies before running the product.