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());
}
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();
}
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();
}
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));
}
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());
}
Aggregations