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;
}
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();
}
Aggregations