private void addNode(final Node<View, Edge> node) { context.register(shapeSetId, node); context.applyElementMutation(node, MutationContext.STATIC); }
/** * It does: * - Registers a new graph element into the structure * - Creates the shape for the element to register, using the shape factory provided * for the given <code>shapeSetId</code> value. * @param shapeSetId The identifier for the ShapeSet to use. * @param candidate The graph element to register. */ @SuppressWarnings("unchecked") public void register(final String shapeSetId, final Element<View<?>> candidate) { final ShapeFactory<Object, Shape> factory = getShapeFactory(shapeSetId); register(factory, candidate, true); }
context.register(shapeSetId, 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()); } }
/** * It does: * - Registers a new graph element into the structure * - Creates the shape for the element to register, using the given shape factory. * @param factory The shape factory to use. * @param candidate The graph element to register. * @param fireEvents If canvas and canvas handled registration events must be fired. */ @SuppressWarnings("unchecked") public void register(final ShapeFactory<Object, Shape> factory, final Element<View<?>> candidate, final boolean fireEvents) { assert factory != null && candidate != null; final Shape shape = factory.newShape(candidate.getContent().getDefinition()); // Set the same identifier as the graph element's one. if (null == shape.getUUID()) { shape.setUUID(candidate.getUUID()); } register(shape, candidate, fireEvents); }
@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(); }
@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(); }
@SuppressWarnings("unchecked") protected void register(final AbstractCanvasHandler context) { context.register(shapeSetId, candidate); // Update view bounds for the element, if not set, by using the values from the shape view. final double[] size = GraphUtils.getNodeSize(candidate.getContent()); if (size[0] <= 0 || size[1] <= 0) { final Shape shape = context.getCanvas().getShape(candidate.getUUID()); final ShapeView shapeView = shape.getShapeView(); final Point2D location = GraphUtils.getPosition(candidate.getContent()); final BoundingBox boundingBox = shapeView.getBoundingBox(); candidate.getContent() .setBounds(Bounds.create(location.getX(), location.getY(), location.getX() + boundingBox.getWidth(), location.getY() + boundingBox.getHeight())); } }