use of org.kie.workbench.common.stunner.core.client.shape.view.event.ResizeEvent 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);
}
}
use of org.kie.workbench.common.stunner.core.client.shape.view.event.ResizeEvent 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());
}
use of org.kie.workbench.common.stunner.core.client.shape.view.event.ResizeEvent 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 };
}
Aggregations