Search in sources :

Example 66 with Element

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

the class BaseCanvasHandlerTest method getElementAtWhenCanvasHasShapeAtPosition.

@Test
@SuppressWarnings("unchecked")
public void getElementAtWhenCanvasHasShapeAtPosition() {
    final Optional<Shape> oShape = Optional.of(mock(Shape.class));
    final Index index = mock(Index.class);
    final Node n = mock(Node.class);
    when(canvas.getShapeAt(anyDouble(), anyDouble())).thenReturn(oShape);
    when(commandExecutionContext.getGraphIndex()).thenReturn(index);
    when(index.getNode(anyString())).thenReturn(n);
    final Optional<Element> oElement = tested.getElementAt(0.0, 0.0);
    assertTrue(oElement.isPresent());
}
Also used : ElementShape(org.kie.workbench.common.stunner.core.client.shape.ElementShape) Shape(org.kie.workbench.common.stunner.core.client.shape.Shape) Node(org.kie.workbench.common.stunner.core.graph.Node) Element(org.kie.workbench.common.stunner.core.graph.Element) Index(org.kie.workbench.common.stunner.core.graph.processing.index.Index) Test(org.junit.Test)

Example 67 with Element

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

the class DockNodeCommand method check.

@SuppressWarnings("unchecked")
protected CommandResult<RuleViolation> check(final GraphCommandExecutionContext context) {
    final Element<? extends Definition<?>> parent = (Element<? extends Definition<?>>) getParent(context);
    final Node<Definition<?>, Edge> candidate = (Node<Definition<?>, Edge>) getCandidate(context);
    final Collection<RuleViolation> dockingRuleViolations = doEvaluate(context, RuleContextBuilder.GraphContexts.docking(getGraph(context), parent, candidate));
    return new GraphCommandResultBuilder(dockingRuleViolations).build();
}
Also used : GraphCommandResultBuilder(org.kie.workbench.common.stunner.core.graph.command.GraphCommandResultBuilder) Element(org.kie.workbench.common.stunner.core.graph.Element) Node(org.kie.workbench.common.stunner.core.graph.Node) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Example 68 with Element

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

the class SetParentNodeCommand method check.

@SuppressWarnings("unchecked")
protected CommandResult<RuleViolation> check(final GraphCommandExecutionContext context) {
    final Element<? extends Definition<?>> parent = (Element<? extends Definition<?>>) getParent(context);
    final Node<Definition<?>, Edge> candidate = (Node<Definition<?>, Edge>) getCandidate(context);
    final Collection<RuleViolation> containmentRuleViolations = doEvaluate(context, RuleContextBuilder.GraphContexts.containment(getGraph(context), parent, candidate));
    return new GraphCommandResultBuilder(containmentRuleViolations).build();
}
Also used : GraphCommandResultBuilder(org.kie.workbench.common.stunner.core.graph.command.GraphCommandResultBuilder) Element(org.kie.workbench.common.stunner.core.graph.Element) Node(org.kie.workbench.common.stunner.core.graph.Node) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Example 69 with Element

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

the class TestingGraphUtils method verifyCardinality.

public static void verifyCardinality(final ElementCardinalityContext context, final Graph graph, final Element<? extends View<?>> candidate, final CardinalityContext.Operation operation) {
    assertNotNull(context);
    final Graph graph1 = context.getGraph();
    final Optional<Element<? extends View<?>>> candidate1 = context.getCandidate();
    final Optional<CardinalityContext.Operation> operation1 = context.getOperation();
    assertNotNull(graph1);
    assertNotNull(operation1);
    assertEquals(graph, graph1);
    assertEquals(candidate, candidate1.orElse(null));
    assertEquals(operation, operation1.orElse(null));
}
Also used : Graph(org.kie.workbench.common.stunner.core.graph.Graph) Element(org.kie.workbench.common.stunner.core.graph.Element) View(org.kie.workbench.common.stunner.core.graph.content.view.View)

Example 70 with Element

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

the class MagnetConnectionTest method testForElement.

@Test
@SuppressWarnings("unchecked")
public void testForElement() {
    Element element = mock(Element.class);
    View<?> content = mock(View.class);
    BoundsImpl bounds = new BoundsImpl(new BoundImpl(10d, 20d), new BoundImpl(100d, 200d));
    when(element.getContent()).thenReturn(content);
    when(content.getBounds()).thenReturn(bounds);
    MagnetConnection m1 = MagnetConnection.Builder.forElement(element);
    assertEquals(45, m1.getLocation().getX(), 0);
    assertEquals(90, m1.getLocation().getY(), 0);
    assertEquals(MagnetConnection.MAGNET_CENTER, m1.getMagnetIndex().getAsInt());
    assertFalse(m1.isAuto());
}
Also used : Element(org.kie.workbench.common.stunner.core.graph.Element) Test(org.junit.Test)

Aggregations

Element (org.kie.workbench.common.stunner.core.graph.Element)85 Test (org.junit.Test)55 View (org.kie.workbench.common.stunner.core.graph.content.view.View)34 Graph (org.kie.workbench.common.stunner.core.graph.Graph)27 FlowElement (org.eclipse.bpmn2.FlowElement)24 ItemAwareElement (org.eclipse.bpmn2.ItemAwareElement)24 RootElement (org.eclipse.bpmn2.RootElement)24 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)24 Definition (org.kie.workbench.common.stunner.core.graph.content.definition.Definition)14 Edge (org.kie.workbench.common.stunner.core.graph.Edge)12 Node (org.kie.workbench.common.stunner.core.graph.Node)11 Map (java.util.Map)7 Optional (java.util.Optional)6 Before (org.junit.Before)6 Collection (java.util.Collection)5 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)5 Shape (org.kie.workbench.common.stunner.core.client.shape.Shape)5 Matchers.anyString (org.mockito.Matchers.anyString)5 Logger (java.util.logging.Logger)4 BPMNDiagram (org.kie.workbench.common.stunner.bpmn.definition.BPMNDiagram)4