use of org.kie.workbench.common.stunner.core.client.canvas.event.ShapeLocationsChangedEvent in project kie-wb-common by kiegroup.
the class LocationControlImplTest method testMove.
@Test
@SuppressWarnings("unchecked")
public void testMove() {
tested.enable(canvasHandler);
tested.register(element);
Point2D location = new Point2D(45d, 65.5d);
tested.move(new Element[] { element }, new Point2D[] { location });
ArgumentCaptor<CanvasCommand> commandArgumentCaptor = ArgumentCaptor.forClass(CanvasCommand.class);
verify(commandManager, times(1)).execute(eq(canvasHandler), commandArgumentCaptor.capture());
ArgumentCaptor<ShapeLocationsChangedEvent> shapeLocationsChangedEventCaptor = ArgumentCaptor.forClass(ShapeLocationsChangedEvent.class);
verify(shapeLocationsChangedEvent, times(1)).fire(shapeLocationsChangedEventCaptor.capture());
assertTrue(shapeLocationsChangedEventCaptor.getValue() instanceof ShapeLocationsChangedEvent);
final UpdateElementPositionCommand command = (UpdateElementPositionCommand) commandArgumentCaptor.getValue();
assertEquals(element, command.getElement());
assertEquals(location, command.getLocation());
}
use of org.kie.workbench.common.stunner.core.client.canvas.event.ShapeLocationsChangedEvent in project kie-wb-common by kiegroup.
the class LocationControlImpl method move.
@Override
@SuppressWarnings("unchecked")
public CommandResult<CanvasViolation> move(final Element[] elements, final Point2D[] locations) {
if (elements.length != locations.length) {
throw new IllegalArgumentException("The length for the elements to move " + "does not match the locations provided.");
}
Command<AbstractCanvasHandler, CanvasViolation> command;
if (elements.length == 1) {
command = createMoveCommand(elements[0], locations[0]);
} else {
final CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation> builder = new CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation>().forward();
int i = 0;
for (final Element element : elements) {
final CanvasCommand<AbstractCanvasHandler> c = createMoveCommand(element, locations[i]);
builder.addCommand(c);
i++;
}
command = builder.build();
}
CommandResult<CanvasViolation> result = getCommandManager().allow(canvasHandler, command);
if (!CommandUtils.isError(result)) {
result = getCommandManager().execute(canvasHandler, command);
if (!CommandUtils.isError(result)) {
List<String> uuids = Arrays.stream(elements).map(Element::getUUID).collect(Collectors.toList());
shapeLocationsChangedEvent.fire(new ShapeLocationsChangedEvent(uuids, canvasHandler));
}
}
return result;
}
Aggregations