Search in sources :

Example 1 with AbstractCanvasHandler

use of org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler in project kie-wb-common by kiegroup.

the class ActionsToolbox method addButton.

private void addButton(final ToolboxAction<AbstractCanvasHandler> action) {
    final AbstractCanvasHandler canvasHandler = canvasHandlerSupplier.get();
    getView().addButton(action.getGlyph(canvasHandler, uuid), action.getTitle(canvasHandler, uuid), event -> action.onMouseClick(canvasHandler, uuid, event));
}
Also used : AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)

Example 2 with AbstractCanvasHandler

use of org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler in project kie-wb-common by kiegroup.

the class CreateConnectorActionTest method testStartDrag.

@SuppressWarnings("unchecked")
private DragProxyCallback testStartDrag() {
    final MouseClickEvent event = mock(MouseClickEvent.class);
    when(event.getX()).thenReturn(100d);
    when(event.getY()).thenReturn(500d);
    when(graphBoundsIndexer.getAt(eq(100d), eq(500d))).thenReturn(targetNode);
    ToolboxAction<AbstractCanvasHandler> cascade = tested.onMouseClick(canvasHandler, NODE_UUID, event);
    assertEquals(tested, cascade);
    verify(edge, times(1)).setSourceNode(eq(element));
    verify(connectorDragProxyFactory, times(1)).proxyFor(eq(canvasHandler));
    ArgumentCaptor<DragProxyCallback> proxyArgumentCaptor = ArgumentCaptor.forClass(DragProxyCallback.class);
    verify(connectorDragProxyFactory, times(1)).show(any(ConnectorDragProxy.Item.class), eq(100), eq(500), proxyArgumentCaptor.capture());
    final DragProxyCallback callback = proxyArgumentCaptor.getValue();
    // Verify drag proxy start.
    callback.onStart(0, 0);
    assertNotNull(tested.getCanvasHighlight());
    verify(graphBoundsIndexer, times(1)).setRootUUID(eq(ROOT_UUID));
    verify(graphBoundsIndexer, times(1)).build(eq(graph));
    verify(edgeBuilderControl, times(1)).enable(eq(canvasHandler));
    ArgumentCaptor<RequiresCommandManager.CommandManagerProvider> providerArgumentCaptor = ArgumentCaptor.forClass(RequiresCommandManager.CommandManagerProvider.class);
    verify(edgeBuilderControl, times(1)).setCommandManagerProvider(providerArgumentCaptor.capture());
    RequiresCommandManager.CommandManagerProvider cmProvider = providerArgumentCaptor.getValue();
    assertEquals(sessionCommandManager, cmProvider.getCommandManager());
    return callback;
}
Also used : AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) RequiresCommandManager(org.kie.workbench.common.stunner.core.client.command.RequiresCommandManager) DragProxyCallback(org.kie.workbench.common.stunner.core.client.components.drag.DragProxyCallback) MouseClickEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickEvent)

Example 3 with AbstractCanvasHandler

use of org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler in project kie-wb-common by kiegroup.

the class CreateNodeActionTest method setup.

@Before
@SuppressWarnings("unchecked")
public void setup() throws Exception {
    when(canvasHandler.getGraphIndex()).thenReturn(graphIndex);
    when(canvasHandler.getDiagram()).thenReturn(diagram);
    when(canvasHandler.getCanvas()).thenReturn(canvas);
    when(canvasHandler.getShapeFactory(eq(SSID_UUID))).thenReturn(shapeFactory);
    when(canvas.getLayer()).thenReturn(layer);
    when(diagram.getGraph()).thenReturn(graph);
    when(diagram.getMetadata()).thenReturn(metadata);
    when(metadata.getShapeSetId()).thenReturn(SSID_UUID);
    when(metadata.getCanvasRootUUID()).thenReturn(ROOT_UUID);
    when(graphIndex.get(eq(NODE_UUID))).thenReturn(element);
    when(graphIndex.getNode(eq(NODE_UUID))).thenReturn(element);
    when(graphIndex.get(eq(EDGE_UUID))).thenReturn(edge);
    when(graphIndex.getEdge(eq(EDGE_UUID))).thenReturn(edge);
    when(graphIndex.get(eq(TARGET_NODE_UUID))).thenReturn(targetNode);
    when(graphIndex.getNode(eq(TARGET_NODE_UUID))).thenReturn(targetNode);
    when(element.getUUID()).thenReturn(NODE_UUID);
    when(element.getContent()).thenReturn(elementContent);
    when(element.asNode()).thenReturn(element);
    when(edge.getUUID()).thenReturn(EDGE_UUID);
    when(edge.asEdge()).thenReturn(edge);
    when(targetNode.getUUID()).thenReturn(TARGET_NODE_UUID);
    when(targetNode.asNode()).thenReturn(targetNode);
    when(targetNode.getContent()).thenReturn(targetNodeContent);
    when(sessionCommandManager.execute(eq(canvasHandler), any(Command.class))).thenReturn(CanvasCommandResultBuilder.SUCCESS);
    when(elementContent.getBounds()).thenReturn(new BoundsImpl(new BoundImpl(0d, 0d), new BoundImpl(100d, 100d)));
    when(targetNodeContent.getBounds()).thenReturn(new BoundsImpl(new BoundImpl(0d, 0d), new BoundImpl(100d, 100d)));
    when(clientFactoryManager.newElement(anyString(), eq(EDGE_ID))).thenReturn((Element) edge);
    when(clientFactoryManager.newElement(anyString(), eq(TARGET_NODE_ID))).thenReturn((Element) targetNode);
    CanvasCommandFactory<AbstractCanvasHandler> canvasCommandFactory = new DefaultCanvasCommandFactory(null, null);
    this.tested = new CreateNodeAction(definitionUtils, clientFactoryManager, canvasLayoutUtils, canvasElementSelectedEvent, translationService, sessionCommandManager, canvasCommandFactory).setEdgeId(EDGE_ID).setNodeId(TARGET_NODE_ID);
}
Also used : AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) 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) BoundImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl) DefaultCanvasCommandFactory(org.kie.workbench.common.stunner.core.client.canvas.command.DefaultCanvasCommandFactory) BoundsImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl) Before(org.junit.Before)

Example 4 with AbstractCanvasHandler

use of org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler in project kie-wb-common by kiegroup.

the class DeleteNodeActionTest method testSkipAction.

@Test
@SuppressWarnings("unchecked")
public void testSkipAction() {
    this.tested = new DeleteNodeAction(translationService, sessionCommandManager, commandFactory, action -> false);
    final MouseClickEvent event = mock(MouseClickEvent.class);
    ToolboxAction<AbstractCanvasHandler> cascade = tested.onMouseClick(canvasHandler, E_UUID, event);
    assertEquals(tested, cascade);
    verify(sessionCommandManager, never()).execute(eq(canvasHandler), any(CanvasCommand.class));
}
Also used : GwtMockitoTestRunner(com.google.gwtmockito.GwtMockitoTestRunner) CanvasCommandFactory(org.kie.workbench.common.stunner.core.client.command.CanvasCommandFactory) Mock(org.mockito.Mock) Index(org.kie.workbench.common.stunner.core.graph.processing.index.Index) RunWith(org.junit.runner.RunWith) 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) Mockito.verify(org.mockito.Mockito.verify) CanvasCommand(org.kie.workbench.common.stunner.core.client.command.CanvasCommand) ClientTranslationService(org.kie.workbench.common.stunner.core.client.i18n.ClientTranslationService) 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) Matchers.eq(org.mockito.Matchers.eq) Mockito.any(org.mockito.Mockito.any) Node(org.kie.workbench.common.stunner.core.graph.Node) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) Mockito.mock(org.mockito.Mockito.mock) 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)

Example 5 with AbstractCanvasHandler

use of org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler in project kie-wb-common by kiegroup.

the class DeleteNodeActionTest 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)).deleteNode(eq(element));
    verify(sessionCommandManager, times(1)).execute(eq(canvasHandler), eq(deleteNodeCommand));
}
Also used : 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)

Aggregations

AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)60 CanvasViolation (org.kie.workbench.common.stunner.core.client.command.CanvasViolation)37 Test (org.junit.Test)30 DMNGridRow (org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridRow)15 CompositeCommand (org.kie.workbench.common.stunner.core.command.impl.CompositeCommand)10 Node (org.kie.workbench.common.stunner.core.graph.Node)10 Command (org.kie.workbench.common.stunner.core.command.Command)9 GraphCommandExecutionContext (org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext)9 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)9 List (org.kie.workbench.common.dmn.api.definition.v1_1.List)8 Edge (org.kie.workbench.common.stunner.core.graph.Edge)8 Point2D (org.kie.workbench.common.stunner.core.graph.content.view.Point2D)7 DecisionRule (org.kie.workbench.common.dmn.api.definition.v1_1.DecisionRule)6 CommandResult (org.kie.workbench.common.stunner.core.command.CommandResult)6 View (org.kie.workbench.common.stunner.core.graph.content.view.View)6 BaseGridRow (org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow)6 Collectors (java.util.stream.Collectors)5 LiteralExpression (org.kie.workbench.common.dmn.api.definition.v1_1.LiteralExpression)5 CanvasSelectionEvent (org.kie.workbench.common.stunner.core.client.canvas.event.selection.CanvasSelectionEvent)5 CanvasCommandFactory (org.kie.workbench.common.stunner.core.client.command.CanvasCommandFactory)5