X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.db.layer0%2Fsrc%2Forg%2Fsimantics%2Fdb%2Flayer0%2Futil%2FLayer0Utils.java;h=d89d7165226e7522fdf0a015a7209418e5185847;hp=56e1e11f23a10893b0b2818c31845e5bbe7d1c48;hb=bb019453a50630910de8e5f0b2992b1234dbd415;hpb=60ef4f8b863d892019a61978a63119dc1ebd852f diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/Layer0Utils.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/Layer0Utils.java index 56e1e11f2..d89d71652 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/Layer0Utils.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/Layer0Utils.java @@ -882,7 +882,7 @@ public class Layer0Utils { public static Collection copyTo(WriteGraph graph, Resource targetContainer, PasteEventHandler handler, CopyHandler copyHandler, PasteHandler pasteHandler) throws DatabaseException { SimanticsClipboardImpl clipboard = new SimanticsClipboardImpl(); - copyHandler.copyToClipboard(graph, clipboard); + copyHandler.copyToClipboard(graph, clipboard, new NullProgressMonitor()); if(targetContainer != null) { if(pasteHandler == null) pasteHandler = graph.adapt(targetContainer, PasteHandler.class); return pasteHandler.pasteFromClipboard(graph, clipboard, handler); @@ -927,6 +927,27 @@ public class Layer0Utils { return stm != null && stm.isAsserted(subject); } + /* + * Works around problems in WriteGraph methods with similar signature. + * Especially handles better some cases with existing literals. + * + */ + public static void claimLiteral(WriteGraph graph, Resource r, Resource p, Resource i, Resource t, Object value, Binding binding) throws DatabaseException { + Statement stm = graph.getPossibleStatement(r, p); + if(stm != null && !stm.isAsserted(r)) { + if(graph.isInstanceOf(stm.getObject(), t)) { + // Existing statement is compatible, reuse the literal + graph.claimValue(stm.getObject(), value, binding); + return; + } else { + // Existing statement is incompatible - remove it + graph.deny(stm); + } + } + // Create new statement + graph.claimLiteral(r, p, i, t, value, binding); + } + public static void setExpression(WriteGraph graph, Variable context, String text, Resource expressionValueType) throws DatabaseException { Resource value = context.getRepresents(graph); @@ -1157,7 +1178,8 @@ public class Layer0Utils { Resource indexRoot = graph.syncRequest(new PossibleVariableIndexRoot(variable)); if(indexRoot == null) return false; - if(variable.equals(indexRoot)) return false; + Resource represents = variable.getPossibleRepresents(graph); + if(represents != null && represents.equals(indexRoot)) return false; return isPublished(graph, indexRoot); } @@ -1192,7 +1214,7 @@ public class Layer0Utils { SimanticsClipboardImpl cp = new SimanticsClipboardImpl(); CopyHandler c1 = graph.adapt(r, CopyHandler.class); - c1.copyToClipboard(graph, cp); + c1.copyToClipboard(graph, cp, null); Collection> reps = cp.getContents(); if(reps.size() != 1) return null; return ClipboardUtils.accept(graph, reps.iterator().next(), SimanticsKeys.KEY_TRANSFERABLE_GRAPH); @@ -1203,7 +1225,7 @@ public class Layer0Utils { SimanticsClipboardImpl cp = new SimanticsClipboardImpl(); CopyHandler c1 = graph.adapt(r, CopyHandler.class); - c1.copyToClipboard(graph, cp); + c1.copyToClipboard(graph, cp, null); Collection> reps = cp.getContents(); if(reps.size() != 1) return null; return ClipboardUtils.accept(graph, reps.iterator().next(), SimanticsKeys.KEY_TRANSFERABLE_GRAPH_SOURCE);