public static Collection<Resource> 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);
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);
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);
}
SimanticsClipboardImpl cp = new SimanticsClipboardImpl();
CopyHandler c1 = graph.adapt(r, CopyHandler.class);
- c1.copyToClipboard(graph, cp);
+ c1.copyToClipboard(graph, cp, null);
Collection<Set<Representation>> reps = cp.getContents();
if(reps.size() != 1) return null;
return ClipboardUtils.accept(graph, reps.iterator().next(), SimanticsKeys.KEY_TRANSFERABLE_GRAPH);
SimanticsClipboardImpl cp = new SimanticsClipboardImpl();
CopyHandler c1 = graph.adapt(r, CopyHandler.class);
- c1.copyToClipboard(graph, cp);
+ c1.copyToClipboard(graph, cp, null);
Collection<Set<Representation>> reps = cp.getContents();
if(reps.size() != 1) return null;
return ClipboardUtils.accept(graph, reps.iterator().next(), SimanticsKeys.KEY_TRANSFERABLE_GRAPH_SOURCE);