Search in sources :

Example 6 with HasEventHandlers

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

the class ControlPointControlImpl method registerHandlers.

@SuppressWarnings("unchecked")
private void registerHandlers(final Element element, final Shape<?> shape) {
    if (shape.getShapeView() instanceof HasEventHandlers && element instanceof Edge && element.getContent() instanceof ViewConnector) {
        final HasEventHandlers hasEventHandlers = (HasEventHandlers) shape.getShapeView();
        // Register handler on the Connector to Add a ControlPoint
        MouseDoubleClickHandler eventHandler = new MouseDoubleClickHandler() {

            @Override
            public void handle(MouseDoubleClickEvent event) {
                addControlPoint((Edge) element, new ControlPointImpl(event.getX(), event.getY()));
            }
        };
        hasEventHandlers.addHandler(ViewEventType.MOUSE_DBL_CLICK, eventHandler);
        registerHandler(element.getUUID(), eventHandler);
    }
}
Also used : ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) MouseDoubleClickHandler(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseDoubleClickHandler) ControlPointImpl(org.kie.workbench.common.stunner.core.graph.content.view.ControlPointImpl) HasEventHandlers(org.kie.workbench.common.stunner.core.client.shape.view.HasEventHandlers) MouseDoubleClickEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseDoubleClickEvent) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Example 7 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 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());
    }
}
Also used : HasEventHandlers(org.kie.workbench.common.stunner.core.client.shape.view.HasEventHandlers)

Example 8 with HasEventHandlers

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

the class LocationControlImpl method register.

@Override
@SuppressWarnings("unchecked")
public void register(final Element element) {
    if (null != element.asNode() && checkNotRegistered(element)) {
        final Canvas<?> canvas = canvasHandler.getCanvas();
        final Shape<?> shape = canvas.getShape(element.getUUID());
        // Drag & constraints.
        shape.getShapeView().setDragEnabled(true);
        if (shape.getShapeView() instanceof HasDragBounds) {
            ensureDragConstraints((HasDragBounds<?>) shape.getShapeView());
        }
        if (shape.getShapeView() instanceof HasEventHandlers) {
            final HasEventHandlers hasEventHandlers = (HasEventHandlers) shape.getShapeView();
            // Change mouse cursor, if shape supports it.
            if (supportsMouseEnter(hasEventHandlers) && supportsMouseExit(hasEventHandlers)) {
                final MouseEnterHandler overHandler = new MouseEnterHandler() {

                    @Override
                    public void handle(MouseEnterEvent event) {
                        canvasHandler.getAbstractCanvas().getView().setCursor(AbstractCanvas.Cursors.MOVE);
                    }
                };
                hasEventHandlers.addHandler(ViewEventType.MOUSE_ENTER, overHandler);
                registerHandler(shape.getUUID(), overHandler);
                final MouseExitHandler outHandler = new MouseExitHandler() {

                    @Override
                    public void handle(MouseExitEvent event) {
                        canvasHandler.getAbstractCanvas().getView().setCursor(AbstractCanvas.Cursors.AUTO);
                    }
                };
                hasEventHandlers.addHandler(ViewEventType.MOUSE_EXIT, outHandler);
                registerHandler(shape.getUUID(), outHandler);
            }
        }
    }
}
Also used : HasDragBounds(org.kie.workbench.common.stunner.core.client.shape.view.HasDragBounds) MouseExitHandler(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseExitHandler) MouseEnterEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseEnterEvent) MouseExitEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseExitEvent) HasEventHandlers(org.kie.workbench.common.stunner.core.client.shape.view.HasEventHandlers) MouseEnterHandler(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseEnterHandler)

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