use of org.kie.workbench.common.stunner.core.graph.Node in project kie-wb-common by kiegroup.
the class GraphValidatorImplTest method testValidateGraph2.
@Test
@SuppressWarnings("unchecked")
public void testValidateGraph2() {
final RuleManager ruleManager = graphTestHandler.ruleManager;
final RuleSet ruleSet = graphTestHandler.ruleSet;
final Graph<DefinitionSet, Node> graph = graphTestHandler.graph;
final TestingGraphInstanceBuilder.TestGraph2 testGraph2 = TestingGraphInstanceBuilder.newGraph2(graphTestHandler);
tested.validate(getGraph(), graphTestHandler.ruleSet, this::assertNoError);
final int evalCount = testGraph2.evaluationsCount + 11;
final ArgumentCaptor<RuleEvaluationContext> contextCaptor = ArgumentCaptor.forClass(RuleEvaluationContext.class);
verify(ruleManager, times(evalCount)).evaluate(eq(ruleSet), contextCaptor.capture());
final List<RuleEvaluationContext> contexts = contextCaptor.getAllValues();
assertEquals(evalCount, contexts.size());
int cindex = testGraph2.evaluationsCount;
verifyCardinality((ElementCardinalityContext) contexts.get(cindex++), graph);
verifyContainment((NodeContainmentContext) contexts.get(cindex++), graph, testGraph2.parentNode);
verifyContainment((NodeContainmentContext) contexts.get(cindex++), testGraph2.parentNode, testGraph2.startNode);
verifyConnection((GraphConnectionContext) contexts.get(cindex++), testGraph2.edge1, testGraph2.startNode, testGraph2.intermNode);
verifyConnectorCardinality((ConnectorCardinalityContext) contexts.get(cindex++), graph, testGraph2.intermNode, testGraph2.edge1, EdgeCardinalityContext.Direction.INCOMING, Optional.empty());
verifyConnectorCardinality((ConnectorCardinalityContext) contexts.get(cindex++), graph, testGraph2.startNode, testGraph2.edge1, EdgeCardinalityContext.Direction.OUTGOING, Optional.empty());
verifyContainment((NodeContainmentContext) contexts.get(cindex++), testGraph2.parentNode, testGraph2.intermNode);
verifyConnection((GraphConnectionContext) contexts.get(cindex++), testGraph2.edge2, testGraph2.intermNode, testGraph2.endNode);
verifyConnectorCardinality((ConnectorCardinalityContext) contexts.get(cindex++), graph, testGraph2.endNode, testGraph2.edge2, EdgeCardinalityContext.Direction.INCOMING, Optional.empty());
verifyConnectorCardinality((ConnectorCardinalityContext) contexts.get(cindex++), graph, testGraph2.intermNode, testGraph2.edge2, EdgeCardinalityContext.Direction.OUTGOING, Optional.empty());
verifyContainment((NodeContainmentContext) contexts.get(cindex++), testGraph2.parentNode, testGraph2.endNode);
}
use of org.kie.workbench.common.stunner.core.graph.Node in project kie-wb-common by kiegroup.
the class NodeDragProxyImpl method show.
@Override
@SuppressWarnings("unchecked")
public DragProxy<AbstractCanvasHandler, Item, NodeDragProxyCallback> show(final Item item, final int x, final int y, final NodeDragProxyCallback callback) {
final AbstractCanvas canvas = canvasHandler.getAbstractCanvas();
final Node<View<?>, Edge> node = item.getNode();
final ShapeFactory<Object, ?> nodeShapeFactory = item.getNodeShapeFactory();
final Edge<View<?>, Node> inEdge = item.getInEdge();
final Node<View<?>, Edge> inEdgeSourceNode = item.getInEdgeSourceNode();
final ShapeFactory<Object, ?> edgeShapeFactory = item.getInEdgeShapeFactory();
final Shape nodeShape = nodeShapeFactory.newShape(node.getContent().getDefinition());
if (nodeShape instanceof ElementShape) {
((ElementShape) nodeShape).applyProperties(node, MutationContext.STATIC);
}
this.transientEdgeShape = (EdgeShape) edgeShapeFactory.newShape(inEdge.getContent().getDefinition());
canvas.addTransientShape(this.transientEdgeShape);
this.transientEdgeShape.applyProperties(inEdge, MutationContext.STATIC);
final Shape<?> edgeSourceNodeShape = canvasHandler.getCanvas().getShape(inEdgeSourceNode.getUUID());
shapeDragProxyFactory.show(nodeShape, x, y, new DragProxyCallback() {
@Override
public void onStart(final int x, final int y) {
callback.onStart(x, y);
drawEdge();
}
@Override
public void onMove(final int x, final int y) {
callback.onMove(x, y);
drawEdge();
}
@Override
public void onComplete(final int x, final int y) {
final MagnetConnection[] connections = createShapeConnections();
callback.onComplete(x, y);
callback.onComplete(x, y, connections[0], connections[1]);
deleteTransientEdgeShape();
canvas.draw();
}
private void drawEdge() {
if (inEdge.getContent() instanceof ViewConnector) {
final ViewConnector viewConnector = (ViewConnector) inEdge.getContent();
final MagnetConnection[] connections = createShapeConnections();
viewConnector.setSourceConnection(connections[0]);
viewConnector.setTargetConnection(connections[1]);
}
NodeDragProxyImpl.this.transientEdgeShape.applyConnections(inEdge, edgeSourceNodeShape.getShapeView(), nodeShape.getShapeView(), MutationContext.STATIC);
canvas.draw();
}
private MagnetConnection[] createShapeConnections() {
return new MagnetConnection[] { MagnetConnection.Builder.forElement(inEdgeSourceNode), MagnetConnection.Builder.forElement(node) };
}
});
return this;
}
use of org.kie.workbench.common.stunner.core.graph.Node in project kie-wb-common by kiegroup.
the class CreateConnectorAction method showDragProxy.
@SuppressWarnings("unchecked")
private DragProxy<AbstractCanvasHandler, ConnectorDragProxy.Item, DragProxyCallback> showDragProxy(final AbstractCanvasHandler canvasHandler, final Edge<? extends ViewConnector<?>, Node> connector, final Node<? extends View<?>, Edge> sourceNode, final int x, final int y) {
// Built and show the drag proxy.
final String ssid = canvasHandler.getDiagram().getMetadata().getShapeSetId();
final ShapeFactory shapeFactory = canvasHandler.getShapeFactory(ssid);
final ConnectorDragProxy.Item connectorDragItem = new ConnectorDragProxy.Item() {
@Override
public Edge<? extends ViewConnector<?>, Node> getEdge() {
return connector;
}
@Override
public Node<? extends View<?>, Edge> getSourceNode() {
return sourceNode;
}
@Override
public ShapeFactory<?, ?> getShapeFactory() {
return shapeFactory;
}
};
return connectorDragProxyFactory.proxyFor(canvasHandler).show(connectorDragItem, x, y, new DragProxyCallback() {
@Override
public void onStart(final int x, final int y) {
start(canvasHandler);
}
@Override
public void onMove(final int x, final int y) {
final Node targetNode = graphBoundsIndexer.getAt(x, y);
final boolean allow = allow(x, y, connector, sourceNode, targetNode);
canvasHighlight.unhighLight();
if (null != targetNode && allow) {
canvasHighlight.highLight(targetNode);
} else if (null != targetNode) {
canvasHighlight.invalid(targetNode);
}
}
@Override
public void onComplete(final int x, final int y) {
final Node targetNode = graphBoundsIndexer.getAt(x, y);
accept(x, y, connector, sourceNode, targetNode);
}
});
}
use of org.kie.workbench.common.stunner.core.graph.Node in project kie-wb-common by kiegroup.
the class FlowActionsToolboxFactory method getActions.
@Override
@SuppressWarnings("unchecked")
public Collection<ToolboxAction<AbstractCanvasHandler>> getActions(final AbstractCanvasHandler canvasHandler, final Element<?> element) {
final Set<ToolboxAction<AbstractCanvasHandler>> actions = new LinkedHashSet<>();
final Node<Definition<Object>, Edge> node = (Node<Definition<Object>, Edge>) element;
final Diagram diagram = canvasHandler.getDiagram();
final String defSetId = diagram.getMetadata().getDefinitionSetId();
// Look for the default connector type and create a button for it.
commonLookups.getAllowedConnectors(defSetId, node, 0, 10).forEach(connectorDefId -> actions.add(createConnectorActions.get().setEdgeId(connectorDefId)));
// It uses the default connector's identifier, for the actual definition set,
// to check the resulting nodes that can be created.
// It also groups the resuling nodes to be created by it's morph base type, and just
// create an action for each morph target.
final String defaultConnectorId = definitionUtils.getDefaultConnectorId(defSetId);
if (null != defaultConnectorId) {
commonLookups.getAllowedMorphDefaultDefinitions(defSetId, diagram.getGraph(), node, defaultConnectorId, 0, 10).forEach(defId -> actions.add(createNodeActions.get().setEdgeId(defaultConnectorId).setNodeId(defId.toString())));
}
return actions;
}
use of org.kie.workbench.common.stunner.core.graph.Node in project kie-wb-common by kiegroup.
the class ShapeUtils method applyConnections.
@SuppressWarnings("unchecked")
public static void applyConnections(final Edge<?, ?> edge, final CanvasHandler canvasHandler, final MutationContext mutationContext) {
final Canvas<?> canvas = canvasHandler.getCanvas();
final Node sourceNode = edge.getSourceNode();
final Node targetNode = edge.getTargetNode();
final Shape<?> source = sourceNode != null ? canvas.getShape(sourceNode.getUUID()) : null;
final Shape<?> target = targetNode != null ? canvas.getShape(targetNode.getUUID()) : null;
EdgeShape connector = (EdgeShape) canvas.getShape(edge.getUUID());
connector.applyConnections(edge, source != null ? source.getShapeView() : null, target != null ? target.getShapeView() : null, mutationContext);
}
Aggregations