use of org.kie.workbench.common.stunner.core.client.canvas.controls.EdgeClipboard in project kie-wb-common by kiegroup.
the class PasteSelectionSessionCommandTest method executeWithMultiSelectionWithEdgesClipboard.
@Test
@SuppressWarnings("unchecked")
public void executeWithMultiSelectionWithEdgesClipboard() {
final Connection sourceConnection = (Connection) ((ViewConnector) graphInstance.edge1.getContent()).getSourceConnection().orElse(null);
final Connection targetConnection = (Connection) ((ViewConnector) graphInstance.edge1.getContent()).getTargetConnection().orElse(null);
final EdgeClipboard clipboard = clipboardControl.buildNewEdgeClipboard(graphInstance.startNode.getUUID(), sourceConnection, graphInstance.intermNode.getUUID(), targetConnection);
clipboardControl.set(graphInstance.startNode, graphInstance.edge1, graphInstance.intermNode);
final Map<String, EdgeClipboard> map = new HashMap<>();
map.put(graphInstance.edge1.getUUID(), clipboard);
when(clipboardControl.getEdgeMap()).thenReturn(map);
assertEquals(1, clipboardControl.getEdgeMap().size());
pasteSelectionSessionCommand.bind(session);
pasteSelectionSessionCommand.setTestEdgeFoundInCanvas(false);
pasteSelectionSessionCommand.setTestEdgeFoundInClipboard(true);
assertEquals(false, pasteSelectionSessionCommand.isEdgeFoundInCanvas(graphInstance.edge1));
assertEquals(true, pasteSelectionSessionCommand.isEdgeFoundInClipboard(graphInstance.edge1));
// Mock the callback of CloneNodeCommand
ArgumentCaptor<Consumer> consumerNode = ArgumentCaptor.forClass(Consumer.class);
ArgumentCaptor<Consumer> consumerNode2 = ArgumentCaptor.forClass(Consumer.class);
when(cloneNodeCommand.getCandidate()).thenReturn(node);
when(cloneNodeCommand2.getCandidate()).thenReturn(node2);
when(canvasCommandFactory.cloneNode(eq(node), any(), any(), consumerNode.capture())).thenReturn(cloneNodeCommand);
when(canvasCommandFactory.cloneNode(eq(node2), any(), any(), consumerNode2.capture())).thenReturn(cloneNodeCommand2);
Map<Node, ArgumentCaptor<Consumer>> consumerMap = new HashMap() {
{
put(node, consumerNode);
put(node2, consumerNode2);
}
};
// Mock the callback of CloneConnectorCommand
ArgumentCaptor<Consumer> consumerEdge = ArgumentCaptor.forClass(Consumer.class);
when(canvasCommandFactory.cloneConnector(any(), Mockito.<String>any(), Mockito.<String>any(), Mockito.<String>any(), consumerEdge.capture())).thenReturn(cloneConnectorCommand);
// apply callbacks mocks
when(sessionCommandManager.execute(eq(canvasHandler), any())).thenAnswer(param -> {
CompositeCommand argument = param.getArgument(1, CompositeCommand.class);
// callback to nodes
argument.getCommands().stream().filter(c -> c instanceof CloneNodeCommand).forEach(c -> {
CloneNodeCommand cloneNodeCommand = (CloneNodeCommand) c;
Node candidate = cloneNodeCommand.getCandidate();
consumerMap.get(candidate).getValue().accept(cloneMap.get(candidate));
});
// callback to connectors
argument.getCommands().stream().filter(c -> c instanceof CloneConnectorCommand).forEach(c -> consumerEdge.getValue().accept(cloneEdge));
return commandResult;
});
// Executing the command
clipboardControl.set(graphInstance.startNode, graphInstance.edge1, graphInstance.intermNode);
when(selectionControl.getSelectedItems()).thenReturn(Arrays.asList(graphInstance.startNode.getUUID(), graphInstance.edge1.getUUID(), graphInstance.intermNode.getUUID()));
CopySelectionSessionCommand.getInstance(sessionManager).bind(session);
pasteSelectionSessionCommand.execute(callback);
verify(canvasCommandFactory, times(1)).cloneNode(eq(graphInstance.startNode), eq(graphInstance.parentNode.getUUID()), eq(new Point2D(X, DEFAULT_PADDING + Y + NODE_SIZE)), any());
verify(canvasCommandFactory, times(1)).cloneConnector(eq(graphInstance.edge1), Mockito.<String>any(), Mockito.<String>any(), Mockito.<String>any(), any());
// check command registry update after execution to allow a single undo/redo
verify(commandRegistry, times(2)).pop();
ArgumentCaptor<Command> commandArgumentCaptor = ArgumentCaptor.forClass(Command.class);
verify(commandRegistry, times(1)).register(commandArgumentCaptor.capture());
assertTrue(commandArgumentCaptor.getValue() instanceof CompositeCommand);
assertEquals(2, ((CompositeCommand) commandArgumentCaptor.getValue()).size());
}
use of org.kie.workbench.common.stunner.core.client.canvas.controls.EdgeClipboard in project kie-wb-common by kiegroup.
the class LocalClipboardControlTest method testEdgeMap.
@Test
public void testEdgeMap() {
final EdgeClipboard clipboard = localClipboardControl.buildNewEdgeClipboard("1D", null, "2D", null);
localClipboardControl.getEdgeMap().put("Node1", clipboard);
assertEquals(localClipboardControl.getEdgeMap().get("Node1").getSource(), clipboard.getSource());
assertEquals(localClipboardControl.getEdgeMap().get("Node1").getSourceConnection(), clipboard.getSourceConnection());
assertEquals(localClipboardControl.getEdgeMap().get("Node1").getTarget(), clipboard.getTarget());
assertEquals(localClipboardControl.getEdgeMap().get("Node1").getTargetConnection(), clipboard.getTargetConnection());
}
use of org.kie.workbench.common.stunner.core.client.canvas.controls.EdgeClipboard in project kie-wb-common by kiegroup.
the class LocalClipboardControl method buildNewEdgeClipboard.
@Override
public EdgeClipboard buildNewEdgeClipboard(final String source, final Connection sourceConnection, final String target, final Connection targetConnection) {
final EdgeClipboard clipboard = new EdgeClipboard();
clipboard.setSource(source);
clipboard.setSourceConnection(sourceConnection);
clipboard.setTarget(target);
clipboard.setTargetConnection(targetConnection);
return clipboard;
}
use of org.kie.workbench.common.stunner.core.client.canvas.controls.EdgeClipboard in project kie-wb-common by kiegroup.
the class PasteSelectionSessionCommand method processConnectors.
private CommandResult<CanvasViolation> processConnectors(Counter processedNodesCountdown) {
if (processedNodesCountdown.equalsToValue(0)) {
final CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation> commandBuilder = createCommandBuilder();
commandBuilder.addCommands(clipboardControl.getElements().stream().filter(element -> element instanceof Edge).map(edge -> (Edge) edge).filter(edge -> isEdgeFoundInCanvas(edge) || isEdgeFoundInClipboard(edge)).map(edge -> {
if (isEdgeFoundInCanvas(edge)) {
return canvasCommandFactory.cloneConnector(edge, clonedElements.get(edge.getSourceNode().getUUID()), clonedElements.get(edge.getTargetNode().getUUID()), getCanvasHandler().getDiagram().getMetadata().getShapeSetId(), cloneEdgeCallback(edge));
} else if (isEdgeFoundInClipboard(edge)) {
final EdgeClipboard edgeData = clipboardControl.getEdgeMap().get(edge.getUUID());
final ViewConnector connectionContent = (ViewConnector) edge.getContent();
connectionContent.setSourceConnection(edgeData.getSourceConnection());
connectionContent.setTargetConnection(edgeData.getTargetConnection());
return canvasCommandFactory.cloneConnector(edge, clonedElements.get(edgeData.getSource()), clonedElements.get(edgeData.getTarget()), getCanvasHandler().getDiagram().getMetadata().getShapeSetId(), cloneEdgeCallback(edge));
}
// this should never happen
return null;
}).collect(Collectors.toList()));
return sessionCommandManager.execute(getCanvasHandler(), commandBuilder.build());
}
return new CanvasCommandResultBuilder().build();
}
use of org.kie.workbench.common.stunner.core.client.canvas.controls.EdgeClipboard in project kie-wb-common by kiegroup.
the class PasteSelectionSessionCommandTest method testFoundOnCanvasAndClipboard.
@Test
@SuppressWarnings("unchecked")
public void testFoundOnCanvasAndClipboard() {
pasteSelectionSessionCommand.bind(session);
pasteSelectionSessionCommand.setTestEdgeFoundInCanvas(false);
pasteSelectionSessionCommand.setTestEdgeFoundInClipboard(true);
final Connection sourceConnection = (Connection) ((ViewConnector) graphInstance.edge1.getContent()).getSourceConnection().orElse(null);
final Connection targetConnection = (Connection) ((ViewConnector) graphInstance.edge1.getContent()).getTargetConnection().orElse(null);
final EdgeClipboard clipboard = clipboardControl.buildNewEdgeClipboard(graphInstance.startNode.getUUID(), sourceConnection, graphInstance.intermNode.getUUID(), targetConnection);
clipboardControl.set(graphInstance.startNode, graphInstance.edge1, graphInstance.intermNode);
final Map<String, EdgeClipboard> map = new HashMap<>();
map.put(graphInstance.edge1.getUUID(), clipboard);
when(clipboardControl.getEdgeMap()).thenReturn(map);
assertEquals(1, clipboardControl.getEdgeMap().size());
assertEquals(false, pasteSelectionSessionCommand.isEdgeFoundInCanvas(graphInstance.edge1));
assertEquals(true, pasteSelectionSessionCommand.isEdgeFoundInClipboard(graphInstance.edge1));
pasteSelectionSessionCommand.setTestEdgeFoundInClipboard(false);
assertEquals(false, pasteSelectionSessionCommand.isEdgeFoundInClipboard(graphInstance.edge2));
pasteSelectionSessionCommand.setTestEdgeFoundInCanvas(true);
assertEquals(false, pasteSelectionSessionCommand.isEdgeFoundInCanvas(graphInstance.edge2));
Node source = graphInstance.edge2.getSourceNode();
Node target = graphInstance.edge2.getTargetNode();
graphInstance.edge2.setSourceNode(null);
assertEquals(false, pasteSelectionSessionCommand.isEdgeFoundInCanvas(graphInstance.edge2));
graphInstance.edge2.setTargetNode(null);
assertEquals(false, pasteSelectionSessionCommand.isEdgeFoundInCanvas(graphInstance.edge2));
graphInstance.edge2.setSourceNode(source);
assertEquals(false, pasteSelectionSessionCommand.isEdgeFoundInCanvas(graphInstance.edge2));
pasteSelectionSessionCommand.setTestEdgeFoundInCanvas(false);
pasteSelectionSessionCommand.setTestEdgeFoundInClipboard(false);
assertEquals(false, pasteSelectionSessionCommand.isEdgeFoundInCanvas(graphInstance.edge2));
assertEquals(false, pasteSelectionSessionCommand.isEdgeFoundInClipboard(graphInstance.edge2));
}
Aggregations