use of org.kie.workbench.common.stunner.client.lienzo.shape.view.wires.WiresShapeView 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.WiresShapeView in project kie-wb-common by kiegroup.
the class LocationControlImplTest method testLocationAcceptor.
@Test
@SuppressWarnings("unchecked")
public void testLocationAcceptor() {
tested.enable(canvasHandler);
tested.register(element);
ArgumentCaptor<ILocationAcceptor> locationAcceptorArgumentCaptor = ArgumentCaptor.forClass(ILocationAcceptor.class);
verify(wiresManager, times(1)).setLocationAcceptor(locationAcceptorArgumentCaptor.capture());
final ILocationAcceptor locationAcceptor = locationAcceptorArgumentCaptor.getValue();
final WiresShapeView wiresContainer = mock(WiresShapeView.class);
when(wiresContainer.getUUID()).thenReturn(ELEMENT_UUID);
final com.ait.lienzo.client.core.types.Point2D point = new com.ait.lienzo.client.core.types.Point2D(40d, 50d);
locationAcceptor.accept(new WiresContainer[] { wiresContainer }, new com.ait.lienzo.client.core.types.Point2D[] { point });
ArgumentCaptor<CanvasCommand> commandArgumentCaptor = ArgumentCaptor.forClass(CanvasCommand.class);
verify(commandManager, times(1)).execute(eq(canvasHandler), commandArgumentCaptor.capture());
final UpdateElementPositionCommand command = (UpdateElementPositionCommand) commandArgumentCaptor.getValue();
assertEquals(element, command.getElement());
assertEquals(new Point2D(40d, 50d), command.getLocation());
}
use of org.kie.workbench.common.stunner.client.lienzo.shape.view.wires.WiresShapeView in project kie-wb-common by kiegroup.
the class WiresCanvasViewTest method testAddShape.
@Test
public void testAddShape() {
final WiresShapeView view = createShape();
canvas.addShape(view);
assertNotNull(canvas.getWiresManager().getShape(view.uuid()));
}
use of org.kie.workbench.common.stunner.client.lienzo.shape.view.wires.WiresShapeView in project kie-wb-common by kiegroup.
the class WiresCanvasViewTest method assertStunnerShapeGroupId.
@Test
public void assertStunnerShapeGroupId() {
final WiresShapeView view = createShape();
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.WiresShapeView in project kie-wb-common by kiegroup.
the class WiresCanvasViewTest method testRemoveShape.
@Test
public void testRemoveShape() {
final WiresShapeView view = createShape();
canvas.addShape(view);
assertNotNull(canvas.getWiresManager().getShape(view.uuid()));
canvas.removeShape(view);
assertNull(canvas.getWiresManager().getShape(view.uuid()));
}
Aggregations