X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.diagram%2Fsrc%2Forg%2Fsimantics%2Fdiagram%2Fflag%2FFlagUtil.java;h=2a0e14b933aa7fad2c5c2364fd07b3c6f898796e;hp=6f884e06afbf8651906977be9ac17df04802eb90;hb=28418dc0f3cc153ba631c201c900b99e45fa03d1;hpb=969bd23cab98a79ca9101af33334000879fb60c5 diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/flag/FlagUtil.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/flag/FlagUtil.java index 6f884e06a..2a0e14b93 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/flag/FlagUtil.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/flag/FlagUtil.java @@ -28,6 +28,7 @@ import org.simantics.db.common.utils.NameUtils; import org.simantics.db.common.utils.OrderedSetUtils; import org.simantics.db.exception.DatabaseException; import org.simantics.db.exception.ServiceException; +import org.simantics.db.function.DbBiFunction; import org.simantics.db.function.DbConsumer; import org.simantics.db.layer0.util.RemoverUtil; import org.simantics.db.layer0.variable.Variable; @@ -130,6 +131,21 @@ public final class FlagUtil { return count; } + public static int forCounterparts(ReadGraph graph, Resource flag, DbBiFunction procedure) throws DatabaseException { + DiagramResource DIA = DiagramResource.getInstance(graph); + int count = 0; + for (Resource connectionJoin : graph.getObjects(flag, DIA.FlagIsJoinedBy)) { + for (Resource otherFlag : graph.getObjects(connectionJoin, DIA.JoinsFlag)) { + if (!flag.equals(otherFlag)) { + if (!procedure.apply(connectionJoin, otherFlag)) + return ++count; + ++count; + } + } + } + return count; + } + /** * Returns all flags that are joined with the given flag including the flag given as parameter. */ @@ -247,14 +263,25 @@ public final class FlagUtil { RemoverUtil.remove(graph, flag); } + /** + * @param graph + * @param flag + * @return true only if the specified flag is joined only + * within the single diagram it resides in + * @throws DatabaseException + */ public static boolean isJoinedInSingleDiagram(ReadGraph graph, Resource flag) throws DatabaseException { - DiagramResource DIA = DiagramResource.getInstance(graph); - Resource counterpart = getPossibleCounterpart(graph, flag); - if (counterpart == null) + Collection counterparts = getCounterparts(graph, flag); + if (counterparts.isEmpty()) return false; - return !Collections.disjoint( - OrderedSetUtils.getOwnerLists(graph, flag, DIA.Diagram), - OrderedSetUtils.getOwnerLists(graph, counterpart, DIA.Diagram)); + DiagramResource DIA = DiagramResource.getInstance(graph); + Collection flagDiagrams = OrderedSetUtils.getOwnerLists(graph, flag, DIA.Diagram); + for (Resource counterpart : counterparts) { + if (Collections.disjoint(flagDiagrams, + OrderedSetUtils.getOwnerLists(graph, counterpart, DIA.Diagram))) + return false; + } + return true; } public static boolean isJoinedBetweenDiagrams(ReadGraph graph, Resource flag) throws DatabaseException {