use of org.kie.workbench.common.stunner.client.lienzo.shape.view.wires.WiresConnectorView 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.client.lienzo.shape.view.wires.WiresConnectorView in project kie-wb-common by kiegroup.
the class WiresCanvasViewTest method testRemoveConnector.
@Test
public void testRemoveConnector() {
final WiresConnectorView view = createConnector();
canvas.addShape(view);
assertTrue(canvas.getWiresManager().getConnectorList().contains(view));
canvas.removeShape(view);
assertFalse(canvas.getWiresManager().getConnectorList().contains(view));
}
use of org.kie.workbench.common.stunner.client.lienzo.shape.view.wires.WiresConnectorView in project kie-wb-common by kiegroup.
the class WiresCanvasView method addShape.
@Override
public WiresCanvas.View addShape(final ShapeView<?> shapeView) {
if (WiresUtils.isWiresShape(shapeView)) {
WiresShape wiresShape = (WiresShape) shapeView;
wiresManager.register(wiresShape);
wiresManager.getMagnetManager().createMagnets(wiresShape, getMagnetCardinals());
WiresUtils.assertShapeGroup(wiresShape.getGroup(), WiresCanvas.WIRES_CANVAS_GROUP_ID);
} else if (WiresUtils.isWiresConnector(shapeView)) {
WiresConnector wiresConnector = (WiresConnector) shapeView;
final WiresConnectorControl connectorControl = wiresManager.register(wiresConnector);
if (shapeView instanceof WiresConnectorView) {
((WiresConnectorView) shapeView).setControl(connectorControl);
}
WiresUtils.assertShapeGroup(wiresConnector.getGroup(), WiresCanvas.WIRES_CANVAS_GROUP_ID);
} else {
super.addShape(shapeView);
}
return this;
}
use of org.kie.workbench.common.stunner.client.lienzo.shape.view.wires.WiresConnectorView in project kie-wb-common by kiegroup.
the class WiresCanvasViewTest method assertStunnerConnectorGroupId.
@Test
public void assertStunnerConnectorGroupId() {
final WiresConnectorView view = createConnector();
canvas.addShape(view);
assertEquals(WiresCanvas.WIRES_CANVAS_GROUP_ID, WiresUtils.getShapeGroup(view.getGroup()));
}
use of org.kie.workbench.common.stunner.client.lienzo.shape.view.wires.WiresConnectorView in project kie-wb-common by kiegroup.
the class WiresCanvasViewTest method testAddConnector.
@Test
public void testAddConnector() {
final WiresConnectorView view = createConnector();
canvas.addShape(view);
assertTrue(canvas.getWiresManager().getConnectorList().contains(view));
}
Aggregations