@Test @SuppressWarnings("unchecked") public void execute() { pasteSelectionSessionCommand.bind(session); ArgumentCaptor<Consumer> consumerArgumentCaptor = ArgumentCaptor.forClass(Consumer.class); when(canvasCommandFactory.cloneNode(any(), any(), any(), consumerArgumentCaptor.capture())).thenReturn(cloneNodeCommand); when(commandResult.getType()).thenAnswer(param -> { consumerArgumentCaptor.getValue().accept(clone); return CommandResult.Type.INFO; }); clipboardControl.set(graphInstance.startNode); when(selectionControl.getSelectedItems()).thenReturn(Arrays.asList(node.getUUID())); CopySelectionSessionCommand.getInstance(sessionManager).bind(session); pasteSelectionSessionCommand.execute(callback); verify(canvasCommandFactory, times(1)) .cloneNode(eq(node), eq(graphInstance.parentNode.getUUID()), eq(new Point2D(X, DEFAULT_PADDING + Y + NODE_SIZE)), any()); clipboardControl.set(graphInstance.startNode); when(selectionControl.getSelectedItems()).thenReturn(Arrays.asList(graphInstance.intermNode.getUUID())); pasteSelectionSessionCommand.execute(callback); verify(canvasCommandFactory, times(1)) .cloneNode(eq(node), eq(graphInstance.intermNode.getUUID()), eq(new Point2D(DEFAULT_PADDING, DEFAULT_PADDING)), any()); clipboardControl.set(graphInstance.startNode); when(selectionControl.getSelectedItems()).thenReturn(Collections.emptyList()); pasteSelectionSessionCommand.execute(callback); verify(canvasCommandFactory, times(1)) .cloneNode(eq(node), eq(CANVAS_UUID), eq(new Point2D(DEFAULT_PADDING, DEFAULT_PADDING)), any()); verify(callback, times(3)).onSuccess(); ArgumentCaptor<CanvasSelectionEvent> canvasElementSelectedEventArgumentCaptor = ArgumentCaptor.forClass(CanvasSelectionEvent.class); verify(selectionEvent, times(3)).fire(canvasElementSelectedEventArgumentCaptor.capture()); assertTrue(canvasElementSelectedEventArgumentCaptor.getAllValues().stream() .allMatch(event -> Objects.equals(event.getIdentifiers().iterator().next(), clone.getUUID()))); clipboardControl.set(graphInstance.startNode); reset(selectionEvent, canvasCommandFactory, callback, commandResult); when(commandResult.getType()).thenReturn(CommandResult.Type.ERROR); pasteSelectionSessionCommand.execute(callback); verify(canvasCommandFactory, times(1)) .cloneNode(eq(node), eq(CANVAS_UUID), eq(new Point2D(DEFAULT_PADDING, DEFAULT_PADDING)), any()); verify(callback, never()).onSuccess(); verify(selectionEvent, never()).fire(canvasElementSelectedEventArgumentCaptor.capture()); }
@Override public <V> void execute(final Callback<V> callback) { checkNotNull("callback", callback); if (clipboardControl.hasElements()) { final CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation> nodesCommandBuilder = createCommandBuilder(); Counter processedNodesCountdown = new Counter((int) clipboardControl.getElements().stream() .filter(element -> element instanceof Node).count()); nodesCommandBuilder.addCommands(clipboardControl.getElements().stream() .filter(element -> element instanceof Node) .filter(Objects::nonNull) .map(node -> (Node<View<?>, Edge>) node) .map(node -> { String newParentUUID = getNewParentUUID(node); return canvasCommandFactory.cloneNode(node, newParentUUID, calculateNewLocation(node, newParentUUID), cloneNodeCallback(node, processedNodesCountdown)); }) .collect(Collectors.toList())); if (Objects.equals(nodesCommandBuilder.size(), 0)) { return; } CommandResult<CanvasViolation> finalResult; if (wasNodesDeletedFromGraph()) { clipboardControl.getRollbackCommands().forEach(command -> nodesCommandBuilder.addFirstCommand(new ReverseCommand(command))); clipboardControl.getRollbackCommands().forEach(node -> nodesCommandBuilder.addCommand(node)); finalResult = executeCommands(nodesCommandBuilder, processedNodesCountdown); } else { finalResult = executeCommands(nodesCommandBuilder, processedNodesCountdown); } if (CommandUtils.isError(finalResult)) { LOGGER.severe("Error pasting selection." + getCanvasViolations(finalResult)); return; } fireSelectedElementEvent(); callback.onSuccess(); clear(); copySelectionSessionCommand.execute(); } }
PasteSelectionSessionCommand extends AbstractClientSessionCommand<EditorSession> { @Override public <V> void execute(final Callback<V> callback) { checkNotNull("callback", callback); if (clipboardControl.hasElements()) { final CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation> nodesCommandBuilder = createCommandBuilder(); Counter processedNodesCountdown = new Counter((int) clipboardControl.getElements().stream() .filter(element -> element instanceof Node).count()); nodesCommandBuilder.addCommands(clipboardControl.getElements().stream() .filter(element -> element instanceof Node) .filter(Objects::nonNull) .map(node -> (Node<View<?>, Edge>) node) .map(node -> { String newParentUUID = getNewParentUUID(node); return canvasCommandFactory.cloneNode(node, newParentUUID, calculateNewLocation(node, newParentUUID), cloneNodeCallback(node, processedNodesCountdown)); }) .collect(Collectors.toList())); if (Objects.equals(nodesCommandBuilder.size(), 0)) { return; } CommandResult<CanvasViolation> finalResult; if (wasNodesDeletedFromGraph()) { clipboardControl.getRollbackCommands().forEach(command -> nodesCommandBuilder.addFirstCommand(new ReverseCommand(command))); clipboardControl.getRollbackCommands().forEach(node -> nodesCommandBuilder.addCommand(node)); finalResult = executeCommands(nodesCommandBuilder, processedNodesCountdown); } else { finalResult = executeCommands(nodesCommandBuilder, processedNodesCountdown); } if (CommandUtils.isError(finalResult)) { LOGGER.severe("Error pasting selection." + getCanvasViolations(finalResult)); return; } fireSelectedElementEvent(); callback.onSuccess(); clear(); copySelectionSessionCommand.execute(); } } }
PasteSelectionSessionCommand extends AbstractClientSessionCommand<EditorSession> { @Override public <V> void execute(final Callback<V> callback) { checkNotNull("callback", callback); if (clipboardControl.hasElements()) { final CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation> nodesCommandBuilder = createCommandBuilder(); Counter processedNodesCountdown = new Counter((int) clipboardControl.getElements().stream() .filter(element -> element instanceof Node).count()); nodesCommandBuilder.addCommands(clipboardControl.getElements().stream() .filter(element -> element instanceof Node) .filter(Objects::nonNull) .map(node -> (Node<View<?>, Edge>) node) .map(node -> { String newParentUUID = getNewParentUUID(node); return canvasCommandFactory.cloneNode(node, newParentUUID, calculateNewLocation(node, newParentUUID), cloneNodeCallback(node, processedNodesCountdown)); }) .collect(Collectors.toList())); if (Objects.equals(nodesCommandBuilder.size(), 0)) { return; } CommandResult<CanvasViolation> finalResult; if (wasNodesDeletedFromGraph()) { clipboardControl.getRollbackCommands().forEach(command -> nodesCommandBuilder.addFirstCommand(new ReverseCommand(command))); clipboardControl.getRollbackCommands().forEach(node -> nodesCommandBuilder.addCommand(node)); finalResult = executeCommands(nodesCommandBuilder, processedNodesCountdown); } else { finalResult = executeCommands(nodesCommandBuilder, processedNodesCountdown); } if (CommandUtils.isError(finalResult)) { LOGGER.severe("Error pasting selection." + getCanvasViolations(finalResult)); return; } fireSelectedElementEvent(); callback.onSuccess(); clear(); copySelectionSessionCommand.execute(); } } protected  PasteSelectionSessionCommand(); @Inject  PasteSelectionSessionCommand(final SessionCommandManager<AbstractCanvasHandler> sessionCommandManager,
                                        @Any ManagedInstance<CanvasCommandFactory<AbstractCanvasHandler>> canvasCommandFactoryInstance,
                                        final Event<CanvasSelectionEvent> selectionEvent,
                                        final DefinitionUtils definitionUtils,
                                        final SessionManager sessionManager); }
PasteSelectionSessionCommand extends AbstractClientSessionCommand<EditorSession> { @Override public <V> void execute(final Callback<V> callback) { checkNotNull("callback", callback); if (clipboardControl.hasElements()) { final CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation> nodesCommandBuilder = createCommandBuilder(); Counter processedNodesCountdown = new Counter((int) clipboardControl.getElements().stream() .filter(element -> element instanceof Node).count()); nodesCommandBuilder.addCommands(clipboardControl.getElements().stream() .filter(element -> element instanceof Node) .filter(Objects::nonNull) .map(node -> (Node<View<?>, Edge>) node) .map(node -> { String newParentUUID = getNewParentUUID(node); return canvasCommandFactory.cloneNode(node, newParentUUID, calculateNewLocation(node, newParentUUID), cloneNodeCallback(node, processedNodesCountdown)); }) .collect(Collectors.toList())); if (Objects.equals(nodesCommandBuilder.size(), 0)) { return; } CommandResult<CanvasViolation> finalResult; if (wasNodesDeletedFromGraph()) { clipboardControl.getRollbackCommands().forEach(command -> nodesCommandBuilder.addFirstCommand(new ReverseCommand(command))); clipboardControl.getRollbackCommands().forEach(node -> nodesCommandBuilder.addCommand(node)); finalResult = executeCommands(nodesCommandBuilder, processedNodesCountdown); } else { finalResult = executeCommands(nodesCommandBuilder, processedNodesCountdown); } if (CommandUtils.isError(finalResult)) { LOGGER.severe("Error pasting selection." + getCanvasViolations(finalResult)); return; } fireSelectedElementEvent(); callback.onSuccess(); clear(); copySelectionSessionCommand.execute(); } } protected  PasteSelectionSessionCommand(); @Inject  PasteSelectionSessionCommand(final SessionCommandManager<AbstractCanvasHandler> sessionCommandManager,
                                        @Any ManagedInstance<CanvasCommandFactory<AbstractCanvasHandler>> canvasCommandFactoryInstance,
                                        final Event<CanvasSelectionEvent> selectionEvent,
                                        final DefinitionUtils definitionUtils,
                                        final SessionManager sessionManager); void setTestEdgeFoundInCanvas(boolean testEdgeFoundInCanvas); void setTestEdgeFoundInClipboard(boolean testEdgeFoundInClipboard); @Override void bind(final EditorSession session); @Override boolean accepts(final ClientSession session); @Override void execute(final Callback<V> callback); boolean isEdgeFoundInClipboard(Edge edge); boolean isEdgeFoundInCanvas(final Edge edge); boolean wasNodesDeletedFromGraph(); void clear(); String getCanvasViolations(CommandResult<CanvasViolation> result); }
PasteSelectionSessionCommand extends AbstractClientSessionCommand<EditorSession> { @Override public <V> void execute(final Callback<V> callback) { checkNotNull("callback", callback); if (clipboardControl.hasElements()) { final CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation> nodesCommandBuilder = createCommandBuilder(); Counter processedNodesCountdown = new Counter((int) clipboardControl.getElements().stream() .filter(element -> element instanceof Node).count()); nodesCommandBuilder.addCommands(clipboardControl.getElements().stream() .filter(element -> element instanceof Node) .filter(Objects::nonNull) .map(node -> (Node<View<?>, Edge>) node) .map(node -> { String newParentUUID = getNewParentUUID(node); return canvasCommandFactory.cloneNode(node, newParentUUID, calculateNewLocation(node, newParentUUID), cloneNodeCallback(node, processedNodesCountdown)); }) .collect(Collectors.toList())); if (Objects.equals(nodesCommandBuilder.size(), 0)) { return; } CommandResult<CanvasViolation> finalResult; if (wasNodesDeletedFromGraph()) { clipboardControl.getRollbackCommands().forEach(command -> nodesCommandBuilder.addFirstCommand(new ReverseCommand(command))); clipboardControl.getRollbackCommands().forEach(node -> nodesCommandBuilder.addCommand(node)); finalResult = executeCommands(nodesCommandBuilder, processedNodesCountdown); } else { finalResult = executeCommands(nodesCommandBuilder, processedNodesCountdown); } if (CommandUtils.isError(finalResult)) { LOGGER.severe("Error pasting selection." + getCanvasViolations(finalResult)); return; } fireSelectedElementEvent(); callback.onSuccess(); clear(); copySelectionSessionCommand.execute(); } } protected  PasteSelectionSessionCommand(); @Inject  PasteSelectionSessionCommand(final SessionCommandManager<AbstractCanvasHandler> sessionCommandManager,
                                        @Any ManagedInstance<CanvasCommandFactory<AbstractCanvasHandler>> canvasCommandFactoryInstance,
                                        final Event<CanvasSelectionEvent> selectionEvent,
                                        final DefinitionUtils definitionUtils,
                                        final SessionManager sessionManager); void setTestEdgeFoundInCanvas(boolean testEdgeFoundInCanvas); void setTestEdgeFoundInClipboard(boolean testEdgeFoundInClipboard); @Override void bind(final EditorSession session); @Override boolean accepts(final ClientSession session); @Override void execute(final Callback<V> callback); boolean isEdgeFoundInClipboard(Edge edge); boolean isEdgeFoundInCanvas(final Edge edge); boolean wasNodesDeletedFromGraph(); void clear(); String getCanvasViolations(CommandResult<CanvasViolation> result);  }