Search in sources :

Example 1 with ResizeHandler

use of org.kie.workbench.common.stunner.core.client.shape.view.event.ResizeHandler in project kie-wb-common by kiegroup.

the class ResizeControlImpl method registerResizeHandlers.

@SuppressWarnings("unchecked")
private void registerResizeHandlers(final Element element, final Shape<?> shape) {
    if (shape.getShapeView() instanceof HasEventHandlers) {
        final HasEventHandlers hasEventHandlers = (HasEventHandlers) shape.getShapeView();
        final ResizeHandler resizeHandler = new ResizeHandler() {

            @Override
            public void start(final ResizeEvent event) {
            }

            @Override
            public void handle(final ResizeEvent event) {
            }

            @Override
            public void end(final ResizeEvent event) {
                LOGGER.log(Level.FINE, "Shape [" + element.getUUID() + "] resized to size {" + event.getWidth() + ", " + event.getHeight() + "] " + "& Coordinates [" + event.getX() + ", " + event.getY() + "]");
                final Shape shape = canvasHandler.getCanvas().getShape(element.getUUID());
                final double x = shape.getShapeView().getShapeX();
                final double y = shape.getShapeView().getShapeY();
                final CommandResult<CanvasViolation> result = doResize(element, x + event.getX(), y + event.getY(), event.getWidth(), event.getHeight());
                if (CommandUtils.isError(result)) {
                    LOGGER.log(Level.WARNING, "Command failed at resize end [result=" + result + "]");
                }
            }
        };
        hasEventHandlers.addHandler(ViewEventType.RESIZE, resizeHandler);
        registerHandler(element.getUUID(), resizeHandler);
    }
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) Shape(org.kie.workbench.common.stunner.core.client.shape.Shape) ResizeHandler(org.kie.workbench.common.stunner.core.client.shape.view.event.ResizeHandler) HasEventHandlers(org.kie.workbench.common.stunner.core.client.shape.view.HasEventHandlers) ResizeEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.ResizeEvent)

Example 2 with ResizeHandler

use of org.kie.workbench.common.stunner.core.client.shape.view.event.ResizeHandler in project kie-wb-common by kiegroup.

the class ResizeControlImplTest method testResize.

@Test
@SuppressWarnings("unchecked")
public void testResize() {
    when(commandManager.execute(eq(canvasHandler), any(Command.class))).thenReturn(CanvasCommandResultBuilder.SUCCESS);
    tested.enable(canvasHandler);
    assertFalse(tested.isRegistered(element));
    tested.register(element);
    verify(shapeEventHandler, times(1)).supports(eq(ViewEventType.RESIZE));
    final ArgumentCaptor<ResizeHandler> resizeHandlerArgumentCaptor = ArgumentCaptor.forClass(ResizeHandler.class);
    verify(shapeEventHandler, times(1)).addHandler(eq(ViewEventType.RESIZE), resizeHandlerArgumentCaptor.capture());
    final ResizeHandler resizeHandler = resizeHandlerArgumentCaptor.getValue();
    final double x = 121.45d;
    final double y = 23.456d;
    final double width = 100d;
    final double height = 200d;
    final ResizeEvent event = new ResizeEvent(x, y, x, y, width, height);
    resizeHandler.end(event);
    final ArgumentCaptor<Command> commandArgumentCaptor = ArgumentCaptor.forClass(Command.class);
    verify(commandManager, times(1)).execute(eq(canvasHandler), commandArgumentCaptor.capture());
    final Command command = commandArgumentCaptor.getValue();
    assertNotNull(command);
    assertTrue(command instanceof AbstractCompositeCommand);
    final List commands = ((AbstractCompositeCommand) command).getCommands();
    assertNotNull(commands);
    assertEquals(4, commands.size());
    assertTrue(commands.get(0) instanceof UpdateElementPositionCommand);
    final UpdateElementPositionCommand positionCommand = (UpdateElementPositionCommand) commands.get(0);
    assertEquals(element, positionCommand.getElement());
    assertEquals(new Point2D(x, y), positionCommand.getLocation());
    assertTrue(commands.get(1) instanceof UpdateElementPropertyCommand);
    final UpdateElementPropertyCommand wPropertyCommand = (UpdateElementPropertyCommand) commands.get(1);
    assertEquals(element, wPropertyCommand.getElement());
    assertEquals(W_PROPERTY_ID, wPropertyCommand.getPropertyId());
    assertEquals(width, wPropertyCommand.getValue());
    assertTrue(commands.get(2) instanceof UpdateElementPropertyCommand);
    final UpdateElementPropertyCommand hPropertyCommand = (UpdateElementPropertyCommand) commands.get(2);
    assertEquals(element, hPropertyCommand.getElement());
    assertEquals(H_PROPERTY_ID, hPropertyCommand.getPropertyId());
    assertEquals(height, hPropertyCommand.getValue());
    assertTrue(commands.get(3) instanceof UpdateElementPropertyCommand);
    final UpdateElementPropertyCommand rPropertyCommand = (UpdateElementPropertyCommand) commands.get(3);
    assertEquals(element, rPropertyCommand.getElement());
    assertEquals(R_PROPERTY_ID, rPropertyCommand.getPropertyId());
    assertEquals(50d, rPropertyCommand.getValue());
}
Also used : UpdateElementPropertyCommand(org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPropertyCommand) AbstractCompositeCommand(org.kie.workbench.common.stunner.core.command.impl.AbstractCompositeCommand) UpdateElementPositionCommand(org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPositionCommand) Command(org.kie.workbench.common.stunner.core.command.Command) AbstractCompositeCommand(org.kie.workbench.common.stunner.core.command.impl.AbstractCompositeCommand) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) ResizeHandler(org.kie.workbench.common.stunner.core.client.shape.view.event.ResizeHandler) List(java.util.List) UpdateElementPositionCommand(org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPositionCommand) UpdateElementPropertyCommand(org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPropertyCommand) ResizeEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.ResizeEvent) Test(org.junit.Test)

Example 3 with ResizeHandler

use of org.kie.workbench.common.stunner.core.client.shape.view.event.ResizeHandler in project kie-wb-common by kiegroup.

the class WiresShapeViewExt method registerResizeHandler.

private HandlerRegistration[] registerResizeHandler(final ViewHandler<ResizeEvent> eventHandler) {
    final ResizeHandler resizeHandler = (ResizeHandler) eventHandler;
    setResizable(true);
    HandlerRegistration r0 = addWiresResizeStartHandler(wiresResizeStartEvent -> {
        final ResizeEvent event = buildResizeEvent(wiresResizeStartEvent);
        resizeHandler.start(event);
        rebuildTextBoundaries(event.getWidth(), event.getHeight());
    });
    HandlerRegistration r1 = addWiresResizeStepHandler(wiresResizeStepEvent -> {
        final ResizeEvent event = buildResizeEvent(wiresResizeStepEvent);
        resizeHandler.handle(event);
        rebuildTextBoundaries(event.getWidth(), event.getHeight());
    });
    HandlerRegistration r2 = addWiresResizeEndHandler(wiresResizeEndEvent -> {
        final ResizeEvent event = buildResizeEvent(wiresResizeEndEvent);
        resizeHandler.end(event);
        rebuildTextBoundaries(event.getWidth(), event.getHeight());
    });
    return new HandlerRegistration[] { r0, r1, r2 };
}
Also used : HandlerRegistration(com.google.gwt.event.shared.HandlerRegistration) ResizeHandler(org.kie.workbench.common.stunner.core.client.shape.view.event.ResizeHandler) AbstractWiresResizeEvent(com.ait.lienzo.client.core.shape.wires.event.AbstractWiresResizeEvent) ResizeEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.ResizeEvent)

Aggregations

ResizeEvent (org.kie.workbench.common.stunner.core.client.shape.view.event.ResizeEvent)3 ResizeHandler (org.kie.workbench.common.stunner.core.client.shape.view.event.ResizeHandler)3 AbstractWiresResizeEvent (com.ait.lienzo.client.core.shape.wires.event.AbstractWiresResizeEvent)1 HandlerRegistration (com.google.gwt.event.shared.HandlerRegistration)1 List (java.util.List)1 Test (org.junit.Test)1 UpdateElementPositionCommand (org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPositionCommand)1 UpdateElementPropertyCommand (org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPropertyCommand)1 CanvasViolation (org.kie.workbench.common.stunner.core.client.command.CanvasViolation)1 Shape (org.kie.workbench.common.stunner.core.client.shape.Shape)1 HasEventHandlers (org.kie.workbench.common.stunner.core.client.shape.view.HasEventHandlers)1 Command (org.kie.workbench.common.stunner.core.command.Command)1 AbstractCompositeCommand (org.kie.workbench.common.stunner.core.command.impl.AbstractCompositeCommand)1 Point2D (org.kie.workbench.common.stunner.core.graph.content.view.Point2D)1