@Override public boolean startNodeTraversal(final List<Node<View, Edge>> parents, final Node<View, Edge> node) { super.startNodeTraversal(parents, node); addNode(node); context.addChild(parents.get(parents.size() - 1), node); return true; }
@Override protected void register(final AbstractCanvasHandler context) { super.register(context); context.addChild(parent, getCandidate()); }
@Override @SuppressWarnings("unchecked") public CommandResult<CanvasViolation> execute(final AbstractCanvasHandler context) { // Only update the child on the canvas side if the candidate is not docked. if (!isDocked(candidate)) { context.addChild(parent, candidate); ShapeUtils.moveViewConnectorsToTop(context, candidate); } return buildResult(); }
@Override public CommandResult<CanvasViolation> execute(final AbstractCanvasHandler context) { context.addChild(getParent(), getCandidate(), index.getAsInt()); context.updateElementProperties(getCandidate(), MutationContext.STATIC); return buildResult(); }
@Override public CommandResult<CanvasViolation> undo(final AbstractCanvasHandler context) { if (!(originalParent.isPresent() && originalIndex.isPresent())) { return new RemoveCanvasChildCommand(getParent(), getCandidate()).execute(context); } else { context.addChild(originalParent.get(), getCandidate(), originalIndex.getAsInt()); context.updateElementProperties(getCandidate(), MutationContext.STATIC); } return buildResult(); } }
@Override public CommandResult<CanvasViolation> execute(final AbstractCanvasHandler context) { if (Objects.isNull(parent) || Objects.isNull(child)) { throw new IllegalArgumentException("Parent and child should not be null"); } context.undock(parent, child); // on canvas side dock removes the parent that was in which it was docked // so, it is necessary to add the current parent getChild().getInEdges().stream() .filter(e -> e.getContent() instanceof Child) .findAny() .ifPresent(e -> context.addChild(e.getSourceNode(), child)); // Check parent node is not being removed from the graph. if (existNode(parent, context)) { context.applyElementMutation(parent, MutationContext.STATIC); } // Check child node is not being removed from the graph. if (existNode(child, context)) { context.applyElementMutation(child, MutationContext.STATIC); } return buildResult(); }
context.dock(dockParentOptional.get(), candidate); } else { parentOptional.ifPresent(parent -> context.addChild(parent, candidate));
@Test @SuppressWarnings("unchecked") public void testUndo() { tested.undo(canvasHandler); verify(canvasHandler).register(SHAPE_SET_ID, candidate); verify(canvasHandler).addChild(parent, candidate, index); verify(canvasHandler).applyElementMutation(eq(candidate), anyObject()); verify(canvasHandler, never()).applyElementMutation(eq(parent), anyObject()); } }