Search in sources :

Example 1 with HasEventHandlers

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

the class LienzoSelectionControl method onRegister.

@Override
protected void onRegister(final Element element) {
    super.onRegister(element);
    final Shape<?> shape = getSelectionControl().getCanvas().getShape(element.getUUID());
    if (null != shape) {
        final ShapeView shapeView = shape.getShapeView();
        if (shapeView instanceof HasEventHandlers) {
            final HasEventHandlers hasEventHandlers = (HasEventHandlers) shapeView;
            if (hasEventHandlers.supports(ViewEventType.MOUSE_CLICK)) {
                final MouseClickHandler clickHandler = new MouseClickHandler() {

                    @Override
                    public void handle(final MouseClickEvent event) {
                        if (event.isButtonLeft() || event.isButtonRight()) {
                            singleSelect(element);
                        }
                    }
                };
                hasEventHandlers.addHandler(ViewEventType.MOUSE_CLICK, clickHandler);
                registerHandler(shape.getUUID(), clickHandler);
            }
        }
    }
}
Also used : MouseClickHandler(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickHandler) HasEventHandlers(org.kie.workbench.common.stunner.core.client.shape.view.HasEventHandlers) ShapeView(org.kie.workbench.common.stunner.core.client.shape.view.ShapeView) MouseClickEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickEvent)

Example 2 with HasEventHandlers

use of org.kie.workbench.common.stunner.core.client.shape.view.HasEventHandlers 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 3 with HasEventHandlers

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

the class CanvasInPlaceTextEditorControlImpl method register.

@Override
public void register(final Element element) {
    if (checkNotRegistered(element)) {
        final Shape<?> shape = getShape(element.getUUID());
        if (null != shape) {
            final ShapeView shapeView = shape.getShapeView();
            if (shapeView instanceof HasEventHandlers) {
                final HasEventHandlers hasEventHandlers = (HasEventHandlers) shapeView;
                if (hasEventHandlers.supports(ViewEventType.TEXT_DBL_CLICK)) {
                    final TextDoubleClickHandler clickHandler = new TextDoubleClickHandler() {

                        @Override
                        public void handle(final TextDoubleClickEvent event) {
                            CanvasInPlaceTextEditorControlImpl.this.show(element, event.getClientX(), event.getClientY());
                        }
                    };
                    hasEventHandlers.addHandler(ViewEventType.TEXT_DBL_CLICK, clickHandler);
                    registerHandler(shape.getUUID(), clickHandler);
                    // Change mouse cursor, if shape supports it.
                    if (hasEventHandlers.supports(ViewEventType.TEXT_ENTER) && hasEventHandlers.supports(ViewEventType.TEXT_EXIT)) {
                        final TextEnterHandler enterHandler = new TextEnterHandler() {

                            @Override
                            public void handle(TextEnterEvent event) {
                                canvasHandler.getAbstractCanvas().getView().setCursor(AbstractCanvas.Cursors.TEXT);
                            }
                        };
                        hasEventHandlers.addHandler(ViewEventType.TEXT_ENTER, enterHandler);
                        registerHandler(shape.getUUID(), enterHandler);
                        final TextExitHandler exitHandler = new TextExitHandler() {

                            @Override
                            public void handle(TextExitEvent event) {
                                canvasHandler.getAbstractCanvas().getView().setCursor(AbstractCanvas.Cursors.AUTO);
                            }
                        };
                        hasEventHandlers.addHandler(ViewEventType.TEXT_EXIT, exitHandler);
                        registerHandler(shape.getUUID(), exitHandler);
                    }
                }
            }
        }
    }
}
Also used : TextEnterEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.TextEnterEvent) TextEnterHandler(org.kie.workbench.common.stunner.core.client.shape.view.event.TextEnterHandler) TextDoubleClickEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.TextDoubleClickEvent) TextExitHandler(org.kie.workbench.common.stunner.core.client.shape.view.event.TextExitHandler) HasEventHandlers(org.kie.workbench.common.stunner.core.client.shape.view.HasEventHandlers) ShapeView(org.kie.workbench.common.stunner.core.client.shape.view.ShapeView) TextExitEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.TextExitEvent) TextDoubleClickHandler(org.kie.workbench.common.stunner.core.client.shape.view.event.TextDoubleClickHandler)

Example 4 with HasEventHandlers

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

the class AbstractCanvasHandlerRegistrationControl method doDeregisterHandler.

private void doDeregisterHandler(final Shape shape, final ViewHandler<?> handler) {
    if (null != shape && null != handler) {
        final HasEventHandlers hasEventHandlers = (HasEventHandlers) shape.getShapeView();
        hasEventHandlers.removeHandler(handler);
        handlers.remove(shape.getUUID());
        disabledHandlers.remove(shape.getUUID());
    }
}
Also used : HasEventHandlers(org.kie.workbench.common.stunner.core.client.shape.view.HasEventHandlers)

Example 5 with HasEventHandlers

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

the class ToolboxControlImpl method register.

@Override
@SuppressWarnings("unchecked")
public void register(final Element element) {
    if (checkNotRegistered(element) && supportsToolbox(element)) {
        final Shape shape = canvasHandler.getCanvas().getShape(element.getUUID());
        final HasEventHandlers hasEventHandlers = (HasEventHandlers) shape.getShapeView();
        if (hasEventHandlers.supports(ViewEventType.MOUSE_CLICK)) {
            final MouseClickHandler clickHandler = new MouseClickHandler() {

                @Override
                public void handle(final MouseClickEvent event) {
                    if (event.isButtonLeft()) {
                        show(element);
                    }
                }
            };
            hasEventHandlers.addHandler(ViewEventType.MOUSE_CLICK, clickHandler);
            registerHandler(element.getUUID(), clickHandler);
        }
    }
}
Also used : Shape(org.kie.workbench.common.stunner.core.client.shape.Shape) MouseClickHandler(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickHandler) HasEventHandlers(org.kie.workbench.common.stunner.core.client.shape.view.HasEventHandlers) MouseClickEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickEvent)

Aggregations

HasEventHandlers (org.kie.workbench.common.stunner.core.client.shape.view.HasEventHandlers)8 Shape (org.kie.workbench.common.stunner.core.client.shape.Shape)2 ShapeView (org.kie.workbench.common.stunner.core.client.shape.view.ShapeView)2 MouseClickEvent (org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickEvent)2 MouseClickHandler (org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickHandler)2 CanvasViolation (org.kie.workbench.common.stunner.core.client.command.CanvasViolation)1 HasDragBounds (org.kie.workbench.common.stunner.core.client.shape.view.HasDragBounds)1 MouseDoubleClickEvent (org.kie.workbench.common.stunner.core.client.shape.view.event.MouseDoubleClickEvent)1 MouseDoubleClickHandler (org.kie.workbench.common.stunner.core.client.shape.view.event.MouseDoubleClickHandler)1 MouseEnterEvent (org.kie.workbench.common.stunner.core.client.shape.view.event.MouseEnterEvent)1 MouseEnterHandler (org.kie.workbench.common.stunner.core.client.shape.view.event.MouseEnterHandler)1 MouseExitEvent (org.kie.workbench.common.stunner.core.client.shape.view.event.MouseExitEvent)1 MouseExitHandler (org.kie.workbench.common.stunner.core.client.shape.view.event.MouseExitHandler)1 ResizeEvent (org.kie.workbench.common.stunner.core.client.shape.view.event.ResizeEvent)1 ResizeHandler (org.kie.workbench.common.stunner.core.client.shape.view.event.ResizeHandler)1 TextDoubleClickEvent (org.kie.workbench.common.stunner.core.client.shape.view.event.TextDoubleClickEvent)1 TextDoubleClickHandler (org.kie.workbench.common.stunner.core.client.shape.view.event.TextDoubleClickHandler)1 TextEnterEvent (org.kie.workbench.common.stunner.core.client.shape.view.event.TextEnterEvent)1 TextEnterHandler (org.kie.workbench.common.stunner.core.client.shape.view.event.TextEnterHandler)1 TextExitEvent (org.kie.workbench.common.stunner.core.client.shape.view.event.TextExitEvent)1