@Test @SuppressWarnings("unchecked") public void testExecute() { final CommandResult<CanvasViolation> result = tested.execute(canvasHandler); assertNotEquals(CommandResult.Type.ERROR, result.getType()); verify(canvasHandler, times(0)).register(anyString(), eq(candidate)); verify(canvasHandler, times(0)).addChild(any(Node.class), any(Node.class)); verify(canvasHandler, times(1)).dock(eq(parent), eq(candidate)); verify(canvasHandler, times(1)).applyElementMutation(eq(candidate), any(MutationContext.class)); verify(canvasHandler, times(1)).applyElementMutation(eq(parent), any(MutationContext.class)); }
@Override public CommandResult<CanvasViolation> execute(final AbstractCanvasHandler context) { getCandidate().getInEdges().stream() .filter(e -> e.getContent() instanceof Child) .findAny() .ifPresent(e -> context.removeChild(e.getSourceNode(), candidate)); ShapeView shapeView = context.getCanvas().getShape(candidate.getUUID()).getShapeView(); Point2D currentPosition = new Point2D(shapeView.getShapeX(), shapeView.getShapeY()); context.applyElementMutation(parent, MutationContext.STATIC); context.applyElementMutation(candidate, MutationContext.STATIC); if (!context.dock(parent, candidate)) { return new CanvasCommandResultBuilder() .addViolation(CanvasViolationImpl.Builder .build(new DockingRuleViolation(parent.getUUID(), candidate.getUUID()))) .build(); } Point2D dockLocation = new Point2D(shapeView.getShapeX(), shapeView.getShapeY()); if (!Objects.equals(currentPosition, dockLocation)) { dockedPositionCallback.ifPresent(callback -> callback.accept(dockLocation)); } return buildResult(); }
CanvasDockNodeCommand extends AbstractCanvasCommand { @Override public CommandResult<CanvasViolation> execute(final AbstractCanvasHandler context) { getCandidate().getInEdges().stream() .filter(e -> e.getContent() instanceof Child) .findAny() .ifPresent(e -> context.removeChild(e.getSourceNode(), candidate)); ShapeView shapeView = context.getCanvas().getShape(candidate.getUUID()).getShapeView(); Point2D currentPosition = new Point2D(shapeView.getShapeX(), shapeView.getShapeY()); context.applyElementMutation(parent, MutationContext.STATIC); context.applyElementMutation(candidate, MutationContext.STATIC); if (!context.dock(parent, candidate)) { return new CanvasCommandResultBuilder() .addViolation(CanvasViolationImpl.Builder .build(new DockingRuleViolation(parent.getUUID(), candidate.getUUID()))) .build(); } Point2D dockLocation = new Point2D(shapeView.getShapeX(), shapeView.getShapeY()); if (!Objects.equals(currentPosition, dockLocation)) { dockedPositionCallback.ifPresent(callback -> callback.accept(dockLocation)); } return buildResult(); } }
CanvasDockNodeCommand extends AbstractCanvasCommand { @Override public CommandResult<CanvasViolation> execute(final AbstractCanvasHandler context) { getCandidate().getInEdges().stream() .filter(e -> e.getContent() instanceof Child) .findAny() .ifPresent(e -> context.removeChild(e.getSourceNode(), candidate)); ShapeView shapeView = context.getCanvas().getShape(candidate.getUUID()).getShapeView(); Point2D currentPosition = new Point2D(shapeView.getShapeX(), shapeView.getShapeY()); context.applyElementMutation(parent, MutationContext.STATIC); context.applyElementMutation(candidate, MutationContext.STATIC); if (!context.dock(parent, candidate)) { return new CanvasCommandResultBuilder() .addViolation(CanvasViolationImpl.Builder .build(new DockingRuleViolation(parent.getUUID(), candidate.getUUID()))) .build(); } Point2D dockLocation = new Point2D(shapeView.getShapeX(), shapeView.getShapeY()); if (!Objects.equals(currentPosition, dockLocation)) { dockedPositionCallback.ifPresent(callback -> callback.accept(dockLocation)); } return buildResult(); } CanvasDockNodeCommand(final Node parent,
                                 final Node candidate);  CanvasDockNodeCommand(final Node parent,
                                 final Node candidate,
                                 final Consumer<Point2D> dockedPositionCallback); }
CanvasDockNodeCommand extends AbstractCanvasCommand { @Override public CommandResult<CanvasViolation> execute(final AbstractCanvasHandler context) { getCandidate().getInEdges().stream() .filter(e -> e.getContent() instanceof Child) .findAny() .ifPresent(e -> context.removeChild(e.getSourceNode(), candidate)); ShapeView shapeView = context.getCanvas().getShape(candidate.getUUID()).getShapeView(); Point2D currentPosition = new Point2D(shapeView.getShapeX(), shapeView.getShapeY()); context.applyElementMutation(parent, MutationContext.STATIC); context.applyElementMutation(candidate, MutationContext.STATIC); if (!context.dock(parent, candidate)) { return new CanvasCommandResultBuilder() .addViolation(CanvasViolationImpl.Builder .build(new DockingRuleViolation(parent.getUUID(), candidate.getUUID()))) .build(); } Point2D dockLocation = new Point2D(shapeView.getShapeX(), shapeView.getShapeY()); if (!Objects.equals(currentPosition, dockLocation)) { dockedPositionCallback.ifPresent(callback -> callback.accept(dockLocation)); } return buildResult(); } CanvasDockNodeCommand(final Node parent,
                                 final Node candidate);  CanvasDockNodeCommand(final Node parent,
                                 final Node candidate,
                                 final Consumer<Point2D> dockedPositionCallback); @Override CommandResult<CanvasViolation> execute(final AbstractCanvasHandler context); @Override CommandResult<CanvasViolation> undo(final AbstractCanvasHandler context); Node getParent(); Node<?, Edge> getCandidate(); @Override String toString(); }
CanvasDockNodeCommand extends AbstractCanvasCommand { @Override public CommandResult<CanvasViolation> execute(final AbstractCanvasHandler context) { getCandidate().getInEdges().stream() .filter(e -> e.getContent() instanceof Child) .findAny() .ifPresent(e -> context.removeChild(e.getSourceNode(), candidate)); ShapeView shapeView = context.getCanvas().getShape(candidate.getUUID()).getShapeView(); Point2D currentPosition = new Point2D(shapeView.getShapeX(), shapeView.getShapeY()); context.applyElementMutation(parent, MutationContext.STATIC); context.applyElementMutation(candidate, MutationContext.STATIC); if (!context.dock(parent, candidate)) { return new CanvasCommandResultBuilder() .addViolation(CanvasViolationImpl.Builder .build(new DockingRuleViolation(parent.getUUID(), candidate.getUUID()))) .build(); } Point2D dockLocation = new Point2D(shapeView.getShapeX(), shapeView.getShapeY()); if (!Objects.equals(currentPosition, dockLocation)) { dockedPositionCallback.ifPresent(callback -> callback.accept(dockLocation)); } return buildResult(); } CanvasDockNodeCommand(final Node parent,
                                 final Node candidate);  CanvasDockNodeCommand(final Node parent,
                                 final Node candidate,
                                 final Consumer<Point2D> dockedPositionCallback); @Override CommandResult<CanvasViolation> execute(final AbstractCanvasHandler context); @Override CommandResult<CanvasViolation> undo(final AbstractCanvasHandler context); Node getParent(); Node<?, Edge> getCandidate(); @Override String toString();  }