From 4d9327aa40c5114f981741752305b7773122b580 Mon Sep 17 00:00:00 2001 From: jsimomaa Date: Wed, 5 Dec 2018 11:04:53 +0200 Subject: [PATCH] Use indexRoot directly for searching vertex/edge mappings gitlab #19 Change-Id: I991bc43cd5f9654f90c7409224ecd069d216f27d --- .../imports/ui/ComponentMappingPage.java | 6 ++++-- .../network/ui/function/Functions.java | 19 +++++++++---------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/org.simantics.district.imports.ui/src/org/simantics/district/imports/ui/ComponentMappingPage.java b/org.simantics.district.imports.ui/src/org/simantics/district/imports/ui/ComponentMappingPage.java index 5cf55511..c74603be 100644 --- a/org.simantics.district.imports.ui/src/org/simantics/district/imports/ui/ComponentMappingPage.java +++ b/org.simantics.district.imports.ui/src/org/simantics/district/imports/ui/ComponentMappingPage.java @@ -20,6 +20,7 @@ import org.eclipse.swt.widgets.Label; import org.simantics.Simantics; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; +import org.simantics.db.common.request.IndexRoot; import org.simantics.db.common.request.ReadRequest; import org.simantics.db.exception.DatabaseException; import org.simantics.district.imports.DistrictImportUtils; @@ -74,10 +75,11 @@ public class ComponentMappingPage extends WizardPage { @Override public void run(ReadGraph graph) throws DatabaseException { + Resource indexRoot = graph.sync(new IndexRoot(model.getParentDiagram())); if (model.isVertexImport()) - componentMappings = Functions.getVertexMappings(graph, model.getParentDiagram()); + componentMappings = Functions.getVertexMappings(graph, indexRoot); else - componentMappings = Functions.getEdgeMappings(graph, model.getParentDiagram()); + componentMappings = Functions.getEdgeMappings(graph, indexRoot); } }); } catch (DatabaseException e) { 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 index cc9b336f..627561a1 100644 --- 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 @@ -109,24 +109,23 @@ public class Functions { return baseMappingModifier(graph, element, DistrictNetworkResource.getInstance(graph).HasMapping, mappingType, context); } - public static Map getVertexMappings(ReadGraph graph, Resource resource) throws DatabaseException { - Map second = getNetworkMappingsByType(graph, resource , DistrictNetworkResource.getInstance(graph).Mapping_VertexMapping); + public static Map getVertexMappings(ReadGraph graph, Resource indexRoot) throws DatabaseException { + Map second = getNetworkMappingsByType(graph, indexRoot, DistrictNetworkResource.getInstance(graph).Mapping_VertexMapping); return second; } - public static Map getEdgeMappings(ReadGraph graph, Resource resource) throws DatabaseException { - Map second = getNetworkMappingsByType(graph, resource , DistrictNetworkResource.getInstance(graph).Mapping_EdgeMapping); + public static Map getEdgeMappings(ReadGraph graph, Resource indexRoot) throws DatabaseException { + Map second = getNetworkMappingsByType(graph, indexRoot, DistrictNetworkResource.getInstance(graph).Mapping_EdgeMapping); return second; } public static Map getCRSs(ReadGraph graph, Resource resource) throws DatabaseException { - Map result = getNetworkMappingsByType(graph, resource, DistrictNetworkResource.getInstance(graph).SpatialRefSystem); + Map result = getNetworkMappingsByType(graph, graph.sync(new IndexRoot(resource)), DistrictNetworkResource.getInstance(graph).SpatialRefSystem); return result; } - public static Map getNetworkMappingsByType(ReadGraph graph, Resource element, Resource mappingType) throws DatabaseException { - Resource indexRoot = graph.sync(new IndexRoot(element)); + public static Map getNetworkMappingsByType(ReadGraph graph, Resource indexRoot, Resource mappingType) throws DatabaseException { List mappings = QueryIndexUtils.searchByType(graph, indexRoot, mappingType); Map result = new HashMap<>(mappings.size()); Layer0 L0 = Layer0.getInstance(graph); @@ -262,9 +261,9 @@ public class Functions { @Override public void run(ReadGraph graph) throws DatabaseException { - - vertexMappings = getVertexMappings(graph, configuration); - edgeMappings = getEdgeMappings(graph, configuration); + Resource indexRoot = graph.sync(new IndexRoot(configuration)); + vertexMappings = getVertexMappings(graph, indexRoot); + edgeMappings = getEdgeMappings(graph, indexRoot); composites = getComposites(graph, configuration); -- 2.47.1