Search in sources :

Example 1 with MouseDoubleClickEvent

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

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

the class ViewEventHandlerManager method registerDoubleClickHandler.

protected HandlerRegistration[] registerDoubleClickHandler(final ViewHandler<ViewEvent> eventHandler) {
    return new HandlerRegistration[] { node.addNodeMouseDoubleClickHandler(nodeMouseDoubleClickEvent -> {
        if (isEnabled()) {
            skipClickHandler();
            final MouseDoubleClickEvent event = new MouseDoubleClickEvent(nodeMouseDoubleClickEvent.getX(), nodeMouseDoubleClickEvent.getY(), nodeMouseDoubleClickEvent.getMouseEvent().getClientX(), nodeMouseDoubleClickEvent.getMouseEvent().getClientY());
            event.setShiftKeyDown(nodeMouseDoubleClickEvent.isShiftKeyDown());
            event.setAltKeyDown(nodeMouseDoubleClickEvent.isAltKeyDown());
            event.setMetaKeyDown(nodeMouseDoubleClickEvent.isMetaKeyDown());
            event.setButtonLeft(nodeMouseDoubleClickEvent.isButtonLeft());
            event.setButtonMiddle(nodeMouseDoubleClickEvent.isButtonMiddle());
            event.setButtonRight(nodeMouseDoubleClickEvent.isButtonRight());
            eventHandler.handle(event);
            restoreClickHandler();
        }
    }) };
}
Also used : HandlerRegistration(com.google.gwt.event.shared.HandlerRegistration) MouseDoubleClickEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseDoubleClickEvent)

Example 3 with MouseDoubleClickEvent

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

the class ViewEventHandlerManagerTest method testDoubleClickHandler.

@Test
@SuppressWarnings("unchecked")
public void testDoubleClickHandler() {
    final ViewHandler<ViewEvent> clickHandler = mock(ViewHandler.class);
    final HandlerRegistration handlerRegistration = mock(HandlerRegistration.class);
    when(node.addNodeMouseDoubleClickHandler(any(NodeMouseDoubleClickHandler.class))).thenReturn(handlerRegistration);
    tested.addHandler(ViewEventType.MOUSE_DBL_CLICK, clickHandler);
    final ArgumentCaptor<NodeMouseDoubleClickHandler> clickHandlerArgumentCaptor = ArgumentCaptor.forClass(NodeMouseDoubleClickHandler.class);
    verify(node, times(1)).addNodeMouseDoubleClickHandler(clickHandlerArgumentCaptor.capture());
    final NodeMouseDoubleClickHandler nodeCLickHandler = clickHandlerArgumentCaptor.getValue();
    final NodeMouseDoubleClickEvent clickEvent = mock(NodeMouseDoubleClickEvent.class);
    final MouseEvent mouseEvent = mock(MouseEvent.class);
    final int x = 102;
    final int y = 410;
    when(clickEvent.getX()).thenReturn(x);
    when(clickEvent.getY()).thenReturn(y);
    when(clickEvent.isButtonLeft()).thenReturn(true);
    when(clickEvent.isButtonRight()).thenReturn(true);
    when(clickEvent.isButtonMiddle()).thenReturn(true);
    when(clickEvent.isShiftKeyDown()).thenReturn(true);
    when(clickEvent.isAltKeyDown()).thenReturn(true);
    when(clickEvent.isMetaKeyDown()).thenReturn(true);
    when(clickEvent.getMouseEvent()).thenReturn(mouseEvent);
    when(mouseEvent.getClientX()).thenReturn(x);
    when(mouseEvent.getClientY()).thenReturn(y);
    nodeCLickHandler.onNodeMouseDoubleClick(clickEvent);
    final ArgumentCaptor<ViewEvent> eventArgumentCaptor = ArgumentCaptor.forClass(ViewEvent.class);
    verify(clickHandler, times(1)).handle(eventArgumentCaptor.capture());
    final MouseDoubleClickEvent viewEvent = (MouseDoubleClickEvent) eventArgumentCaptor.getValue();
    assertEquals(x, viewEvent.getX(), 0d);
    assertEquals(y, viewEvent.getY(), 0d);
    assertEquals(x, viewEvent.getClientX(), 0d);
    assertEquals(y, viewEvent.getClientY(), 0d);
    assertTrue(viewEvent.isButtonLeft());
    assertTrue(viewEvent.isButtonRight());
    assertTrue(viewEvent.isButtonMiddle());
    assertTrue(viewEvent.isAltKeyDown());
    assertTrue(viewEvent.isMetaKeyDown());
    assertTrue(viewEvent.isShiftKeyDown());
    assertNotNull(tested.getRegistrationMap().get(ViewEventType.MOUSE_DBL_CLICK));
}
Also used : HandlerRegistration(com.google.gwt.event.shared.HandlerRegistration) MouseEvent(com.google.gwt.event.dom.client.MouseEvent) ViewEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.ViewEvent) MouseDoubleClickEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseDoubleClickEvent) NodeMouseDoubleClickEvent(com.ait.lienzo.client.core.event.NodeMouseDoubleClickEvent) NodeMouseDoubleClickEvent(com.ait.lienzo.client.core.event.NodeMouseDoubleClickEvent) NodeMouseDoubleClickHandler(com.ait.lienzo.client.core.event.NodeMouseDoubleClickHandler) Test(org.junit.Test)

Aggregations

MouseDoubleClickEvent (org.kie.workbench.common.stunner.core.client.shape.view.event.MouseDoubleClickEvent)3 HandlerRegistration (com.google.gwt.event.shared.HandlerRegistration)2 NodeMouseDoubleClickEvent (com.ait.lienzo.client.core.event.NodeMouseDoubleClickEvent)1 NodeMouseDoubleClickHandler (com.ait.lienzo.client.core.event.NodeMouseDoubleClickHandler)1 MouseEvent (com.google.gwt.event.dom.client.MouseEvent)1 Test (org.junit.Test)1 HasEventHandlers (org.kie.workbench.common.stunner.core.client.shape.view.HasEventHandlers)1 MouseDoubleClickHandler (org.kie.workbench.common.stunner.core.client.shape.view.event.MouseDoubleClickHandler)1 ViewEvent (org.kie.workbench.common.stunner.core.client.shape.view.event.ViewEvent)1 Edge (org.kie.workbench.common.stunner.core.graph.Edge)1 ControlPointImpl (org.kie.workbench.common.stunner.core.graph.content.view.ControlPointImpl)1 ViewConnector (org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector)1