]> gerrit.simantics Code Review - simantics/3d.git/commitdiff
Add "New Plant" as model browser action. 38/3138/2
authorReino Ruusu <reino.ruusu@semantum.fi>
Wed, 21 Aug 2019 12:27:11 +0000 (15:27 +0300)
committerReino Ruusu <reino.ruusu@semantum.fi>
Wed, 21 Aug 2019 15:54:35 +0000 (18:54 +0300)
Change-Id: I60d036fbc2cf726fbdf7e2961def4f34c8d45483

org.simantics.plant3d.ontology/graph/plant3d_viewpoint.pgraph
org.simantics.plant3d.ontology/src/org/simantics/plant3d/ontology/Plant3D.java
org.simantics.plant3d/adapters.xml
org.simantics.plant3d/src/org/simantics/plant3d/handlers/NewPlantHandler.java

index 0c42f7ff38de3230b37fe3e824ef2b757729388b..5be0264c6b26bac365eb34702ceb96b479dd1e74 100644 (file)
@@ -19,8 +19,8 @@ PBC = P3D.P3DBrowseContext : VP.BrowseContext
     @VP.constantImageRule P3D.Builtin.Straight IMAGES.Straight
     @VP.constantImageRule P3D.EndComponent IMAGES.Component
     @VP.constantImageRule P3D.PipeRun IMAGES.Straight
-    @VP.relationChildRule PROJ.Project L0.ConsistsOf P3D.Plant
-    @VP.relationChildRule PROJ.Project L0.ConsistsOf CSG.Model
+    @VP.relationChildRule L0.Library L0.ConsistsOf P3D.Plant
+    @VP.relationChildRule L0.Library L0.ConsistsOf CSG.Model
     @VP.relationChildRule P3D.Node P3D.children P3D.Node
     @VP.relationChildRule P3D.Node P3D.HasNozzle P3D.Node
 
@@ -40,35 +40,9 @@ IMAGES.Tank : IMAGE.PngImage
     @L0.loadBytes "images/tank.png"
     
 MAC = P3D.P3DActionContext : VP.BrowseContext
-    VP.BrowseContext.IsIncludedIn PROJ.ProjectActionContext    
-
-
-MAC.newContribution : L0.Template
-    @template %actionContext %label %action %image
-        %actionContext
-            VP.BrowseContext.HasActionContribution _ : VP.ActionContribution
-                L0.HasLabel %label
-                VP.ActionContribution.HasImage %image
-                VP.ActionContribution.HasCategory VP.NewActionCategory
-                VP.ActionContribution.HasNodeType P3D.Plant
-                VP.ActionContribution.HasAction %action
+    VP.BrowseContext.IsIncludedIn PROJ.ProjectActionContext
     
-MAC.newTypeContribution : L0.Template
-    @template %actionContext %label %action %type %image
-        %actionContext
-            VP.BrowseContext.HasActionContribution _ : VP.ActionContribution
-                L0.HasLabel %label
-                VP.ActionContribution.HasImage %image
-                VP.ActionContribution.HasCategory VP.NewActionCategory
-                VP.ActionContribution.HasNodeType %type
-                VP.ActionContribution.HasAction %action
-                
-MAC.editTypeContribution : L0.Template
-    @template %actionContext %label %action %type %image
-        %actionContext
-            VP.BrowseContext.HasActionContribution _ : VP.ActionContribution
-                L0.HasLabel %label
-                VP.ActionContribution.HasImage %image
-                VP.ActionContribution.HasCategory VP.EditActionCategory
-                VP.ActionContribution.HasNodeType %type
-                VP.ActionContribution.HasAction %action
\ No newline at end of file
+    @VP.actionContribution "Plant" L0.Library IMAGES.Factory VP.NewActionCategory P3D.Actions.NewPlant
+
+P3D.Actions : L0.Library
+P3D.Actions.NewPlant : L0.Action
index 817c94758fd61cd2bc89ebed997a1d904128b7e5..a9659d88970535e28987365b2b1bf3cc803eda63 100644 (file)
@@ -10,6 +10,8 @@ import org.simantics.db.service.QueryControl;
 
 public class Plant3D {
     
+    public final Resource Actions;
+    public final Resource Actions_NewPlant;
     public final Resource Builtin;
     public final Resource Builtin_BallValve;
     public final Resource Builtin_BallValveGeometryProvider;
@@ -26,7 +28,6 @@ public class Plant3D {
     public final Resource Builtin_ElbowGeometryProvider;
     public final Resource Builtin_GateValve;
     public final Resource Builtin_GateValveGeometryProvider;
-    public final Resource Builtin_GeometryProvider;
     public final Resource Builtin_HorizontalTank;
     public final Resource Builtin_HorizontalTankGeometryProvider;
     public final Resource Builtin_Nozzle;
@@ -45,6 +46,7 @@ public class Plant3D {
     public final Resource Equipment;
     public final Resource FixedAngleTurnComponent;
     public final Resource FixedLengthInlineComponent;
+    public final Resource GeometryProvider;
     public final Resource HasAlternativePipeRun;
     public final Resource HasBranch0;
     public final Resource HasBranch1;
@@ -98,9 +100,6 @@ public class Plant3D {
     public final Resource NozzleOf;
     public final Resource OffsetComponent;
     public final Resource P3DActionContext;
-    public final Resource P3DActionContext_editTypeContribution;
-    public final Resource P3DActionContext_newContribution;
-    public final Resource P3DActionContext_newTypeContribution;
     public final Resource P3DBrowseContext;
     public final Resource Parameter;
     public final Resource PipeRun;
@@ -115,13 +114,15 @@ public class Plant3D {
     public final Resource TurnComponent;
     public final Resource VariableAngleTurnComponent;
     public final Resource VariableLengthInlineComponent;
-    public final Resource childen;
-    public final Resource childen_Inverse;
+    public final Resource children;
+    public final Resource children_Inverse;
     public final Resource hasGeometry;
     public final Resource hasParameter;
     public final Resource hasParameterValue;
         
     public static class URIs {
+        public static final String Actions = "http://www.simantics.org/Plant3D-0.1/Actions";
+        public static final String Actions_NewPlant = "http://www.simantics.org/Plant3D-0.1/Actions/NewPlant";
         public static final String Builtin = "http://www.simantics.org/Plant3D-0.1/Builtin";
         public static final String Builtin_BallValve = "http://www.simantics.org/Plant3D-0.1/Builtin/BallValve";
         public static final String Builtin_BallValveGeometryProvider = "http://www.simantics.org/Plant3D-0.1/Builtin/BallValveGeometryProvider";
@@ -138,7 +139,6 @@ public class Plant3D {
         public static final String Builtin_ElbowGeometryProvider = "http://www.simantics.org/Plant3D-0.1/Builtin/ElbowGeometryProvider";
         public static final String Builtin_GateValve = "http://www.simantics.org/Plant3D-0.1/Builtin/GateValve";
         public static final String Builtin_GateValveGeometryProvider = "http://www.simantics.org/Plant3D-0.1/Builtin/GateValveGeometryProvider";
-        public static final String Builtin_GeometryProvider = "http://www.simantics.org/Plant3D-0.1/Builtin/GeometryProvider";
         public static final String Builtin_HorizontalTank = "http://www.simantics.org/Plant3D-0.1/Builtin/HorizontalTank";
         public static final String Builtin_HorizontalTankGeometryProvider = "http://www.simantics.org/Plant3D-0.1/Builtin/HorizontalTankGeometryProvider";
         public static final String Builtin_Nozzle = "http://www.simantics.org/Plant3D-0.1/Builtin/Nozzle";
@@ -157,6 +157,7 @@ public class Plant3D {
         public static final String Equipment = "http://www.simantics.org/Plant3D-0.1/Equipment";
         public static final String FixedAngleTurnComponent = "http://www.simantics.org/Plant3D-0.1/FixedAngleTurnComponent";
         public static final String FixedLengthInlineComponent = "http://www.simantics.org/Plant3D-0.1/FixedLengthInlineComponent";
+        public static final String GeometryProvider = "http://www.simantics.org/Plant3D-0.1/GeometryProvider";
         public static final String HasAlternativePipeRun = "http://www.simantics.org/Plant3D-0.1/HasAlternativePipeRun";
         public static final String HasBranch0 = "http://www.simantics.org/Plant3D-0.1/HasBranch0";
         public static final String HasBranch1 = "http://www.simantics.org/Plant3D-0.1/HasBranch1";
@@ -210,9 +211,6 @@ public class Plant3D {
         public static final String NozzleOf = "http://www.simantics.org/Plant3D-0.1/NozzleOf";
         public static final String OffsetComponent = "http://www.simantics.org/Plant3D-0.1/OffsetComponent";
         public static final String P3DActionContext = "http://www.simantics.org/Plant3D-0.1/P3DActionContext";
-        public static final String P3DActionContext_editTypeContribution = "http://www.simantics.org/Plant3D-0.1/P3DActionContext/editTypeContribution";
-        public static final String P3DActionContext_newContribution = "http://www.simantics.org/Plant3D-0.1/P3DActionContext/newContribution";
-        public static final String P3DActionContext_newTypeContribution = "http://www.simantics.org/Plant3D-0.1/P3DActionContext/newTypeContribution";
         public static final String P3DBrowseContext = "http://www.simantics.org/Plant3D-0.1/P3DBrowseContext";
         public static final String Parameter = "http://www.simantics.org/Plant3D-0.1/Parameter";
         public static final String PipeRun = "http://www.simantics.org/Plant3D-0.1/PipeRun";
@@ -227,8 +225,8 @@ public class Plant3D {
         public static final String TurnComponent = "http://www.simantics.org/Plant3D-0.1/TurnComponent";
         public static final String VariableAngleTurnComponent = "http://www.simantics.org/Plant3D-0.1/VariableAngleTurnComponent";
         public static final String VariableLengthInlineComponent = "http://www.simantics.org/Plant3D-0.1/VariableLengthInlineComponent";
-        public static final String childen = "http://www.simantics.org/Plant3D-0.1/childen";
-        public static final String childen_Inverse = "http://www.simantics.org/Plant3D-0.1/childen/Inverse";
+        public static final String children = "http://www.simantics.org/Plant3D-0.1/children";
+        public static final String children_Inverse = "http://www.simantics.org/Plant3D-0.1/children/Inverse";
         public static final String hasGeometry = "http://www.simantics.org/Plant3D-0.1/hasGeometry";
         public static final String hasParameter = "http://www.simantics.org/Plant3D-0.1/hasParameter";
         public static final String hasParameterValue = "http://www.simantics.org/Plant3D-0.1/hasParameterValue";
@@ -244,6 +242,8 @@ public class Plant3D {
     }
     
     public Plant3D(ReadGraph graph) {
+        Actions = getResourceOrNull(graph, URIs.Actions);
+        Actions_NewPlant = getResourceOrNull(graph, URIs.Actions_NewPlant);
         Builtin = getResourceOrNull(graph, URIs.Builtin);
         Builtin_BallValve = getResourceOrNull(graph, URIs.Builtin_BallValve);
         Builtin_BallValveGeometryProvider = getResourceOrNull(graph, URIs.Builtin_BallValveGeometryProvider);
@@ -260,7 +260,6 @@ public class Plant3D {
         Builtin_ElbowGeometryProvider = getResourceOrNull(graph, URIs.Builtin_ElbowGeometryProvider);
         Builtin_GateValve = getResourceOrNull(graph, URIs.Builtin_GateValve);
         Builtin_GateValveGeometryProvider = getResourceOrNull(graph, URIs.Builtin_GateValveGeometryProvider);
-        Builtin_GeometryProvider = getResourceOrNull(graph, URIs.Builtin_GeometryProvider);
         Builtin_HorizontalTank = getResourceOrNull(graph, URIs.Builtin_HorizontalTank);
         Builtin_HorizontalTankGeometryProvider = getResourceOrNull(graph, URIs.Builtin_HorizontalTankGeometryProvider);
         Builtin_Nozzle = getResourceOrNull(graph, URIs.Builtin_Nozzle);
@@ -279,6 +278,7 @@ public class Plant3D {
         Equipment = getResourceOrNull(graph, URIs.Equipment);
         FixedAngleTurnComponent = getResourceOrNull(graph, URIs.FixedAngleTurnComponent);
         FixedLengthInlineComponent = getResourceOrNull(graph, URIs.FixedLengthInlineComponent);
+        GeometryProvider = getResourceOrNull(graph, URIs.GeometryProvider);
         HasAlternativePipeRun = getResourceOrNull(graph, URIs.HasAlternativePipeRun);
         HasBranch0 = getResourceOrNull(graph, URIs.HasBranch0);
         HasBranch1 = getResourceOrNull(graph, URIs.HasBranch1);
@@ -332,9 +332,6 @@ public class Plant3D {
         NozzleOf = getResourceOrNull(graph, URIs.NozzleOf);
         OffsetComponent = getResourceOrNull(graph, URIs.OffsetComponent);
         P3DActionContext = getResourceOrNull(graph, URIs.P3DActionContext);
-        P3DActionContext_editTypeContribution = getResourceOrNull(graph, URIs.P3DActionContext_editTypeContribution);
-        P3DActionContext_newContribution = getResourceOrNull(graph, URIs.P3DActionContext_newContribution);
-        P3DActionContext_newTypeContribution = getResourceOrNull(graph, URIs.P3DActionContext_newTypeContribution);
         P3DBrowseContext = getResourceOrNull(graph, URIs.P3DBrowseContext);
         Parameter = getResourceOrNull(graph, URIs.Parameter);
         PipeRun = getResourceOrNull(graph, URIs.PipeRun);
@@ -349,8 +346,8 @@ public class Plant3D {
         TurnComponent = getResourceOrNull(graph, URIs.TurnComponent);
         VariableAngleTurnComponent = getResourceOrNull(graph, URIs.VariableAngleTurnComponent);
         VariableLengthInlineComponent = getResourceOrNull(graph, URIs.VariableLengthInlineComponent);
-        childen = getResourceOrNull(graph, URIs.childen);
-        childen_Inverse = getResourceOrNull(graph, URIs.childen_Inverse);
+        children = getResourceOrNull(graph, URIs.children);
+        children_Inverse = getResourceOrNull(graph, URIs.children_Inverse);
         hasGeometry = getResourceOrNull(graph, URIs.hasGeometry);
         hasParameter = getResourceOrNull(graph, URIs.hasParameter);
         hasParameterValue = getResourceOrNull(graph, URIs.hasParameterValue);
index a3f17be39d70963c8fa3e95e895673c894d38545..9efc3b18469ff8e549fe2fe2c454c5091b8dd3e6 100644 (file)
@@ -46,4 +46,9 @@
   <this />
  </resource>
 </target>
+
+<target interface="org.simantics.db.layer0.adapter.ActionFactory">
+  <resource uri="http://www.simantics.org/Plant3D-0.1/Actions/NewPlant"
+            class="org.simantics.plant3d.handlers.NewPlantHandler"/>
+</target>
 </adapters>
\ No newline at end of file
index 42e64cfe56579923246bfb4810d2effa33b60a20..7429e775df3d5c756a53ec5eec0f14f4313a6936 100644 (file)
@@ -13,16 +13,42 @@ import org.simantics.db.WriteGraph;
 import org.simantics.db.common.request.WriteRequest;
 import org.simantics.db.common.utils.NameUtils;
 import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.adapter.ActionFactory;
 import org.simantics.layer0.Layer0;
 import org.simantics.plant3d.Activator;
 import org.simantics.plant3d.utils.P3DUtil;
 
-public class NewPlantHandler extends AbstractHandler {
+public class NewPlantHandler extends AbstractHandler implements ActionFactory {
 
+       // Action factory method
+       @Override
+       public Runnable create(final Object target) {
+               if (!(target instanceof Resource))
+                       return null;
+               
+               return new Runnable() {
+                       @Override
+                       public void run() {
+                               createNewPlantJob((Resource) target);
+                       }
+               };
+       }
+       
+       // Handler method
        @Override
        public Object execute(ExecutionEvent event) throws ExecutionException {
                final Resource library = Simantics.getProject().get();
                
+               createNewPlantJob(library);
+               return null;
+       }
+
+       /**
+        * Create a new plant as a user-triggered job.
+        * 
+        * @param library  Parent resource for the new plant.
+        */
+       public static void createNewPlantJob(final Resource library) {
                Job job = new Job("Create Plant ") {
                        @Override
                        protected IStatus run(IProgressMonitor monitor) {
@@ -49,6 +75,5 @@ public class NewPlantHandler extends AbstractHandler {
                };
                job.setUser(true);
                job.schedule();
-               return null;
        }
 }