@Override @SuppressWarnings("unchecked") protected CloneConnectorCommand initialize(final GraphCommandExecutionContext context) { super.initialize(context); this.sourceNode = (Node<? extends View<?>, Edge>) getNode(context, sourceNodeUUID); this.targetNode = (Node<? extends View<?>, Edge>) getNode(context, targetNodeUUID); if (!(candidate.getContent() instanceof ViewConnector)) { throw new IllegalArgumentException("Candidate: " + candidate.getTargetNode() + " content should be a ViewConnector"); } //clone candidate ViewConnector edgeContent = (ViewConnector) candidate.getContent(); final Object bean = edgeContent.getDefinition(); clone = context.getFactoryManager().newElement(UUID.uuid(), bean.getClass()).asEdge(); //Cloning the candidate content with properties Object clonedDefinition = context.getDefinitionManager().cloneManager().clone(edgeContent.getDefinition(), ClonePolicy.ALL); ViewConnector clonedContent = (ViewConnector) clone.getContent(); clonedContent.setDefinition(clonedDefinition); // Magnet being moved on node ViewConnector connectionContent = (ViewConnector) candidate.getContent(); this.sourceConnection = (Connection) connectionContent.getSourceConnection().orElse(null); this.targetConnection = (Connection) connectionContent.getTargetConnection().orElse(null); commands.add(new AddConnectorCommand(sourceNode, clone, sourceConnection)); commands.add(new SetConnectionTargetNodeCommand(targetNode, clone, targetConnection)); // Add the candidate into index, so child commands can find it. getMutableIndex(context).addEdge(clone); return this; }
when(factoryManager.newElement(anyString(), any(Class.class))).thenReturn(cloneElement); when(cloneElement.asNode()).thenReturn(clone); when(cloneElement.asEdge()).thenReturn(cloneEdge); when(cloneEdge.getContent()).thenReturn(connectorContent); when(cloneEdge.getUUID()).thenReturn(CLONE_EDGE_UUID);
@Override @SuppressWarnings("unchecked") public ToolboxAction<AbstractCanvasHandler> onMouseClick(final AbstractCanvasHandler canvasHandler, final String uuid, final MouseClickEvent event) { // Obtain the connector and source node instances for proxying. final Element<?> element = CanvasLayoutUtils.getElement(canvasHandler, uuid); final Node<View<?>, Edge> sourceNode = (Node<View<?>, Edge>) element.asNode(); final Edge<? extends ViewConnector<?>, Node> connector = (Edge<? extends ViewConnector<?>, Node>) clientFactoryManager .newElement(UUID.uuid(), edgeId) .asEdge(); // Set the transient connection to the source node, for further rule evaluations. connector.setSourceNode(sourceNode); // Built and show a connector drag proxy, to check and finally set // candidate the target node. final double x = event.getX(); final double y = event.getY(); dragProxy = showDragProxy(canvasHandler, connector, sourceNode, (int) x, (int) y); return this; }
.newElement(UUID.uuid(), connectorId) .asEdge(); final Node<View<?>, Edge> targetNode = (Node<View<?>, Edge>) clientFactoryManager