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());
}
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());
}
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;
}
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();
}
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));
}
Aggregations