use of org.kie.workbench.common.stunner.core.command.Command in project kie-wb-common by kiegroup.
the class CommandRegistryImplTest method testPeek.
@Test
public void testPeek() {
tested.register(command);
Command result = tested.peek();
assertNotNull(result);
assertEquals(command, result);
List<Command> result2 = tested.getCommandHistory();
assertNotNull(result2);
assertFalse(result2.isEmpty());
}
use of org.kie.workbench.common.stunner.core.command.Command in project kie-wb-common by kiegroup.
the class CommandRegistryImplTest method testRegisterCommand.
@Test
public void testRegisterCommand() {
tested.register(command);
Command result = tested.peek();
assertNotNull(result);
assertEquals(command, result);
}
use of org.kie.workbench.common.stunner.core.command.Command in project kie-wb-common by kiegroup.
the class ResizeControlImpl method getResizeCommands.
/**
* It provides the necessary canvas commands in order to update the domain model with new values that will met
* the new bounding box size.
* It always updates the element's position, as resize can update it, and it updates as well some of the bean's properties.
*/
private List<Command<AbstractCanvasHandler, CanvasViolation>> getResizeCommands(final Element<? extends Definition<?>> element, final double w, final double h) {
final Definition content = element.getContent();
final Object def = content.getDefinition();
final DefinitionAdapter<Object> adapter = canvasHandler.getDefinitionManager().adapters().registry().getDefinitionAdapter(def.getClass());
final List<Command<AbstractCanvasHandler, CanvasViolation>> result = new LinkedList<>();
final Object width = adapter.getMetaProperty(PropertyMetaTypes.WIDTH, def);
if (null != width) {
appendCommandForModelProperty(element, width, w, result);
}
final Object height = adapter.getMetaProperty(PropertyMetaTypes.HEIGHT, def);
if (null != height) {
appendCommandForModelProperty(element, height, h, result);
}
final Object radius = adapter.getMetaProperty(PropertyMetaTypes.RADIUS, def);
if (null != radius) {
final double r = w > h ? (h / 2) : (w / 2);
appendCommandForModelProperty(element, radius, r, result);
}
return result;
}
use of org.kie.workbench.common.stunner.core.command.Command 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.command.Command 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