/** * When an element has been changed, this method produces to update the handler and the canvas * and mutates the shape bind to the given element using new properties and/or values. * This method checks all available element properties and can potentially change whatever property * that produces any visual effect on the canvas, but no produces coordinates or bounds size updates. * @param element The element that has been updated. * @param mutationContext The context for the shape mutations. */ public void updateElementProperties(final Element element, final MutationContext mutationContext) { applyElementMutation(element, false, true, mutationContext); }
/** * When an element has been changed, this method produces to update the coordinates for * the shape bind to the given element. * @param element The element that has been updated. * @param mutationContext The context for the shape mutations. */ public void updateElementPosition(final Element element, final MutationContext mutationContext) { applyElementMutation(element, true, false, mutationContext); }
/** * When an element has been changed, this method produces to update the handler and the canvas * and mutates the shape bind to the given element using new properties and/or values. * This method checks all available element properties and can potentially change * the shape coordinates, size,or whatever property that produces any visual effect on the canvas. * @param element The element that has been updated. * @param mutationContext The context for the shape mutations. */ public void applyElementMutation(final Element element, final MutationContext mutationContext) { applyElementMutation(element, true, true, mutationContext); }
private void addNode(final Node<View, Edge> node) { context.register(shapeSetId, node); context.applyElementMutation(node, MutationContext.STATIC); }
@Override @SuppressWarnings("unchecked") public CommandResult<CanvasViolation> execute(final AbstractCanvasHandler context) { final CommandResult<CanvasViolation> result = super.execute(context); context.applyElementMutation(parent, MutationContext.STATIC); return result; }
@Override public CommandResult<CanvasViolation> execute(final AbstractCanvasHandler context) { register(context); context.applyElementMutation(candidate, 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(); }
@Override public CommandResult<CanvasViolation> execute(final AbstractCanvasHandler context) { if (null != parent) { context.removeChild(parent, candidate); } context.deregister(candidate); if (null != parent) { context.applyElementMutation(parent, MutationContext.STATIC); } return buildResult(); }
@SuppressWarnings("unchecked") public void applyElementMutation(final Element candidate, final boolean applyPosition, final boolean applyProperties, final MutationContext mutationContext) { if (null != candidate && !isCanvasRoot(candidate)) { final Shape shape = getCanvas().getShape(candidate.getUUID()); applyElementMutation(shape, candidate, applyPosition, applyProperties, mutationContext); } }
@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()); } }
context.applyElementMutation(candidate, MutationContext.STATIC);
@Override @SuppressWarnings("unchecked") public CommandResult<CanvasViolation> execute(final AbstractCanvasHandler context) { context.register(ssid, candidate); context.applyElementMutation(candidate, MutationContext.STATIC); context.applyElementMutation(parent, MutationContext.STATIC); // Dock the candidate shape into the parent one. if (!context.dock(parent, candidate)) { return new CanvasCommandResultBuilder() .addViolation(CanvasViolationImpl.Builder .build(new DockingRuleViolation(parent.getUUID(), candidate.getUUID()))) .build(); } return buildResult(); }
@Override public CommandResult<CanvasViolation> execute(final AbstractCanvasHandler context) { // For the canvas side, docking the candidate shape into the parent one implies // that it has to be set as a child as well. // So first remove the current parent for the candidate shape, if any. 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()); // Update both shape view's attributes. context.applyElementMutation(parent, MutationContext.STATIC); context.applyElementMutation(candidate, MutationContext.STATIC); // Dock the candidate shape into the parent one. 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(); }
@Override @SuppressWarnings("unchecked") public CommandResult<CanvasViolation> execute(final AbstractCanvasHandler context) { context.register(shapeSetId, candidate); context.applyElementMutation(candidate, MutationContext.STATIC); if (candidate.getContent() instanceof ViewConnector) { ControlPoint[] controlPoints = ((ViewConnector) candidate.getContent()).getControlPoints().stream().toArray(ControlPoint[]::new); CommandResult<CanvasViolation> addControlPointsResult = new AddCanvasControlPointCommand(candidate, controlPoints).execute(context); ShapeUtils.hideControlPoints(candidate, context); if (CommandUtils.isError(addControlPointsResult)) { return addControlPointsResult; } } ShapeUtils.updateEdgeConnections(candidate, context); ShapeUtils.applyConnections(candidate, context, MutationContext.STATIC); final Node source = candidate.getSourceNode(); if (null != source) { context.notifyCanvasElementUpdated(source); } return buildResult(); }
results.toString()); canvasHandler.applyElementMutation(edge, MutationContext.STATIC); buildCallback.onSuccess(edge.getUUID());
@SuppressWarnings("unchecked") protected void updateConnectorShape(final Edge<? extends ViewConnector<?>, Node> inEdge, final Node targetNode, final Connection sourceConnection, final Connection targetConnection) { final ViewConnector connectorContent = (ViewConnector) inEdge.getContent(); canvasHandler.applyElementMutation(inEdge, MutationContext.STATIC); final EdgeShape edgeShape = (EdgeShape) canvasHandler.getCanvas().getShape(inEdge.getUUID()); final Node source = inEdge.getSourceNode(); if (null != source && null != targetNode) { final Shape<?> sShape = canvasHandler.getCanvas().getShape(source.getUUID()); final Shape<?> tShape = canvasHandler.getCanvas().getShape(targetNode.getUUID()); connectorContent.setSourceConnection(sourceConnection); connectorContent.setTargetConnection(targetConnection); edgeShape.applyConnections(inEdge, sShape.getShapeView(), tShape.getShapeView(), MutationContext.STATIC); } }