Search in sources :

Example 16 with MouseClickEvent

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

the class CreateNodeActionTest method testAction.

@Test
@SuppressWarnings("unchecked")
public void testAction() {
    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);
    ArgumentCaptor<Command> commandArgumentCaptor = ArgumentCaptor.forClass(Command.class);
    verify(sessionCommandManager, times(1)).execute(eq(canvasHandler), commandArgumentCaptor.capture());
    DeferredCompositeCommand command = (DeferredCompositeCommand) commandArgumentCaptor.getValue();
    DeferredCommand c0 = (DeferredCommand) command.getCommands().get(0);
    DeferredCommand c1 = (DeferredCommand) command.getCommands().get(1);
    DeferredCommand c2 = (DeferredCommand) command.getCommands().get(2);
    DeferredCommand c3 = (DeferredCommand) command.getCommands().get(3);
    AddNodeCommand addNodeCommand = (AddNodeCommand) c0.getCommand();
    UpdateElementPositionCommand updateElementPositionCommand = (UpdateElementPositionCommand) c1.getCommand();
    AddConnectorCommand addConnectorCommand = (AddConnectorCommand) c2.getCommand();
    SetConnectionTargetNodeCommand setTargetNodeCommand = (SetConnectionTargetNodeCommand) c3.getCommand();
    assertEquals(targetNode, addNodeCommand.getCandidate());
    assertEquals("ss1", addNodeCommand.getShapeSetId());
    assertEquals(edge, addConnectorCommand.getCandidate());
    assertEquals(element, addConnectorCommand.getSource());
    assertEquals("ss1", addConnectorCommand.getShapeSetId());
    assertEquals(edge, setTargetNodeCommand.getEdge());
    assertEquals(targetNode, setTargetNodeCommand.getNode());
    assertEquals(targetNode, updateElementPositionCommand.getElement());
    assertEquals(new Point2D(100d, 500d), updateElementPositionCommand.getLocation());
    final ArgumentCaptor<CanvasSelectionEvent> eventArgumentCaptor = ArgumentCaptor.forClass(CanvasSelectionEvent.class);
    verify(canvasElementSelectedEvent, times(1)).fire(eventArgumentCaptor.capture());
    final CanvasSelectionEvent eCaptured = eventArgumentCaptor.getValue();
    assertEquals(TARGET_NODE_UUID, eCaptured.getIdentifiers().iterator().next());
}
Also used : DeferredCompositeCommand(org.kie.workbench.common.stunner.core.command.impl.DeferredCompositeCommand) SetConnectionTargetNodeCommand(org.kie.workbench.common.stunner.core.client.canvas.command.SetConnectionTargetNodeCommand) AddNodeCommand(org.kie.workbench.common.stunner.core.client.canvas.command.AddNodeCommand) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) CanvasSelectionEvent(org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasSelectionEvent) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) AddConnectorCommand(org.kie.workbench.common.stunner.core.client.canvas.command.AddConnectorCommand) UpdateElementPositionCommand(org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPositionCommand) SetConnectionTargetNodeCommand(org.kie.workbench.common.stunner.core.client.canvas.command.SetConnectionTargetNodeCommand) Command(org.kie.workbench.common.stunner.core.command.Command) DeferredCompositeCommand(org.kie.workbench.common.stunner.core.command.impl.DeferredCompositeCommand) AddNodeCommand(org.kie.workbench.common.stunner.core.client.canvas.command.AddNodeCommand) DeferredCommand(org.kie.workbench.common.stunner.core.command.impl.DeferredCommand) UpdateElementPositionCommand(org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPositionCommand) AddConnectorCommand(org.kie.workbench.common.stunner.core.client.canvas.command.AddConnectorCommand) MouseClickEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickEvent) DeferredCommand(org.kie.workbench.common.stunner.core.command.impl.DeferredCommand) Test(org.junit.Test)

Example 17 with MouseClickEvent

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

the class MorphNodeActionTest 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 18 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 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 19 with MouseClickEvent

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

the class AbstractActionsToolboxView method addButton.

@Override
public V addButton(Glyph glyph, String title, Consumer<MouseClickEvent> clickEventConsumer) {
    final ButtonItem button = toolboxFactory.buttons().button(renderGlyph(glyph, getGlyphSize())).decorate(createDecorator()).tooltip(tooltip.createItem(title)).onMouseEnter(event -> onMouseEnter()).onMouseExit(event -> onMouseExit()).onClick(event -> clickEventConsumer.accept(new MouseClickEvent(event.getX(), event.getY(), event.getMouseEvent().getClientX(), event.getMouseEvent().getClientY())));
    addButton(button);
    return cast();
}
Also used : ButtonItem(org.kie.workbench.common.stunner.lienzo.toolbox.items.ButtonItem) DecoratorItem(org.kie.workbench.common.stunner.lienzo.toolbox.items.DecoratorItem) Text(com.ait.lienzo.client.core.shape.Text) ToolboxTextTooltip(org.kie.workbench.common.stunner.lienzo.toolbox.items.tooltip.ToolboxTextTooltip) Group(com.ait.lienzo.client.core.shape.Group) AbstractCanvas(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvas) WiresCanvas(org.kie.workbench.common.stunner.client.lienzo.canvas.wires.WiresCanvas) ActionsToolbox(org.kie.workbench.common.stunner.core.client.components.toolbox.actions.ActionsToolbox) Consumer(java.util.function.Consumer) MouseClickEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickEvent) Layer(com.ait.lienzo.client.core.shape.Layer) LienzoGlyphRenderers(org.kie.workbench.common.stunner.client.lienzo.components.glyph.LienzoGlyphRenderers) Glyph(org.kie.workbench.common.stunner.core.definition.shape.Glyph) ActionsToolboxView(org.kie.workbench.common.stunner.core.client.components.toolbox.actions.ActionsToolboxView) WiresShapeToolbox(org.kie.workbench.common.stunner.lienzo.toolbox.items.impl.WiresShapeToolbox) ToolboxFactory(org.kie.workbench.common.stunner.lienzo.toolbox.items.impl.ToolboxFactory) WiresShape(com.ait.lienzo.client.core.shape.wires.WiresShape) ButtonItem(org.kie.workbench.common.stunner.lienzo.toolbox.items.ButtonItem) MouseClickEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickEvent)

Example 20 with MouseClickEvent

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

the class AbstractActionsToolboxViewTest method testAddButton.

@SuppressWarnings("unchecked")
protected void testAddButton(final Consumer<MouseClickEvent> clickEventConsumer) {
    // Verify tootlip.
    verify(toolboxTooltip, times(1)).createItem(eq("title1"));
    verify(buttonItem, times(1)).tooltip(any(TooltipItem.class));
    // Verify mouse enter.
    final ArgumentCaptor<NodeMouseEnterHandler> enterHandlerArgumentCaptor = ArgumentCaptor.forClass(NodeMouseEnterHandler.class);
    verify(buttonItem, times(1)).onMouseEnter(enterHandlerArgumentCaptor.capture());
    final NodeMouseEnterHandler enterHandler = enterHandlerArgumentCaptor.getValue();
    final NodeMouseEnterEvent mouseEnterEvent = mock(NodeMouseEnterEvent.class);
    enterHandler.onNodeMouseEnter(mouseEnterEvent);
    verify(canvasView, times(1)).setCursor(eq(AbstractCanvas.Cursors.POINTER));
    // Verify mouse exit.
    final ArgumentCaptor<NodeMouseExitHandler> exitHandlerArgumentCaptor = ArgumentCaptor.forClass(NodeMouseExitHandler.class);
    verify(buttonItem, times(1)).onMouseExit(exitHandlerArgumentCaptor.capture());
    final NodeMouseExitHandler exitHandler = exitHandlerArgumentCaptor.getValue();
    final NodeMouseExitEvent mouseExitEvent = mock(NodeMouseExitEvent.class);
    exitHandler.onNodeMouseExit(mouseExitEvent);
    verify(canvasView, times(1)).setCursor(eq(AbstractCanvas.Cursors.AUTO));
    // Verify mouse click.
    final ArgumentCaptor<NodeMouseClickHandler> clickHandlerArgumentCaptor = ArgumentCaptor.forClass(NodeMouseClickHandler.class);
    verify(buttonItem, times(1)).onClick(clickHandlerArgumentCaptor.capture());
    final NodeMouseClickHandler clickHandler = clickHandlerArgumentCaptor.getValue();
    final NodeMouseClickEvent mouseClickEvent = mock(NodeMouseClickEvent.class);
    when(mouseClickEvent.getMouseEvent()).thenReturn(mock(MouseEvent.class));
    clickHandler.onNodeMouseClick(mouseClickEvent);
    verify(clickEventConsumer, times(1)).accept(any(MouseClickEvent.class));
}
Also used : NodeMouseClickHandler(com.ait.lienzo.client.core.event.NodeMouseClickHandler) MouseEvent(com.google.gwt.event.dom.client.MouseEvent) NodeMouseEnterEvent(com.ait.lienzo.client.core.event.NodeMouseEnterEvent) NodeMouseExitHandler(com.ait.lienzo.client.core.event.NodeMouseExitHandler) NodeMouseEnterHandler(com.ait.lienzo.client.core.event.NodeMouseEnterHandler) TooltipItem(org.kie.workbench.common.stunner.lienzo.toolbox.items.TooltipItem) NodeMouseExitEvent(com.ait.lienzo.client.core.event.NodeMouseExitEvent) NodeMouseClickEvent(com.ait.lienzo.client.core.event.NodeMouseClickEvent) NodeMouseClickEvent(com.ait.lienzo.client.core.event.NodeMouseClickEvent) MouseClickEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickEvent)

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