Search in sources :

Example 1 with BoundsExceededViolation

use of org.kie.workbench.common.stunner.core.rule.violations.BoundsExceededViolation in project kie-wb-common by kiegroup.

the class ResizeControlImpl method doResize.

@SuppressWarnings("unchecked")
private CommandResult<CanvasViolation> doResize(final Element<? extends View<?>> element, final Double x, final Double y, final double w, final double h) {
    // Calculate the new graph element's bounds.
    final Point2D current = (null != x && null != y) ? new Point2D(x, y) : GraphUtils.getPosition(element.getContent());
    final BoundsImpl newBounds = new BoundsImpl(new BoundImpl(current.getX(), current.getY()), new BoundImpl(current.getX() + w, current.getY() + h));
    // Check the new bound values that come from the user's action do not exceed graph ones.
    if (!GraphUtils.checkBoundsExceeded(canvasHandler.getDiagram().getGraph(), newBounds)) {
        final CanvasViolation cv = CanvasViolationImpl.Builder.build(new BoundsExceededViolation(newBounds).setUUID(canvasHandler.getUuid()));
        return new CommandResultImpl<>(CommandResult.Type.ERROR, Collections.singleton(cv));
    }
    // Execute the update position and update property/ies command/s on the bean instance to achieve the new bounds.
    final List<Command<AbstractCanvasHandler, CanvasViolation>> commands = getResizeCommands(element, w, h);
    final CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation> commandBuilder = new CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation>();
    if (null != commands) {
        if (null != x && null != y) {
            commandBuilder.addCommand(canvasCommandFactory.updatePosition((Node<View<?>, Edge>) element, new Point2D(x, y)));
        }
        commands.forEach(commandBuilder::addCommand);
    }
    final CommandResult<CanvasViolation> resizeResults = getCommandManager().execute(canvasHandler, commandBuilder.build());
    // Update the view bounds on the node content after successful resize.
    if (!CommandUtils.isError(resizeResults)) {
        element.getContent().setBounds(newBounds);
    }
    return resizeResults;
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) BoundImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl) Node(org.kie.workbench.common.stunner.core.graph.Node) BoundsExceededViolation(org.kie.workbench.common.stunner.core.rule.violations.BoundsExceededViolation) CompositeCommand(org.kie.workbench.common.stunner.core.command.impl.CompositeCommand) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) Command(org.kie.workbench.common.stunner.core.command.Command) CompositeCommand(org.kie.workbench.common.stunner.core.command.impl.CompositeCommand) BoundsImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl) CommandResultImpl(org.kie.workbench.common.stunner.core.command.impl.CommandResultImpl)

Example 2 with BoundsExceededViolation

use of org.kie.workbench.common.stunner.core.rule.violations.BoundsExceededViolation in project kie-wb-common by kiegroup.

the class UpdateElementPositionCommand method checkBounds.

@SuppressWarnings("unchecked")
private CommandResult<RuleViolation> checkBounds(final GraphCommandExecutionContext context) {
    final Element<? extends View<?>> element = getNodeNotNull(context);
    final Graph<DefinitionSet, Node> graph = (Graph<DefinitionSet, Node>) getGraph(context);
    final BoundsImpl newBounds = getTargetBounds(element);
    final GraphCommandResultBuilder result = new GraphCommandResultBuilder();
    final Bounds parentBounds = getParentBounds(element, graph);
    if (GraphUtils.checkBoundsExceeded(parentBounds, newBounds)) {
        ((View) element.getContent()).setBounds(newBounds);
    } else {
        result.addViolation(new BoundsExceededViolation(parentBounds).setUUID(element.getUUID()));
    }
    return result.build();
}
Also used : Graph(org.kie.workbench.common.stunner.core.graph.Graph) GraphCommandResultBuilder(org.kie.workbench.common.stunner.core.graph.command.GraphCommandResultBuilder) Node(org.kie.workbench.common.stunner.core.graph.Node) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) BoundsExceededViolation(org.kie.workbench.common.stunner.core.rule.violations.BoundsExceededViolation) DefinitionSet(org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet) BoundsImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl) View(org.kie.workbench.common.stunner.core.graph.content.view.View)

Aggregations

Node (org.kie.workbench.common.stunner.core.graph.Node)2 BoundsImpl (org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl)2 BoundsExceededViolation (org.kie.workbench.common.stunner.core.rule.violations.BoundsExceededViolation)2 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)1 CanvasViolation (org.kie.workbench.common.stunner.core.client.command.CanvasViolation)1 Command (org.kie.workbench.common.stunner.core.command.Command)1 CommandResultImpl (org.kie.workbench.common.stunner.core.command.impl.CommandResultImpl)1 CompositeCommand (org.kie.workbench.common.stunner.core.command.impl.CompositeCommand)1 Graph (org.kie.workbench.common.stunner.core.graph.Graph)1 GraphCommandResultBuilder (org.kie.workbench.common.stunner.core.graph.command.GraphCommandResultBuilder)1 Bounds (org.kie.workbench.common.stunner.core.graph.content.Bounds)1 DefinitionSet (org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet)1 BoundImpl (org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl)1 Point2D (org.kie.workbench.common.stunner.core.graph.content.view.Point2D)1 View (org.kie.workbench.common.stunner.core.graph.content.view.View)1