Search in sources :

Example 36 with Point2D

use of org.kie.workbench.common.stunner.core.graph.content.view.Point2D in project kie-wb-common by kiegroup.

the class CanvasLayoutUtilsTest method getNextOutOfCanvas.

// TODO (AlessioP & Roger):
@Test
@Ignore
@SuppressWarnings("unchecked")
public void getNextOutOfCanvas() {
    when(ruleManager.evaluate(eq(ruleSet), any(RuleEvaluationContext.class))).thenReturn(ruleViolations);
    when(ruleViolations.violations(Violation.Type.ERROR)).thenReturn(ruleViolationIterable);
    when(ruleViolations.violations(Violation.Type.ERROR).iterator()).thenReturn(ruleViolationIterator);
    when(ruleViolations.violations(Violation.Type.ERROR).iterator().hasNext()).thenReturn(true);
    this.graphTestHandler = new TestingGraphMockHandler();
    graphInstance = TestingGraphInstanceBuilder.newGraph1(graphTestHandler);
    Node node = mock(Node.class);
    Bounds boundsNode = new BoundsImpl(new BoundImpl(100d, 0d), new BoundImpl(300d, 1400d));
    View viewNode = mock(View.class);
    when(node.getContent()).thenReturn(viewNode);
    when(viewNode.getBounds()).thenReturn(boundsNode);
    Node newNode = mock(Node.class);
    Bounds boundsNewNode = new BoundsImpl(new BoundImpl(100d, 200d), new BoundImpl(300d, 300d));
    View viewNewNode = mock(View.class);
    when(newNode.getContent()).thenReturn(viewNewNode);
    when(viewNewNode.getBounds()).thenReturn(boundsNewNode);
    when(canvasHandler.getDiagram().getGraph()).thenReturn(graphInstance.graph);
    when(graphBoundsIndexer.getAt(140.0, 0.0, 200.0, 100.0, null)).thenReturn(node);
    graphInstance.startNode.getOutEdges().clear();
    Point2D next = canvasLayoutUtils.getNext(canvasHandler, graphInstance.startNode, newNode);
    Node<View<?>, Edge> intermNode = (Node<View<?>, Edge>) graphInstance.intermNode;
    double[] size = GraphUtils.getNodeSize(intermNode.getContent());
    assertTrue(next.getX() > size[0]);
    assertTrue(next.getY() == CanvasLayoutUtils.getPaddingY());
}
Also used : Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) Node(org.kie.workbench.common.stunner.core.graph.Node) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) BoundImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl) RuleEvaluationContext(org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext) TestingGraphMockHandler(org.kie.workbench.common.stunner.core.TestingGraphMockHandler) BoundsImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 37 with Point2D

use of org.kie.workbench.common.stunner.core.graph.content.view.Point2D 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 38 with Point2D

use of org.kie.workbench.common.stunner.core.graph.content.view.Point2D 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)

Example 39 with Point2D

use of org.kie.workbench.common.stunner.core.graph.content.view.Point2D in project kie-wb-common by kiegroup.

the class CanvasDefinitionTooltipTest method testShowById.

@Test
public void testShowById() {
    final Point2D point = new Point2D(55, 6);
    tested.show("def1", point);
    verify(textTooltip, times(1)).show(eq("def1theTestTitle"), eq(point));
    verify(textTooltip, never()).hide();
    verify(textTooltip, never()).destroy();
}
Also used : Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) Test(org.junit.Test)

Example 40 with Point2D

use of org.kie.workbench.common.stunner.core.graph.content.view.Point2D in project kie-wb-common by kiegroup.

the class NodeShapeImplTest method testApplyPosition.

@Test
public void testApplyPosition() {
    tested.applyPosition(element, MutationContext.STATIC);
    verify(view, times(1)).setShapeLocation(new Point2D(10d, 20d));
}
Also used : Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) Test(org.junit.Test)

Aggregations

Point2D (org.kie.workbench.common.stunner.core.graph.content.view.Point2D)55 Test (org.junit.Test)25 Edge (org.kie.workbench.common.stunner.core.graph.Edge)18 View (org.kie.workbench.common.stunner.core.graph.content.view.View)17 Node (org.kie.workbench.common.stunner.core.graph.Node)15 Command (org.kie.workbench.common.stunner.core.command.Command)10 BoundImpl (org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl)10 BoundsImpl (org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl)10 Before (org.junit.Before)9 Bounds (org.kie.workbench.common.stunner.core.graph.content.Bounds)7 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)6 CompositeCommand (org.kie.workbench.common.stunner.core.command.impl.CompositeCommand)6 TestingGraphMockHandler (org.kie.workbench.common.stunner.core.TestingGraphMockHandler)5 UpdateElementPositionCommand (org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPositionCommand)5 Ignore (org.junit.Ignore)4 Element (org.kie.workbench.common.stunner.core.graph.Element)4 AbstractCanvas (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvas)3 CanvasCommand (org.kie.workbench.common.stunner.core.client.command.CanvasCommand)3 ShapeView (org.kie.workbench.common.stunner.core.client.shape.view.ShapeView)3 CommandResult (org.kie.workbench.common.stunner.core.command.CommandResult)3