Search in sources :

Example 1 with ShapeLocationsChangedEvent

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());
}
Also used : ShapeLocationsChangedEvent(org.kie.workbench.common.stunner.core.client.canvas.event.ShapeLocationsChangedEvent) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) UpdateElementPositionCommand(org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPositionCommand) CanvasCommand(org.kie.workbench.common.stunner.core.client.command.CanvasCommand) Test(org.junit.Test)

Example 2 with ShapeLocationsChangedEvent

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;
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) Element(org.kie.workbench.common.stunner.core.graph.Element) CompositeCommand(org.kie.workbench.common.stunner.core.command.impl.CompositeCommand) ShapeLocationsChangedEvent(org.kie.workbench.common.stunner.core.client.canvas.event.ShapeLocationsChangedEvent) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)

Aggregations

ShapeLocationsChangedEvent (org.kie.workbench.common.stunner.core.client.canvas.event.ShapeLocationsChangedEvent)2 Test (org.junit.Test)1 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)1 UpdateElementPositionCommand (org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPositionCommand)1 CanvasCommand (org.kie.workbench.common.stunner.core.client.command.CanvasCommand)1 CanvasViolation (org.kie.workbench.common.stunner.core.client.command.CanvasViolation)1 CompositeCommand (org.kie.workbench.common.stunner.core.command.impl.CompositeCommand)1 Element (org.kie.workbench.common.stunner.core.graph.Element)1 Point2D (org.kie.workbench.common.stunner.core.graph.content.view.Point2D)1