Search in sources :

Example 11 with MouseClickEvent

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

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

the class MorphNodeToolboxActionTest method testAction.

@Test
public void testAction() {
    final MouseClickEvent event = mock(MouseClickEvent.class);
    ToolboxAction<AbstractCanvasHandler> cascade = tested.onMouseClick(canvasHandler, E_UUID, event);
    assertEquals(tested, cascade);
    verify(commandFactory, times(1)).morphNode(eq(element), eq(morphDefinition), eq(MORPH_TARGET_ID), eq(SSID_UUID));
    verify(sessionCommandManager, times(1)).execute(eq(canvasHandler), eq(morphNodeCommand));
    final ArgumentCaptor<CanvasSelectionEvent> eventArgumentCaptor = ArgumentCaptor.forClass(CanvasSelectionEvent.class);
    verify(canvasElementSelectedEvent, times(1)).fire(eventArgumentCaptor.capture());
    final CanvasSelectionEvent eCaptured = eventArgumentCaptor.getValue();
    assertEquals(E_UUID, eCaptured.getIdentifiers().iterator().next());
}
Also used : AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) 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)

Example 13 with MouseClickEvent

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

the class CreateNodeToolboxActionTest method testOnMouseClick.

@Test
public void testOnMouseClick() {
    when(canvasLayoutUtils.getNext(eq(canvasHandler), eq(element), eq(targetNode))).thenReturn(new Point2D(100d, 500d));
    final MouseClickEvent event = mock(MouseClickEvent.class);
    when(event.getX()).thenReturn(100d);
    when(event.getY()).thenReturn(500d);
    ToolboxAction<AbstractCanvasHandler> cascade = tested.onMouseClick(canvasHandler, NODE_UUID, event);
    assertEquals(tested, cascade);
    verify(action).executeAction(canvasHandler, NODE_UUID, TARGET_NODE_ID, EDGE_ID);
}
Also used : AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) MouseClickEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickEvent) Test(org.junit.Test)

Example 14 with MouseClickEvent

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

the class DeleteNodeToolboxActionTest method testAction.

@Test
public void testAction() {
    final MouseClickEvent event = mock(MouseClickEvent.class);
    final ToolboxAction<AbstractCanvasHandler> cascade = tested.onMouseClick(canvasHandler, E_UUID, event);
    assertEquals(tested, cascade);
    verify(commandFactory, times(1)).deleteNode(eq(element));
    verify(sessionCommandManager, times(1)).execute(eq(canvasHandler), eq(deleteNodeCommand));
    verify(clearSelectionEventEventSourceMock).fire(any(CanvasClearSelectionEvent.class));
}
Also used : CanvasClearSelectionEvent(org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasClearSelectionEvent) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) MouseClickEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickEvent) Test(org.junit.Test)

Example 15 with MouseClickEvent

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

the class DeleteNodeToolboxActionTest method testSkipAction.

@Test
@SuppressWarnings("unchecked")
public void testSkipAction() {
    this.tested = new DeleteNodeToolboxAction(translationService, sessionCommandManager, commandFactories, definitionUtils, action -> false, clearSelectionEventEventSourceMock);
    final MouseClickEvent event = mock(MouseClickEvent.class);
    final ToolboxAction<AbstractCanvasHandler> cascade = tested.onMouseClick(canvasHandler, E_UUID, event);
    assertEquals(tested, cascade);
    verify(sessionCommandManager, never()).execute(eq(canvasHandler), any(CanvasCommand.class));
    verify(clearSelectionEventEventSourceMock, never()).fire(any(CanvasClearSelectionEvent.class));
}
Also used : GwtMockitoTestRunner(com.google.gwtmockito.GwtMockitoTestRunner) CanvasClearSelectionEvent(org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasClearSelectionEvent) DefinitionUtils(org.kie.workbench.common.stunner.core.util.DefinitionUtils) Mock(org.mockito.Mock) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) RunWith(org.junit.runner.RunWith) ClientTranslationService(org.kie.workbench.common.stunner.core.client.i18n.ClientTranslationService) ManagedInstanceStub(org.kie.workbench.common.stunner.core.client.ManagedInstanceStub) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) Before(org.junit.Before) Index(org.kie.workbench.common.stunner.core.graph.processing.index.Index) Test(org.junit.Test) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) SessionCommandManager(org.kie.workbench.common.stunner.core.client.command.SessionCommandManager) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) Mockito.verify(org.mockito.Mockito.verify) CanvasCommand(org.kie.workbench.common.stunner.core.client.command.CanvasCommand) MouseClickEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickEvent) CoreTranslationMessages(org.kie.workbench.common.stunner.core.i18n.CoreTranslationMessages) Mockito.never(org.mockito.Mockito.never) DefaultCanvasCommandFactory(org.kie.workbench.common.stunner.core.client.canvas.command.DefaultCanvasCommandFactory) EventSourceMock(org.uberfire.mocks.EventSourceMock) Mockito.any(org.mockito.Mockito.any) Node(org.kie.workbench.common.stunner.core.graph.Node) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) CanvasClearSelectionEvent(org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasClearSelectionEvent) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) MouseClickEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickEvent) CanvasCommand(org.kie.workbench.common.stunner.core.client.command.CanvasCommand) Test(org.junit.Test)

Aggregations

MouseClickEvent (org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickEvent)25 Test (org.junit.Test)17 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)11 CanvasSelectionEvent (org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasSelectionEvent)7 MouseClickHandler (org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickHandler)7 CanvasClearSelectionEvent (org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasClearSelectionEvent)4 Node (org.kie.workbench.common.stunner.core.graph.Node)4 NodeMouseClickEvent (com.ait.lienzo.client.core.event.NodeMouseClickEvent)2 NodeMouseClickHandler (com.ait.lienzo.client.core.event.NodeMouseClickHandler)2 MouseEvent (com.google.gwt.event.dom.client.MouseEvent)2 GwtMockitoTestRunner (com.google.gwtmockito.GwtMockitoTestRunner)2 Consumer (java.util.function.Consumer)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Before (org.junit.Before)2 RunWith (org.junit.runner.RunWith)2 EditExpressionEvent (org.kie.workbench.common.dmn.client.events.EditExpressionEvent)2 CanvasCommand (org.kie.workbench.common.stunner.core.client.command.CanvasCommand)2 SessionCommandManager (org.kie.workbench.common.stunner.core.client.command.SessionCommandManager)2 ClientTranslationService (org.kie.workbench.common.stunner.core.client.i18n.ClientTranslationService)2 HasEventHandlers (org.kie.workbench.common.stunner.core.client.shape.view.HasEventHandlers)2