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=6167334fdd79815ad98a60cb1db1762d611a116f;hp=ae65e87f88476bf6b2059e8899d5a63266816fee;hb=f2f1f3fe7b467654a0afa4e586ebcd06a54ebfea;hpb=61033f112b0a2e643bf8530b99bcf90c64464f30 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 ae65e87f8..6167334fd 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 @@ -22,6 +22,7 @@ import org.simantics.db.Resource; import org.simantics.db.common.request.ObjectsWithType; import org.simantics.db.common.request.PossibleIndexRoot; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.function.DbConsumer; import org.simantics.db.layer0.adapter.SubgraphExtent.ExtentStatus; import org.simantics.db.layer0.adapter.impl.DefaultCopyHandler; import org.simantics.db.layer0.util.TransferableGraphConfiguration2; @@ -64,39 +65,63 @@ public class CompositeCopyHandler extends DefaultCopyHandler { if(indexRoot == null) throw new DatabaseException("Composite is not part of any index root"); String indexRootUri = graph.getURI(indexRoot); + DbConsumer identifierExcluder = r -> { + if (r != null) + exclusions.addAll(graph.getObjects(r, L0.identifier)); + }; + for(Resource resource : resources) { // Process all connection joins. // This is the only way to access all of them. for (Resource diagram : graph.getObjects(resource, MOD.CompositeToDiagram)) { - for (Resource flag : graph.syncRequest(new ObjectsWithType(diagram, L0.ConsistsOf, DIA.Flag))) { - for (Resource join : graph.getObjects(flag, DIA.FlagIsJoinedBy)) { - // Joins with external references are omitted - for (Resource comp : graph.getObjects(join, SR.JoinsComposite)) { - if (!resourceSet.contains(comp)) - exclusions.add(join); - } - // This code excludes joins with flags to external - // diagrams that are not connected (have no - // configuration for the flag) - for (Resource flag2 : graph.getObjects(join, DIA.JoinsFlag)) { - Resource diagram2 = graph.getPossibleObject(flag2, L0.PartOf); - if (diagram2 != null) { - Resource comp = graph.getPossibleObject(diagram2, MOD.DiagramToComposite); + identifierExcluder.accept(diagram); + + for (Resource element : graph.getObjects(diagram, L0.ConsistsOf)) { + identifierExcluder.accept(element); + + Set types = graph.getTypes(element); + + // Check all diagram flag elements for necessary exclusions. + if (types.contains(DIA.Flag)) { + for (Resource join : graph.getObjects(element, DIA.FlagIsJoinedBy)) { + // Joins with external references are omitted + for (Resource comp : graph.getObjects(join, SR.JoinsComposite)) { if (!resourceSet.contains(comp)) - exclusions.add(join); + exclusions.add(join); + } + // This code excludes joins with flags to external + // diagrams that are not connected (have no + // configuration for the flag) + for (Resource flag2 : graph.getObjects(join, DIA.JoinsFlag)) { + Resource diagram2 = graph.getPossibleObject(flag2, L0.PartOf); + if (diagram2 != null) { + Resource comp = graph.getPossibleObject(diagram2, MOD.DiagramToComposite); + if (!resourceSet.contains(comp)) + exclusions.add(join); + } + } + } + } + + // Check all diagram monitor elements. + // Any components referenced that are external to the exported diagrams must be excluded from the export. + // This will leave the monitors without a monitored component but export and import will work anyway. + if (types.contains(DIA.Monitor)) { + for (Resource monitoredComponent : graph.getObjects(element, DIA.HasMonitorComponent)) { + Resource monitoredComponentComposite = graph.getPossibleObject(monitoredComponent, L0.PartOf); + if (monitoredComponentComposite != null && !resourceSet.contains(monitoredComponentComposite)) { + exclusions.add(monitoredComponent); } } } - } - // Check all diagram monitor elements. - // Any components referenced that are external to the exported diagrams must be excluded from the export. - // This will leave the monitors without a monitored component but export and import will work anyway. - for (Resource ref : graph.syncRequest(new ObjectsWithType(diagram, L0.ConsistsOf, DIA.Monitor))) { - for (Resource monitoredComponent : graph.getObjects(ref, DIA.HasMonitorComponent)) { - Resource monitoredComponentComposite = graph.getPossibleObject(monitoredComponent, L0.PartOf); - if (monitoredComponentComposite != null && !resourceSet.contains(monitoredComponentComposite)) { - exclusions.add(monitoredComponent); + // Check all diagram reference elements for necessary exclusions. + if (types.contains(MOD.ReferenceElement)) { + for (Resource rel : graph.getObjects(element, L0.ConsistsOf)) { + identifierExcluder.accept(rel); + for (Resource invRel : graph.getObjects(rel, L0.ConsistsOf)) { + identifierExcluder.accept(invRel); + } } } } @@ -119,13 +144,11 @@ public class CompositeCopyHandler extends DefaultCopyHandler { // Include resource as root CompositeInfo info = CompositeInfo.fromResource(graph, resource); 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); + identifierExcluder.accept(resource); // Include components as roots - for(Resource child : graph.sync(new ObjectsWithType(resource, L0.ConsistsOf, SR.Component))) { - DiagramComponentInfo cinfo = DiagramComponentInfo.fromResource(graph, info, child); - id = graph.getPossibleObject(child, L0.identifier); - if(id != null) exclusions.add(id); + for (Resource child : graph.sync(new ObjectsWithType(resource, L0.ConsistsOf, SR.Component))) { + DiagramComponentInfo cinfo = DiagramComponentInfo.fromResource(graph, info, child); + identifierExcluder.accept(child); roots.add(new RootSpec(child, cinfo.getTGName(info), true, typeId(graph, L0, indexRootUri, child))); } }