Search in sources :

Example 1 with MouseClickHandler

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

the class LienzoSelectionControlTest method testRegisterAndClick.

@Test
public void testRegisterAndClick() {
    tested.init(canvasHandler);
    tested.register(element);
    verify(selectionControl, times(1)).register(eq(element));
    ArgumentCaptor<MouseClickHandler> clickHandlerCaptor = ArgumentCaptor.forClass(MouseClickHandler.class);
    verify(shapeViewHandlers, times(1)).supports(eq(ViewEventType.MOUSE_CLICK));
    verify(shapeViewHandlers, times(1)).addHandler(eq(ViewEventType.MOUSE_CLICK), clickHandlerCaptor.capture());
    final MouseClickHandler clickHandler = clickHandlerCaptor.getValue();
    assertEquals(clickHandler, tested.getHandlers().get(ELEMENT_UUID));
    MouseClickEvent event = mock(MouseClickEvent.class);
    when(event.isButtonLeft()).thenReturn(true);
    clickHandler.handle(event);
    verify(selectionControl, times(1)).select(eq(element.getUUID()));
}
Also used : MouseClickHandler(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickHandler) MouseClickEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickEvent) Test(org.junit.Test)

Example 2 with MouseClickHandler

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

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

the class MapSelectionControl method doInit.

@Override
protected void doInit() {
    // Click handler for the canvas area - cleans current selection, if any.
    final MouseClickHandler clickHandler = new MouseClickHandler() {

        @Override
        public void handle(final MouseClickEvent event) {
            if (event.isButtonLeft() || event.isButtonRight()) {
                clearSelection(false);
                final String canvasRootUUID = getRootUUID();
                fireCanvasClear();
                if (null != canvasRootUUID) {
                    selectionEventConsumer.accept(new CanvasSelectionEvent(canvasHandler, canvasRootUUID));
                }
            }
        }
    };
    getCanvas().addHandler(ViewEventType.MOUSE_CLICK, clickHandler);
    this.layerClickHandler = clickHandler;
}
Also used : MouseClickHandler(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickHandler) CanvasSelectionEvent(org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasSelectionEvent) MouseClickEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickEvent)

Example 4 with MouseClickHandler

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

the class MapSelectionControl method enable.

@Override
public void enable(final H canvasHandler) {
    super.enable(canvasHandler);
    final Layer layer = canvasHandler.getCanvas().getLayer();
    // Click handler for the canvas area - cleans current selection, if any.
    final MouseClickHandler clickHandler = new MouseClickHandler() {

        @Override
        public void handle(final MouseClickEvent event) {
            if (event.isButtonLeft() || event.isButtonRight()) {
                clearSelection(false);
                final String canvasRootUUID = getRootUUID();
                fireCanvasClear();
                if (null != canvasRootUUID) {
                    selectionEventConsumer.accept(new CanvasSelectionEvent(canvasHandler, canvasRootUUID));
                }
            }
        }
    };
    layer.addHandler(ViewEventType.MOUSE_CLICK, clickHandler);
    this.layerClickHandler = clickHandler;
}
Also used : MouseClickHandler(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickHandler) CanvasSelectionEvent(org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasSelectionEvent) Layer(org.kie.workbench.common.stunner.core.client.canvas.Layer) MouseClickEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickEvent)

Example 5 with MouseClickHandler

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

the class MapSelectionControlTest method testLayerClickAndClear.

@Test
public void testLayerClickAndClear() {
    when(metadata.getCanvasRootUUID()).thenReturn(null);
    tested.init(canvasHandler);
    final ArgumentCaptor<MouseClickHandler> clickHandlerArgumentCaptor = ArgumentCaptor.forClass(MouseClickHandler.class);
    verify(canvas, times(1)).addHandler(eq(ViewEventType.MOUSE_CLICK), clickHandlerArgumentCaptor.capture());
    final MouseClickHandler clickHandler = clickHandlerArgumentCaptor.getValue();
    final MouseClickEvent event = new MouseClickEvent(12, 20, 30, 40);
    event.setButtonLeft(true);
    event.setShiftKeyDown(false);
    clickHandler.handle(event);
    verify(clearSelectionEvent, times(1)).fire(any(CanvasClearSelectionEvent.class));
    verify(elementSelectedEvent, never()).fire(any(CanvasSelectionEvent.class));
}
Also used : CanvasClearSelectionEvent(org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasClearSelectionEvent) MouseClickHandler(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickHandler) CanvasSelectionEvent(org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasSelectionEvent) MouseClickEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickEvent) Test(org.junit.Test)

Aggregations

MouseClickEvent (org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickEvent)7 MouseClickHandler (org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickHandler)7 CanvasSelectionEvent (org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasSelectionEvent)4 Test (org.junit.Test)3 CanvasClearSelectionEvent (org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasClearSelectionEvent)2 HasEventHandlers (org.kie.workbench.common.stunner.core.client.shape.view.HasEventHandlers)2 Layer (org.kie.workbench.common.stunner.core.client.canvas.Layer)1 Shape (org.kie.workbench.common.stunner.core.client.shape.Shape)1 ShapeView (org.kie.workbench.common.stunner.core.client.shape.view.ShapeView)1