Search in sources :

Example 41 with View

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

the class CanvasLayoutUtilsTest method getNextFromRootWithParent.

@Test
@SuppressWarnings("unchecked")
public void getNextFromRootWithParent() {
    this.graphTestHandlerParent = new TestingGraphMockHandler();
    graphInstanceParent = TestingGraphInstanceBuilder.newGraph2(graphTestHandlerParent);
    Node node = mock(Node.class);
    Bounds boundsNode = new BoundsImpl(new BoundImpl(100d, 100d), new BoundImpl(300d, 200d));
    View viewNode = mock(View.class);
    when(node.getContent()).thenReturn(viewNode);
    when(viewNode.getBounds()).thenReturn(boundsNode);
    when(canvasHandler.getDiagram().getGraph()).thenReturn(graphInstanceParent.graph);
    Point2D next = canvasLayoutUtils.getNext(canvasHandler, graphInstanceParent.startNode, node);
    Node<View<?>, Edge> start = (Node<View<?>, Edge>) graphInstanceParent.startNode;
    double[] size = GraphUtils.getNodeSize(start.getContent());
    assertTrue(next.getX() == CanvasLayoutUtils.getPaddingX());
    assertTrue(next.getY() > size[1]);
}
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) 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) Test(org.junit.Test)

Example 42 with View

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

the class CanvasLayoutUtilsTest method getNextNewTaskWithNonEmptyPosition.

// TODO (AlessioP & Roger):
@Test
@Ignore
@SuppressWarnings("unchecked")
public void getNextNewTaskWithNonEmptyPosition() {
    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 newNode = mock(Node.class);
    Bounds boundsNewNode = new BoundsImpl(new BoundImpl(200d, 300d), new BoundImpl(300d, 400d));
    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, 100.0, 100.0, null)).thenReturn(graphInstance.intermNode);
    graphInstance.startNode.getOutEdges().clear();
    Point2D next = canvasLayoutUtils.getNext(canvasHandler, graphInstance.startNode, newNode);
    Node<View<?>, Edge> startNode = (Node<View<?>, Edge>) graphInstance.startNode;
    double[] sizeStartNode = GraphUtils.getNodeSize(startNode.getContent());
    Node<View<?>, Edge> intermNode = (Node<View<?>, Edge>) graphInstance.intermNode;
    double[] sizeIntermNode = GraphUtils.getNodeSize(intermNode.getContent());
    assertTrue(next.getX() == sizeStartNode[0] + CanvasLayoutUtils.getPaddingX());
    assertTrue(next.getY() > sizeIntermNode[1]);
}
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 43 with View

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

the class GraphBoundsIndexerImplTest method testGetAreaAt.

@Test
public void testGetAreaAt() {
    Point2D position = GraphUtils.getPosition((View) graphInstanceParent.startNode.getContent());
    double[] size = GraphUtils.getNodeSize((View) graphInstanceParent.startNode.getContent());
    double getAtX = position.getX() + (size[0] / 2);
    double getAtY = position.getY() + (size[1] / 2);
    Node<View<?>, Edge> node = graphBoundsIndexerImpl.getAt(getAtX, getAtY, size[0], size[1], graphInstanceParent.parentNode);
    assertNotNull(node);
    Node<View<?>, Edge> nodeFreePosition = graphBoundsIndexerImpl.getAt(getAtX, getAtY + 400, size[0], size[1], graphInstanceParent.parentNode);
    assertNull(nodeFreePosition);
}
Also used : Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Test(org.junit.Test)

Example 44 with View

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

the class GraphBoundsIndexerImplTest method testGetAreaAtWithParent.

@Test
public void testGetAreaAtWithParent() {
    Point2D position = GraphUtils.getPosition((View) graphInstanceParent.startNode.getContent());
    double[] size = GraphUtils.getNodeSize((View) graphInstanceParent.startNode.getContent());
    double getAtX = position.getX() + (size[0] / 2);
    double getAtY = position.getY() + (size[1] / 2);
    Node<View<?>, Edge> node = graphBoundsIndexerImpl.getAt(getAtX, getAtY, size[0], size[1], graphInstanceParent.parentNode);
    assertNotNull(node);
    Node<View<?>, Edge> nodeAtFreePosition = graphBoundsIndexerImpl.getAt(getAtX, getAtY + 200, size[0], size[1], graphInstanceParent.parentNode);
    assertNull(nodeAtFreePosition);
}
Also used : Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Test(org.junit.Test)

Example 45 with View

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

the class AbstractGraphRuleHandlerTest method mockNode.

@SuppressWarnings("unchecked")
protected Node mockNode(String id, Set<String> labels) {
    Node e = mock(Node.class);
    View v = mock(View.class);
    Object d = mock(Object.class);
    when(e.getContent()).thenReturn(v);
    when(v.getDefinition()).thenReturn(d);
    when(definitionAdapter.getId(eq(d))).thenReturn(id);
    when(definitionAdapter.getLabels(eq(d))).thenReturn(labels);
    when(e.getLabels()).thenReturn(labels);
    return e;
}
Also used : Node(org.kie.workbench.common.stunner.core.graph.Node) View(org.kie.workbench.common.stunner.core.graph.content.view.View)

Aggregations

View (org.kie.workbench.common.stunner.core.graph.content.view.View)144 Edge (org.kie.workbench.common.stunner.core.graph.Edge)100 Node (org.kie.workbench.common.stunner.core.graph.Node)57 Test (org.junit.Test)49 Graph (org.kie.workbench.common.stunner.core.graph.Graph)45 Element (org.kie.workbench.common.stunner.core.graph.Element)36 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)32 BPMNGeneralSet (org.kie.workbench.common.stunner.bpmn.definition.property.general.BPMNGeneralSet)31 Documentation (org.kie.workbench.common.stunner.bpmn.definition.property.general.Documentation)31 Name (org.kie.workbench.common.stunner.bpmn.definition.property.general.Name)31 FlowElement (org.eclipse.bpmn2.FlowElement)26 ItemAwareElement (org.eclipse.bpmn2.ItemAwareElement)26 RootElement (org.eclipse.bpmn2.RootElement)26 Bounds (org.kie.workbench.common.stunner.core.graph.content.Bounds)21 EventPropertyReader (org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.properties.EventPropertyReader)16 Point2D (org.kie.workbench.common.stunner.core.graph.content.view.Point2D)16 DataIOSet (org.kie.workbench.common.stunner.bpmn.definition.property.dataio.DataIOSet)14 BoundImpl (org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl)12 BoundsImpl (org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl)12 ProcessVariables (org.kie.workbench.common.stunner.bpmn.definition.property.variables.ProcessVariables)10