@Test public void testExecuteAction() { final AbstractCanvasHandler canvasHandler = mock(AbstractCanvasHandler.class); final String sourceNodeId = "src-id"; final String targetNodeId = "dest-id"; final String connectorId = "edge-id"; final AbstractCanvas canvas = mock(AbstractCanvas.class); doReturn(canvas).when(canvasHandler).getCanvas(); doReturn(canvas).when(canvasHandler).getAbstractCanvas(); final Diagram diagram = mock(Diagram.class); doReturn(diagram).when(canvasHandler).getDiagram(); final Metadata metadata = mock(Metadata.class); doReturn(metadata).when(diagram).getMetadata(); final String shapeSetId = "shape-set-id"; doReturn(shapeSetId).when(metadata).getShapeSetId(); final Index graphIndex = mock(Index.class); doReturn(graphIndex).when(canvasHandler).getGraphIndex(); final Element sourceElement = mock(Element.class); doReturn(sourceElement).when(graphIndex).get(sourceNodeId); final Node sourceNode = mock(Node.class); final View sourceElementContent = mock(View.class); doReturn(sourceElementContent).when(sourceNode).getContent(); doReturn(Bounds.create(10d, 0d, 200d, 100d)).when(sourceElementContent).getBounds(); doReturn(sourceNode).when(sourceElement).asNode(); doReturn(Collections.emptyList()).when(sourceNode).getInEdges(); final Element targetNodeElement = mock(Element.class); doReturn(targetNodeElement).when(clientFactoryManager).newElement(anyString(), eq(targetNodeId)); final Node targetNode = mock(Node.class); final View targetElementContent = mock(View.class); doReturn(targetElementContent).when(targetNode).getContent(); doReturn(Bounds.create(-100d, 0d, 0d, 100d)).when(targetElementContent).getBounds(); doReturn(targetNode).when(targetNodeElement).asNode(); final String targetNodeUuid = "target-uuid"; doReturn(targetNodeUuid).when(targetNode).getUUID(); final Element connectorElement = mock(Element.class); doReturn(connectorElement).when(clientFactoryManager).newElement(anyString(), eq(connectorId)); final Edge connectorEdge = mock(Edge.class); doReturn(connectorEdge).when(connectorElement).asEdge(); when(canvasLayoutUtils.getNext(eq(canvasHandler), eq(sourceNode), eq(targetNode))) .thenReturn(new Point2D(100d, 500d)); createNodeAction.executeAction(canvasHandler, sourceNodeId, targetNodeId, connectorId); final ArgumentCaptor<Command> commandArgumentCaptor = ArgumentCaptor.forClass(Command.class); verify(sessionCommandManager).execute(eq(canvasHandler), commandArgumentCaptor.capture()); final DeferredCompositeCommand command = (DeferredCompositeCommand) commandArgumentCaptor.getValue(); final DeferredCommand c0 = (DeferredCommand) command.getCommands().get(0); final DeferredCommand c1 = (DeferredCommand) command.getCommands().get(1); final DeferredCommand c2 = (DeferredCommand) command.getCommands().get(2); final DeferredCommand c3 = (DeferredCommand) command.getCommands().get(3); final AddNodeCommand addNodeCommand = (AddNodeCommand) c0.getCommand(); final UpdateElementPositionCommand updateElementPositionCommand = (UpdateElementPositionCommand) c1.getCommand(); final AddConnectorCommand addConnectorCommand = (AddConnectorCommand) c2.getCommand(); final SetConnectionTargetNodeCommand setTargetNodeCommand = (SetConnectionTargetNodeCommand) c3.getCommand(); Assertions.assertThat(targetNode).isEqualTo(addNodeCommand.getCandidate()); Assertions.assertThat(shapeSetId).isEqualTo(addNodeCommand.getShapeSetId()); Assertions.assertThat(connectorEdge).isEqualTo(addConnectorCommand.getCandidate()); Assertions.assertThat(sourceNode).isEqualTo(addConnectorCommand.getSource()); Assertions.assertThat(shapeSetId).isEqualTo(addConnectorCommand.getShapeSetId()); Assertions.assertThat(connectorEdge).isEqualTo(setTargetNodeCommand.getEdge()); Assertions.assertThat(targetNode).isEqualTo(setTargetNodeCommand.getNode()); Assertions.assertThat(targetNode).isEqualTo(updateElementPositionCommand.getElement()); Assertions.assertThat(new Point2D(100d, 500d)).isEqualTo(updateElementPositionCommand.getLocation()); final ArgumentCaptor<CanvasSelectionEvent> eventArgumentCaptor = ArgumentCaptor.forClass(CanvasSelectionEvent.class); verify(selectionEvent).fire(eventArgumentCaptor.capture()); final CanvasSelectionEvent eCaptured = eventArgumentCaptor.getValue(); Assertions.assertThat(targetNodeUuid).isEqualTo(eCaptured.getIdentifiers().iterator().next()); Assertions.assertThat(addConnectorCommand.getConnection()).isInstanceOf(MagnetConnection.class); Assertions.assertThat(((MagnetConnection) addConnectorCommand.getConnection()).getMagnetIndex().getAsInt()) .isEqualTo(MagnetConnection.MAGNET_LEFT); Assertions.assertThat(setTargetNodeCommand.getConnection()).isInstanceOf(MagnetConnection.class); Assertions.assertThat(((MagnetConnection) setTargetNodeCommand.getConnection()).getMagnetIndex().getAsInt()) .isEqualTo(MagnetConnection.MAGNET_RIGHT); }
@Override @SuppressWarnings("unchecked") public void executeAction(final AbstractCanvasHandler canvasHandler, final String sourceNodeId, final String targetNodeId, final String connectorId) { final Element<View<?>> element = (Element<View<?>>) CanvasLayoutUtils.getElement(canvasHandler, sourceNodeId); final Node<View<?>, Edge> sourceNode = element.asNode(); final Edge<? extends ViewConnector<?>, Node> connector = (Edge<? extends ViewConnector<?>, Node>) clientFactoryManager .newElement(UUID.uuid(), connectorId) .asEdge(); final Node<View<?>, Edge> targetNode = (Node<View<?>, Edge>) clientFactoryManager .newElement(UUID.uuid(), targetNodeId) .asNode(); final Metadata metadata = canvasHandler.getDiagram().getMetadata(); final Annotation qualifier = definitionUtils.getQualifier(metadata.getDefinitionSetId()); final CanvasCommandFactory<AbstractCanvasHandler> commandFactory = lookup(canvasCommandFactories, qualifier); final DeferredCompositeCommand.Builder builder = new DeferredCompositeCommand.Builder() .deferCommand(() -> addNode(canvasHandler, commandFactory, sourceNode, targetNode)) .deferCommand(() -> updateNodeLocation(canvasHandler, commandFactory, sourceNode, targetNode)) .deferCommand(() -> addEdge(canvasHandler, commandFactory, sourceNode, targetNode, connector)) .deferCommand(() -> setEdgeTarget(commandFactory, connector, targetNode, sourceNode)); final CommandResult result = sessionCommandManager.execute(canvasHandler, builder.build()); if (!CommandUtils.isError(result)) { CanvasLayoutUtils.fireElementSelectedEvent(selectionEvent, canvasHandler, targetNode.getUUID()); } }
GeneralCreateNodeAction implements CreateNodeAction<AbstractCanvasHandler> { @Override @SuppressWarnings("unchecked") public void executeAction(final AbstractCanvasHandler canvasHandler, final String sourceNodeId, final String targetNodeId, final String connectorId) { final Element<View<?>> element = (Element<View<?>>) CanvasLayoutUtils.getElement(canvasHandler, sourceNodeId); final Node<View<?>, Edge> sourceNode = element.asNode(); final Edge<? extends ViewConnector<?>, Node> connector = (Edge<? extends ViewConnector<?>, Node>) clientFactoryManager .newElement(UUID.uuid(), connectorId) .asEdge(); final Node<View<?>, Edge> targetNode = (Node<View<?>, Edge>) clientFactoryManager .newElement(UUID.uuid(), targetNodeId) .asNode(); final Metadata metadata = canvasHandler.getDiagram().getMetadata(); final Annotation qualifier = definitionUtils.getQualifier(metadata.getDefinitionSetId()); final CanvasCommandFactory<AbstractCanvasHandler> commandFactory = lookup(canvasCommandFactories, qualifier); final DeferredCompositeCommand.Builder builder = new DeferredCompositeCommand.Builder() .deferCommand(() -> addNode(canvasHandler, commandFactory, sourceNode, targetNode)) .deferCommand(() -> updateNodeLocation(canvasHandler, commandFactory, sourceNode, targetNode)) .deferCommand(() -> addEdge(canvasHandler, commandFactory, sourceNode, targetNode, connector)) .deferCommand(() -> setEdgeTarget(commandFactory, connector, targetNode, sourceNode)); final CommandResult result = sessionCommandManager.execute(canvasHandler, builder.build()); if (!CommandUtils.isError(result)) { CanvasLayoutUtils.fireElementSelectedEvent(selectionEvent, canvasHandler, targetNode.getUUID()); } } }
GeneralCreateNodeAction implements CreateNodeAction<AbstractCanvasHandler> { @Override @SuppressWarnings("unchecked") public void executeAction(final AbstractCanvasHandler canvasHandler, final String sourceNodeId, final String targetNodeId, final String connectorId) { final Element<View<?>> element = (Element<View<?>>) CanvasLayoutUtils.getElement(canvasHandler, sourceNodeId); final Node<View<?>, Edge> sourceNode = element.asNode(); final Edge<? extends ViewConnector<?>, Node> connector = (Edge<? extends ViewConnector<?>, Node>) clientFactoryManager .newElement(UUID.uuid(), connectorId) .asEdge(); final Node<View<?>, Edge> targetNode = (Node<View<?>, Edge>) clientFactoryManager .newElement(UUID.uuid(), targetNodeId) .asNode(); final Metadata metadata = canvasHandler.getDiagram().getMetadata(); final Annotation qualifier = definitionUtils.getQualifier(metadata.getDefinitionSetId()); final CanvasCommandFactory<AbstractCanvasHandler> commandFactory = lookup(canvasCommandFactories, qualifier); final DeferredCompositeCommand.Builder builder = new DeferredCompositeCommand.Builder() .deferCommand(() -> addNode(canvasHandler, commandFactory, sourceNode, targetNode)) .deferCommand(() -> updateNodeLocation(canvasHandler, commandFactory, sourceNode, targetNode)) .deferCommand(() -> addEdge(canvasHandler, commandFactory, sourceNode, targetNode, connector)) .deferCommand(() -> setEdgeTarget(commandFactory, connector, targetNode, sourceNode)); final CommandResult result = sessionCommandManager.execute(canvasHandler, builder.build()); if (!CommandUtils.isError(result)) { CanvasLayoutUtils.fireElementSelectedEvent(selectionEvent, canvasHandler, targetNode.getUUID()); } } @Inject  GeneralCreateNodeAction(final DefinitionUtils definitionUtils,
                                   final ClientFactoryManager clientFactoryManager,
                                   final CanvasLayoutUtils canvasLayoutUtils,
                                   final Event<CanvasSelectionEvent> selectionEvent,
                                   final SessionCommandManager<AbstractCanvasHandler> sessionCommandManager,
                                   final @Any ManagedInstance<DefaultCanvasCommandFactory> canvasCommandFactories); }
GeneralCreateNodeAction implements CreateNodeAction<AbstractCanvasHandler> { @Override @SuppressWarnings("unchecked") public void executeAction(final AbstractCanvasHandler canvasHandler, final String sourceNodeId, final String targetNodeId, final String connectorId) { final Element<View<?>> element = (Element<View<?>>) CanvasLayoutUtils.getElement(canvasHandler, sourceNodeId); final Node<View<?>, Edge> sourceNode = element.asNode(); final Edge<? extends ViewConnector<?>, Node> connector = (Edge<? extends ViewConnector<?>, Node>) clientFactoryManager .newElement(UUID.uuid(), connectorId) .asEdge(); final Node<View<?>, Edge> targetNode = (Node<View<?>, Edge>) clientFactoryManager .newElement(UUID.uuid(), targetNodeId) .asNode(); final Metadata metadata = canvasHandler.getDiagram().getMetadata(); final Annotation qualifier = definitionUtils.getQualifier(metadata.getDefinitionSetId()); final CanvasCommandFactory<AbstractCanvasHandler> commandFactory = lookup(canvasCommandFactories, qualifier); final DeferredCompositeCommand.Builder builder = new DeferredCompositeCommand.Builder() .deferCommand(() -> addNode(canvasHandler, commandFactory, sourceNode, targetNode)) .deferCommand(() -> updateNodeLocation(canvasHandler, commandFactory, sourceNode, targetNode)) .deferCommand(() -> addEdge(canvasHandler, commandFactory, sourceNode, targetNode, connector)) .deferCommand(() -> setEdgeTarget(commandFactory, connector, targetNode, sourceNode)); final CommandResult result = sessionCommandManager.execute(canvasHandler, builder.build()); if (!CommandUtils.isError(result)) { CanvasLayoutUtils.fireElementSelectedEvent(selectionEvent, canvasHandler, targetNode.getUUID()); } } @Inject  GeneralCreateNodeAction(final DefinitionUtils definitionUtils,
                                   final ClientFactoryManager clientFactoryManager,
                                   final CanvasLayoutUtils canvasLayoutUtils,
                                   final Event<CanvasSelectionEvent> selectionEvent,
                                   final SessionCommandManager<AbstractCanvasHandler> sessionCommandManager,
                                   final @Any ManagedInstance<DefaultCanvasCommandFactory> canvasCommandFactories); @Override @SuppressWarnings("unchecked") void executeAction(final AbstractCanvasHandler canvasHandler,
                              final String sourceNodeId,
                              final String targetNodeId,
                              final String connectorId); @PreDestroy void destroy(); }
GeneralCreateNodeAction implements CreateNodeAction<AbstractCanvasHandler> { @Override @SuppressWarnings("unchecked") public void executeAction(final AbstractCanvasHandler canvasHandler, final String sourceNodeId, final String targetNodeId, final String connectorId) { final Element<View<?>> element = (Element<View<?>>) CanvasLayoutUtils.getElement(canvasHandler, sourceNodeId); final Node<View<?>, Edge> sourceNode = element.asNode(); final Edge<? extends ViewConnector<?>, Node> connector = (Edge<? extends ViewConnector<?>, Node>) clientFactoryManager .newElement(UUID.uuid(), connectorId) .asEdge(); final Node<View<?>, Edge> targetNode = (Node<View<?>, Edge>) clientFactoryManager .newElement(UUID.uuid(), targetNodeId) .asNode(); final Metadata metadata = canvasHandler.getDiagram().getMetadata(); final Annotation qualifier = definitionUtils.getQualifier(metadata.getDefinitionSetId()); final CanvasCommandFactory<AbstractCanvasHandler> commandFactory = lookup(canvasCommandFactories, qualifier); final DeferredCompositeCommand.Builder builder = new DeferredCompositeCommand.Builder() .deferCommand(() -> addNode(canvasHandler, commandFactory, sourceNode, targetNode)) .deferCommand(() -> updateNodeLocation(canvasHandler, commandFactory, sourceNode, targetNode)) .deferCommand(() -> addEdge(canvasHandler, commandFactory, sourceNode, targetNode, connector)) .deferCommand(() -> setEdgeTarget(commandFactory, connector, targetNode, sourceNode)); final CommandResult result = sessionCommandManager.execute(canvasHandler, builder.build()); if (!CommandUtils.isError(result)) { CanvasLayoutUtils.fireElementSelectedEvent(selectionEvent, canvasHandler, targetNode.getUUID()); } } @Inject  GeneralCreateNodeAction(final DefinitionUtils definitionUtils,
                                   final ClientFactoryManager clientFactoryManager,
                                   final CanvasLayoutUtils canvasLayoutUtils,
                                   final Event<CanvasSelectionEvent> selectionEvent,
                                   final SessionCommandManager<AbstractCanvasHandler> sessionCommandManager,
                                   final @Any ManagedInstance<DefaultCanvasCommandFactory> canvasCommandFactories); @Override @SuppressWarnings("unchecked") void executeAction(final AbstractCanvasHandler canvasHandler,
                              final String sourceNodeId,
                              final String targetNodeId,
                              final String connectorId); @PreDestroy void destroy();  }