Search in sources :

Example 21 with AbstractCanvasHandler

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

the class CaseManagementContainmentAcceptorControlImpl method evaluate.

private boolean evaluate(final Element parent, final Node[] children, final Function<Command<AbstractCanvasHandler, CanvasViolation>, CommandResult<CanvasViolation>> executor) {
    if (parent == null && (children == null || children.length == 0)) {
        return false;
    }
    final Node child = children[0];
    final Optional<Edge<?, Node>> edge = getFirstIncomingEdge(child, e -> e.getContent() instanceof Child);
    if (edge.isPresent()) {
        final Command<AbstractCanvasHandler, CanvasViolation> command = buildCommands(parent, child, edge.get());
        final CommandResult<CanvasViolation> result = executor.apply(command);
        return isCommandSuccess(result);
    }
    return true;
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) Node(org.kie.workbench.common.stunner.core.graph.Node) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Child(org.kie.workbench.common.stunner.core.graph.content.relationship.Child)

Example 22 with AbstractCanvasHandler

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

the class StartEventFilterProvider method isParentAnEventSubProcess.

private boolean isParentAnEventSubProcess(final String uuid) {
    AbstractCanvasHandler canvasHandler = (AbstractCanvasHandler) sessionManager.getCurrentSession().getCanvasHandler();
    Node node = canvasHandler.getGraphIndex().getNode(uuid);
    Element<?> parent = GraphUtils.getParent(node);
    if (null != parent && null != parent.asNode() && parent.asNode().getContent() instanceof View) {
        return ((Node<View<?>, Edge>) parent.asNode()).getContent().getDefinition().getClass().equals(EventSubprocess.class);
    }
    return false;
}
Also used : AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) Node(org.kie.workbench.common.stunner.core.graph.Node) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Example 23 with AbstractCanvasHandler

use of org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler 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 24 with AbstractCanvasHandler

use of org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler 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 25 with AbstractCanvasHandler

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

the class CanvasDefinitionTooltipTest method testConfigure.

@Test
public void testConfigure() {
    final AbstractCanvasHandler canvasHandler = mock(AbstractCanvasHandler.class);
    final AbstractCanvas canvas = mock(AbstractCanvas.class);
    final AbstractCanvas.View canvasView = mock(AbstractCanvas.View.class);
    final Layer layer = mock(Layer.class);
    final Transform transform = mock(Transform.class);
    when(canvasHandler.getCanvas()).thenReturn(canvas);
    when(canvasHandler.getAbstractCanvas()).thenReturn(canvas);
    when(canvas.getLayer()).thenReturn(layer);
    when(layer.getTransform()).thenReturn(transform);
    when(canvas.getView()).thenReturn(canvasView);
    when(canvasView.getAbsoluteX()).thenReturn(220d);
    when(canvasView.getAbsoluteY()).thenReturn(50.5d);
    final CanvasDefinitionTooltip t = tested.configure(canvasHandler);
    assertEquals(tested, t);
    verify(textTooltip, times(1)).setTransform(eq(transform));
    final ArgumentCaptor<Point2D> pointCaptor = ArgumentCaptor.forClass(Point2D.class);
    verify(textTooltip, times(1)).setCanvasLocation(pointCaptor.capture());
    final Point2D point = pointCaptor.getValue();
    assertEquals(220d, point.getX(), 0);
    assertEquals(50.5d, point.getY(), 0);
}
Also used : AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) AbstractCanvas(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvas) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) Transform(org.kie.workbench.common.stunner.core.client.canvas.Transform) Layer(org.kie.workbench.common.stunner.core.client.canvas.Layer) 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