]> gerrit.simantics Code Review - simantics/district.git/commitdiff
Some more added functionality to simantics district editor etc 03/303/1
authorjsimomaa <jani.simomaa@gmail.com>
Wed, 1 Feb 2017 09:26:31 +0000 (11:26 +0200)
committerjsimomaa <jani.simomaa@gmail.com>
Wed, 1 Feb 2017 09:26:31 +0000 (11:26 +0200)
refs #6958

Change-Id: I92a39fffe451b11fe5fa3ab57414f9729637fce9

31 files changed:
org.simantics.district.feature/test.csv [new file with mode: 0644]
org.simantics.district.network.ontology/META-INF/MANIFEST.MF
org.simantics.district.network.ontology/graph.tg
org.simantics.district.network.ontology/graph/DistrictNetwork.pgraph
org.simantics.district.network.ontology/src/org/simantics/district/network/ontology/DistrictNetworkResource.java
org.simantics.district.network.ui/META-INF/MANIFEST.MF
org.simantics.district.network.ui/adapters.xml
org.simantics.district.network.ui/fragment.e4xmi
org.simantics.district.network.ui/plugin.xml
org.simantics.district.network.ui/src/org/simantics/district/network/ui/DNEdgeBuilder.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/DNGraphLayerUtil.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictDiagramViewer.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/NetworkDrawingParticipant.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictDiagramClassAdapter.java [new file with mode: 0644]
org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkEdgeElement.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkEdgeElementFactory.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkVertexElement.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkVertexElementFactory.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/contributions/JoinVerticesHandler.java [new file with mode: 0644]
org.simantics.district.network.ui/src/org/simantics/district/network/ui/contributions/RunMappingHandler.java [new file with mode: 0644]
org.simantics.district.network.ui/src/org/simantics/district/network/ui/contributions/SetFocusableDynamicMenuContribution.java [new file with mode: 0644]
org.simantics.district.network.ui/src/org/simantics/district/network/ui/contributions/SetFocusableHandler.java [new file with mode: 0644]
org.simantics.district.network.ui/src/org/simantics/district/network/ui/function/Functions.java [new file with mode: 0644]
org.simantics.district.network.ui/src/org/simantics/district/network/ui/internal/Activator.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkEdgeNode.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkVertexNode.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/NetworkDrawingNode.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/DNPointerInteractor.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/DNTranslateMode.java
org.simantics.district.network/META-INF/MANIFEST.MF
org.simantics.district.network/src/org/simantics/district/network/DistrictNetworkUtil.java

diff --git a/org.simantics.district.feature/test.csv b/org.simantics.district.feature/test.csv
new file mode 100644 (file)
index 0000000..96e4e39
--- /dev/null
@@ -0,0 +1,3 @@
+x1;y1;z1;x2;y2;z2
+1;2;3;2;4;6
+3;5;3;3;4;5
\ No newline at end of file
index 18b8713dd065a7c6bf5458a757f604637ac44b6a..6ac026c7a36e349c39cb07f44b34c9e21de4a4ab 100644 (file)
@@ -9,6 +9,7 @@ Require-Bundle: org.simantics.layer0,
  org.simantics.modeling.ontology;bundle-version="1.2.0",
  org.simantics.viewpoint.ontology;bundle-version="1.2.0",
  org.simantics.image2.ontology;bundle-version="1.2.0",
- org.simantics.selectionview.ontology;bundle-version="1.2.0"
+ org.simantics.selectionview.ontology;bundle-version="1.2.0",
+ org.simantics.selectionview.ui.ontology;bundle-version="1.1.0"
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
 Export-Package: org.simantics.district.network.ontology
index 73e40a0a1923b4316f1a849382e9159d1cfdd0bd..eb85b78f36866f49f02c868cfb4e77af829d8a24 100644 (file)
Binary files a/org.simantics.district.network.ontology/graph.tg and b/org.simantics.district.network.ontology/graph.tg differ
index 2c6ac584641ce3c3c2a2374b9b15fe3033481abe..ade6b1c5992bd63011cc5eabe4119e56b71e8e46 100644 (file)
@@ -5,8 +5,7 @@ MOD = <http://www.simantics.org/Modeling-1.2>
 VP = <http://www.simantics.org/Viewpoint-1.2>
 IMAGE = <http://www.simantics.org/Image2-1.2>
 SEL = <http://www.simantics.org/SelectionView-1.2>
-
-MBC = MOD.ModelingBrowseContext
+SEL_UI = <http://www.simantics.org/SelectionViewUI-1.1>
 
 DN = <http://www.simantics.org/DistrictNetwork-1.0> : L0.Ontology
     @L0.new
@@ -16,12 +15,12 @@ DN = <http://www.simantics.org/DistrictNetwork-1.0> : L0.Ontology
 DN.Layer <T DIA.Layer
 
 DN.Edge <T DIA.Element : L0.Type
-    @L0.assert DN.HasMapping ""
+    @L0.assert DN.HasMapping DN.Mapping.Dummy
     @L0.assert DN.Bidirectional false
     @L0.assert DN.Edge.HasDiameter 1
 
 DN.Vertex <T DIA.Element : L0.Type
-    @L0.assert DN.HasMapping ""
+    @L0.assert DN.HasMapping DN.Mapping.Dummy
     @L0.assert DN.Bidirectional false
 
 DN.Bidirectional <R L0.HasProperty : SEL.GenericParameterType
@@ -29,20 +28,34 @@ DN.Bidirectional <R L0.HasProperty : SEL.GenericParameterType
     L0.HasRange L0.Boolean
     L0.readOnly false
 
-DN.EdgeDefaultMapping <R L0.HasProperty : SEL.GenericParameterType
+DN.EdgeDefaultMapping <R L0.HasProperty : DN.EdgeMappingParameterType
     L0.HasLabel "Default Edge mapping"
-    L0.HasRange L0.String
-    L0.readOnly false
 
-DN.VertexDefaultMapping <R L0.HasProperty : SEL.GenericParameterType
+DN.VertexDefaultMapping <R L0.HasProperty : DN.VertexMappingParameterType
     L0.HasLabel "Default Vertex mapping"
-    L0.HasRange L0.String
-    L0.readOnly false
 
-DN.HasMapping <R L0.HasProperty : SEL.GenericParameterType
+DN.Functions : L0.Library
+
+DN.VertexMappingParameterType <T SEL.GenericParameterType
+  @L0.assert SEL.HasDisplayValue
+    _ : SEL.DisplayValue
+      SEL.HasEnumerationValues DN.Functions.enumerationValues : L0.Function
+      SEL.HasCustomModifier DN.Functions.defaultVertexMappingModifier : L0.Function
+
+DN.EdgeMappingParameterType <T SEL.GenericParameterType
+  @L0.assert SEL.HasDisplayValue
+    _ : SEL.DisplayValue
+      SEL.HasEnumerationValues DN.Functions.enumerationValues
+      SEL.HasCustomModifier DN.Functions.defaultEdgeMappingModifier : L0.Function
+
+DN.MappingParameterType <T SEL.GenericParameterType
+  @L0.assert SEL.HasDisplayValue
+    _ : SEL.DisplayValue
+      SEL.HasEnumerationValues DN.Functions.enumerationValues
+      SEL.HasCustomModifier DN.Functions.mappingModifier : L0.Function
+
+DN.HasMapping <R L0.HasProperty : DN.MappingParameterType
     L0.HasLabel "Mapping"
-    L0.HasRange DN.Mapping.EdgeMapping
-    L0.readOnly false
 
 DN.Edge.HasDiameter <R L0.HasProperty : SEL.GenericParameterType
     L0.HasLabel "Diameter"
@@ -58,9 +71,11 @@ DN.HasInLayerTag <R L0.HasProperty
 
 DN.Connection <T DIA.Connection
 
+DN.Mapping.Dummy : DN.Mapping.Base
+
 DN.Diagram <T DIA.Diagram
-    @L0.assert DN.VertexDefaultMapping ""
-    @L0.assert DN.EdgeDefaultMapping ""
+    @L0.assert DN.VertexDefaultMapping DN.Mapping.Dummy
+    @L0.assert DN.EdgeDefaultMapping DN.Mapping.Dummy
 
 DN.AddLayerToDNDiagramTemplate <T L0.Template
 
@@ -80,7 +95,10 @@ DN.HasSRID <R L0.HasProperty
 DN.HasSRTEXT <R L0.HasProperty
     L0.HasRange L0.String
 
+DN.Functions.compositeInstantiator : L0.ExternalValue
+
 DN.Composite <T STR.Composite
+    STR.Composite.instantiationFunction DN.Functions.compositeInstantiator
     @L0.assert MOD.HasModelingTemplate
         _ : MOD.DiagramTemplate
             MOD.HasDiagramType DN.Diagram
@@ -97,6 +115,8 @@ DN.HasEndVertex <R L0.DependsOn
     L0.HasRange DN.Vertex
     L0.InverseOf DN.HasEndVertex_Inverse <R L0.IsRelatedTo
 
+MBC = MOD.ModelingBrowseContext
+
 DNAC.newDiagramContribution : L0.Template
     @template %actionContext %label %image %action
         %actionContext
@@ -111,6 +131,13 @@ DNAC = DN.ActionContext : VP.BrowseContext
     VP.BrowseContext.IsIncludedIn MOD.ModelingActionContext
     @DNAC.newDiagramContribution "DN Diagram" IMAGES.ConfigurationFolder ACTIONS.NewDNDiagram
 
+DNBC = DN.BrowseContext : VP.BrowseContext
+    VP.BrowseContext.IsIncludedIn MOD.ModelingBrowseContext
+    VP.BrowseContext.Includes SEL_UI.StandardPropertiesBase.BrowseContext
+    
+    @VP.customModifierRule    DN.Edge    VP.ResourceLabelModifierRule
+
+
 ACTIONS = DN.Actions : L0.Library
 
 ACTIONS.NewDNDiagram : MOD.NewComposite
@@ -122,22 +149,26 @@ IMAGES = DN.Images : L0.Library
 IMAGES.ConfigurationFolder : IMAGE.PngImage
     @L0.loadBytes "images/Configuration.png"
 
-    
 // Component MAPPING
 DN.Mapping <T L0.Library
 
+DN.Functions.convertToValue : L0.ExternalValue
+
+DN.Mapping.Base <T L0.Value
+  @L0.assert L0.ConvertsToValueWith DN.Functions.convertToValue
+
 DN.Mapping.Terminal <T L0.Entity
 
 DN.Mapping.TerminalPair <T L0.Entity
     >-- DN.Mapping.InputTerminal --> DN.Mapping.Terminal <R L0.HasProperty
     >-- DN.Mapping.OutputTerminal --> DN.Mapping.Terminal <R L0.HasProperty
 
-DN.Mapping.VertexMapping <T L0.Entity
-    >-- DN.Mapping.ComponentType --> STR.ComponentType <R L0.HasProperty
+DN.Mapping.VertexMapping <T DN.Mapping.Base
+    >-- DN.Mapping.ComponentType --> STR.ComponentType <R L0.DependsOn
     >-- DN.Mapping.VertexMapping.ElevationAttribute --> L0.String <R L0.HasProperty
     >-- DN.Mapping.Terminals --> DN.Mapping.TerminalPair <R L0.HasProperty
 
-DN.Mapping.EdgeMapping <T L0.Entity
+DN.Mapping.EdgeMapping <T DN.Mapping.Base
     >-- DN.Mapping.ComponentType
     >-- DN.Mapping.EdgeMapping.Bidirectional --> L0.Boolean <R L0.HasProperty
     >-- DN.Mapping.EdgeMapping.LengthAttribute --> L0.String <R L0.HasProperty
index 6ab511e1273b22b33522537c6ad5585f32f9e92a..714f808578ff9116403d494689c9792e26a18bb3 100644 (file)
-package org.simantics.district.network.ontology;\r
-\r
-import org.simantics.db.RequestProcessor;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.request.Read;\r
-import org.simantics.db.Session;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.service.QueryControl;\r
-\r
-public class DistrictNetworkResource {\r
-    \r
-    public final Resource ActionContext;\r
-    public final Resource ActionContext_newDiagramContribution;\r
-    public final Resource Actions;\r
-    public final Resource Actions_NewDNDiagram;\r
-    public final Resource AddLayerToDNDiagramTemplate;\r
-    public final Resource Bidirectional;\r
-    public final Resource Bidirectional_Inverse;\r
-    public final Resource Composite;\r
-    public final Resource Connection;\r
-    public final Resource Diagram;\r
-    public final Resource EPSG_4326;\r
-    public final Resource Edge;\r
-    public final Resource EdgeDefaultMapping;\r
-    public final Resource EdgeDefaultMapping_Inverse;\r
-    public final Resource Edge_HasDiameter;\r
-    public final Resource Edge_HasDiameter_Inverse;\r
-    public final Resource HasEndVertex;\r
-    public final Resource HasEndVertex_Inverse;\r
-    public final Resource HasInLayerTag;\r
-    public final Resource HasInLayerTag_Inverse;\r
-    public final Resource HasMapping;\r
-    public final Resource HasMapping_Inverse;\r
-    public final Resource HasSRID;\r
-    public final Resource HasSRID_Inverse;\r
-    public final Resource HasSRTEXT;\r
-    public final Resource HasSRTEXT_Inverse;\r
-    public final Resource HasSpatialRefSystem;\r
-    public final Resource HasSpatialRefSystem_Inverse;\r
-    public final Resource HasStartVertex;\r
-    public final Resource HasStartVertex_Inverse;\r
-    public final Resource Images;\r
-    public final Resource Images_ConfigurationFolder;\r
-    public final Resource InLayer;\r
-    public final Resource Layer;\r
-    public final Resource Mapping;\r
-    public final Resource Mapping_ComponentType;\r
-    public final Resource Mapping_ComponentType_Inverse;\r
-    public final Resource Mapping_EdgeMapping;\r
-    public final Resource Mapping_EdgeMapping_Bidirectional;\r
-    public final Resource Mapping_EdgeMapping_Bidirectional_Inverse;\r
-    public final Resource Mapping_EdgeMapping_DiameterAttribute;\r
-    public final Resource Mapping_EdgeMapping_DiameterAttribute_Inverse;\r
-    public final Resource Mapping_EdgeMapping_LengthAttribute;\r
-    public final Resource Mapping_EdgeMapping_LengthAttribute_Inverse;\r
-    public final Resource Mapping_InputTerminal;\r
-    public final Resource Mapping_InputTerminal_Inverse;\r
-    public final Resource Mapping_OutputTerminal;\r
-    public final Resource Mapping_OutputTerminal_Inverse;\r
-    public final Resource Mapping_Terminal;\r
-    public final Resource Mapping_TerminalPair;\r
-    public final Resource Mapping_Terminals;\r
-    public final Resource Mapping_Terminals_Inverse;\r
-    public final Resource Mapping_VertexMapping;\r
-    public final Resource Mapping_VertexMapping_ElevationAttribute;\r
-    public final Resource Mapping_VertexMapping_ElevationAttribute_Inverse;\r
-    public final Resource SpatialRefSystem;\r
-    public final Resource Vertex;\r
-    public final Resource VertexDefaultMapping;\r
-    public final Resource VertexDefaultMapping_Inverse;\r
-        \r
-    public static class URIs {\r
-        public static final String ActionContext = "http://www.simantics.org/DistrictNetwork-1.0/ActionContext";\r
-        public static final String ActionContext_newDiagramContribution = "http://www.simantics.org/DistrictNetwork-1.0/ActionContext/newDiagramContribution";\r
-        public static final String Actions = "http://www.simantics.org/DistrictNetwork-1.0/Actions";\r
-        public static final String Actions_NewDNDiagram = "http://www.simantics.org/DistrictNetwork-1.0/Actions/NewDNDiagram";\r
-        public static final String AddLayerToDNDiagramTemplate = "http://www.simantics.org/DistrictNetwork-1.0/AddLayerToDNDiagramTemplate";\r
-        public static final String Bidirectional = "http://www.simantics.org/DistrictNetwork-1.0/Bidirectional";\r
-        public static final String Bidirectional_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Bidirectional/Inverse";\r
-        public static final String Composite = "http://www.simantics.org/DistrictNetwork-1.0/Composite";\r
-        public static final String Connection = "http://www.simantics.org/DistrictNetwork-1.0/Connection";\r
-        public static final String Diagram = "http://www.simantics.org/DistrictNetwork-1.0/Diagram";\r
-        public static final String EPSG_4326 = "http://www.simantics.org/DistrictNetwork-1.0/EPSG_4326";\r
-        public static final String Edge = "http://www.simantics.org/DistrictNetwork-1.0/Edge";\r
-        public static final String EdgeDefaultMapping = "http://www.simantics.org/DistrictNetwork-1.0/EdgeDefaultMapping";\r
-        public static final String EdgeDefaultMapping_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/EdgeDefaultMapping/Inverse";\r
-        public static final String Edge_HasDiameter = "http://www.simantics.org/DistrictNetwork-1.0/Edge/HasDiameter";\r
-        public static final String Edge_HasDiameter_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Edge/HasDiameter/Inverse";\r
-        public static final String HasEndVertex = "http://www.simantics.org/DistrictNetwork-1.0/HasEndVertex";\r
-        public static final String HasEndVertex_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/HasEndVertex_Inverse";\r
-        public static final String HasInLayerTag = "http://www.simantics.org/DistrictNetwork-1.0/HasInLayerTag";\r
-        public static final String HasInLayerTag_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/HasInLayerTag/Inverse";\r
-        public static final String HasMapping = "http://www.simantics.org/DistrictNetwork-1.0/HasMapping";\r
-        public static final String HasMapping_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/HasMapping/Inverse";\r
-        public static final String HasSRID = "http://www.simantics.org/DistrictNetwork-1.0/HasSRID";\r
-        public static final String HasSRID_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/HasSRID/Inverse";\r
-        public static final String HasSRTEXT = "http://www.simantics.org/DistrictNetwork-1.0/HasSRTEXT";\r
-        public static final String HasSRTEXT_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/HasSRTEXT/Inverse";\r
-        public static final String HasSpatialRefSystem = "http://www.simantics.org/DistrictNetwork-1.0/HasSpatialRefSystem";\r
-        public static final String HasSpatialRefSystem_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/HasSpatialRefSystem/Inverse";\r
-        public static final String HasStartVertex = "http://www.simantics.org/DistrictNetwork-1.0/HasStartVertex";\r
-        public static final String HasStartVertex_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/HasStartVertex_Inverse";\r
-        public static final String Images = "http://www.simantics.org/DistrictNetwork-1.0/Images";\r
-        public static final String Images_ConfigurationFolder = "http://www.simantics.org/DistrictNetwork-1.0/Images/ConfigurationFolder";\r
-        public static final String InLayer = "http://www.simantics.org/DistrictNetwork-1.0/InLayer";\r
-        public static final String Layer = "http://www.simantics.org/DistrictNetwork-1.0/Layer";\r
-        public static final String Mapping = "http://www.simantics.org/DistrictNetwork-1.0/Mapping";\r
-        public static final String Mapping_ComponentType = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/ComponentType";\r
-        public static final String Mapping_ComponentType_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/ComponentType/Inverse";\r
-        public static final String Mapping_EdgeMapping = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/EdgeMapping";\r
-        public static final String Mapping_EdgeMapping_Bidirectional = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/EdgeMapping/Bidirectional";\r
-        public static final String Mapping_EdgeMapping_Bidirectional_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/EdgeMapping/Bidirectional/Inverse";\r
-        public static final String Mapping_EdgeMapping_DiameterAttribute = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/EdgeMapping/DiameterAttribute";\r
-        public static final String Mapping_EdgeMapping_DiameterAttribute_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/EdgeMapping/DiameterAttribute/Inverse";\r
-        public static final String Mapping_EdgeMapping_LengthAttribute = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/EdgeMapping/LengthAttribute";\r
-        public static final String Mapping_EdgeMapping_LengthAttribute_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/EdgeMapping/LengthAttribute/Inverse";\r
-        public static final String Mapping_InputTerminal = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/InputTerminal";\r
-        public static final String Mapping_InputTerminal_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/InputTerminal/Inverse";\r
-        public static final String Mapping_OutputTerminal = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/OutputTerminal";\r
-        public static final String Mapping_OutputTerminal_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/OutputTerminal/Inverse";\r
-        public static final String Mapping_Terminal = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/Terminal";\r
-        public static final String Mapping_TerminalPair = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/TerminalPair";\r
-        public static final String Mapping_Terminals = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/Terminals";\r
-        public static final String Mapping_Terminals_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/Terminals/Inverse";\r
-        public static final String Mapping_VertexMapping = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/VertexMapping";\r
-        public static final String Mapping_VertexMapping_ElevationAttribute = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/VertexMapping/ElevationAttribute";\r
-        public static final String Mapping_VertexMapping_ElevationAttribute_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/VertexMapping/ElevationAttribute/Inverse";\r
-        public static final String SpatialRefSystem = "http://www.simantics.org/DistrictNetwork-1.0/SpatialRefSystem";\r
-        public static final String Vertex = "http://www.simantics.org/DistrictNetwork-1.0/Vertex";\r
-        public static final String VertexDefaultMapping = "http://www.simantics.org/DistrictNetwork-1.0/VertexDefaultMapping";\r
-        public static final String VertexDefaultMapping_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/VertexDefaultMapping/Inverse";\r
-    }\r
-    \r
-    public static Resource getResourceOrNull(ReadGraph graph, String uri) {\r
-        try {\r
-            return graph.getResource(uri);\r
-        } catch(DatabaseException e) {\r
-            System.err.println(e.getMessage());\r
-            return null;\r
-        }\r
-    }\r
-    \r
-    public DistrictNetworkResource(ReadGraph graph) {\r
-        ActionContext = getResourceOrNull(graph, URIs.ActionContext);\r
-        ActionContext_newDiagramContribution = getResourceOrNull(graph, URIs.ActionContext_newDiagramContribution);\r
-        Actions = getResourceOrNull(graph, URIs.Actions);\r
-        Actions_NewDNDiagram = getResourceOrNull(graph, URIs.Actions_NewDNDiagram);\r
-        AddLayerToDNDiagramTemplate = getResourceOrNull(graph, URIs.AddLayerToDNDiagramTemplate);\r
-        Bidirectional = getResourceOrNull(graph, URIs.Bidirectional);\r
-        Bidirectional_Inverse = getResourceOrNull(graph, URIs.Bidirectional_Inverse);\r
-        Composite = getResourceOrNull(graph, URIs.Composite);\r
-        Connection = getResourceOrNull(graph, URIs.Connection);\r
-        Diagram = getResourceOrNull(graph, URIs.Diagram);\r
-        EPSG_4326 = getResourceOrNull(graph, URIs.EPSG_4326);\r
-        Edge = getResourceOrNull(graph, URIs.Edge);\r
-        EdgeDefaultMapping = getResourceOrNull(graph, URIs.EdgeDefaultMapping);\r
-        EdgeDefaultMapping_Inverse = getResourceOrNull(graph, URIs.EdgeDefaultMapping_Inverse);\r
-        Edge_HasDiameter = getResourceOrNull(graph, URIs.Edge_HasDiameter);\r
-        Edge_HasDiameter_Inverse = getResourceOrNull(graph, URIs.Edge_HasDiameter_Inverse);\r
-        HasEndVertex = getResourceOrNull(graph, URIs.HasEndVertex);\r
-        HasEndVertex_Inverse = getResourceOrNull(graph, URIs.HasEndVertex_Inverse);\r
-        HasInLayerTag = getResourceOrNull(graph, URIs.HasInLayerTag);\r
-        HasInLayerTag_Inverse = getResourceOrNull(graph, URIs.HasInLayerTag_Inverse);\r
-        HasMapping = getResourceOrNull(graph, URIs.HasMapping);\r
-        HasMapping_Inverse = getResourceOrNull(graph, URIs.HasMapping_Inverse);\r
-        HasSRID = getResourceOrNull(graph, URIs.HasSRID);\r
-        HasSRID_Inverse = getResourceOrNull(graph, URIs.HasSRID_Inverse);\r
-        HasSRTEXT = getResourceOrNull(graph, URIs.HasSRTEXT);\r
-        HasSRTEXT_Inverse = getResourceOrNull(graph, URIs.HasSRTEXT_Inverse);\r
-        HasSpatialRefSystem = getResourceOrNull(graph, URIs.HasSpatialRefSystem);\r
-        HasSpatialRefSystem_Inverse = getResourceOrNull(graph, URIs.HasSpatialRefSystem_Inverse);\r
-        HasStartVertex = getResourceOrNull(graph, URIs.HasStartVertex);\r
-        HasStartVertex_Inverse = getResourceOrNull(graph, URIs.HasStartVertex_Inverse);\r
-        Images = getResourceOrNull(graph, URIs.Images);\r
-        Images_ConfigurationFolder = getResourceOrNull(graph, URIs.Images_ConfigurationFolder);\r
-        InLayer = getResourceOrNull(graph, URIs.InLayer);\r
-        Layer = getResourceOrNull(graph, URIs.Layer);\r
-        Mapping = getResourceOrNull(graph, URIs.Mapping);\r
-        Mapping_ComponentType = getResourceOrNull(graph, URIs.Mapping_ComponentType);\r
-        Mapping_ComponentType_Inverse = getResourceOrNull(graph, URIs.Mapping_ComponentType_Inverse);\r
-        Mapping_EdgeMapping = getResourceOrNull(graph, URIs.Mapping_EdgeMapping);\r
-        Mapping_EdgeMapping_Bidirectional = getResourceOrNull(graph, URIs.Mapping_EdgeMapping_Bidirectional);\r
-        Mapping_EdgeMapping_Bidirectional_Inverse = getResourceOrNull(graph, URIs.Mapping_EdgeMapping_Bidirectional_Inverse);\r
-        Mapping_EdgeMapping_DiameterAttribute = getResourceOrNull(graph, URIs.Mapping_EdgeMapping_DiameterAttribute);\r
-        Mapping_EdgeMapping_DiameterAttribute_Inverse = getResourceOrNull(graph, URIs.Mapping_EdgeMapping_DiameterAttribute_Inverse);\r
-        Mapping_EdgeMapping_LengthAttribute = getResourceOrNull(graph, URIs.Mapping_EdgeMapping_LengthAttribute);\r
-        Mapping_EdgeMapping_LengthAttribute_Inverse = getResourceOrNull(graph, URIs.Mapping_EdgeMapping_LengthAttribute_Inverse);\r
-        Mapping_InputTerminal = getResourceOrNull(graph, URIs.Mapping_InputTerminal);\r
-        Mapping_InputTerminal_Inverse = getResourceOrNull(graph, URIs.Mapping_InputTerminal_Inverse);\r
-        Mapping_OutputTerminal = getResourceOrNull(graph, URIs.Mapping_OutputTerminal);\r
-        Mapping_OutputTerminal_Inverse = getResourceOrNull(graph, URIs.Mapping_OutputTerminal_Inverse);\r
-        Mapping_Terminal = getResourceOrNull(graph, URIs.Mapping_Terminal);\r
-        Mapping_TerminalPair = getResourceOrNull(graph, URIs.Mapping_TerminalPair);\r
-        Mapping_Terminals = getResourceOrNull(graph, URIs.Mapping_Terminals);\r
-        Mapping_Terminals_Inverse = getResourceOrNull(graph, URIs.Mapping_Terminals_Inverse);\r
-        Mapping_VertexMapping = getResourceOrNull(graph, URIs.Mapping_VertexMapping);\r
-        Mapping_VertexMapping_ElevationAttribute = getResourceOrNull(graph, URIs.Mapping_VertexMapping_ElevationAttribute);\r
-        Mapping_VertexMapping_ElevationAttribute_Inverse = getResourceOrNull(graph, URIs.Mapping_VertexMapping_ElevationAttribute_Inverse);\r
-        SpatialRefSystem = getResourceOrNull(graph, URIs.SpatialRefSystem);\r
-        Vertex = getResourceOrNull(graph, URIs.Vertex);\r
-        VertexDefaultMapping = getResourceOrNull(graph, URIs.VertexDefaultMapping);\r
-        VertexDefaultMapping_Inverse = getResourceOrNull(graph, URIs.VertexDefaultMapping_Inverse);\r
-    }\r
-    \r
-    public static DistrictNetworkResource getInstance(ReadGraph graph) {\r
-        Session session = graph.getSession();\r
-        DistrictNetworkResource ret = session.peekService(DistrictNetworkResource.class);\r
-        if(ret == null) {\r
-            QueryControl qc = graph.getService(QueryControl.class);\r
-            ret = new DistrictNetworkResource(qc.getIndependentGraph(graph));\r
-            session.registerService(DistrictNetworkResource.class, ret);\r
-        }\r
-        return ret;\r
-    }\r
-    \r
-    public static DistrictNetworkResource getInstance(RequestProcessor session) throws DatabaseException {\r
-        DistrictNetworkResource ret = session.peekService(DistrictNetworkResource.class);\r
-        if(ret == null) {\r
-            ret = session.syncRequest(new Read<DistrictNetworkResource>() {\r
-                public DistrictNetworkResource perform(ReadGraph graph) throws DatabaseException {\r
-                    QueryControl qc = graph.getService(QueryControl.class);\r
-                    return new DistrictNetworkResource(qc.getIndependentGraph(graph));\r
-                }\r
-            });\r
-            session.registerService(DistrictNetworkResource.class, ret);\r
-        }\r
-        return ret;\r
-    }\r
-    \r
-}\r
-\r
+package org.simantics.district.network.ontology;
+
+import org.simantics.db.RequestProcessor;
+import org.simantics.db.Resource;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.request.Read;
+import org.simantics.db.Session;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.service.QueryControl;
+
+public class DistrictNetworkResource {
+    
+    public final Resource ActionContext;
+    public final Resource ActionContext_newDiagramContribution;
+    public final Resource Actions;
+    public final Resource Actions_NewDNDiagram;
+    public final Resource AddLayerToDNDiagramTemplate;
+    public final Resource Bidirectional;
+    public final Resource Bidirectional_Inverse;
+    public final Resource BrowseContext;
+    public final Resource Composite;
+    public final Resource Connection;
+    public final Resource Diagram;
+    public final Resource EPSG_4326;
+    public final Resource Edge;
+    public final Resource EdgeDefaultMapping;
+    public final Resource EdgeDefaultMapping_Inverse;
+    public final Resource EdgeMappingParameterType;
+    public final Resource Edge_HasDiameter;
+    public final Resource Edge_HasDiameter_Inverse;
+    public final Resource Functions;
+    public final Resource Functions_compositeInstantiator;
+    public final Resource Functions_convertToValue;
+    public final Resource Functions_defaultEdgeMappingModifier;
+    public final Resource Functions_defaultVertexMappingModifier;
+    public final Resource Functions_enumerationValues;
+    public final Resource Functions_mappingModifier;
+    public final Resource HasEndVertex;
+    public final Resource HasEndVertex_Inverse;
+    public final Resource HasInLayerTag;
+    public final Resource HasInLayerTag_Inverse;
+    public final Resource HasMapping;
+    public final Resource HasMapping_Inverse;
+    public final Resource HasSRID;
+    public final Resource HasSRID_Inverse;
+    public final Resource HasSRTEXT;
+    public final Resource HasSRTEXT_Inverse;
+    public final Resource HasSpatialRefSystem;
+    public final Resource HasSpatialRefSystem_Inverse;
+    public final Resource HasStartVertex;
+    public final Resource HasStartVertex_Inverse;
+    public final Resource Images;
+    public final Resource Images_ConfigurationFolder;
+    public final Resource InLayer;
+    public final Resource Layer;
+    public final Resource Mapping;
+    public final Resource MappingParameterType;
+    public final Resource Mapping_Base;
+    public final Resource Mapping_ComponentType;
+    public final Resource Mapping_ComponentType_Inverse;
+    public final Resource Mapping_Dummy;
+    public final Resource Mapping_EdgeMapping;
+    public final Resource Mapping_EdgeMapping_Bidirectional;
+    public final Resource Mapping_EdgeMapping_Bidirectional_Inverse;
+    public final Resource Mapping_EdgeMapping_DiameterAttribute;
+    public final Resource Mapping_EdgeMapping_DiameterAttribute_Inverse;
+    public final Resource Mapping_EdgeMapping_LengthAttribute;
+    public final Resource Mapping_EdgeMapping_LengthAttribute_Inverse;
+    public final Resource Mapping_InputTerminal;
+    public final Resource Mapping_InputTerminal_Inverse;
+    public final Resource Mapping_OutputTerminal;
+    public final Resource Mapping_OutputTerminal_Inverse;
+    public final Resource Mapping_Terminal;
+    public final Resource Mapping_TerminalPair;
+    public final Resource Mapping_Terminals;
+    public final Resource Mapping_Terminals_Inverse;
+    public final Resource Mapping_VertexMapping;
+    public final Resource Mapping_VertexMapping_ElevationAttribute;
+    public final Resource Mapping_VertexMapping_ElevationAttribute_Inverse;
+    public final Resource SpatialRefSystem;
+    public final Resource Vertex;
+    public final Resource VertexDefaultMapping;
+    public final Resource VertexDefaultMapping_Inverse;
+    public final Resource VertexMappingParameterType;
+        
+    public static class URIs {
+        public static final String ActionContext = "http://www.simantics.org/DistrictNetwork-1.0/ActionContext";
+        public static final String ActionContext_newDiagramContribution = "http://www.simantics.org/DistrictNetwork-1.0/ActionContext/newDiagramContribution";
+        public static final String Actions = "http://www.simantics.org/DistrictNetwork-1.0/Actions";
+        public static final String Actions_NewDNDiagram = "http://www.simantics.org/DistrictNetwork-1.0/Actions/NewDNDiagram";
+        public static final String AddLayerToDNDiagramTemplate = "http://www.simantics.org/DistrictNetwork-1.0/AddLayerToDNDiagramTemplate";
+        public static final String Bidirectional = "http://www.simantics.org/DistrictNetwork-1.0/Bidirectional";
+        public static final String Bidirectional_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Bidirectional/Inverse";
+        public static final String BrowseContext = "http://www.simantics.org/DistrictNetwork-1.0/BrowseContext";
+        public static final String Composite = "http://www.simantics.org/DistrictNetwork-1.0/Composite";
+        public static final String Connection = "http://www.simantics.org/DistrictNetwork-1.0/Connection";
+        public static final String Diagram = "http://www.simantics.org/DistrictNetwork-1.0/Diagram";
+        public static final String EPSG_4326 = "http://www.simantics.org/DistrictNetwork-1.0/EPSG_4326";
+        public static final String Edge = "http://www.simantics.org/DistrictNetwork-1.0/Edge";
+        public static final String EdgeDefaultMapping = "http://www.simantics.org/DistrictNetwork-1.0/EdgeDefaultMapping";
+        public static final String EdgeDefaultMapping_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/EdgeDefaultMapping/Inverse";
+        public static final String EdgeMappingParameterType = "http://www.simantics.org/DistrictNetwork-1.0/EdgeMappingParameterType";
+        public static final String Edge_HasDiameter = "http://www.simantics.org/DistrictNetwork-1.0/Edge/HasDiameter";
+        public static final String Edge_HasDiameter_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Edge/HasDiameter/Inverse";
+        public static final String Functions = "http://www.simantics.org/DistrictNetwork-1.0/Functions";
+        public static final String Functions_compositeInstantiator = "http://www.simantics.org/DistrictNetwork-1.0/Functions/compositeInstantiator";
+        public static final String Functions_convertToValue = "http://www.simantics.org/DistrictNetwork-1.0/Functions/convertToValue";
+        public static final String Functions_defaultEdgeMappingModifier = "http://www.simantics.org/DistrictNetwork-1.0/Functions/defaultEdgeMappingModifier";
+        public static final String Functions_defaultVertexMappingModifier = "http://www.simantics.org/DistrictNetwork-1.0/Functions/defaultVertexMappingModifier";
+        public static final String Functions_enumerationValues = "http://www.simantics.org/DistrictNetwork-1.0/Functions/enumerationValues";
+        public static final String Functions_mappingModifier = "http://www.simantics.org/DistrictNetwork-1.0/Functions/mappingModifier";
+        public static final String HasEndVertex = "http://www.simantics.org/DistrictNetwork-1.0/HasEndVertex";
+        public static final String HasEndVertex_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/HasEndVertex_Inverse";
+        public static final String HasInLayerTag = "http://www.simantics.org/DistrictNetwork-1.0/HasInLayerTag";
+        public static final String HasInLayerTag_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/HasInLayerTag/Inverse";
+        public static final String HasMapping = "http://www.simantics.org/DistrictNetwork-1.0/HasMapping";
+        public static final String HasMapping_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/HasMapping/Inverse";
+        public static final String HasSRID = "http://www.simantics.org/DistrictNetwork-1.0/HasSRID";
+        public static final String HasSRID_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/HasSRID/Inverse";
+        public static final String HasSRTEXT = "http://www.simantics.org/DistrictNetwork-1.0/HasSRTEXT";
+        public static final String HasSRTEXT_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/HasSRTEXT/Inverse";
+        public static final String HasSpatialRefSystem = "http://www.simantics.org/DistrictNetwork-1.0/HasSpatialRefSystem";
+        public static final String HasSpatialRefSystem_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/HasSpatialRefSystem/Inverse";
+        public static final String HasStartVertex = "http://www.simantics.org/DistrictNetwork-1.0/HasStartVertex";
+        public static final String HasStartVertex_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/HasStartVertex_Inverse";
+        public static final String Images = "http://www.simantics.org/DistrictNetwork-1.0/Images";
+        public static final String Images_ConfigurationFolder = "http://www.simantics.org/DistrictNetwork-1.0/Images/ConfigurationFolder";
+        public static final String InLayer = "http://www.simantics.org/DistrictNetwork-1.0/InLayer";
+        public static final String Layer = "http://www.simantics.org/DistrictNetwork-1.0/Layer";
+        public static final String Mapping = "http://www.simantics.org/DistrictNetwork-1.0/Mapping";
+        public static final String MappingParameterType = "http://www.simantics.org/DistrictNetwork-1.0/MappingParameterType";
+        public static final String Mapping_Base = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/Base";
+        public static final String Mapping_ComponentType = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/ComponentType";
+        public static final String Mapping_ComponentType_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/ComponentType/Inverse";
+        public static final String Mapping_Dummy = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/Dummy";
+        public static final String Mapping_EdgeMapping = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/EdgeMapping";
+        public static final String Mapping_EdgeMapping_Bidirectional = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/EdgeMapping/Bidirectional";
+        public static final String Mapping_EdgeMapping_Bidirectional_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/EdgeMapping/Bidirectional/Inverse";
+        public static final String Mapping_EdgeMapping_DiameterAttribute = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/EdgeMapping/DiameterAttribute";
+        public static final String Mapping_EdgeMapping_DiameterAttribute_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/EdgeMapping/DiameterAttribute/Inverse";
+        public static final String Mapping_EdgeMapping_LengthAttribute = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/EdgeMapping/LengthAttribute";
+        public static final String Mapping_EdgeMapping_LengthAttribute_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/EdgeMapping/LengthAttribute/Inverse";
+        public static final String Mapping_InputTerminal = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/InputTerminal";
+        public static final String Mapping_InputTerminal_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/InputTerminal/Inverse";
+        public static final String Mapping_OutputTerminal = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/OutputTerminal";
+        public static final String Mapping_OutputTerminal_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/OutputTerminal/Inverse";
+        public static final String Mapping_Terminal = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/Terminal";
+        public static final String Mapping_TerminalPair = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/TerminalPair";
+        public static final String Mapping_Terminals = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/Terminals";
+        public static final String Mapping_Terminals_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/Terminals/Inverse";
+        public static final String Mapping_VertexMapping = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/VertexMapping";
+        public static final String Mapping_VertexMapping_ElevationAttribute = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/VertexMapping/ElevationAttribute";
+        public static final String Mapping_VertexMapping_ElevationAttribute_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/Mapping/VertexMapping/ElevationAttribute/Inverse";
+        public static final String SpatialRefSystem = "http://www.simantics.org/DistrictNetwork-1.0/SpatialRefSystem";
+        public static final String Vertex = "http://www.simantics.org/DistrictNetwork-1.0/Vertex";
+        public static final String VertexDefaultMapping = "http://www.simantics.org/DistrictNetwork-1.0/VertexDefaultMapping";
+        public static final String VertexDefaultMapping_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/VertexDefaultMapping/Inverse";
+        public static final String VertexMappingParameterType = "http://www.simantics.org/DistrictNetwork-1.0/VertexMappingParameterType";
+    }
+    
+    public static Resource getResourceOrNull(ReadGraph graph, String uri) {
+        try {
+            return graph.getResource(uri);
+        } catch(DatabaseException e) {
+            System.err.println(e.getMessage());
+            return null;
+        }
+    }
+    
+    public DistrictNetworkResource(ReadGraph graph) {
+        ActionContext = getResourceOrNull(graph, URIs.ActionContext);
+        ActionContext_newDiagramContribution = getResourceOrNull(graph, URIs.ActionContext_newDiagramContribution);
+        Actions = getResourceOrNull(graph, URIs.Actions);
+        Actions_NewDNDiagram = getResourceOrNull(graph, URIs.Actions_NewDNDiagram);
+        AddLayerToDNDiagramTemplate = getResourceOrNull(graph, URIs.AddLayerToDNDiagramTemplate);
+        Bidirectional = getResourceOrNull(graph, URIs.Bidirectional);
+        Bidirectional_Inverse = getResourceOrNull(graph, URIs.Bidirectional_Inverse);
+        BrowseContext = getResourceOrNull(graph, URIs.BrowseContext);
+        Composite = getResourceOrNull(graph, URIs.Composite);
+        Connection = getResourceOrNull(graph, URIs.Connection);
+        Diagram = getResourceOrNull(graph, URIs.Diagram);
+        EPSG_4326 = getResourceOrNull(graph, URIs.EPSG_4326);
+        Edge = getResourceOrNull(graph, URIs.Edge);
+        EdgeDefaultMapping = getResourceOrNull(graph, URIs.EdgeDefaultMapping);
+        EdgeDefaultMapping_Inverse = getResourceOrNull(graph, URIs.EdgeDefaultMapping_Inverse);
+        EdgeMappingParameterType = getResourceOrNull(graph, URIs.EdgeMappingParameterType);
+        Edge_HasDiameter = getResourceOrNull(graph, URIs.Edge_HasDiameter);
+        Edge_HasDiameter_Inverse = getResourceOrNull(graph, URIs.Edge_HasDiameter_Inverse);
+        Functions = getResourceOrNull(graph, URIs.Functions);
+        Functions_compositeInstantiator = getResourceOrNull(graph, URIs.Functions_compositeInstantiator);
+        Functions_convertToValue = getResourceOrNull(graph, URIs.Functions_convertToValue);
+        Functions_defaultEdgeMappingModifier = getResourceOrNull(graph, URIs.Functions_defaultEdgeMappingModifier);
+        Functions_defaultVertexMappingModifier = getResourceOrNull(graph, URIs.Functions_defaultVertexMappingModifier);
+        Functions_enumerationValues = getResourceOrNull(graph, URIs.Functions_enumerationValues);
+        Functions_mappingModifier = getResourceOrNull(graph, URIs.Functions_mappingModifier);
+        HasEndVertex = getResourceOrNull(graph, URIs.HasEndVertex);
+        HasEndVertex_Inverse = getResourceOrNull(graph, URIs.HasEndVertex_Inverse);
+        HasInLayerTag = getResourceOrNull(graph, URIs.HasInLayerTag);
+        HasInLayerTag_Inverse = getResourceOrNull(graph, URIs.HasInLayerTag_Inverse);
+        HasMapping = getResourceOrNull(graph, URIs.HasMapping);
+        HasMapping_Inverse = getResourceOrNull(graph, URIs.HasMapping_Inverse);
+        HasSRID = getResourceOrNull(graph, URIs.HasSRID);
+        HasSRID_Inverse = getResourceOrNull(graph, URIs.HasSRID_Inverse);
+        HasSRTEXT = getResourceOrNull(graph, URIs.HasSRTEXT);
+        HasSRTEXT_Inverse = getResourceOrNull(graph, URIs.HasSRTEXT_Inverse);
+        HasSpatialRefSystem = getResourceOrNull(graph, URIs.HasSpatialRefSystem);
+        HasSpatialRefSystem_Inverse = getResourceOrNull(graph, URIs.HasSpatialRefSystem_Inverse);
+        HasStartVertex = getResourceOrNull(graph, URIs.HasStartVertex);
+        HasStartVertex_Inverse = getResourceOrNull(graph, URIs.HasStartVertex_Inverse);
+        Images = getResourceOrNull(graph, URIs.Images);
+        Images_ConfigurationFolder = getResourceOrNull(graph, URIs.Images_ConfigurationFolder);
+        InLayer = getResourceOrNull(graph, URIs.InLayer);
+        Layer = getResourceOrNull(graph, URIs.Layer);
+        Mapping = getResourceOrNull(graph, URIs.Mapping);
+        MappingParameterType = getResourceOrNull(graph, URIs.MappingParameterType);
+        Mapping_Base = getResourceOrNull(graph, URIs.Mapping_Base);
+        Mapping_ComponentType = getResourceOrNull(graph, URIs.Mapping_ComponentType);
+        Mapping_ComponentType_Inverse = getResourceOrNull(graph, URIs.Mapping_ComponentType_Inverse);
+        Mapping_Dummy = getResourceOrNull(graph, URIs.Mapping_Dummy);
+        Mapping_EdgeMapping = getResourceOrNull(graph, URIs.Mapping_EdgeMapping);
+        Mapping_EdgeMapping_Bidirectional = getResourceOrNull(graph, URIs.Mapping_EdgeMapping_Bidirectional);
+        Mapping_EdgeMapping_Bidirectional_Inverse = getResourceOrNull(graph, URIs.Mapping_EdgeMapping_Bidirectional_Inverse);
+        Mapping_EdgeMapping_DiameterAttribute = getResourceOrNull(graph, URIs.Mapping_EdgeMapping_DiameterAttribute);
+        Mapping_EdgeMapping_DiameterAttribute_Inverse = getResourceOrNull(graph, URIs.Mapping_EdgeMapping_DiameterAttribute_Inverse);
+        Mapping_EdgeMapping_LengthAttribute = getResourceOrNull(graph, URIs.Mapping_EdgeMapping_LengthAttribute);
+        Mapping_EdgeMapping_LengthAttribute_Inverse = getResourceOrNull(graph, URIs.Mapping_EdgeMapping_LengthAttribute_Inverse);
+        Mapping_InputTerminal = getResourceOrNull(graph, URIs.Mapping_InputTerminal);
+        Mapping_InputTerminal_Inverse = getResourceOrNull(graph, URIs.Mapping_InputTerminal_Inverse);
+        Mapping_OutputTerminal = getResourceOrNull(graph, URIs.Mapping_OutputTerminal);
+        Mapping_OutputTerminal_Inverse = getResourceOrNull(graph, URIs.Mapping_OutputTerminal_Inverse);
+        Mapping_Terminal = getResourceOrNull(graph, URIs.Mapping_Terminal);
+        Mapping_TerminalPair = getResourceOrNull(graph, URIs.Mapping_TerminalPair);
+        Mapping_Terminals = getResourceOrNull(graph, URIs.Mapping_Terminals);
+        Mapping_Terminals_Inverse = getResourceOrNull(graph, URIs.Mapping_Terminals_Inverse);
+        Mapping_VertexMapping = getResourceOrNull(graph, URIs.Mapping_VertexMapping);
+        Mapping_VertexMapping_ElevationAttribute = getResourceOrNull(graph, URIs.Mapping_VertexMapping_ElevationAttribute);
+        Mapping_VertexMapping_ElevationAttribute_Inverse = getResourceOrNull(graph, URIs.Mapping_VertexMapping_ElevationAttribute_Inverse);
+        SpatialRefSystem = getResourceOrNull(graph, URIs.SpatialRefSystem);
+        Vertex = getResourceOrNull(graph, URIs.Vertex);
+        VertexDefaultMapping = getResourceOrNull(graph, URIs.VertexDefaultMapping);
+        VertexDefaultMapping_Inverse = getResourceOrNull(graph, URIs.VertexDefaultMapping_Inverse);
+        VertexMappingParameterType = getResourceOrNull(graph, URIs.VertexMappingParameterType);
+    }
+    
+    public static DistrictNetworkResource getInstance(ReadGraph graph) {
+        Session session = graph.getSession();
+        DistrictNetworkResource ret = session.peekService(DistrictNetworkResource.class);
+        if(ret == null) {
+            QueryControl qc = graph.getService(QueryControl.class);
+            ret = new DistrictNetworkResource(qc.getIndependentGraph(graph));
+            session.registerService(DistrictNetworkResource.class, ret);
+        }
+        return ret;
+    }
+    
+    public static DistrictNetworkResource getInstance(RequestProcessor session) throws DatabaseException {
+        DistrictNetworkResource ret = session.peekService(DistrictNetworkResource.class);
+        if(ret == null) {
+            ret = session.syncRequest(new Read<DistrictNetworkResource>() {
+                public DistrictNetworkResource perform(ReadGraph graph) throws DatabaseException {
+                    QueryControl qc = graph.getService(QueryControl.class);
+                    return new DistrictNetworkResource(qc.getIndependentGraph(graph));
+                }
+            });
+            session.registerService(DistrictNetworkResource.class, ret);
+        }
+        return ret;
+    }
+    
+}
+
index 1a7ea47d3a5ac75d68edf66e00e3c9e9f98e3866..49df92f576410c8aa339578e332f7734f4a32aa1 100644 (file)
@@ -3,6 +3,8 @@ Bundle-ManifestVersion: 2
 Bundle-Name: Simantics District Network UI
 Bundle-SymbolicName: org.simantics.district.network.ui;singleton:=true
 Bundle-Version: 1.0.0.qualifier
+Bundle-Activator: org.simantics.district.network.ui.internal.Activator
+Export-Package: org.simantics.district.network.ui.adapters
 Require-Bundle: org.eclipse.e4.ui.model.workbench;bundle-version="1.1.100.v20150407-1430",
  org.eclipse.swt,
  org.simantics.g2d,
@@ -15,8 +17,14 @@ Require-Bundle: org.eclipse.e4.ui.model.workbench;bundle-version="1.1.100.v20150
  org.simantics.utils.datastructures,
  org.simantics.district.network;bundle-version="1.0.0",
  org.simantics.layer0.utils,
- org.simantics.district.maps
+ org.simantics.district.maps,
+ org.slf4j.api,
+ org.simantics.db.indexing,
+ org.eclipse.e4.ui.services,
+ org.eclipse.e4.core.di,
+ org.eclipse.e4.ui.di,
+ org.eclipse.e4.core.commands,
+ org.eclipse.e4.core.contexts
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
-Export-Package: org.simantics.district.network.ui.adapters
+Import-Package: javax.inject;version="1.0.0"
 Bundle-ActivationPolicy: lazy
-Bundle-Activator: org.simantics.district.network.ui.internal.Activator
index 8fdfa320536d5f813632e6beaba8f75a653f22b3..eda331ba784dc63fbe56d3ca1ed57945d76a80a0 100644 (file)
@@ -1,47 +1,52 @@
-<?xml version="1.0" encoding="UTF-8"?>\r
-<adapters>\r
-    <target interface="org.simantics.diagram.adapter.ElementFactory">\r
-        <resource uri="http://www.simantics.org/DistrictNetwork-1.0/Edge"\r
-            class="org.simantics.district.network.ui.adapters.DistrictNetworkEdgeElementFactory">\r
-            <graph />\r
-        </resource>\r
-        <type uri="http://www.simantics.org/DistrictNetwork-1.0/Edge"\r
-            class="org.simantics.district.network.ui.adapters.DistrictNetworkEdgeElementFactory">\r
-            <graph />\r
-        </type>\r
-        <resource uri="http://www.simantics.org/DistrictNetwork-1.0/Vertex"\r
-            class="org.simantics.district.network.ui.adapters.DistrictNetworkVertexElementFactory">\r
-            <graph />\r
-        </resource>\r
-        <type uri="http://www.simantics.org/DistrictNetwork-1.0/Vertex"\r
-            class="org.simantics.district.network.ui.adapters.DistrictNetworkVertexElementFactory">\r
-            <graph />\r
-        </type>\r
-    </target>\r
-    \r
-    <target interface="org.simantics.db.layer0.adapter.Remover">\r
-        <type uri="http://www.simantics.org/DistrictNetwork-1.0/Vertex"\r
-            class="org.simantics.district.network.ui.DNElementRemover">\r
-            <this />\r
-        </type>\r
-        <type uri="http://www.simantics.org/DistrictNetwork-1.0/Edge"\r
-            class="org.simantics.district.network.ui.DNElementRemover">\r
-            <this />\r
-        </type>\r
-    </target>\r
-    \r
-    <target interface="org.simantics.db.layer0.adapter.Template">\r
-        <type uri="http://www.simantics.org/DistrictNetwork-1.0/AddLayerToDNDiagramTemplate"\r
-            class="org.simantics.district.network.ui.templates.AddLayerToDNDiagramTemplate">\r
-            <this />\r
-        </type>\r
-    </target>\r
-    \r
-    <target interface="org.simantics.diagram.synchronization.graph.layer.IGraphLayerUtil">\r
-        <resource uri="http://www.simantics.org/DistrictNetwork-1.0/Layer"\r
-            class="org.simantics.district.network.ui.DNGraphLayerUtil">\r
-            <this />\r
-        </resource>\r
-    </target>\r
-    \r
+<?xml version="1.0" encoding="UTF-8"?>
+<adapters>
+    <target interface="org.simantics.diagram.adapter.ElementFactory">
+        <resource uri="http://www.simantics.org/DistrictNetwork-1.0/Edge"
+            class="org.simantics.district.network.ui.adapters.DistrictNetworkEdgeElementFactory">
+            <graph />
+        </resource>
+        <type uri="http://www.simantics.org/DistrictNetwork-1.0/Edge"
+            class="org.simantics.district.network.ui.adapters.DistrictNetworkEdgeElementFactory">
+            <graph />
+        </type>
+        <resource uri="http://www.simantics.org/DistrictNetwork-1.0/Vertex"
+            class="org.simantics.district.network.ui.adapters.DistrictNetworkVertexElementFactory">
+            <graph />
+        </resource>
+        <type uri="http://www.simantics.org/DistrictNetwork-1.0/Vertex"
+            class="org.simantics.district.network.ui.adapters.DistrictNetworkVertexElementFactory">
+            <graph />
+        </type>
+    </target>
+    
+    <target interface="org.simantics.g2d.diagram.DiagramClass">
+        <baseType uri="http://www.simantics.org/DistrictNetwork-1.0/Diagram" />
+        <adapter uri="http://www.simantics.org/DistrictNetwork-1.0/Diagram"
+            adapterClass="org.simantics.district.network.ui.adapters.DistrictDiagramClassAdapter" />
+    </target>
+    
+    <target interface="org.simantics.db.layer0.adapter.Remover">
+        <type uri="http://www.simantics.org/DistrictNetwork-1.0/Vertex"
+            class="org.simantics.district.network.ui.DNElementRemover">
+            <this />
+        </type>
+        <type uri="http://www.simantics.org/DistrictNetwork-1.0/Edge"
+            class="org.simantics.district.network.ui.DNElementRemover">
+            <this />
+        </type>
+    </target>
+    
+    <target interface="org.simantics.db.layer0.adapter.Template">
+        <type uri="http://www.simantics.org/DistrictNetwork-1.0/AddLayerToDNDiagramTemplate"
+            class="org.simantics.district.network.ui.templates.AddLayerToDNDiagramTemplate">
+            <this />
+        </type>
+    </target>
+    
+    <target interface="org.simantics.diagram.synchronization.graph.layer.IGraphLayerUtil">
+        <resource uri="http://www.simantics.org/DistrictNetwork-1.0/Layer"
+            class="org.simantics.district.network.ui.DNGraphLayerUtil">
+            <this />
+        </resource>
+    </target>
 </adapters>
\ No newline at end of file
index 526195f231b78888b8f80abaa21a628d6f95c6ba..e4a2fbcbcb5bb55cba23dce810bddf0add1dd7c5 100644 (file)
@@ -1,17 +1,35 @@
-<?xml version="1.0" encoding="ASCII"?>\r
-<fragment:ModelFragments xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:basic="http://www.eclipse.org/ui/2010/UIModel/application/descriptor/basic" xmlns:commands="http://www.eclipse.org/ui/2010/UIModel/application/commands" xmlns:fragment="http://www.eclipse.org/ui/2010/UIModel/fragment" xmlns:menu="http://www.eclipse.org/ui/2010/UIModel/application/ui/menu" xmi:id="_lkvWIML0Eea1mdgpHNVHMA">\r
-  <fragments xsi:type="fragment:StringModelFragment" xmi:id="_nMVscML8Eea1mdgpHNVHMA" featurename="descriptors" parentElementId="xpath:/">\r
-    <elements xsi:type="basic:PartDescriptor" xmi:id="_bSU8EML9Eea1mdgpHNVHMA" elementId="org.simantics.district.network.ui.partdescriptor.districteditor" label="District Editor" tooltip="Test" contributionURI="bundleclass://org.simantics.district.network.ui/org.simantics.district.network.ui.DistrictEditor"/>\r
-  </fragments>\r
-  <fragments xsi:type="fragment:StringModelFragment" xmi:id="_4mZBIML_Eea1mdgpHNVHMA" featurename="commands" parentElementId="xpath:/">\r
-    <elements xsi:type="commands:Command" xmi:id="_6lrYUML_Eea1mdgpHNVHMA" elementId="org.simantics.district.network.ui.command.openDistrictEditor" commandName="Open District Editor"/>\r
-  </fragments>\r
-  <fragments xsi:type="fragment:StringModelFragment" xmi:id="_Js7rUMMAEea1mdgpHNVHMA" featurename="menuContributions" parentElementId="xpath:/">\r
-    <elements xsi:type="menu:MenuContribution" xmi:id="_MbrJgMMAEea1mdgpHNVHMA" elementId="org.simantics.district.network.ui.menucontribution.0" parentId="help">\r
-      <children xsi:type="menu:HandledMenuItem" xmi:id="_0D7tIMMAEea1mdgpHNVHMA" elementId="org.simantics.district.network.ui.handledmenuitem.opendistricteditor" label="Open District Editor" command="_6lrYUML_Eea1mdgpHNVHMA"/>\r
-    </elements>\r
-  </fragments>\r
-  <fragments xsi:type="fragment:StringModelFragment" xmi:id="_dbiHcMMBEea1mdgpHNVHMA" featurename="handlers" parentElementId="xpath:/">\r
-    <elements xsi:type="commands:Handler" xmi:id="_ffHv0MMBEea1mdgpHNVHMA" elementId="org.simantics.district.network.ui.handler.0"/>\r
-  </fragments>\r
-</fragment:ModelFragments>\r
+<?xml version="1.0" encoding="ASCII"?>
+<fragment:ModelFragments xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:basic="http://www.eclipse.org/ui/2010/UIModel/application/descriptor/basic" xmlns:commands="http://www.eclipse.org/ui/2010/UIModel/application/commands" xmlns:fragment="http://www.eclipse.org/ui/2010/UIModel/fragment" xmlns:menu="http://www.eclipse.org/ui/2010/UIModel/application/ui/menu" xmi:id="_lkvWIML0Eea1mdgpHNVHMA">
+  <imports xsi:type="commands:Command" xmi:id="_luNasN8NEeaigNyzMJBOrg" elementId="org.simantics.modeling.ui.importSVG"/>
+  <fragments xsi:type="fragment:StringModelFragment" xmi:id="_nMVscML8Eea1mdgpHNVHMA" featurename="descriptors" parentElementId="xpath:/">
+    <elements xsi:type="basic:PartDescriptor" xmi:id="_bSU8EML9Eea1mdgpHNVHMA" elementId="org.simantics.district.network.ui.partdescriptor.districteditor" label="District Editor" tooltip="Test" contributionURI="bundleclass://org.simantics.district.network.ui/org.simantics.district.network.ui.DistrictEditor"/>
+  </fragments>
+  <fragments xsi:type="fragment:StringModelFragment" xmi:id="_4mZBIML_Eea1mdgpHNVHMA" featurename="commands" parentElementId="xpath:/">
+    <elements xsi:type="commands:Command" xmi:id="_6lrYUML_Eea1mdgpHNVHMA" elementId="org.simantics.district.network.ui.command.openDistrictEditor" commandName="Open District Editor"/>
+    <elements xsi:type="commands:Command" xmi:id="_zhiBwN16Eea73Pr1j_7O0Q" elementId="org.simantics.district.network.ui.command.runmapping" commandName="Run mapping"/>
+    <elements xsi:type="commands:Command" xmi:id="_A1HBQOFYEeaJP6VyXP72Jw" elementId="org.simantics.district.network.ui.joinVertices" commandName="Join Vertices"/>
+    <elements xsi:type="commands:Command" xmi:id="_QzdUQOIcEeaJP6VyXP72Jw" elementId="org.simantics.district.network.ui.setFocusable" commandName="Set Focusable"/>
+  </fragments>
+  <fragments xsi:type="fragment:StringModelFragment" xmi:id="_Js7rUMMAEea1mdgpHNVHMA" featurename="menuContributions" parentElementId="xpath:/">
+    <elements xsi:type="menu:MenuContribution" xmi:id="_MbrJgMMAEea1mdgpHNVHMA" elementId="org.simantics.district.network.ui.menucontribution.0" parentId="help">
+      <children xsi:type="menu:HandledMenuItem" xmi:id="_0D7tIMMAEea1mdgpHNVHMA" elementId="org.simantics.district.network.ui.handledmenuitem.opendistricteditor" label="Open District Editor" command="_6lrYUML_Eea1mdgpHNVHMA"/>
+    </elements>
+    <elements xsi:type="menu:MenuContribution" xmi:id="_T-jiEN8NEeaigNyzMJBOrg" elementId="org.simantics.district.network.ui.menucontribution.districtDiagramPopup" parentId="#DistrictDiagramPopup">
+      <children xsi:type="menu:HandledMenuItem" xmi:id="_VCxYIN8NEeaigNyzMJBOrg" elementId="org.simantics.district.network.ui.handledmenuitem.importImage" label="Import PNG/SVG Image" iconURI="platform:/plugin/org.simantics.modeling.ui/icons/image_add.png" tooltip="Import PNG/SVG Image as a layout" command="_luNasN8NEeaigNyzMJBOrg"/>
+      <children xsi:type="menu:HandledMenuItem" xmi:id="_O_UgUOIgEeaJP6VyXP72Jw" elementId="org.simantics.district.network.ui.handledmenuitem.joinvertices" label="Join Vertices" iconURI="platform:/plugin/org.simantics.ui/icons/etool16/arrow_join.png" tooltip="Join multiple vertices as one" command="_A1HBQOFYEeaJP6VyXP72Jw"/>
+      <children xsi:type="menu:DynamicMenuContribution" xmi:id="_dieAsOIgEeaJP6VyXP72Jw" elementId="org.simantics.district.network.ui.dynamicmenucontribution.setFocusable" label="Set Focusable" contributionURI="bundleclass://org.simantics.district.network.ui/org.simantics.district.network.ui.contributions.SetFocusableDynamicMenuContribution"/>
+    </elements>
+  </fragments>
+  <fragments xsi:type="fragment:StringModelFragment" xmi:id="_dbiHcMMBEea1mdgpHNVHMA" featurename="handlers" parentElementId="xpath:/">
+    <elements xsi:type="commands:Handler" xmi:id="_ffHv0MMBEea1mdgpHNVHMA" elementId="org.simantics.district.network.ui.handler.runmapping" contributionURI="bundleclass://org.simantics.district.network.ui/org.simantics.district.network.ui.contributions.RunMappingHandler" command="_zhiBwN16Eea73Pr1j_7O0Q"/>
+    <elements xsi:type="commands:Handler" xmi:id="_DPcVsOFYEeaJP6VyXP72Jw" elementId="org.simantics.district.network.ui.handler.joinVertices" contributionURI="bundleclass://org.simantics.district.network.ui/org.simantics.district.network.ui.contributions.JoinVerticesHandler" command="_A1HBQOFYEeaJP6VyXP72Jw"/>
+    <elements xsi:type="commands:Handler" xmi:id="_VPgBwOIcEeaJP6VyXP72Jw" elementId="org.simantics.district.network.ui.handler.setFocusable" contributionURI="bundleclass://org.simantics.district.network.ui/org.simantics.district.network.ui.contributions.SetFocusableHandler" command="_QzdUQOIcEeaJP6VyXP72Jw"/>
+  </fragments>
+  <fragments xsi:type="fragment:StringModelFragment" xmi:id="_Rf7koN16Eea73Pr1j_7O0Q" featurename="trimContributions" parentElementId="xpath:/">
+    <elements xsi:type="menu:TrimContribution" xmi:id="_c57iwN16Eea73Pr1j_7O0Q" elementId="org.simantics.district.network.ui.trimcontribution.0" parentId="org.eclipse.ui.main.toolbar">
+      <children xsi:type="menu:ToolBar" xmi:id="_vdgLoN16Eea73Pr1j_7O0Q" elementId="org.simantics.district.network.ui.toolbar.0">
+        <children xsi:type="menu:HandledToolItem" xmi:id="_v99NUN16Eea73Pr1j_7O0Q" elementId="org.simantics.district.network.ui.handledtoolitem.domapping" label="Do mapping" tooltip="testtsts" command="_zhiBwN16Eea73Pr1j_7O0Q"/>
+      </children>
+    </elements>
+  </fragments>
+</fragment:ModelFragments>
index 7e6e8c13f15c84cc5714d0e0f6f666afd6a398d3..826432f96becceff038bd996783d00e75299df63 100644 (file)
@@ -1,30 +1,41 @@
-<?xml version="1.0" encoding="UTF-8"?>\r
-<plugin>\r
-\r
-   <extension\r
-         id="org.simantics.district.network.ui.fragment"\r
-         point="org.eclipse.e4.workbench.model">\r
-      <fragment\r
-            uri="fragment.e4xmi">\r
-      </fragment>\r
-   </extension>\r
-   <extension\r
-         point="org.eclipse.ui.editors">\r
-      <editor\r
-            name="District Network Diagram Editor"\r
-            icon="icons/diagramEditor.png"\r
-            class="org.simantics.district.network.ui.DistrictDiagramEditor:viewer=org.simantics.district.network.ui.DistrictDiagramViewer"\r
-            contributorClass="org.simantics.modeling.ui.diagramEditor.DiagramViewerActionContributor"\r
-            matchingStrategy="org.simantics.ui.workbench.editor.input.ResourceEditorInputMatchingStrategy"\r
-            id="org.simantics.district.network.ui.diagrameditor">\r
-      </editor>\r
-   </extension>\r
-   <extension\r
-         point="org.simantics.ui.resourceEditorAdapter">\r
-      <adapterClass\r
-            groupId="org.simantics.diagramEditor.group"\r
-            priority="300"\r
-            class="org.simantics.district.network.ui.OpenDiagramFromConfigurationAdapter">\r
-      </adapterClass>\r
-   </extension>\r
-</plugin>\r
+<?xml version="1.0" encoding="UTF-8"?>
+<plugin>
+
+   <extension
+         id="org.simantics.district.network.ui.fragment"
+         point="org.eclipse.e4.workbench.model">
+      <fragment
+            uri="fragment.e4xmi">
+      </fragment>
+   </extension>
+   <extension
+         point="org.eclipse.ui.editors">
+      <editor
+            name="District Network Diagram Editor"
+            icon="icons/diagramEditor.png"
+            class="org.simantics.district.network.ui.DistrictDiagramEditor:viewer=org.simantics.district.network.ui.DistrictDiagramViewer"
+            contributorClass="org.simantics.modeling.ui.diagramEditor.DiagramViewerActionContributor"
+            matchingStrategy="org.simantics.ui.workbench.editor.input.ResourceEditorInputMatchingStrategy"
+            id="org.simantics.district.network.ui.diagrameditor">
+      </editor>
+   </extension>
+   <extension
+         point="org.simantics.ui.resourceEditorAdapter">
+      <adapterClass
+            groupId="org.simantics.diagramEditor.group"
+            priority="300"
+            class="org.simantics.district.network.ui.OpenDiagramFromConfigurationAdapter">
+      </adapterClass>
+   </extension>
+   <extension
+         point="org.simantics.scl.reflection.binding">
+      <namespace
+            path="http://www.simantics.org/DistrictNetwork-1.0/Functions">
+                <externalClass className="org.simantics.db.Resource"/>
+                <externalClass className="org.simantics.db.ReadGraph"/>
+                <externalClass className="org.simantics.db.WriteGraph"/>
+                <externalClass className="org.simantics.db.layer0.variable.Variable"/>
+                <class className="org.simantics.district.network.ui.function.Functions"/>
+      </namespace>
+   </extension>
+</plugin>
index 687ca337b85689f6dd749fcba1fbfde04a9bec7b..ebdb9e87adde5dd422eeedcac5dea37c5fea5d97 100644 (file)
@@ -34,7 +34,7 @@ public class DNEdgeBuilder {
         glm = context.get(GraphSynchronizationHints.GRAPH_LAYER_MANAGER);
     }
 
-    public void create(WriteGraph graph, double[] start, double[] end) throws DatabaseException {
+    public void create(WriteGraph graph, double[] start, double[] end, double padding) throws DatabaseException {
         
         DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
         
@@ -46,8 +46,8 @@ public class DNEdgeBuilder {
         
         // 2. Add vertices
         Collection<Resource> vertices = graph.syncRequest(new ObjectsWithType(diagramResource, Layer0.getInstance(graph).ConsistsOf, DistrictNetworkResource.getInstance(graph).Vertex));
-        Resource startVertex = getOrCreateVertex(graph, vertices, start);
-        Resource endVertex = getOrCreateVertex(graph, vertices, end);
+        Resource startVertex = getOrCreateVertex(graph, vertices, start, padding);
+        Resource endVertex = getOrCreateVertex(graph, vertices, end, padding);
         
         graph.claim(edge, DN.HasStartVertex, startVertex);
         graph.claim(edge, DN.HasEndVertex, endVertex);
@@ -68,12 +68,13 @@ public class DNEdgeBuilder {
         glm.putElementOnVisibleLayers(diagram, graph, res);
     }
 
-    private Resource getOrCreateVertex(WriteGraph graph, Collection<Resource> vertices, double[] coords) throws DatabaseException {
+    private Resource getOrCreateVertex(WriteGraph graph, Collection<Resource> vertices, double[] coords, double padding) throws DatabaseException {
         Resource vertex = null;
+        double halfPadding = padding / 2;
         for (Resource vertx : vertices) {
             double[] existingCoords = graph.getRelatedValue2(vertx, DiagramResource.getInstance(graph).HasLocation, Bindings.DOUBLE_ARRAY);
-            Rectangle2D existing = new Rectangle2D.Double(existingCoords[0], existingCoords[1], 1, 1);
-            Rectangle2D tobecreated = new Rectangle2D.Double(coords[0], coords[1], 1, 1);
+            Rectangle2D existing = new Rectangle2D.Double(existingCoords[0] - halfPadding, existingCoords[1] - halfPadding, padding, padding);
+            Rectangle2D tobecreated = new Rectangle2D.Double(coords[0] - halfPadding, coords[1] - halfPadding, padding, padding);
             if (existing.intersects(tobecreated)) {
                 vertex = vertx;
                 break;
index 27905a55e56b05ac1322075b6e067f3bd663569d..a036f78d5215e0536eea8e4d5a0d7c573f534353 100644 (file)
@@ -1,66 +1,83 @@
-package org.simantics.district.network.ui;\r
-\r
-import java.util.Collections;\r
-import java.util.HashMap;\r
-import java.util.Map;\r
-\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.WriteGraph;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.diagram.stubs.DiagramResource;\r
-import org.simantics.diagram.synchronization.graph.layer.GraphLayer;\r
-import org.simantics.diagram.synchronization.graph.layer.GraphLayerUtil;\r
-import org.simantics.diagram.synchronization.graph.layer.IGraphLayerUtil;\r
-import org.simantics.district.network.ontology.DistrictNetworkResource;\r
-import org.simantics.layer0.Layer0;\r
-\r
-public class DNGraphLayerUtil implements IGraphLayerUtil {\r
-\r
-    public DNGraphLayerUtil(Resource layer) {\r
-        \r
-    }\r
-\r
-    @Override\r
-    public GraphLayer loadLayer(ReadGraph graph, Resource layer) throws DatabaseException {\r
-        Layer0 L0 = Layer0.getInstance(graph);\r
-        DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);\r
-        String name = graph.getRelatedValue(layer, L0.HasName);\r
-        Resource inLayer = graph.getSingleObject(layer, DN.HasInLayerTag);\r
-        \r
-        Map<String, Resource> properties = new HashMap<>();\r
-        properties.put("IN_LAYER", inLayer);\r
-\r
-        return new GraphLayer(name, layer, properties);\r
-    }\r
-\r
-    @Override\r
-    public GraphLayer createLayer(WriteGraph graph, String layerName, boolean active) throws DatabaseException {\r
-        Layer0 L0 = Layer0.getInstance(graph);\r
-        DiagramResource DIA = DiagramResource.getInstance(graph);\r
-        DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);\r
-        \r
-        \r
-        Resource layer = graph.newResource();\r
-        graph.claim(layer, L0.InstanceOf, null, DN.Layer);\r
-\r
-        // Assign tagging relations\r
-        Resource inLayerTag = GraphLayerUtil.newTag(graph, L0, DN.InLayer);\r
-        graph.claim(layer, DN.HasInLayerTag, inLayerTag);\r
-\r
-        // Assign shared name property for all, the layer and the tags\r
-        Resource name = graph.newResource();\r
-        graph.claim(name, L0.InstanceOf, null, L0.String);\r
-        graph.claimValue(name, layerName);\r
-\r
-        graph.claim(layer, L0.HasName, name);\r
-        graph.claim(inLayerTag, L0.HasName, name);\r
-        \r
-        graph.claim(layer, DN.HasSpatialRefSystem, DN.EPSG_4326);\r
-\r
-        GraphLayerUtil.setLayerActive(graph, DIA, layer, active);\r
-\r
-        return new GraphLayer(layerName, layer, Collections.emptyMap());\r
-    }\r
-\r
-}\r
+package org.simantics.district.network.ui;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.diagram.stubs.DiagramResource;
+import org.simantics.diagram.synchronization.graph.layer.GraphLayer;
+import org.simantics.diagram.synchronization.graph.layer.GraphLayerUtil;
+import org.simantics.diagram.synchronization.graph.layer.IGraphLayerUtil;
+import org.simantics.district.network.ontology.DistrictNetworkResource;
+import org.simantics.layer0.Layer0;
+
+public class DNGraphLayerUtil implements IGraphLayerUtil {
+
+    public DNGraphLayerUtil(Resource layer) {
+        
+    }
+
+    @Override
+    public GraphLayer loadLayer(ReadGraph graph, Resource layer) throws DatabaseException {
+        Layer0 L0 = Layer0.getInstance(graph);
+        DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
+        DiagramResource DIA = DiagramResource.getInstance(graph);
+        String name = graph.getRelatedValue(layer, L0.HasName);
+        Resource inLayer = graph.getSingleObject(layer, DN.HasInLayerTag);
+        Resource visible = graph.getSingleObject(layer, DIA.HasVisibleTag);
+        Resource focusable = graph.getSingleObject(layer, DIA.HasFocusableTag);
+        
+        Map<String, Resource> properties = new HashMap<>();
+        properties.put(GraphLayer.PROP_FOCUSABLE, focusable);
+        properties.put(GraphLayer.PROP_VISIBLE, visible);
+        properties.put("IN_LAYER", inLayer);
+
+        return new GraphLayer(name, layer, properties);
+    }
+
+    @Override
+    public GraphLayer createLayer(WriteGraph graph, String layerName, boolean active) throws DatabaseException {
+        Layer0 L0 = Layer0.getInstance(graph);
+        DiagramResource DIA = DiagramResource.getInstance(graph);
+        DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
+        
+        
+        Resource layer = graph.newResource();
+        graph.claim(layer, L0.InstanceOf, null, DN.Layer);
+
+        // Assign tagging relations
+        Resource inLayerTag = GraphLayerUtil.newTag(graph, L0, DN.InLayer);
+        // for backwards compatibility
+        Resource visibleTag = GraphLayerUtil.newTag(graph, L0, DIA.IsVisible);
+        Resource focusableTag = GraphLayerUtil.newTag(graph, L0, DIA.IsFocusable);
+        graph.claim(layer, DN.HasInLayerTag, inLayerTag);
+        // for backwards compatibility
+        graph.claim(layer, DIA.HasVisibleTag, visibleTag);
+        graph.claim(layer, DIA.HasFocusableTag, focusableTag);
+
+        // Assign shared name property for all, the layer and the tags
+        Resource name = graph.newResource();
+        graph.claim(name, L0.InstanceOf, null, L0.String);
+        graph.claimValue(name, layerName);
+
+        graph.claim(layer, L0.HasName, name);
+        graph.claim(inLayerTag, L0.HasName, name);
+        graph.claim(visibleTag, L0.HasName, name);
+        graph.claim(focusableTag, L0.HasName, name);
+        
+        graph.claim(layer, DN.HasSpatialRefSystem, DN.EPSG_4326);
+
+        GraphLayerUtil.setLayerActive(graph, DIA, layer, active);
+
+        Map<String, Resource> properties = new HashMap<>();
+        properties.put("IN_LAYER", inLayerTag);
+        properties.put(GraphLayer.PROP_FOCUSABLE, focusableTag);
+        properties.put(GraphLayer.PROP_VISIBLE, visibleTag);
+        
+        return new GraphLayer(layerName, layer, properties);
+    }
+
+}
index 5155ccd2d54778c434f0d28d6c7462e929423d01..57480180f2e44807f5319ff878f1a93dea0f8061 100644 (file)
@@ -30,6 +30,10 @@ public class DistrictDiagramViewer extends DiagramViewer {
         ctx.add(new NetworkDrawingParticipant());
     }
     
+    protected String getPopupId() {
+        return "#DistrictDiagramPopup";
+    }
+    
     @Override
     public void initializeCanvasContext(CanvasContext ctx) {
         super.initializeCanvasContext(ctx);
index 6ae6097c183b5a3e8b4cef542a12794fd3cfc11f..a340d8591f625f0fdb78a7de27edaec6b34c3112 100644 (file)
@@ -1,39 +1,83 @@
-\r
-package org.simantics.district.network.ui;\r
-\r
-import org.simantics.district.network.ui.nodes.NetworkDrawingNode;\r
-import org.simantics.g2d.canvas.impl.SGNodeReflection.SGInit;\r
-import org.simantics.g2d.diagram.IDiagram;\r
-import org.simantics.g2d.diagram.participant.AbstractDiagramParticipant;\r
-import org.simantics.scenegraph.g2d.G2DParentNode;\r
-import org.simantics.utils.datastructures.hints.IHintContext.Key;\r
-import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;\r
-\r
-public class NetworkDrawingParticipant extends AbstractDiagramParticipant {\r
-\r
-    /**\r
-     * A hint key for terminal pick distance in control pixels.\r
-     * @see #PICK_DIST\r
-     */\r
-    public static final Key KEY_PICK_DISTANCE = new KeyOf(Double.class, "PICK_DISTANCE");\r
-\r
-    /**\r
-     * Default terminal pick distance in control pixels.\r
-     * @see #DEFAULT_PICK_DISTANCE\r
-     */\r
-    public static final double PICK_DIST = 10;\r
-    \r
-    private NetworkDrawingNode node;\r
-    \r
-    @SGInit\r
-    public void initSG(G2DParentNode parent) {\r
-        node = parent.addNode("networkDrawingNode", NetworkDrawingNode.class);\r
-        node.setNetworkDrawingParticipant(this);\r
-    }\r
-    \r
-    @Override\r
-    protected void onDiagramSet(IDiagram newDiagram, IDiagram oldDiagram) {\r
-        node.setDiagram(newDiagram);\r
-    }\r
-\r
-}\r
+
+package org.simantics.district.network.ui;
+
+import java.awt.geom.Point2D;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.simantics.district.network.ui.adapters.DistrictNetworkVertexElement;
+import org.simantics.district.network.ui.nodes.DistrictNetworkVertexNode;
+import org.simantics.district.network.ui.nodes.NetworkDrawingNode;
+import org.simantics.g2d.canvas.impl.DependencyReflection.Dependency;
+import org.simantics.g2d.canvas.impl.SGNodeReflection.SGInit;
+import org.simantics.g2d.diagram.IDiagram;
+import org.simantics.g2d.diagram.handler.PickContext;
+import org.simantics.g2d.diagram.handler.PickRequest;
+import org.simantics.g2d.diagram.participant.AbstractDiagramParticipant;
+import org.simantics.g2d.element.IElement;
+import org.simantics.scenegraph.g2d.G2DNode;
+import org.simantics.scenegraph.g2d.G2DParentNode;
+import org.simantics.utils.datastructures.hints.IHintContext.Key;
+import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;
+
+public class NetworkDrawingParticipant extends AbstractDiagramParticipant {
+
+    @Dependency
+    PickContext pick;
+    
+    /**
+     * A hint key for terminal pick distance in control pixels.
+     * @see #PICK_DIST
+     */
+    public static final Key KEY_PICK_DISTANCE = new KeyOf(Double.class, "PICK_DISTANCE");
+
+    /**
+     * Default terminal pick distance in control pixels.
+     * @see #DEFAULT_PICK_DISTANCE
+     */
+    public static final double PICK_DIST = 10;
+    
+    private NetworkDrawingNode node;
+    
+    @SGInit
+    public void initSG(G2DParentNode parent) {
+        node = parent.addNode("networkDrawingNode", NetworkDrawingNode.class);
+        node.setNetworkDrawingParticipant(this);
+    }
+    
+    @Override
+    protected void onDiagramSet(IDiagram newDiagram, IDiagram oldDiagram) {
+        node.setDiagram(newDiagram);
+    }
+
+    public boolean pickHoveredElement(Point2D currentMousePos) {
+        PickRequest req = new PickRequest(currentMousePos.getX(), currentMousePos.getY());
+        List<IElement> pickables = new ArrayList<IElement>();
+        pick.pick(diagram, req, pickables);
+        
+        List<IElement> snap = new ArrayList<>(diagram.getSnapshot());
+        
+        snap.removeAll(pickables);
+        
+        boolean changed = false;
+        for (IElement sn : snap) {
+            G2DNode node = sn.getHint(DistrictNetworkVertexElement.KEY_DN_VERTEX_NODE);
+            if (node instanceof DistrictNetworkVertexNode) {
+                if (((DistrictNetworkVertexNode) node).hover(false) && !changed) {
+                    changed = true;
+                }
+            }
+        }
+        
+        for (IElement elem : pickables) {
+            G2DNode node = elem.getHint(DistrictNetworkVertexElement.KEY_DN_VERTEX_NODE);
+            if (node instanceof DistrictNetworkVertexNode) {
+                if (((DistrictNetworkVertexNode) node).hover(true) && !changed) {
+                    changed = true;
+                }
+            }
+        }
+        return changed;
+    }
+
+}
diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictDiagramClassAdapter.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictDiagramClassAdapter.java
new file mode 100644 (file)
index 0000000..fe3ed93
--- /dev/null
@@ -0,0 +1,89 @@
+package org.simantics.district.network.ui.adapters;
+
+import org.simantics.Simantics;
+import org.simantics.db.AsyncReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.common.request.WriteRequest;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.procedure.AsyncProcedure;
+import org.simantics.diagram.adapter.DiagramClassAdapter;
+import org.simantics.diagram.synchronization.IModifiableSynchronizationContext;
+import org.simantics.diagram.synchronization.SynchronizationHints;
+import org.simantics.diagram.synchronization.graph.DiagramGraphUtil;
+import org.simantics.diagram.synchronization.graph.GraphSynchronizationHints;
+import org.simantics.diagram.synchronization.graph.layer.GraphLayer;
+import org.simantics.diagram.synchronization.graph.layer.GraphLayerManager;
+import org.simantics.g2d.diagram.DiagramClass;
+import org.simantics.g2d.diagram.IDiagram;
+import org.simantics.g2d.diagram.handler.SubstituteElementClass;
+import org.simantics.g2d.element.ElementClass;
+import org.simantics.g2d.element.ElementHints;
+import org.simantics.g2d.element.IElement;
+import org.simantics.g2d.element.handler.ElementLayerListener;
+import org.simantics.g2d.layers.ILayer;
+
+public class DistrictDiagramClassAdapter extends DiagramClassAdapter {
+
+    static final SubstituteElementClass DINSTANCE = new DistrictDiagramSubstituteElementClass();
+
+    @Override
+    public void adapt(AsyncReadGraph g, Resource source, Resource r, AsyncProcedure<DiagramClass> procedure) {
+        procedure.execute(g, INSTANCE.newClassWith(DINSTANCE));
+    }
+
+    static class DistrictDiagramElementLayerListenerImpl implements ElementLayerListener {
+
+        private static final long serialVersionUID = 7723435000661141433L;
+
+        @Override
+        public void visibilityChanged(IElement e, ILayer layer, boolean visible) {
+            IModifiableSynchronizationContext context = e.getDiagram().getHint(SynchronizationHints.CONTEXT);
+            GraphLayerManager layerManager = context.get(GraphSynchronizationHints.GRAPH_LAYER_MANAGER);
+            GraphLayer gl = layerManager.getGraphLayer(layer.getName());
+            if (gl != null) {
+                changeTag(e, gl.getVisible(), visible);
+            }
+        }
+
+        @Override
+        public void focusabilityChanged(IElement e, ILayer layer, boolean focusable) {
+            IModifiableSynchronizationContext context = e.getDiagram().getHint(SynchronizationHints.CONTEXT);
+            GraphLayerManager layerManager = context.get(GraphSynchronizationHints.GRAPH_LAYER_MANAGER);
+            GraphLayer gl = layerManager.getGraphLayer(layer.getName());
+            if (gl != null) {
+                changeTag(e, gl.getFocusable(), focusable);
+            }
+        }
+
+        void changeTag(IElement e, Resource tag, boolean set) {
+            Object object = e.getHint(ElementHints.KEY_OBJECT);
+            Resource tagged;
+            if (object instanceof Resource)
+                tagged = (Resource) object;
+            else
+                tagged = null;
+            if (tagged == null)
+                return;
+            
+            Simantics.getSession().asyncRequest(new WriteRequest() {
+                
+                @Override
+                public void perform(WriteGraph graph) throws DatabaseException {
+                    DiagramGraphUtil.tag(graph, tagged, tag, set);
+                }
+            });
+        }
+    }
+
+    static class DistrictDiagramSubstituteElementClass implements SubstituteElementClass {
+
+        static final ElementLayerListener LAYER_LISTENER = new DistrictDiagramElementLayerListenerImpl();
+
+        @Override
+        public ElementClass substitute(IDiagram d, ElementClass ec) {
+            return ec.newClassWith(LAYER_LISTENER);
+        }
+
+    }
+}
index a53c02d2e0ba98708b8661cf64379f4f6a232545..12f26182dca15fe03cd4cf02ff6588a2a3954f3f 100644 (file)
-package org.simantics.district.network.ui.adapters;\r
-\r
-import java.awt.geom.Rectangle2D;\r
-\r
-import org.simantics.district.network.ui.DistrictNetworkEdge;\r
-import org.simantics.district.network.ui.nodes.DistrictNetworkEdgeNode;\r
-import org.simantics.g2d.element.ElementClass;\r
-import org.simantics.g2d.element.ElementUtils;\r
-import org.simantics.g2d.element.IElement;\r
-import org.simantics.g2d.element.SceneGraphNodeKey;\r
-import org.simantics.g2d.element.handler.InternalSize;\r
-import org.simantics.g2d.element.handler.SceneGraph;\r
-import org.simantics.g2d.element.handler.impl.DefaultTransform;\r
-import org.simantics.scenegraph.g2d.G2DParentNode;\r
-import org.simantics.utils.datastructures.hints.IHintContext.Key;\r
-import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;\r
-\r
-public class DistrictNetworkEdgeElement {\r
-\r
-    public static final Key KEY_DN_EDGE = new KeyOf(DistrictNetworkEdge.class, "DN_EDGE");\r
-    public static final Key KEY_DN_EDGE_NODE = new SceneGraphNodeKey(DistrictNetworkEdgeNode.class, "DN_EDGE_NODE");\r
-    \r
-    public static final ElementClass CLASS =\r
-            ElementClass.compile(\r
-                    DefaultTransform.INSTANCE,\r
-                    DNEdgeInternalSize.INSTANCE,\r
-                    DNEdgeSceneGraph.INSTANCE\r
-            ).setId(DistrictNetworkEdgeElement.class.getSimpleName());\r
-    \r
-    static final class DNEdgeSceneGraph implements SceneGraph {\r
-        \r
-        public static final DNEdgeSceneGraph INSTANCE = new DNEdgeSceneGraph();\r
-\r
-        private static final long serialVersionUID = 8894367073815556871L;\r
-\r
-        @Override\r
-        public void init(IElement edgeElement, G2DParentNode parent) {\r
-            DistrictNetworkEdge edge = edgeElement.getHint(KEY_DN_EDGE);\r
-            if (edge == null) {\r
-                cleanup(edgeElement);\r
-            } else {\r
-                DistrictNetworkEdgeNode node = edgeElement.getHint(KEY_DN_EDGE_NODE);\r
-                if (node == null) {\r
-                    node = parent.addNode(ElementUtils.generateNodeId(edgeElement), DistrictNetworkEdgeNode.class);\r
-                    edgeElement.setHint(KEY_DN_EDGE_NODE, node);\r
-                }\r
-                node.setDNEdge(edge);\r
-            }\r
-        }\r
-\r
-        @Override\r
-        public void cleanup(IElement edge) {\r
-            ElementUtils.removePossibleNode(edge, KEY_DN_EDGE_NODE);\r
-            edge.removeHint(KEY_DN_EDGE_NODE);\r
-        }\r
-    }\r
-    \r
-    static final class DNEdgeInternalSize implements InternalSize {\r
-\r
-        private static final long serialVersionUID = -2725017034692179676L;\r
-        \r
-        public static final DNEdgeInternalSize INSTANCE = new DNEdgeInternalSize();\r
-\r
-        @Override\r
-        public Rectangle2D getBounds(IElement e, Rectangle2D size) {\r
-            DistrictNetworkEdge edge = e.getHint(KEY_DN_EDGE);\r
-            if (size == null)\r
-                size = new Rectangle2D.Double();\r
-            edge.getBounds(size);\r
-\r
-            return size;\r
-        }\r
-        \r
-    }\r
-}\r
+package org.simantics.district.network.ui.adapters;
+
+import java.awt.geom.Rectangle2D;
+import java.util.Collection;
+import java.util.Collections;
+
+import org.simantics.district.network.ui.DistrictNetworkEdge;
+import org.simantics.district.network.ui.nodes.DistrictNetworkEdgeNode;
+import org.simantics.g2d.connection.handler.ConnectionHandler;
+import org.simantics.g2d.diagram.handler.Topology.Connection;
+import org.simantics.g2d.element.ElementClass;
+import org.simantics.g2d.element.ElementUtils;
+import org.simantics.g2d.element.IElement;
+import org.simantics.g2d.element.SceneGraphNodeKey;
+import org.simantics.g2d.element.handler.InternalSize;
+import org.simantics.g2d.element.handler.SceneGraph;
+import org.simantics.g2d.element.handler.impl.DefaultTransform;
+import org.simantics.g2d.element.handler.impl.SimpleElementLayers;
+import org.simantics.scenegraph.g2d.G2DParentNode;
+import org.simantics.utils.datastructures.hints.IHintContext.Key;
+import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class DistrictNetworkEdgeElement {
+
+    public static final Key KEY_DN_EDGE = new KeyOf(DistrictNetworkEdge.class, "DN_EDGE");
+    public static final Key KEY_DN_EDGE_NODE = new SceneGraphNodeKey(DistrictNetworkEdgeNode.class, "DN_EDGE_NODE");
+    
+    public static final ElementClass CLASS =
+            ElementClass.compile(
+                    DefaultTransform.INSTANCE,
+                    DNEdgeInternalSize.INSTANCE,
+                    DNEdgeSceneGraph.INSTANCE,
+                    DNEdgeConnectionHandler.INSTANCE,
+                    SimpleElementLayers.INSTANCE
+            ).setId(DistrictNetworkEdgeElement.class.getSimpleName());
+    
+    static final class DNEdgeSceneGraph implements SceneGraph {
+        
+        public static final DNEdgeSceneGraph INSTANCE = new DNEdgeSceneGraph();
+
+        private static final long serialVersionUID = 8894367073815556871L;
+
+        @Override
+        public void init(IElement edgeElement, G2DParentNode parent) {
+            DistrictNetworkEdge edge = edgeElement.getHint(KEY_DN_EDGE);
+            if (edge == null) {
+                cleanup(edgeElement);
+            } else {
+                DistrictNetworkEdgeNode node = edgeElement.getHint(KEY_DN_EDGE_NODE);
+                if (node == null) {
+                    node = parent.addNode(ElementUtils.generateNodeId(edgeElement), DistrictNetworkEdgeNode.class);
+                    edgeElement.setHint(KEY_DN_EDGE_NODE, node);
+                }
+                node.setDNEdge(edge);
+            }
+        }
+
+        @Override
+        public void cleanup(IElement edge) {
+            ElementUtils.removePossibleNode(edge, KEY_DN_EDGE_NODE);
+            edge.removeHint(KEY_DN_EDGE_NODE);
+        }
+    }
+    
+    static final class DNEdgeInternalSize implements InternalSize {
+
+        private static final Logger LOGGER = LoggerFactory.getLogger(DNEdgeInternalSize.class);
+        
+        private static final long serialVersionUID = -2725017034692179676L;
+        
+        public static final DNEdgeInternalSize INSTANCE = new DNEdgeInternalSize();
+
+        @Override
+        public Rectangle2D getBounds(IElement e, Rectangle2D size) {
+            DistrictNetworkEdge edge = e.getHint(KEY_DN_EDGE);
+            if (size == null)
+                size = new Rectangle2D.Double();
+            if (edge != null)
+                edge.getBounds(size);
+            else
+                LOGGER.debug("Element {} does not have edge!", e);
+
+            return size;
+        }
+        
+    }
+    
+    static class DNEdgeConnectionHandler implements ConnectionHandler {
+
+        private static final long serialVersionUID = -410377314637446238L;
+        
+        public static final DNEdgeConnectionHandler INSTANCE = new DNEdgeConnectionHandler();
+
+        @Override
+        public Collection<IElement> getChildren(IElement connection, Collection<IElement> result) {
+            return Collections.emptyList();
+        }
+
+        @Override
+        public Collection<IElement> getBranchPoints(IElement connection, Collection<IElement> result) {
+            return Collections.emptyList();
+        }
+
+        @Override
+        public Collection<IElement> getSegments(IElement connection, Collection<IElement> result) {
+            return Collections.emptyList();
+        }
+
+        @Override
+        public Collection<Connection> getTerminalConnections(IElement connection, Collection<Connection> result) {
+            return Collections.emptyList();
+        }
+    }
+}
index ff1d844faf936c93a5344db9804a768c85a29991..63590990cd9ba421097cd65270be0b6cf8faaa4c 100644 (file)
@@ -1,62 +1,75 @@
-package org.simantics.district.network.ui.adapters;\r
-\r
-import java.awt.geom.Path2D;\r
-\r
-import org.simantics.db.AsyncReadGraph;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.procedure.AsyncProcedure;\r
-import org.simantics.diagram.adapter.SyncElementFactory;\r
-import org.simantics.diagram.stubs.DiagramResource;\r
-import org.simantics.diagram.ui.DiagramModelHints;\r
-import org.simantics.district.network.ontology.DistrictNetworkResource;\r
-import org.simantics.district.network.ui.DistrictNetworkEdge;\r
-import org.simantics.g2d.canvas.ICanvasContext;\r
-import org.simantics.g2d.diagram.IDiagram;\r
-import org.simantics.g2d.element.ElementClass;\r
-import org.simantics.g2d.element.IElement;\r
-import org.simantics.g2d.element.handler.impl.StaticObjectAdapter;\r
-\r
-public class DistrictNetworkEdgeElementFactory extends SyncElementFactory {\r
-\r
-    public static final ElementClass CLASS = DistrictNetworkEdgeElement.CLASS;\r
-    \r
-    private DistrictNetworkResource DN;\r
-    private DiagramResource DIA;\r
-    \r
-    public DistrictNetworkEdgeElementFactory(ReadGraph graph) {\r
-        this.DN = DistrictNetworkResource.getInstance(graph);\r
-        this.DIA = DiagramResource.getInstance(graph);\r
-    }\r
-    \r
-    @Override\r
-    public void create(AsyncReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementType, AsyncProcedure<ElementClass> procedure) {\r
-        procedure.execute(graph, CLASS.newClassWith(false, new StaticObjectAdapter(elementType)));\r
-    }\r
-    \r
-    @Override\r
-    protected Resource getElementClassBaseType(AsyncReadGraph graph) {\r
-        return DN.Edge;\r
-    }\r
-    \r
-    @Override\r
-    public void load(ReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource edgeResource, IElement element) throws DatabaseException {\r
-        \r
-        Resource diagramRuntime = diagram.getHint(DiagramModelHints.KEY_DIAGRAM_RUNTIME_RESOURCE);\r
-        \r
-        Resource startVertex = graph.getSingleObject(edgeResource, DN.HasStartVertex);\r
-        Resource endVertex = graph.getSingleObject(edgeResource, DN.HasEndVertex);\r
-        \r
-        double[] startCoords = graph.getRelatedValue2(startVertex, DIA.HasLocation);\r
-        double[] endCoords = graph.getRelatedValue2(endVertex, DIA.HasLocation);\r
-        \r
-        Path2D path = new Path2D.Double();\r
-        path.moveTo(startCoords[0], startCoords[1]);\r
-        path.lineTo(endCoords[0], endCoords[1]);\r
-        \r
-        DistrictNetworkEdge edge = new DistrictNetworkEdge(path);\r
-        \r
-        element.setHint(DistrictNetworkEdgeElement.KEY_DN_EDGE, edge);\r
-    }\r
-}\r
+package org.simantics.district.network.ui.adapters;
+
+import java.awt.geom.Path2D;
+
+import org.simantics.db.AsyncReadGraph;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.procedure.AsyncProcedure;
+import org.simantics.diagram.adapter.SyncElementFactory;
+import org.simantics.diagram.stubs.DiagramResource;
+import org.simantics.diagram.synchronization.IModifiableSynchronizationContext;
+import org.simantics.diagram.synchronization.SynchronizationHints;
+import org.simantics.diagram.synchronization.graph.GraphSynchronizationHints;
+import org.simantics.diagram.synchronization.graph.layer.GraphLayerManager;
+import org.simantics.diagram.ui.DiagramModelHints;
+import org.simantics.district.network.ontology.DistrictNetworkResource;
+import org.simantics.district.network.ui.DistrictNetworkEdge;
+import org.simantics.g2d.canvas.ICanvasContext;
+import org.simantics.g2d.diagram.DiagramHints;
+import org.simantics.g2d.diagram.IDiagram;
+import org.simantics.g2d.element.ElementClass;
+import org.simantics.g2d.element.IElement;
+import org.simantics.g2d.element.handler.impl.StaticObjectAdapter;
+import org.simantics.g2d.layers.ILayersEditor;
+
+public class DistrictNetworkEdgeElementFactory extends SyncElementFactory {
+
+    public static final ElementClass CLASS = DistrictNetworkEdgeElement.CLASS;
+    
+    private DistrictNetworkResource DN;
+    private DiagramResource DIA;
+    
+    public DistrictNetworkEdgeElementFactory(ReadGraph graph) {
+        this.DN = DistrictNetworkResource.getInstance(graph);
+        this.DIA = DiagramResource.getInstance(graph);
+    }
+    
+    @Override
+    public void create(AsyncReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementType, AsyncProcedure<ElementClass> procedure) {
+        procedure.execute(graph, CLASS.newClassWith(false, new StaticObjectAdapter(elementType)));
+    }
+    
+    @Override
+    protected Resource getElementClassBaseType(AsyncReadGraph graph) {
+        return DN.Edge;
+    }
+    
+    @Override
+    public void load(ReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource edgeResource, IElement element) throws DatabaseException {
+        
+        Resource diagramRuntime = diagram.getHint(DiagramModelHints.KEY_DIAGRAM_RUNTIME_RESOURCE);
+        
+        Resource startVertex = graph.getSingleObject(edgeResource, DN.HasStartVertex);
+        Resource endVertex = graph.getSingleObject(edgeResource, DN.HasEndVertex);
+        
+        double[] startCoords = graph.getRelatedValue2(startVertex, DIA.HasLocation);
+        double[] endCoords = graph.getRelatedValue2(endVertex, DIA.HasLocation);
+        
+        Path2D path = new Path2D.Double();
+        path.moveTo(startCoords[0], startCoords[1]);
+        path.lineTo(endCoords[0], endCoords[1]);
+        
+        DistrictNetworkEdge edge = new DistrictNetworkEdge(path);
+        
+        element.setHint(DistrictNetworkEdgeElement.KEY_DN_EDGE, edge);
+        
+        IModifiableSynchronizationContext context = diagram.getHint(SynchronizationHints.CONTEXT);
+        GraphLayerManager layerManager = context.get(GraphSynchronizationHints.GRAPH_LAYER_MANAGER);
+        
+        ILayersEditor layersEditor = diagram.getHint(DiagramHints.KEY_LAYERS_EDITOR);
+        layerManager.loadLayersForElement(graph, layersEditor, element, edgeResource);
+        
+    }
+}
index 339d51d4149d8f2664a2b154d87c4b48a5bd2a0e..3e64bc3193957d249df2d6371cc5dfbcbc422d65 100644 (file)
@@ -1,78 +1,79 @@
-package org.simantics.district.network.ui.adapters;\r
-\r
-import java.awt.Dimension;\r
-import java.awt.geom.AffineTransform;\r
-import java.awt.geom.Rectangle2D;\r
-\r
-import org.simantics.district.network.ui.nodes.DistrictNetworkVertexNode;\r
-import org.simantics.g2d.element.ElementClass;\r
-import org.simantics.g2d.element.ElementUtils;\r
-import org.simantics.g2d.element.IElement;\r
-import org.simantics.g2d.element.SceneGraphNodeKey;\r
-import org.simantics.g2d.element.handler.InternalSize;\r
-import org.simantics.g2d.element.handler.SceneGraph;\r
-import org.simantics.g2d.element.handler.impl.DefaultTransform;\r
-import org.simantics.scenegraph.g2d.G2DParentNode;\r
-import org.simantics.utils.datastructures.hints.IHintContext.Key;\r
-import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;\r
-\r
-public class DistrictNetworkVertexElement {\r
-\r
-    public static final Key KEY_DN_VERTEX = new KeyOf(DistrictNetworkVertex.class, "DN_VERTEX");\r
-    public static final Key KEY_DN_VERTEX_NODE = new SceneGraphNodeKey(DistrictNetworkVertexNode.class, "DN_VERTEX_NODE");\r
-    \r
-    public static final ElementClass CLASS =\r
-            ElementClass.compile(\r
-                    DefaultTransform.INSTANCE,\r
-                    DNVertexInternalSize.INSTANCE,\r
-                    DNVertexSceneGraph.INSTANCE\r
-            ).setId(DistrictNetworkVertexElement.class.getSimpleName());\r
-    \r
-    static final class DNVertexSceneGraph implements SceneGraph {\r
-        \r
-        public static final DNVertexSceneGraph INSTANCE = new DNVertexSceneGraph();\r
-\r
-        private static final long serialVersionUID = 8894367073815556871L;\r
-\r
-        @Override\r
-        public void init(IElement edgeElement, G2DParentNode parent) {\r
-            DistrictNetworkVertex vertex = edgeElement.getHint(KEY_DN_VERTEX);\r
-            if (vertex == null) {\r
-                cleanup(edgeElement);\r
-            } else {\r
-                DistrictNetworkVertexNode node = edgeElement.getHint(KEY_DN_VERTEX_NODE);\r
-                if (node == null) {\r
-                    node = parent.addNode(ElementUtils.generateNodeId(edgeElement), DistrictNetworkVertexNode.class);\r
-                    edgeElement.setHint(KEY_DN_VERTEX_NODE, node);\r
-                }\r
-                node.setVertex(vertex);\r
-                \r
-                AffineTransform at = ElementUtils.getTransform(edgeElement);\r
-                if(at != null)\r
-                    node.setTransform(at);\r
-            }\r
-        }\r
-\r
-        @Override\r
-        public void cleanup(IElement edge) {\r
-            ElementUtils.removePossibleNode(edge, KEY_DN_VERTEX_NODE);\r
-            edge.removeHint(KEY_DN_VERTEX_NODE);\r
-        }\r
-    }\r
-    \r
-    static final class DNVertexInternalSize implements InternalSize {\r
-\r
-        public static final DNVertexInternalSize INSTANCE = new DNVertexInternalSize();\r
-        \r
-        private static final long serialVersionUID = 2625702114278956461L;\r
-\r
-        @Override\r
-        public Rectangle2D getBounds(IElement e, Rectangle2D size) {\r
-            if (size == null)\r
-                size = new Rectangle2D.Double();\r
-            size.setFrame(-0.5, -0.5, 1, 1);\r
-            return size;\r
-        }\r
-        \r
-    }\r
-}\r
+package org.simantics.district.network.ui.adapters;
+
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Rectangle2D;
+
+import org.simantics.district.network.ui.nodes.DistrictNetworkVertexNode;
+import org.simantics.g2d.element.ElementClass;
+import org.simantics.g2d.element.ElementUtils;
+import org.simantics.g2d.element.IElement;
+import org.simantics.g2d.element.SceneGraphNodeKey;
+import org.simantics.g2d.element.handler.InternalSize;
+import org.simantics.g2d.element.handler.SceneGraph;
+import org.simantics.g2d.element.handler.impl.DefaultTransform;
+import org.simantics.g2d.element.handler.impl.SimpleElementLayers;
+import org.simantics.scenegraph.g2d.G2DParentNode;
+import org.simantics.utils.datastructures.hints.IHintContext.Key;
+import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;
+
+public class DistrictNetworkVertexElement {
+
+    public static final Key KEY_DN_VERTEX = new KeyOf(DistrictNetworkVertex.class, "DN_VERTEX");
+    public static final Key KEY_DN_VERTEX_NODE = new SceneGraphNodeKey(DistrictNetworkVertexNode.class, "DN_VERTEX_NODE");
+    
+    public static final ElementClass CLASS =
+            ElementClass.compile(
+                    DefaultTransform.INSTANCE,
+                    DNVertexInternalSize.INSTANCE,
+                    DNVertexSceneGraph.INSTANCE,
+                    SimpleElementLayers.INSTANCE
+            ).setId(DistrictNetworkVertexElement.class.getSimpleName());
+    
+    static final class DNVertexSceneGraph implements SceneGraph {
+        
+        public static final DNVertexSceneGraph INSTANCE = new DNVertexSceneGraph();
+
+        private static final long serialVersionUID = 8894367073815556871L;
+
+        @Override
+        public void init(IElement edgeElement, G2DParentNode parent) {
+            DistrictNetworkVertex vertex = edgeElement.getHint(KEY_DN_VERTEX);
+            if (vertex == null) {
+                cleanup(edgeElement);
+            } else {
+                DistrictNetworkVertexNode node = edgeElement.getHint(KEY_DN_VERTEX_NODE);
+                if (node == null) {
+                    node = parent.addNode(ElementUtils.generateNodeId(edgeElement), DistrictNetworkVertexNode.class);
+                    edgeElement.setHint(KEY_DN_VERTEX_NODE, node);
+                }
+                node.setVertex(vertex);
+                
+                AffineTransform at = ElementUtils.getTransform(edgeElement);
+                if(at != null)
+                    node.setTransform(at);
+            }
+        }
+
+        @Override
+        public void cleanup(IElement edge) {
+            ElementUtils.removePossibleNode(edge, KEY_DN_VERTEX_NODE);
+            edge.removeHint(KEY_DN_VERTEX_NODE);
+        }
+    }
+    
+    static final class DNVertexInternalSize implements InternalSize {
+
+        public static final DNVertexInternalSize INSTANCE = new DNVertexInternalSize();
+        
+        private static final long serialVersionUID = 2625702114278956461L;
+
+        @Override
+        public Rectangle2D getBounds(IElement e, Rectangle2D size) {
+            if (size == null)
+                size = new Rectangle2D.Double();
+            size.setFrame(-0.5, -0.5, 1, 1);
+            return size;
+        }
+        
+    }
+}
index c19716469d243e81ce7f35ead2b7799310d49c46..976abd48596ccf177065addfa8ffbc1914e1904e 100644 (file)
@@ -1,52 +1,64 @@
-package org.simantics.district.network.ui.adapters;\r
-\r
-import java.awt.geom.AffineTransform;\r
-\r
-import org.simantics.db.AsyncReadGraph;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.procedure.AsyncProcedure;\r
-import org.simantics.diagram.adapter.SyncElementFactory;\r
-import org.simantics.diagram.stubs.DiagramResource;\r
-import org.simantics.district.network.ontology.DistrictNetworkResource;\r
-import org.simantics.g2d.canvas.ICanvasContext;\r
-import org.simantics.g2d.diagram.IDiagram;\r
-import org.simantics.g2d.element.ElementClass;\r
-import org.simantics.g2d.element.ElementUtils;\r
-import org.simantics.g2d.element.IElement;\r
-import org.simantics.g2d.element.handler.impl.StaticObjectAdapter;\r
-\r
-public class DistrictNetworkVertexElementFactory extends SyncElementFactory {\r
-\r
-    public static final ElementClass CLASS = DistrictNetworkVertexElement.CLASS;\r
-    private DistrictNetworkResource DN;\r
-    private DiagramResource DIA;\r
-\r
-    public DistrictNetworkVertexElementFactory(ReadGraph graph) {\r
-        this.DN = DistrictNetworkResource.getInstance(graph);\r
-        this.DIA = DiagramResource.getInstance(graph);\r
-    }\r
-\r
-    @Override\r
-    public void create(AsyncReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementType, AsyncProcedure<ElementClass> procedure) {\r
-        procedure.execute(graph, CLASS.newClassWith(false, new StaticObjectAdapter(elementType)));\r
-    }\r
-\r
-    @Override\r
-    protected Resource getElementClassBaseType(AsyncReadGraph graph) {\r
-        return DN.Vertex;\r
-    }\r
-\r
-    @Override\r
-    public void load(ReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource vertexResource, IElement element) throws DatabaseException {\r
-        \r
-        double[] coords = graph.getRelatedValue(vertexResource, DIA.HasLocation);\r
-        DistrictNetworkVertex vertex = new DistrictNetworkVertex(coords);\r
-        element.setHint(DistrictNetworkVertexElement.KEY_DN_VERTEX, vertex);\r
-        \r
-        // set element transform based on layer SRS and coords\r
-        AffineTransform at = new AffineTransform(1, 0, 0, 1, coords[0], coords[1]);\r
-        ElementUtils.setTransform(element, at);\r
-    }\r
-}\r
+package org.simantics.district.network.ui.adapters;
+
+import java.awt.geom.AffineTransform;
+
+import org.simantics.db.AsyncReadGraph;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.procedure.AsyncProcedure;
+import org.simantics.diagram.adapter.SyncElementFactory;
+import org.simantics.diagram.stubs.DiagramResource;
+import org.simantics.diagram.synchronization.IModifiableSynchronizationContext;
+import org.simantics.diagram.synchronization.SynchronizationHints;
+import org.simantics.diagram.synchronization.graph.GraphSynchronizationHints;
+import org.simantics.diagram.synchronization.graph.layer.GraphLayerManager;
+import org.simantics.district.network.ontology.DistrictNetworkResource;
+import org.simantics.g2d.canvas.ICanvasContext;
+import org.simantics.g2d.diagram.DiagramHints;
+import org.simantics.g2d.diagram.IDiagram;
+import org.simantics.g2d.element.ElementClass;
+import org.simantics.g2d.element.ElementUtils;
+import org.simantics.g2d.element.IElement;
+import org.simantics.g2d.element.handler.impl.StaticObjectAdapter;
+import org.simantics.g2d.layers.ILayersEditor;
+
+public class DistrictNetworkVertexElementFactory extends SyncElementFactory {
+
+    public static final ElementClass CLASS = DistrictNetworkVertexElement.CLASS;
+    private DistrictNetworkResource DN;
+    private DiagramResource DIA;
+
+    public DistrictNetworkVertexElementFactory(ReadGraph graph) {
+        this.DN = DistrictNetworkResource.getInstance(graph);
+        this.DIA = DiagramResource.getInstance(graph);
+    }
+
+    @Override
+    public void create(AsyncReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementType, AsyncProcedure<ElementClass> procedure) {
+        procedure.execute(graph, CLASS.newClassWith(false, new StaticObjectAdapter(elementType)));
+    }
+
+    @Override
+    protected Resource getElementClassBaseType(AsyncReadGraph graph) {
+        return DN.Vertex;
+    }
+
+    @Override
+    public void load(ReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource vertexResource, IElement element) throws DatabaseException {
+        
+        double[] coords = graph.getRelatedValue(vertexResource, DIA.HasLocation);
+        DistrictNetworkVertex vertex = new DistrictNetworkVertex(coords);
+        element.setHint(DistrictNetworkVertexElement.KEY_DN_VERTEX, vertex);
+        
+        // set element transform based on layer SRS and coords
+        AffineTransform at = new AffineTransform(1, 0, 0, 1, coords[0], coords[1]);
+        ElementUtils.setTransform(element, at);
+        
+        IModifiableSynchronizationContext context = diagram.getHint(SynchronizationHints.CONTEXT);
+        GraphLayerManager layerManager = context.get(GraphSynchronizationHints.GRAPH_LAYER_MANAGER);
+        
+        ILayersEditor layersEditor = diagram.getHint(DiagramHints.KEY_LAYERS_EDITOR);
+        layerManager.loadLayersForElement(graph, layersEditor, element, vertexResource);
+    }
+}
diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/contributions/JoinVerticesHandler.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/contributions/JoinVerticesHandler.java
new file mode 100644 (file)
index 0000000..9a8c1d2
--- /dev/null
@@ -0,0 +1,60 @@
+package org.simantics.district.network.ui.contributions;
+
+import java.util.List;
+
+import javax.inject.Named;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.e4.core.di.annotations.CanExecute;
+import org.eclipse.e4.core.di.annotations.Execute;
+import org.eclipse.e4.ui.services.IServiceConstants;
+import org.eclipse.jface.viewers.ISelection;
+import org.simantics.DatabaseJob;
+import org.simantics.Simantics;
+import org.simantics.db.Resource;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.common.request.WriteRequest;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.SelectionHints;
+import org.simantics.district.network.DistrictNetworkUtil;
+import org.simantics.district.network.ui.internal.Activator;
+import org.simantics.utils.ui.ISelectionUtils;
+
+public class JoinVerticesHandler {
+
+    @CanExecute
+    public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION) ISelection selection) {
+        List<Resource> vertices = ISelectionUtils.getPossibleKeys(selection, SelectionHints.KEY_MAIN, Resource.class);
+        return vertices.size() > 1;
+    }
+    
+    @Execute
+    public void execute(@Named(IServiceConstants.ACTIVE_SELECTION) Object selection) {
+        final List<Resource> vertices = ISelectionUtils.getPossibleKeys(selection, SelectionHints.KEY_MAIN, Resource.class);
+        if (vertices.size() <= 1)
+            return;
+        Job job = new DatabaseJob("Join selected vertices") {
+            
+            @Override
+            protected IStatus run(IProgressMonitor monitor) {
+                try {
+                    Simantics.getSession().syncRequest(new WriteRequest() {
+                        
+                        @Override
+                        public void perform(WriteGraph graph) throws DatabaseException {
+                            DistrictNetworkUtil.joinVertices(graph, vertices);
+                        }
+                    });
+                } catch (DatabaseException e) {
+                    return new Status(IStatus.ERROR, Activator.PLUGIN_ID, getName() + " failed.", e);
+                }
+                return Status.OK_STATUS;
+            }
+        };
+        job.setUser(true);
+        job.schedule();
+    }
+}
diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/contributions/RunMappingHandler.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/contributions/RunMappingHandler.java
new file mode 100644 (file)
index 0000000..5ae0c0d
--- /dev/null
@@ -0,0 +1,56 @@
+package org.simantics.district.network.ui.contributions;
+
+import javax.inject.Named;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.e4.core.di.annotations.CanExecute;
+import org.eclipse.e4.core.di.annotations.Execute;
+import org.eclipse.e4.ui.model.application.ui.basic.MPart;
+import org.eclipse.e4.ui.services.IServiceConstants;
+import org.eclipse.ui.IEditorPart;
+import org.simantics.DatabaseJob;
+import org.simantics.Simantics;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.common.request.WriteRequest;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.district.network.ui.internal.Activator;
+import org.simantics.ui.workbench.IResourceEditorInput;
+import org.simantics.ui.workbench.e4.E4WorkbenchUtils;
+
+public class RunMappingHandler {
+
+    @CanExecute
+    public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART) MPart mActiveEditorPart) {
+        IEditorPart activeEditorPart = E4WorkbenchUtils.getActiveIEditorPart(mActiveEditorPart);
+        return activeEditorPart != null;
+    }
+    
+    @Execute
+    public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart mActiveEditorPart) {
+        Job job = new DatabaseJob("Map network to Apros") {
+            
+            @Override
+            protected IStatus run(IProgressMonitor monitor) {
+                try {
+                    IEditorPart activeEditorPart = E4WorkbenchUtils.getActiveIEditorPart(mActiveEditorPart);
+                    IResourceEditorInput input = (IResourceEditorInput) activeEditorPart.getEditorInput();
+                    Simantics.getSession().syncRequest(new WriteRequest() {
+                        
+                        @Override
+                        public void perform(WriteGraph graph) throws DatabaseException {
+                            Object result = Simantics.applySCL("Apros/District/DistrictMapping", "mapNetworkToAprosProgress", graph, monitor, input.getResource());
+                        }
+                    });
+                } catch (DatabaseException e) {
+                    return new Status(IStatus.ERROR, Activator.PLUGIN_ID, getName() + " failed.", e);
+                }
+                return Status.OK_STATUS;
+            }
+        };
+        job.setUser(true);
+        job.schedule();
+    }
+}
diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/contributions/SetFocusableDynamicMenuContribution.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/contributions/SetFocusableDynamicMenuContribution.java
new file mode 100644 (file)
index 0000000..d2c2ed5
--- /dev/null
@@ -0,0 +1,93 @@
+package org.simantics.district.network.ui.contributions;
+
+import java.awt.geom.Point2D;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.inject.Named;
+
+import org.eclipse.e4.core.contexts.IEclipseContext;
+import org.eclipse.e4.ui.di.AboutToHide;
+import org.eclipse.e4.ui.di.AboutToShow;
+import org.eclipse.e4.ui.model.application.ui.basic.MPart;
+import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
+import org.eclipse.e4.ui.model.application.ui.menu.MMenuElement;
+import org.eclipse.e4.ui.model.application.ui.menu.MMenuFactory;
+import org.eclipse.e4.ui.services.IServiceConstants;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.ui.IEditorPart;
+import org.simantics.g2d.canvas.ICanvasContext;
+import org.simantics.g2d.diagram.DiagramHints;
+import org.simantics.g2d.diagram.IDiagram;
+import org.simantics.g2d.diagram.handler.PickContext;
+import org.simantics.g2d.diagram.handler.PickRequest;
+import org.simantics.g2d.element.IElement;
+import org.simantics.g2d.element.handler.ElementLayers;
+import org.simantics.g2d.layers.ILayer;
+import org.simantics.g2d.layers.ILayersEditor;
+import org.simantics.ui.workbench.e4.E4WorkbenchUtils;
+
+public class SetFocusableDynamicMenuContribution {
+
+    public static final String SET_FOCUSABLE_ID = "org.simantics.district.network.ui.setFocusable";
+    public static final String FOCUSABLE_ELEMENTS = "org.simantics.district.network.ui.focusableElements";
+
+    @AboutToShow
+    public void aboutToShow(IEclipseContext popupContext, @Named(IServiceConstants.ACTIVE_SELECTION) ISelection selection, List<MMenuElement> items, @Named(IServiceConstants.ACTIVE_PART) MPart part) {
+        
+        IEditorPart editorPart = E4WorkbenchUtils.getActiveIEditorPart(part);
+        IDiagram diagram = editorPart.getAdapter(IDiagram.class);
+        if (diagram == null)
+            return;
+        
+        PickContext pick = diagram.getDiagramClass().getSingleItem(PickContext.class);
+        if (pick == null)
+            return;
+        
+        ICanvasContext ctx = (ICanvasContext) editorPart.getAdapter(ICanvasContext.class);
+        if (ctx == null)
+            return;
+
+        Point2D canvasPosition = ctx.getHintStack().getHint(DiagramHints.POPUP_MENU_CANVAS_POSITION);
+        if (canvasPosition == null)
+            return;
+        
+        List<IElement> result = new ArrayList<>();
+        
+        ILayersEditor le = diagram.getHint(DiagramHints.KEY_LAYERS_EDITOR);
+        // Quite hackish solution..
+        boolean oldIgnore = le.getIgnoreFocusSettings();
+        le.setIgnoreFocusSettings(true);
+        pick.pick(diagram, new PickRequest(canvasPosition.getX(), canvasPosition.getY()), result);
+        le.setIgnoreFocusSettings(oldIgnore);
+        
+        boolean allow = false;
+        
+        for (IElement elem : result) {
+            ElementLayers el = elem.getElementClass().getAtMostOneItemOfClass(ElementLayers.class);
+            for (ILayer layer : le.getVisibleLayers()) {
+                boolean focusable = el.isFocusable(elem, layer);
+                if (!focusable)
+                    allow = true;
+            }
+        }
+        
+        MHandledMenuItem dynamicItem = MMenuFactory.INSTANCE.createHandledMenuItem();
+        if (allow)
+            dynamicItem.setLabel("Allow focusing");
+        else
+            dynamicItem.setLabel("Disallow focusing");
+
+        dynamicItem.setContributorURI("platform:/plugin/org.simantics.district.network.ui");
+        dynamicItem.setIconURI("platform:/plugin/org.simantics.modeling.ui/icons/shape_handles.png");
+        dynamicItem.setCommand(E4WorkbenchUtils.getMCommandById(SET_FOCUSABLE_ID));
+        items.add(dynamicItem);
+        
+        popupContext.set(FOCUSABLE_ELEMENTS, result);
+    }
+
+    @AboutToHide
+    public void aboutToHide(IEclipseContext popupContext) {
+        popupContext.remove(FOCUSABLE_ELEMENTS);
+    }
+}
diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/contributions/SetFocusableHandler.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/contributions/SetFocusableHandler.java
new file mode 100644 (file)
index 0000000..b0cfad3
--- /dev/null
@@ -0,0 +1,53 @@
+
+package org.simantics.district.network.ui.contributions;
+
+import java.util.Collection;
+
+import javax.inject.Named;
+
+import org.eclipse.e4.core.contexts.IEclipseContext;
+import org.eclipse.e4.core.di.annotations.CanExecute;
+import org.eclipse.e4.core.di.annotations.Execute;
+import org.eclipse.e4.ui.model.application.ui.basic.MPart;
+import org.eclipse.e4.ui.services.IServiceConstants;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.ui.IEditorPart;
+import org.simantics.g2d.diagram.DiagramHints;
+import org.simantics.g2d.diagram.IDiagram;
+import org.simantics.g2d.element.IElement;
+import org.simantics.g2d.element.handler.ElementLayers;
+import org.simantics.g2d.layers.ILayer;
+import org.simantics.g2d.layers.ILayers;
+import org.simantics.ui.workbench.e4.E4WorkbenchUtils;
+
+public class SetFocusableHandler {
+
+    @CanExecute
+    public boolean canExecute(IEclipseContext popupContext, @Named(IServiceConstants.ACTIVE_SELECTION) ISelection selection) {
+        @SuppressWarnings("unchecked")
+        Collection<IElement> elements = (Collection<IElement>) popupContext.get(SetFocusableDynamicMenuContribution.FOCUSABLE_ELEMENTS);
+        return !elements.isEmpty();
+    }
+    
+    @Execute
+    public void execute(IEclipseContext popupContext, @Named(IServiceConstants.ACTIVE_SELECTION) ISelection selection, @Named(IServiceConstants.ACTIVE_PART) MPart activePart) {
+        IEditorPart editorPart = E4WorkbenchUtils.getActiveIEditorPart(activePart);
+        
+        IDiagram diagram = editorPart.getAdapter(IDiagram.class);
+        if (diagram == null)
+            return;
+        
+        @SuppressWarnings("unchecked")
+        Collection<IElement> selectedElements = (Collection<IElement>) popupContext.get(SetFocusableDynamicMenuContribution.FOCUSABLE_ELEMENTS);
+        
+        ILayers le = diagram.getHint(DiagramHints.KEY_LAYERS);
+        for (IElement elem : selectedElements) {
+            ElementLayers el = elem.getElementClass().getAtMostOneItemOfClass(ElementLayers.class);
+            for (ILayer layer : le.getVisibleLayers()) {
+                boolean focusable = el.isFocusable(elem, layer);
+                el.setFocusability(elem, layer, !focusable);
+            }
+        }
+    }
+
+}
\ No newline at end of file
diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/function/Functions.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/function/Functions.java
new file mode 100644 (file)
index 0000000..016a142
--- /dev/null
@@ -0,0 +1,329 @@
+package org.simantics.district.network.ui.function;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.dialogs.SelectionStatusDialog;
+import org.simantics.NameLabelUtil;
+import org.simantics.Simantics;
+import org.simantics.browsing.ui.common.modifiers.EnumeratedValue;
+import org.simantics.browsing.ui.common.modifiers.Enumeration;
+import org.simantics.browsing.ui.graph.impl.GraphEnumerationModifier;
+import org.simantics.databoard.Bindings;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.Session;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.common.request.IndexRoot;
+import org.simantics.db.common.request.ReadRequest;
+import org.simantics.db.common.request.WriteRequest;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.exception.RuntimeDatabaseException;
+import org.simantics.db.layer0.variable.Variable;
+import org.simantics.db.layer0.variable.Variables.Role;
+import org.simantics.db.procedure.Procedure;
+import org.simantics.diagram.stubs.DiagramResource;
+import org.simantics.district.network.ontology.DistrictNetworkResource;
+import org.simantics.layer0.Layer0;
+import org.simantics.modeling.ModelingResources;
+import org.simantics.modeling.ModelingUtils;
+import org.simantics.modeling.adapters.NewCompositeActionFactory;
+import org.simantics.modeling.typicals.TypicalUtil;
+import org.simantics.scl.reflection.annotations.SCLValue;
+import org.simantics.structural.stubs.StructuralResource2;
+import org.simantics.ui.workbench.action.DefaultActions;
+import org.simantics.utils.ui.SWTUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class Functions {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(Functions.class);
+    
+    private Functions() {
+    }
+
+    private static class HasMappingEnumerationModifier extends GraphEnumerationModifier {
+
+        public HasMappingEnumerationModifier(Session session, Resource subject, Resource relation, Enumeration<Resource> enumeration, Resource value) {
+            super(session, subject, relation, enumeration, value);
+        }
+
+    }
+
+    @SCLValue(type = "ReadGraph -> Resource -> Variable -> b")
+    public static Object defaultEdgeMappingModifier(ReadGraph graph, Resource resource, final Variable context) throws DatabaseException {
+        Resource diagram = resolveElement(graph, context);
+        DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
+        return baseMappingModifier(graph, diagram, DN.EdgeDefaultMapping, DN.Mapping_EdgeMapping, context);
+    }
+    
+    @SCLValue(type = "ReadGraph -> Resource -> Variable -> b")
+    public static Object defaultVertexMappingModifier(ReadGraph graph, Resource resource, final Variable context) throws DatabaseException {
+        System.out.println(graph.getURI(resource));
+        System.out.println(context.getURI(graph));
+        
+        Resource diagram = resolveElement(graph, context);
+        DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
+        return baseMappingModifier(graph, diagram, DN.VertexDefaultMapping, DN.Mapping_VertexMapping, context);
+    }
+    
+    @SCLValue(type = "ReadGraph -> Resource -> Variable -> b")
+    public static Object mappingModifier(ReadGraph graph, Resource resource, final Variable context) throws DatabaseException {
+        
+        Resource element = resolveElement(graph, context);
+        Resource mappingType = resolveMappingType(graph, element);
+        return baseMappingModifier(graph, element, DistrictNetworkResource.getInstance(graph).HasMapping, mappingType, context);
+    }
+
+    public static Map<String, Resource> getVertexMappings(ReadGraph graph, Resource resource) throws DatabaseException {
+        return getNetworkMappingsByType(graph, resource , DistrictNetworkResource.getInstance(graph).Mapping_VertexMapping);
+    }
+
+    public static Map<String, Resource> getEdgeMappings(ReadGraph graph, Resource resource) throws DatabaseException {
+        return getNetworkMappingsByType(graph, resource , DistrictNetworkResource.getInstance(graph).Mapping_EdgeMapping);
+    }
+
+    public static Map<String, Resource> getNetworkMappingsByType(ReadGraph graph, Resource element, Resource mappingType) throws DatabaseException {
+        Resource indexRoot = graph.sync(new IndexRoot(element));
+        List<Resource> mappings = ModelingUtils.searchByType(graph, indexRoot, mappingType);
+        Map<String, Resource> result = new HashMap<>(mappings.size());
+        Layer0 L0 = Layer0.getInstance(graph);
+        mappings.forEach(mapping -> {
+            try {
+                String name = graph.getRelatedValue2(mapping, L0.HasName);
+                result.put(name, mapping);
+            } catch (DatabaseException e) {
+                e.printStackTrace();
+            }
+        });
+        return result;
+    }
+    
+    private static Object baseMappingModifier(ReadGraph graph, Resource element, Resource property, Resource mappingType, Variable context) throws DatabaseException {
+        Resource indexRoot = graph.sync(new IndexRoot(element));
+        List<Resource> mappings = ModelingUtils.searchByType(graph, indexRoot, mappingType);
+        Enumeration<Resource> enums = Enumeration
+                .make(mappings.stream().map(m -> createEnumeratedValue(graph, m)).collect(Collectors.toList()));
+        
+        Resource currentMapping = graph.getSingleObject(element, property);
+        
+        return new HasMappingEnumerationModifier(Simantics.getSession(), element, property, enums, currentMapping);
+    }
+    
+    private static Resource resolveMappingType(ReadGraph graph, Resource element) throws DatabaseException {
+        DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
+        if (graph.isInstanceOf(element, DN.Edge))
+            return DN.Mapping_EdgeMapping;
+        else if (graph.isInstanceOf(element, DN.Vertex))
+            return DN.Mapping_VertexMapping;
+        throw new IllegalStateException("No mapping type found for element " + element + " : " + graph.getPossibleURI(element));
+    }
+
+    private static Resource resolveElement(ReadGraph graph, Variable variable) throws DatabaseException {
+        Role role = variable.getPossibleRole(graph);
+        if (role.equals(Role.PROPERTY))
+            return resolveElement(graph, variable.getParent(graph));
+        else
+            return variable.getRepresents(graph);
+    }
+
+    private static EnumeratedValue<Resource> createEnumeratedValue(ReadGraph graph, Resource resource) {
+        try {
+            String label = NameLabelUtil.modalName(graph, resource);
+            return new EnumeratedValue<Resource>(label, resource);
+        } catch (DatabaseException e) {
+            throw new RuntimeDatabaseException(e);
+        }
+    }
+    
+    @SCLValue(type = "ReadGraph -> Resource -> a -> b")
+    public static Object enumerationValues(ReadGraph graph, Resource resource, Object context) throws DatabaseException {
+        Variable var = (Variable) context;
+        System.out.println(graph.getURI(resource));
+        System.out.println(var.getURI(graph));
+        return Collections.emptyList();
+    }
+    
+    @SCLValue(type = "ReadGraph -> Resource -> a -> b")
+    public static Object convertToValue(ReadGraph graph, Resource resource, Object context) throws DatabaseException {
+        return graph.getRelatedValue2(resource, Layer0.getInstance(graph).HasName, Bindings.STRING);
+//        return null;
+    }
+    
+    
+    @SCLValue(type = "Resource -> String -> Resource -> Resource")
+    public static Resource compositeInstantiator(final Resource compositeType, final String defaultName, final Resource target) throws DatabaseException {
+        
+        return TypicalUtil.syncExec(procedure -> {
+            if (!SWTUtils.asyncExec(PlatformUI.getWorkbench().getDisplay(), () -> {
+                try {
+                    queryInitialValuesAndCreateComposite(compositeType, target, defaultName, procedure);
+                } catch (Throwable t) {
+                    procedure.exception(t);
+                }
+            })) {
+                procedure.execute(null);
+            }
+        });
+    }
+
+    private static class DefaultMappingsDialog extends SelectionStatusDialog {
+
+        private Combo vertexMappingCombo;
+        private Combo edgeMappingCombo;
+        private Combo crsCombo;
+        private Composite composite;
+        
+        private Resource configuration;
+        private Map<String, Resource> vertexMappings = new HashMap<>();
+        private Map<String, Resource> edgeMappings = new HashMap<>();
+        
+        private Resource defaultVertexMapping;
+        private Resource defaultEdgeMapping;
+
+        protected DefaultMappingsDialog(Shell parentShell, Resource configuration) {
+            super(parentShell);
+            this.configuration = configuration;
+            setTitle("Select mappings for new DN diagram");
+        }
+
+        public Resource getDefaultVertexMapping() {
+            return defaultVertexMapping;
+        }
+
+        public Resource getDefaultEdgeMapping() {
+            return defaultEdgeMapping;
+        }
+
+        @Override
+        protected Control createDialogArea(Composite parent) {
+            composite = (Composite) super.createDialogArea(parent);
+            
+            createMappingsGroup(composite);
+            createCRSSettingsGroup(composite);
+            
+            // compute default values
+            Simantics.getSession().asyncRequest(new ReadRequest() {
+
+                @Override
+                public void run(ReadGraph graph) throws DatabaseException {
+                    
+                    vertexMappings = getVertexMappings(graph, configuration);
+                    edgeMappings = getEdgeMappings(graph, configuration);
+                    
+                    composite.getDisplay().asyncExec(() -> {
+                        
+                        vertexMappingCombo.setItems(vertexMappings.keySet().toArray(new String[vertexMappings.size()]));
+                        edgeMappingCombo.setItems(edgeMappings.keySet().toArray(new String[edgeMappings.size()]));
+                        vertexMappingCombo.select(0);
+                        edgeMappingCombo.select(0);
+                    }); 
+                    
+                }
+            });
+            return composite;
+        }
+        
+        private void createMappingsGroup(Composite parent) {
+            Group group= new Group(parent, SWT.NONE);
+            group.setFont(parent.getFont());
+            group.setText("Default mappings");
+            GridDataFactory.fillDefaults().grab(true, false).applyTo(group);
+            group.setLayout(new GridLayout(1, false));
+            
+            Composite cmposite = new Composite(group, SWT.NONE);
+            cmposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
+            cmposite.setLayout(new GridLayout(2, false));
+            
+            Label vertexMappingLabel = new Label(cmposite, SWT.NONE);
+            vertexMappingLabel.setText("Default vertex mapping");
+
+            vertexMappingCombo = new Combo(cmposite, SWT.READ_ONLY | SWT.BORDER);
+            GridDataFactory.fillDefaults().grab(true, false).applyTo(vertexMappingCombo);
+            
+            Label edgeMappingLabel = new Label(cmposite, SWT.NONE);
+            edgeMappingLabel.setText("Default edge mapping");
+
+            edgeMappingCombo = new Combo(cmposite, SWT.READ_ONLY | SWT.BORDER);
+            GridDataFactory.fillDefaults().grab(true, false).applyTo(edgeMappingCombo);
+        }
+        
+        private void createCRSSettingsGroup(Composite parent) {
+            Group group= new Group(parent, SWT.NONE);
+            group.setFont(parent.getFont());
+            group.setText("CRS settings");
+            GridDataFactory.fillDefaults().grab(true, false).applyTo(group);
+            group.setLayout(new GridLayout(1, false));
+            
+            Composite cmposite = new Composite(group, SWT.NONE);
+            cmposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
+            cmposite.setLayout(new GridLayout(2, false));
+            
+            Label vertexMappingLabel = new Label(cmposite, SWT.NONE);
+            vertexMappingLabel.setText("Default CRS");
+
+            crsCombo = new Combo(cmposite, SWT.READ_ONLY | SWT.BORDER);
+            GridData textData = new GridData(SWT.FILL, SWT.CENTER, true, false);
+            crsCombo.setLayoutData(textData);
+        }
+        
+
+        @Override
+        protected void computeResult() {
+            defaultVertexMapping = vertexMappings.get(vertexMappingCombo.getItem(vertexMappingCombo.getSelectionIndex()));
+            defaultEdgeMapping = edgeMappings.get(edgeMappingCombo.getItem(edgeMappingCombo.getSelectionIndex()));
+        }
+        
+    }
+    
+    private static void queryInitialValuesAndCreateComposite(final Resource compositeType, final Resource target,
+            String defaultName, final Procedure<Resource> procedure) {
+        DefaultMappingsDialog dialog = new DefaultMappingsDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), target);
+
+        if (dialog.open() != Dialog.OK) {
+            procedure.execute(null);
+            return;
+        }
+        Simantics.getSession().asyncRequest(
+                NewCompositeActionFactory.createCompositeRequest(target, defaultName, compositeType),
+                new Procedure<Resource>() {
+                    @Override
+                    public void execute(Resource composite) {
+                        Simantics.getSession().asyncRequest(new WriteRequest() {
+                            
+                            @Override
+                            public void perform(WriteGraph graph) throws DatabaseException {
+                                DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
+                                Resource diagram = graph.getSingleObject(composite, ModelingResources.getInstance(graph).CompositeToDiagram);
+                                graph.claim(diagram, DN.EdgeDefaultMapping, dialog.getDefaultEdgeMapping());
+                                graph.claim(diagram, DN.VertexDefaultMapping, dialog.getDefaultVertexMapping());
+                            }
+                        });
+                        DefaultActions.asyncPerformDefaultAction(Simantics.getSession(), composite, false, false, true);
+                        procedure.execute(composite);
+                    }
+
+                    @Override
+                    public void exception(Throwable t) {
+                        LOGGER.error("Failed to create composite, see exception for details.", t);
+                        procedure.exception(t);
+                    }
+                });
+    }
+}
index 1e7a4d512fae8ba7216410f91c6adec6578416f9..977fe30c670ec13fd6d1c179faff03716c20befa 100644 (file)
@@ -1,18 +1,25 @@
-package org.simantics.district.network.ui.internal;\r
-\r
-import org.osgi.framework.BundleActivator;\r
-import org.osgi.framework.BundleContext;\r
-\r
-public class Activator implements BundleActivator {\r
-\r
-    @Override\r
-    public void start(BundleContext context) throws Exception {\r
-\r
-    }\r
-\r
-    @Override\r
-    public void stop(BundleContext context) throws Exception {\r
-\r
-    }\r
-\r
-}\r
+package org.simantics.district.network.ui.internal;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+public class Activator implements BundleActivator {
+
+    public static final String PLUGIN_ID = "org.simantics.district.network.ui";
+    private static BundleContext context;
+
+    @Override
+    public void start(BundleContext context) throws Exception {
+        Activator.context = context;
+    }
+
+    @Override
+    public void stop(BundleContext context) throws Exception {
+        Activator.context = null;
+    }
+    
+    public static BundleContext getContext() {
+        return context;
+    }
+
+}
index 4abeee8b8b8b013fa90da556494dfc0ecb445604..408625f5aeeaa0bcafc139c636291d921860124d 100644 (file)
@@ -23,7 +23,7 @@ public class DistrictNetworkEdgeNode extends G2DNode {
     private DistrictNetworkEdge edge;
     private Rectangle2D bounds;
     
-    private Stroke stroke = new BasicStroke(2);
+    private static final Stroke STROKE = new BasicStroke(4, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
     private boolean scaleStroke = true;
 
     @Override
@@ -42,7 +42,7 @@ public class DistrictNetworkEdgeNode extends G2DNode {
         }
         
         Object aaHint = g2d.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
-        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
+        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
 
         Color oldColor = g2d.getColor();
         BasicStroke oldStroke = (BasicStroke) g2d.getStroke();
@@ -55,12 +55,12 @@ public class DistrictNetworkEdgeNode extends G2DNode {
 //        }
 //        
         g2d.setColor(Color.BLUE);
-        if (stroke != null) {
-            if (scaleStroke && stroke instanceof BasicStroke) {
-                BasicStroke bs = GeometryUtils.scaleStroke(stroke, (float) (1.0 / GeometryUtils.getScale(g2d.getTransform())));
+        if (STROKE != null) {
+            if (scaleStroke && STROKE instanceof BasicStroke) {
+                BasicStroke bs = GeometryUtils.scaleStroke(STROKE, (float) (1.0 / GeometryUtils.getScale(g2d.getTransform())));
                 g2d.setStroke(bs);
             } else {
-                g2d.setStroke(stroke);
+                g2d.setStroke(STROKE);
             }
         }
         // render
index a126ee5942a841f50a2108684a364a78052a4554..8dcd5183a6cb1545ad201b681f45fefbe9d5adc6 100644 (file)
@@ -11,21 +11,27 @@ import java.awt.geom.Rectangle2D;
 import org.simantics.district.network.ui.adapters.DistrictNetworkVertex;
 import org.simantics.scenegraph.g2d.G2DNode;
 import org.simantics.scenegraph.utils.GeometryUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class DistrictNetworkVertexNode extends G2DNode {
 
+    private static final Logger LOGGER = LoggerFactory.getLogger(DistrictNetworkVertexNode.class);
+    
     private static final long serialVersionUID = -2641639101400236719L;
     private DistrictNetworkVertex vertex;
+
+    private static final double left = -0.5;
+    private static final double top = -0.5;
+    private static final double width = 1;
+    private static final double height = 1;
     
-    private static final double scale = 1;
-    
-    private double left = -0.5;
-    private double top = -0.5;
-    private double width = 1;
-    private double height = 1;
+    private static final Rectangle2D NORMAL = new Rectangle2D.Double(left, top, width, height);
+    private static final Rectangle2D HOVERED = new Rectangle2D.Double(left * 2, top * 2, width * 2, height * 2);
     
     private Stroke stroke = new BasicStroke(2);
     private boolean scaleStroke = true;
+    private boolean hover;
 
     @Override
     public void init() {
@@ -48,18 +54,24 @@ public class DistrictNetworkVertexNode extends G2DNode {
         Stroke oldStroke = g2d.getStroke();
         
         g2d.setColor(Color.RED);
-        if (stroke != null) {
-            if (scaleStroke && stroke instanceof BasicStroke) {
-                BasicStroke bs = GeometryUtils.scaleStroke(stroke, (float) (1.0 / GeometryUtils.getScale(g2d.getTransform())));
-                g2d.setStroke(bs);
-            } else {
-                g2d.setStroke(stroke);
-            }
+        
+        double scaleRecip = 1;
+        if (scaleStroke) {
+            double scale = GeometryUtils.getScale(g2d.getTransform());
+            
+            //System.out.println("scale: " + scale);
+            scaleRecip = 1.0 / scale;
         }
-        // render
+        scaleRecip = 8.0 * scaleRecip;
         
-        Rectangle2D.Double rect = new Rectangle2D.Double(left / scale, top / scale, width / scale, height / scale);
-        g2d.draw(rect);
+        Rectangle2D toDraw;
+        if (hover) {
+            toDraw = new Rectangle2D.Double(HOVERED.getX() * scaleRecip, HOVERED.getY() * scaleRecip, HOVERED.getWidth() * scaleRecip, HOVERED.getHeight() * scaleRecip);
+        } else {
+            toDraw = new Rectangle2D.Double(NORMAL.getX() * scaleRecip, NORMAL.getY() * scaleRecip, NORMAL.getWidth() * scaleRecip, NORMAL.getHeight() * scaleRecip);
+        }
+        // render
+        g2d.fill(toDraw);
         
         // Reset stats
         g2d.setColor(oldColor);
@@ -73,11 +85,22 @@ public class DistrictNetworkVertexNode extends G2DNode {
 
     @Override
     public Rectangle2D getBoundsInLocal() {
-        return new Rectangle2D.Double(left / scale, top / scale, width / scale, height / scale);
+        return NORMAL;
     }
 
     public void setVertex(DistrictNetworkVertex vertex) {
         this.vertex = vertex;
     }
 
+    public boolean hover(boolean hover) {
+//        if (hover && LOGGER.isDebugEnabled())
+//            LOGGER.debug("Hovering " + this);
+        boolean changed = false;
+        if (this.hover != hover) {
+            this.hover = hover;
+            changed = true;
+        }
+        return changed;
+    }
+
 }
index a9c96e9b37c3e295b452c33eb521374079af9f3d..147442343c13b6b7c3dfa42ab04694757aa4f834 100644 (file)
@@ -24,6 +24,7 @@ import org.simantics.g2d.canvas.IToolMode;
 import org.simantics.g2d.diagram.IDiagram;
 import org.simantics.scenegraph.g2d.G2DNode;
 import org.simantics.scenegraph.g2d.events.EventTypes;
+import org.simantics.scenegraph.g2d.events.KeyEvent.KeyPressedEvent;
 import org.simantics.scenegraph.g2d.events.MouseEvent;
 import org.simantics.scenegraph.g2d.events.MouseEvent.MouseClickEvent;
 import org.simantics.scenegraph.g2d.events.MouseEvent.MouseDoubleClickedEvent;
@@ -35,6 +36,8 @@ public class NetworkDrawingNode extends G2DNode {
 
     private static final long serialVersionUID = -3475301184009620573L;
     
+    private Point2D currentMousePos = null;
+    
     private List<Point2D> nodes = new ArrayList<>();
 
     private Resource diagramResource;
@@ -73,6 +76,8 @@ public class NetworkDrawingNode extends G2DNode {
 
     @Override
     public void render(Graphics2D g2d) {
+        if (nodes.isEmpty())
+            return;
         
         Path2D path = new Path2D.Double();
         Iterator<Point2D> nodeIter = nodes.iterator();
@@ -84,6 +89,8 @@ public class NetworkDrawingNode extends G2DNode {
             Point2D node = nodeIter.next();
             path.lineTo(node.getX(), node.getY());
         }
+        if (currentMousePos != null)
+            path.lineTo(currentMousePos.getX(), currentMousePos.getY());
         
         Color old = g2d.getColor();
         Stroke oldStroke = g2d.getStroke();
@@ -112,7 +119,7 @@ public class NetworkDrawingNode extends G2DNode {
     
     @Override
     public int getEventMask() {
-        return EventTypes.MouseMask;
+        return EventTypes.AnyMask;
     }
     
     @Override
@@ -145,6 +152,9 @@ public class NetworkDrawingNode extends G2DNode {
     }
     
     private void createEdge(Point2D start, Point2D end) {
+        
+        double padding = GeometryUtils.getScale(getTransform());
+        
         double[] startCoords = new double[] { start.getX(), start.getY() };
         double[] endCoords = new double[] { end.getX(), end.getY() };
         
@@ -153,12 +163,12 @@ public class NetworkDrawingNode extends G2DNode {
             
             @Override
             public void perform(WriteGraph graph) throws DatabaseException {
-                builder.create(graph, startCoords, endCoords);
+                builder.create(graph, startCoords, endCoords, padding);
             }
         });
         
     }
-    
+
     @Override
     protected boolean mouseClicked(MouseClickEvent e) {
         // check ToolMode
@@ -168,9 +178,12 @@ public class NetworkDrawingNode extends G2DNode {
                 committed = false;
                 return false;
             }
-            Point2D localPos = NodeUtil.worldToLocal(this, e.controlPosition, new Point2D.Double());
-            nodes.add(new Point2D.Double(localPos.getX(), localPos.getY()));
-            
+            if (e.button == MouseEvent.RIGHT_BUTTON && !nodes.isEmpty()) {
+                nodes.remove(nodes.size() - 1);
+            } else if (e.button == MouseEvent.LEFT_BUTTON) {
+                Point2D localPos = NodeUtil.worldToLocal(this, e.controlPosition, new Point2D.Double());
+                nodes.add(new Point2D.Double(localPos.getX(), localPos.getY()));
+            }
             repaint();
             return true;
         }
@@ -183,6 +196,34 @@ public class NetworkDrawingNode extends G2DNode {
 
     @Override
     protected boolean mouseMoved(MouseMovedEvent e) {
+        IToolMode mode = getToolMode();
+        if (mode == Hints.CONNECTTOOL || e.hasAnyModifier(MouseEvent.ALT_MASK | MouseEvent.ALT_GRAPH_MASK)) {
+            boolean repaint = false;
+            Point2D p = NodeUtil.worldToLocal(this, e.controlPosition, new Point2D.Double());
+            if (participant.pickHoveredElement(p)) {
+                repaint = true;
+            }
+            if (!nodes.isEmpty()) {
+                currentMousePos = p;
+                
+                repaint();
+                return true;
+            }
+            currentMousePos = null;
+            if (repaint == true)
+                repaint();
+        }
         return super.mouseMoved(e);
     }
+    
+    @Override
+    protected boolean keyPressed(KeyPressedEvent e) {
+        if (e.keyCode == java.awt.event.KeyEvent.VK_ESCAPE) {
+            nodes.clear();
+            repaint();
+            return true;
+        }
+        return super.keyPressed(e);
+            
+    }
 }
\ No newline at end of file
index acb0acacba55246f739a174c9d3d850de4835201..a1a8ae5ac5169ff2216549c3b537137f29ab17f7 100644 (file)
@@ -11,8 +11,10 @@ import org.simantics.g2d.canvas.ICanvasParticipant;
 import org.simantics.g2d.diagram.handler.PickRequest.PickSorter;
 import org.simantics.g2d.diagram.participant.pointertool.PointerInteractor;
 import org.simantics.g2d.diagram.participant.pointertool.TerminalUtil.TerminalInfo;
+import org.simantics.g2d.element.ElementHints;
 import org.simantics.g2d.element.IElement;
-import org.simantics.scenegraph.g2d.G2DNode;
+import org.simantics.scenegraph.g2d.IG2DNode;
+import org.simantics.scenegraph.g2d.nodes.SingleElementNode;
 
 public class DNPointerInteractor extends PointerInteractor {
 
@@ -21,8 +23,8 @@ public class DNPointerInteractor extends PointerInteractor {
         @Override
         public void sort(List<IElement> elements) {
             Collections.sort(elements, (e1, e2) -> {
-                G2DNode e1node = getNode(e1);
-                G2DNode e2node = getNode(e2);
+                IG2DNode e1node = getNode(e1);
+                IG2DNode e2node = getNode(e2);
                 if (e1node.getZIndex() < e2node.getZIndex())
                     return -1;
                 else if (e1node.getZIndex() > e2node.getZIndex())
@@ -31,10 +33,17 @@ public class DNPointerInteractor extends PointerInteractor {
             });
         }
 
-        private static G2DNode getNode(IElement element) {
-            G2DNode node = element.getHint(DistrictNetworkEdgeElement.KEY_DN_EDGE_NODE);
+        private static IG2DNode getNode(IElement element) {
+            IG2DNode node = element.getHint(DistrictNetworkEdgeElement.KEY_DN_EDGE_NODE);
             if (node == null)
                 node = element.getHint(DistrictNetworkVertexElement.KEY_DN_VERTEX_NODE);
+            if (node == null) {
+                node = element.getHint(ElementHints.KEY_SG_NODE);
+                if (node instanceof SingleElementNode) {
+                    SingleElementNode snode = (SingleElementNode) node;
+                    node = snode.getNodes().iterator().next();
+                }
+            }
             return node;
         }
     }
index 7d8af3d67f1103c4bca0db0765f374f19bca101f..27de17e921f0ce9bb765a9f022075eee8504f9d3 100644 (file)
@@ -11,6 +11,7 @@ import org.simantics.db.WriteGraph;
 import org.simantics.db.common.CommentMetadata;
 import org.simantics.db.common.request.WriteRequest;
 import org.simantics.db.exception.DatabaseException;
+import org.simantics.diagram.elements.ElementTransforms;
 import org.simantics.diagram.elements.ElementTransforms.TransformedObject;
 import org.simantics.diagram.stubs.DiagramResource;
 import org.simantics.district.network.ontology.DistrictNetworkResource;
@@ -46,24 +47,26 @@ public class DNTranslateMode extends TranslateMode {
                         Object obj = ElementUtils.getObject(e);
                         if (obj instanceof Resource) {
                             Resource res = (Resource) obj;
+                            AffineTransform at = ElementUtils.getLocalTransform(e, new AffineTransform());
                             if (graph.isInstanceOf(res, DN.Vertex)) {
-                                AffineTransform at = ElementUtils.getLocalTransform(e, new AffineTransform());
-                                transformed.add( new TransformedObject((Resource) obj, at) );
-                                
-                                
                                 // write to db
                                 double[] coords = new double[] { at.getTranslateX(), at.getTranslateY() };
                                 graph.claimLiteral(res, DIA.HasLocation, coords);
+                            } else {
+                                // fallback to normal HasTransforms
+                                transformed.add( new TransformedObject((Resource) obj, at) );
                             }
                         }
                     }
-                    
                     if (!transformed.isEmpty()) {
+                        graph.markUndoPoint();
+                        // Normal transforms
+                        ElementTransforms.setTransformRequest(transformed).perform(graph);
+                        
                         CommentMetadata cm = graph.getMetadata(CommentMetadata.class);
                         graph.addMetadata(cm.add("Translated " + transformed.size() + " "
                                 + (transformed.size() == 1 ? "element" : "elements")
                                 + " by (" + dx + "," + dy + ") mm."));
-                        graph.markUndoPoint();
                     }
                 }
             });
index 03d4574c0e43beb7b57dff3fb0749bb023b3be7b..2aaaa26eb14aa3cd392ffb7812d2da74199b6fbe 100644 (file)
@@ -8,5 +8,6 @@ Require-Bundle: org.simantics.db,
  org.simantics.layer0;bundle-version="1.1.0",
  org.simantics.district.network.ontology,
  org.simantics.diagram.ontology;bundle-version="2.2.0",
- org.simantics.db.common
+ org.simantics.db.common,
+ org.simantics.db.layer0
 Export-Package: org.simantics.district.network
index 25503407e66f38f83b49d26dbdcd2334ccd59893..9bdec1b590367107660947593d32e122d6cddf98 100644 (file)
@@ -1,36 +1,64 @@
-package org.simantics.district.network;\r
-\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.WriteGraph;\r
-import org.simantics.db.common.utils.OrderedSetUtils;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.diagram.stubs.DiagramResource;\r
-import org.simantics.district.network.ontology.DistrictNetworkResource;\r
-import org.simantics.layer0.Layer0;\r
-\r
-public class DistrictNetworkUtil {\r
-\r
-    public static Resource createEdge(WriteGraph graph, Resource composite) throws DatabaseException {\r
-        Layer0 L0 = Layer0.getInstance(graph);\r
-        DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);\r
-        \r
-        Resource edge = graph.newResource();\r
-        graph.claim(edge, L0.InstanceOf, DN.Edge);\r
-        OrderedSetUtils.addFirst(graph, composite, edge);\r
-        graph.claim(composite, L0.ConsistsOf, L0.PartOf, edge);\r
-        return edge;\r
-    }\r
-    \r
-    public static Resource createVertex(WriteGraph graph, Resource composite, double[] coords) throws DatabaseException {\r
-        Layer0 L0 = Layer0.getInstance(graph);\r
-        DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);\r
-        DiagramResource DIA = DiagramResource.getInstance(graph);\r
-        Resource vertex = graph.newResource();\r
-        graph.claim(vertex, L0.InstanceOf, DN.Vertex);\r
-        graph.claimLiteral(vertex, DIA.HasLocation, coords);\r
-        OrderedSetUtils.addFirst(graph, composite, vertex);\r
-        graph.claim(composite, L0.ConsistsOf, L0.PartOf, vertex);\r
-        \r
-        return vertex;\r
-    }\r
-}\r
+package org.simantics.district.network;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+import org.simantics.db.Resource;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.common.utils.OrderedSetUtils;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.util.RemoverUtil;
+import org.simantics.diagram.stubs.DiagramResource;
+import org.simantics.district.network.ontology.DistrictNetworkResource;
+import org.simantics.layer0.Layer0;
+
+public class DistrictNetworkUtil {
+
+    public static Resource createEdge(WriteGraph graph, Resource composite) throws DatabaseException {
+        Layer0 L0 = Layer0.getInstance(graph);
+        DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
+        
+        Resource edge = graph.newResource();
+        graph.claim(edge, L0.InstanceOf, DN.Edge);
+        OrderedSetUtils.add(graph, composite, edge);
+        graph.claim(composite, L0.ConsistsOf, L0.PartOf, edge);
+        return edge;
+    }
+    
+    public static Resource createVertex(WriteGraph graph, Resource composite, double[] coords) throws DatabaseException {
+        Layer0 L0 = Layer0.getInstance(graph);
+        DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
+        DiagramResource DIA = DiagramResource.getInstance(graph);
+        Resource vertex = graph.newResource();
+        graph.claim(vertex, L0.InstanceOf, DN.Vertex);
+        graph.claimLiteral(vertex, DIA.HasLocation, coords);
+        OrderedSetUtils.add(graph, composite, vertex);
+        graph.claim(composite, L0.ConsistsOf, L0.PartOf, vertex);
+        
+        return vertex;
+    }
+    
+    public static Resource joinVertices(WriteGraph graph, Collection<Resource> vertices) throws DatabaseException {
+        if (vertices.isEmpty())
+            throw new IllegalArgumentException("vertices-collection should not be empty for joining vertices!");
+        DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
+        Iterator<Resource> verticeIterator = vertices.iterator();
+        Resource master = verticeIterator.next();
+        while (verticeIterator.hasNext()) {
+            Resource slave = verticeIterator.next();
+            Resource composite = graph.getSingleObject(slave, Layer0.getInstance(graph).PartOf);
+            Collection<Resource> startVertexEdges = graph.getObjects(slave, DN.HasStartVertex_Inverse);
+            for (Resource startVertexEdge : startVertexEdges) {
+                graph.deny(startVertexEdge, DN.HasStartVertex);
+                graph.claim(startVertexEdge, DN.HasStartVertex, master);
+            }
+            Collection<Resource> endVertexEdges = graph.getObjects(slave, DN.HasEndVertex_Inverse);
+            for (Resource endVertexEdge : endVertexEdges) {
+                graph.deny(endVertexEdge, DN.HasEndVertex);
+                graph.claim(endVertexEdge, DN.HasEndVertex, master);
+            }
+            OrderedSetUtils.remove(graph, composite, slave);
+        }
+        return master;
+    }
+}