Search in sources :

Example 1 with MouseExitHandler

use of org.kie.workbench.common.stunner.core.client.shape.view.event.MouseExitHandler 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 AbstractCanvas<?> canvas = canvasHandler.getAbstractCanvas();
        final Shape<?> shape = canvas.getShape(element.getUUID());
        final ShapeView shapeView = shape.getShapeView();
        // Enable drag & ensure location constraints are set, if any.
        shapeView.setDragEnabled(true);
        ensureDragConstraints(canvas, shapeView);
        // Register handlers.
        if (shape.getShapeView() instanceof HasEventHandlers) {
            final HasEventHandlers hasEventHandlers = (HasEventHandlers) shapeView;
            // 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.DEFAULT);
                    }
                };
                hasEventHandlers.addHandler(ViewEventType.MOUSE_EXIT, outHandler);
                registerHandler(shape.getUUID(), outHandler);
                // Adding DragHandler on the shape to check whether the moving shape is not selected, th
                final DragHandler dragHandler = new DragHandler() {

                    @Override
                    public void start(DragEvent event) {
                    // Instead of firing the event on Drag start, now will be fired at the end, hence improving performance
                    }

                    @Override
                    public void end(DragEvent event) {
                        selectionEvent.fire(new CanvasSelectionEvent(canvasHandler, shape.getUUID()));
                    }

                    @Override
                    public void handle(DragEvent event) {
                    }
                };
                hasEventHandlers.addHandler(ViewEventType.DRAG, dragHandler);
                registerHandler(shape.getUUID(), dragHandler);
            }
        }
    }
}
Also used : DragEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.DragEvent) CanvasSelectionEvent(org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasSelectionEvent) MouseExitHandler(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseExitHandler) MouseEnterEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseEnterEvent) DragHandler(org.kie.workbench.common.stunner.core.client.shape.view.event.DragHandler) MouseExitEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseExitEvent) HasEventHandlers(org.kie.workbench.common.stunner.core.client.shape.view.HasEventHandlers) ShapeView(org.kie.workbench.common.stunner.core.client.shape.view.ShapeView) MouseEnterHandler(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseEnterHandler)

Aggregations

CanvasSelectionEvent (org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasSelectionEvent)1 HasEventHandlers (org.kie.workbench.common.stunner.core.client.shape.view.HasEventHandlers)1 ShapeView (org.kie.workbench.common.stunner.core.client.shape.view.ShapeView)1 DragEvent (org.kie.workbench.common.stunner.core.client.shape.view.event.DragEvent)1 DragHandler (org.kie.workbench.common.stunner.core.client.shape.view.event.DragHandler)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