use of org.kie.workbench.common.stunner.core.client.shape.EdgeShape 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.client.shape.EdgeShape 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);
}
use of org.kie.workbench.common.stunner.core.client.shape.EdgeShape in project kie-wb-common by kiegroup.
the class ConnectorDragProxyImpl method show.
@Override
@SuppressWarnings("unchecked")
public DragProxy<AbstractCanvasHandler, Item, DragProxyCallback> show(final Item item, final int x, final int y, final DragProxyCallback callback) {
// Source connector's shape - Obtain the shape for the source node.
final Node<View<?>, Edge> sourceNode = item.getSourceNode();
final Shape<?> sourceNodeShape = getCanvas().getShape(sourceNode.getUUID());
// Target connector's shape - Create a temporary shape view, that will act as the connector's target node.
final WiresShapeView transientShapeView = new WiresShapeView<>(new MultiPath().rect(0, 0, 1, 1).setFillAlpha(0).setStrokeAlpha(0));
getWiresManager().getMagnetManager().createMagnets(transientShapeView);
// Create the transient connector's shape and view.
final Edge<View<?>, Node> edge = item.getEdge();
final Shape<?> edgeShape = ((ShapeFactory<Object, ?>) item.getShapeFactory()).newShape(edge.getContent().getDefinition());
final EdgeShape connectorShape = (EdgeShape) edgeShape;
this.connectorShapeView = (WiresConnectorView<?>) edgeShape.getShapeView();
// Register and update shape's view as for edge bean's state.
getWiresManager().register(connectorShapeView);
connectorShape.applyProperties(edge, MutationContext.STATIC);
// Apply connector's connections for both source and target shapes.
// Using center connector strategy, so magnet index 0.
final MagnetConnection centerConnection = new MagnetConnection.Builder().atX(0).atY(0).magnet(0).build();
connectorShapeView.connect(sourceNodeShape.getShapeView(), centerConnection, transientShapeView, centerConnection);
// Optimize the index and show the drag proxy for the temporary shape view.
graphBoundsIndexer.build(canvasHandler.getDiagram().getGraph());
shapeViewDragProxyFactory.show(transientShapeView, x, y, new DragProxyCallback() {
@Override
public void onStart(final int x, final int y) {
callback.onStart(x, y);
// As using center magnet, update the connection.
connectorShapeView.updateForCenterConnection();
}
@Override
public void onMove(final int x, final int y) {
callback.onMove(x, y);
// As using center magnet, update the connection.
connectorShapeView.updateForCenterConnection();
}
@Override
public void onComplete(final int x, final int y) {
callback.onComplete(x, y);
deregisterTransientConnector();
getCanvas().draw();
}
});
return this;
}
use of org.kie.workbench.common.stunner.core.client.shape.EdgeShape in project kie-wb-common by kiegroup.
the class ShapeUtilsTest method testApplyConnections.
@Test
@SuppressWarnings("unchecked")
public void testApplyConnections() {
final Shape startNodeShape = mock(Shape.class);
final ShapeView startNodeShapeView = mock(ShapeView.class);
final Shape intermNodeShape = mock(Shape.class);
final ShapeView intermNodeShapeView = mock(ShapeView.class);
final EdgeShape edge1EdgeShape = mock(EdgeShape.class);
when(canvas.getShape(eq(instance2.startNode.getUUID()))).thenReturn(startNodeShape);
when(canvas.getShape(eq(instance2.intermNode.getUUID()))).thenReturn(intermNodeShape);
when(canvas.getShape(eq(instance2.edge1.getUUID()))).thenReturn(edge1EdgeShape);
when(startNodeShape.getShapeView()).thenReturn(startNodeShapeView);
when(intermNodeShape.getShapeView()).thenReturn(intermNodeShapeView);
when(edge1EdgeShape.getShapeView()).thenReturn(edge1ShapeView);
ShapeUtils.applyConnections(instance2.edge1, canvasHandler, MutationContext.STATIC);
verify(edge1EdgeShape, times(1)).applyConnections(eq(instance2.edge1), eq(startNodeShapeView), eq(intermNodeShapeView), eq(MutationContext.STATIC));
}
use of org.kie.workbench.common.stunner.core.client.shape.EdgeShape in project kie-wb-common by kiegroup.
the class ConnectorProxyTest method testStart.
@Test
@SuppressWarnings("unchecked")
public void testStart() {
CanvasCommand<AbstractCanvasHandler> command = mock(CanvasCommand.class);
doReturn(command).when(commandFactory).addConnector(eq(sourceNode), eq(edge), any(MagnetConnection.class), eq(SHAPE_SET_ID));
double x = 1d;
double y = 2d;
tested.init();
tested.start(x, y);
verify(proxy, times(1)).start(eq(x), eq(y));
EdgeShape edgeShape = view.getShapeBuilder().get();
assertEquals(connector, edgeShape);
verify(proxy, times(1)).execute(eq(command));
}
Aggregations