]> gerrit.simantics Code Review - simantics/platform.git/blob - docs/Developer/ModelBrowser/ModelBrowserContributions.md
Mapped dev-wiki conversion situation for situational awareness
[simantics/platform.git] / docs / Developer / ModelBrowser / ModelBrowserContributions.md
1 To avoid typical errors while defining ontology contributions to model browser follow the following check list:
2
3 ## Step 1: Ontology Plug-in
4
5 Define an ontology plugin (`org.mylib.ontology`).
6
7 Define dependencies from Simantics plugins in MANIFEST.MF/Dependencies/Required Plug-ins:
8
9 ```
10 org.simantics.layer0
11 org.simantics.modeling.ontology
12 org.simantics.viewpoint.ontology
13 org.simantics.action.ontology
14 ```
15
16 Include the following definitions into your ontology file (*.pgraph):
17
18 ```
19 L0 = <http://www.simantics.org/Layer0-1.1>
20 VP = <http://www.simantics.org/Viewpoint-1.2>
21 ACT = <http://www.simantics.org/Action-1.1>
22 MOD = <http://www.simantics.org/Modeling-1.2>
23 ```
24
25 Define a new library (www.mylib.org) for your ontology under Simantics database root (*http://*):
26
27 ```
28 MY_LIB = <http://www.mylib.org> : L0.Library
29   @L0.new
30 ```
31
32 Define your ontology under the library and specify its ResourceClass:
33
34 ```
35 MY_ONTOLOGY = <http://www.mylib.org/MyOntology-1.0> : L0.Ontology
36   @L0.new
37   L0.HasResourceClass "org.mylib.MyOntologyResource" : L0.String
38 ```
39
40 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.
41
42 ```
43 Name: http://www.mylib.org/MyOntology
44 ```
45
46 Export the package (org.mylib) of ResourceClass in MANIFEST.MF/Runtime/Exported Packages.
47
48 Define a new context and include it into MOD.ModelingActionContext
49
50 ```
51 MY_AC = MY_ONTOLOGY.MyActionContext : VP.BrowseContext
52 VP.BrowseContext.IsIncludedIn MOD.ModelingActionContext
53 ```
54
55 Define a new ActionContribution for each action in this context
56
57 ```
58 MY_AC
59   VP.BrowseContext.HasActionContribution _ : VP.ActionContribution
60     L0.HasLabel "My action..."        
61     VP.ActionContribution.HasAction MY_ONTOLOGY.MyAction : ACT.Action
62     VP.ActionContribution.HasNodeType
63       L0.Entity
64 ```
65
66 ## Step 2: Implementation Plug-in
67
68 Define a plugin for implementation (org.mylib). Options: Generate an activator=checked, This plug-in will make contributions to the UI=checked.
69
70 Define dependencies from Simantics plugins in *MANIFEST.MF/Dependencies/Required Plug-ins*
71
72 ```
73 org.simantics.db.layer0
74 ```
75
76 Define a new package `src/org.mylib.actions`.
77
78 Define a new Java class `MyAction.java` under `org.mylib.actions` package
79
80 ```java
81 package org.mylib.actions;
82 import org.simantics.db.layer0.adapter.ActionFactory;
83 import org.simantics.db.Resource;
84
85 public class MyAction implements ActionFactory {
86     @Override
87     public Runnable create(Object target) {
88         if (!(target instanceof Resource))
89             return null;
90         final Resource res = (Resource) target;
91         return new Runnable() {
92             @Override
93             public void run() {
94                 // TODO: put your code here
95             }
96         };
97     }
98 }
99 ```
100
101 Create a new file (`adapters.xml`, [see spec](../Database/ResourceAdaptation.md)) under implementation plugin to map URI (*unversioned*) of your action to Java class implementation. The content of the file is as follows:
102
103 ```xml
104 <?xml version="1.0" encoding="UTF-8"?>
105 <adapters>
106     <target interface="org.simantics.db.layer0.adapter.ActionFactory">
107         <resource
108             uri="http://www.mylib.org/MyOntology-0.0/MyAction"
109             class="org.mylib.actions.MyAction" />       
110     </target>
111 </adapters>
112 ```
113
114 You can check correctness of URI by Graph Debugger to search a resource:
115
116 ```
117 http://www.mylib.org/MyOntology-1.0/MyAction
118 ```
119
120 Note! Use *versioned URI* (0.0 -> 1.0) while searching with Graph Debugger.
121
122 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.
123
124 Export the implementation package (`org.mylib.actions`) of MyAction.java in *MANIFEST.MF/Runtime/Exported Packages*.
125
126 ## Step 3: Product
127
128 Include the ontology and the implementation plug-ins into your product configuration (Debug Configurations/Plug-ins) and validate Plug-ins dependencies before running the product.