private void handleCtrlV(final Key[] keys) { if (doKeysMatch(keys, Key.CONTROL, Key.V)) { this.execute(); } }
@Override protected void doDestroy() { super.doDestroy(); clear(); clipboardControl = null; }
protected void onCopySelectionCommandExecuted(@Observes CopySelectionSessionCommandExecutedEvent event) { checkNotNull("event", event); if (Objects.equals(getSession(), event.getClientSession())) { setEnabled(true); fire(); } }
final CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation> nodesCommandBuilder = createCommandBuilder(); .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 (wasNodesDeletedFromGraph()) { clipboardControl.getRollbackCommands().forEach(command -> command.undo(getCanvasHandler())); finalResult = executeCommands(nodesCommandBuilder, processedNodesCountdown); clipboardControl.getRollbackCommands().forEach(command -> command.execute(getCanvasHandler())); } else { finalResult = executeCommands(nodesCommandBuilder, processedNodesCountdown); LOGGER.severe("Error pasting selection." + getCanvasViolations(finalResult)); return; fireSelectedElementEvent(); callback.onSuccess(); clear();
private String getNewParentUUID(Node node) { //getting parent if selected Optional<Element> selectedParent = getSelectedParentElement(node.getUUID()); if (selectedParent.isPresent() && !Objects.equals(selectedParent.get().getUUID(), node.getUUID()) && checkIfExistsOnCanvas(selectedParent.get().getUUID())) { return selectedParent.get().getUUID(); } //getting node parent if no different parent is selected String nodeParentUUID = clipboardControl.getParent(node.getUUID()); if (selectedParent.isPresent() && Objects.equals(selectedParent.get().getUUID(), node.getUUID()) && Objects.nonNull(nodeParentUUID) && checkIfExistsOnCanvas(nodeParentUUID)) { return nodeParentUUID; } //return default parent that is the canvas in case no parent matches return getCanvasRootUUID(); }
private Point2D calculateNewLocation(final Node<? extends View<?>, Edge> node, String newParentUUID) { Point2D position = GraphUtils.getPosition(node.getContent()); //new parent different from the source node if (hasParentChanged(node, newParentUUID)) { return new Point2D(DEFAULT_PADDING, DEFAULT_PADDING); } //node is still on canvas (not deleted) if (existsOnCanvas(node)) { double x = position.getX(); double max = getYPositionStatistics().getMax(); double min = getYPositionStatistics().getMin(); double y = max + (position.getY() - min) + DEFAULT_PADDING; return new Point2D(x, y); } //default or node was deleted return position; }
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) .filter(Objects::nonNull) .map(edge -> (Edge) edge) .filter(edge -> Objects.nonNull(edge.getSourceNode()) && Objects.nonNull(clonedElements.get(edge.getSourceNode().getUUID())) && Objects.nonNull(edge.getTargetNode()) && Objects.nonNull(clonedElements.get(edge.getTargetNode().getUUID()))) .map(edge -> canvasCommandFactory.cloneConnector(edge, clonedElements.get(edge.getSourceNode().getUUID()), clonedElements.get(edge.getTargetNode().getUUID()), getCanvasHandler().getDiagram().getMetadata().getShapeSetId(), cloneEdgeCallback(edge))) .collect(Collectors.toList())); return sessionCommandManager.execute(getCanvasHandler(), commandBuilder.build()); } return new CanvasCommandResultBuilder().build(); }
protected void onCutSelectionCommandExecuted(@Observes CutSelectionSessionCommandExecutedEvent event) { checkNotNull("event", event); if (Objects.equals(getSession(), event.getClientSession())) { setEnabled(true); fire(); } }
private void paste() { sessionCommands.getPasteSelectionSessionCommand().execute(); }