use of org.kie.workbench.common.stunner.core.client.command.CanvasViolation 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.client.command.CanvasViolation in project kie-wb-common by kiegroup.
the class AddCanvasConnectorCommand method execute.
@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();
}
use of org.kie.workbench.common.stunner.core.client.command.CanvasViolation in project kie-wb-common by kiegroup.
the class EdgeBuilderControlImpl method build.
@Override
@SuppressWarnings("unchecked")
public void build(final EdgeBuildRequest request, final BuildCallback buildCallback) {
final double x = request.getX();
final double y = request.getY();
final Edge<? extends ViewConnector<?>, Node> edge = request.getEdge();
final AbstractCanvasHandler<?, ?> wch = canvasHandler;
final Node<? extends View<?>, Edge> inNode = request.getInNode();
final Node<? extends View<?>, Edge> outNode = request.getOutNode();
final Canvas canvas = canvasHandler.getCanvas();
if (null == inNode) {
throw new RuntimeException(" An edge must be into the outgoing edges list from a node.");
}
final String ssid = canvasHandler.getDiagram().getMetadata().getShapeSetId();
final CompositeCommand.Builder commandBuilder = new CompositeCommand.Builder().addCommand(commandFactory.addConnector(inNode, edge, MagnetConnection.Builder.forElement(inNode), ssid));
if (null != outNode) {
commandBuilder.addCommand(commandFactory.setTargetNode(outNode, edge, MagnetConnection.Builder.forElement(outNode)));
}
final CommandResult<CanvasViolation> results = getCommandManager().execute(wch, commandBuilder.build());
if (CommandUtils.isError(results)) {
LOGGER.log(Level.WARNING, results.toString());
}
canvasHandler.applyElementMutation(edge, MutationContext.STATIC);
buildCallback.onSuccess(edge.getUUID());
}
use of org.kie.workbench.common.stunner.core.client.command.CanvasViolation in project kie-wb-common by kiegroup.
the class NotificationMessageUtilsTest method testCanvasValidationMessage.
@Test
public void testCanvasValidationMessage() {
final RuleViolation ruleViolation = mock(RuleViolation.class);
final CanvasViolation canvasViolation = mock(CanvasViolation.class);
when(canvasViolation.getViolationType()).thenReturn(Violation.Type.ERROR);
when(canvasViolation.getRuleViolation()).thenReturn(ruleViolation);
when(ruleViolation.getViolationType()).thenReturn(Violation.Type.ERROR);
when(ruleViolation.getViolationType()).thenReturn(Violation.Type.ERROR);
final Iterable<CanvasViolation> violations = Collections.singletonList(canvasViolation);
when(translationService.getValue(eq("aKey"))).thenReturn("aValue");
when(translationService.getViolationMessage(eq(canvasViolation))).thenReturn("cv1");
String message = NotificationMessageUtils.getCanvasValidationsErrorMessage(translationService, "aKey", violations);
message = new SafeHtmlBuilder().appendEscapedLines(message).toSafeHtml().asString();
assertEquals("aValue." + HTML_NEW_LINE + "R" + COLON + HTML_NEW_LINE + OPEN_BRA + "1" + CLOSE_BRA + "(ERROR) " + "cv1" + HTML_NEW_LINE, message);
}
use of org.kie.workbench.common.stunner.core.client.command.CanvasViolation in project kie-wb-common by kiegroup.
the class NotificationsObserverTest method testNotifyCommandSuccess.
@Test
@SuppressWarnings("unchecked")
public void testNotifyCommandSuccess() {
final Command command = mock(Command.class);
final CommandResult<CanvasViolation> result = mock(CommandResult.class);
final CanvasCommandExecutedEvent<? extends CanvasHandler> commandExecutedEvent = new CanvasCommandExecutedEvent<>(canvasHandler, command, result);
commandNotification = new CommandNotification(Notification.Type.INFO, notificationContext, command, "message1");
tested.onGraphCommandExecuted(commandExecutedEvent);
verify(onNotification, times(1)).execute(eq(commandNotification));
verify(commandSuccess, times(1)).execute(eq(commandNotification));
verify(commandFailed, never()).execute(any(CommandNotification.class));
verify(validationSuccess, never()).execute(any(ValidationSuccessNotification.class));
verify(validationFailed, never()).execute(any(ValidationFailedNotification.class));
}
Aggregations