use of org.kie.workbench.common.stunner.core.client.components.drag.DragProxyCallback 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.client.components.drag.DragProxyCallback in project kie-wb-common by kiegroup.
the class CreateConnectorActionTest method testStartDrag.
@SuppressWarnings("unchecked")
private DragProxyCallback testStartDrag() {
final MouseClickEvent event = mock(MouseClickEvent.class);
when(event.getX()).thenReturn(100d);
when(event.getY()).thenReturn(500d);
when(graphBoundsIndexer.getAt(eq(100d), eq(500d))).thenReturn(targetNode);
ToolboxAction<AbstractCanvasHandler> cascade = tested.onMouseClick(canvasHandler, NODE_UUID, event);
assertEquals(tested, cascade);
verify(edge, times(1)).setSourceNode(eq(element));
verify(connectorDragProxyFactory, times(1)).proxyFor(eq(canvasHandler));
ArgumentCaptor<DragProxyCallback> proxyArgumentCaptor = ArgumentCaptor.forClass(DragProxyCallback.class);
verify(connectorDragProxyFactory, times(1)).show(any(ConnectorDragProxy.Item.class), eq(100), eq(500), proxyArgumentCaptor.capture());
final DragProxyCallback callback = proxyArgumentCaptor.getValue();
// Verify drag proxy start.
callback.onStart(0, 0);
assertNotNull(tested.getCanvasHighlight());
verify(graphBoundsIndexer, times(1)).setRootUUID(eq(ROOT_UUID));
verify(graphBoundsIndexer, times(1)).build(eq(graph));
verify(edgeBuilderControl, times(1)).enable(eq(canvasHandler));
ArgumentCaptor<RequiresCommandManager.CommandManagerProvider> providerArgumentCaptor = ArgumentCaptor.forClass(RequiresCommandManager.CommandManagerProvider.class);
verify(edgeBuilderControl, times(1)).setCommandManagerProvider(providerArgumentCaptor.capture());
RequiresCommandManager.CommandManagerProvider cmProvider = providerArgumentCaptor.getValue();
assertEquals(sessionCommandManager, cmProvider.getCommandManager());
return callback;
}
use of org.kie.workbench.common.stunner.core.client.components.drag.DragProxyCallback in project kie-wb-common by kiegroup.
the class CreateConnectorActionTest method testCancelConnector.
@Test
public void testCancelConnector() {
DragProxyCallback callback = testStartDrag();
assertTrue(dragProxy == tested.getDragProxy());
testMoveDrag(callback);
tested.cancelConnector(cancelCanvasAction);
verify(dragProxy, times(1)).clear();
assertNull(tested.getDragProxy());
}
use of org.kie.workbench.common.stunner.core.client.components.drag.DragProxyCallback in project kie-wb-common by kiegroup.
the class CreateConnectorActionTest method testAction.
@Test
@SuppressWarnings("unchecked")
public void testAction() {
final DragProxyCallback callback = testStartDrag();
testMoveDrag(callback);
testCompleteDrag(callback);
}
use of org.kie.workbench.common.stunner.core.client.components.drag.DragProxyCallback 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;
}
Aggregations