X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.modeling%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Fadapters%2FCompositeCopyHandler.java;h=ae65e87f88476bf6b2059e8899d5a63266816fee;hp=144448d9cff358a9e26a78126a278a04cf9b80a1;hb=22703b9675e377d3620fb5b9fe1e4c3adc18edc4;hpb=29a9155f55ac9ccaef1b3fd163e7c4230fcd4d1c diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/adapters/CompositeCopyHandler.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/adapters/CompositeCopyHandler.java index 144448d9c..ae65e87f8 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/adapters/CompositeCopyHandler.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/adapters/CompositeCopyHandler.java @@ -60,6 +60,10 @@ public class CompositeCopyHandler extends DefaultCopyHandler { Set externals = new HashSet<>(); List roots = new ArrayList<>(); + Resource indexRoot = graph.syncRequest(new PossibleIndexRoot(resources.iterator().next())); + if(indexRoot == null) throw new DatabaseException("Composite is not part of any index root"); + String indexRootUri = graph.getURI(indexRoot); + for(Resource resource : resources) { // Process all connection joins. // This is the only way to access all of them. @@ -113,28 +117,20 @@ public class CompositeCopyHandler extends DefaultCopyHandler { } // Include resource as root -// GUID rootId = graph.getRelatedValue(resource, L0.identifier, GUID.BINDING); -// String rootName = graph.getRelatedValue(resource, L0.HasName, Bindings.STRING); -// String escapedRootName = URIStringUtils.escape(rootName); -// String escapedPath = ModelingUtils.getDiagramCompositePath(graph, resource); CompositeInfo info = CompositeInfo.fromResource(graph, resource); - roots.add(new RootSpec(resource, info.getTGName(), true)); + roots.add(new RootSpec(resource, info.getTGName(), true, typeId(graph, L0, indexRootUri, resource))); Resource id = graph.getPossibleObject(resource, L0.identifier); if(id != null) exclusions.add(id); // Include components as roots for(Resource child : graph.sync(new ObjectsWithType(resource, L0.ConsistsOf, SR.Component))) { DiagramComponentInfo cinfo = DiagramComponentInfo.fromResource(graph, info, child); -// GUID childId = graph.getRelatedValue(resource, L0.identifier, GUID.BINDING); -// String childName = graph.getRelatedValue(child, L0.HasName, Bindings.STRING); id = graph.getPossibleObject(child, L0.identifier); if(id != null) exclusions.add(id); - roots.add(new RootSpec(child, cinfo.getTGName(info), true)); + roots.add(new RootSpec(child, cinfo.getTGName(info), true, typeId(graph, L0, indexRootUri, child))); } } - Resource model = graph.syncRequest(new PossibleIndexRoot(resources.iterator().next())); - if(model == null) throw new DatabaseException("Composite is not part of any index root"); - roots.add(new RootSpec(model, "%model", false)); + roots.add(new RootSpec(indexRoot, "%model", false)); TransferableGraphConfiguration2 config = TransferableGraphConfiguration2.createWithNames2(graph, roots, exclusions, true, false); for (Resource external : externals) @@ -142,4 +138,14 @@ public class CompositeCopyHandler extends DefaultCopyHandler { return config; } + private static String typeId(ReadGraph graph, Layer0 L0, String indexRootUri, Resource r) throws DatabaseException { + Resource type = graph.getPossibleType(r, L0.Entity); + if (type == null) + return Layer0.URIs.Entity; + String typeUri = graph.getPossibleURI(type); + if (typeUri == null || !typeUri.startsWith(indexRootUri)) + return typeUri; + return "%model" + typeUri.substring(indexRootUri.length()); + } + }