@Test public void testExecute() { cloneCanvasNodeCommand.execute(canvasHandler); AbstractCompositeCommand<AbstractCanvasHandler, CanvasViolation> commands = cloneCanvasNodeCommand.getCommands(); assertEquals(commands.size(), 6); assertTrue(commands.getCommands().stream() .filter(command -> command instanceof CloneCanvasNodeCommand) .map(command -> (CloneCanvasNodeCommand) command) .allMatch(command -> Objects.equals(command.getCandidate(), graphInstance.startNode) || Objects.equals(command.getCandidate(), graphInstance.intermNode) || Objects.equals(command.getCandidate(), graphInstance.endNode))); assertTrue(commands.getCommands().stream() .filter(command -> command instanceof AddCanvasConnectorCommand) .map(command -> (AddCanvasConnectorCommand) command) .allMatch(command -> Objects.equals(command.getCandidate(), graphInstance.edge1) || Objects.equals(command.getCandidate(), graphInstance.edge2))); }
@Override public CommandResult<CanvasViolation> execute(AbstractCanvasHandler context) { commands = new CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation>() .reverse() .build(); commands.addCommand(createAddCanvasChildNodeCommand(getParent(), getCandidate(), getShapeSetId())); if (GraphUtils.hasChildren(getCandidate())) { Graph graph = context.getGraphIndex().getGraph(); List<Edge> clonedEdges = new ArrayList<>(); childrenTraverseProcessor.get() .setRootUUID(getCandidate().getUUID()) .traverse(graph, new AbstractChildrenTraverseCallback<Node<View, Edge>, Edge<Child, Node>>() { @Override public boolean startNodeTraversal(List<Node<View, Edge>> parents, Node<View, Edge> node) { commands.addCommand(createCloneCanvasNodeCommand(getCandidate(), node, getShapeSetId())); clonedEdges.addAll(node.getOutEdges()); return false; } }); clonedEdges.stream() .filter(edge -> edge.getContent() instanceof Dock) .forEach(edge -> commands.addCommand(new CanvasDockNodeCommand(edge.getSourceNode(), edge.getTargetNode()))); clonedEdges .stream() .filter(edge -> edge.getContent() instanceof ViewConnector) .forEach(edge -> commands.addCommand(new AddCanvasConnectorCommand((Edge) edge, getShapeSetId()))); } if (GraphUtils.hasDockedNodes(getCandidate())) { List<Edge> edges = getCandidate().getOutEdges(); edges.stream() .filter(edge -> edge.getContent() instanceof Dock) .map(edge -> edge.getTargetNode()) .forEach(targetNode -> { commands.addCommand(new AddCanvasChildNodeCommand(getParent(), targetNode, getShapeSetId())); commands.addCommand(new CanvasDockNodeCommand(getCandidate(), targetNode)); }); } return commands.execute(context); }
CloneCanvasNodeCommand extends AbstractCanvasCommand { @Override public CommandResult<CanvasViolation> execute(AbstractCanvasHandler context) { commands = new CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation>() .reverse() .build(); commands.addCommand(createAddCanvasChildNodeCommand(getParent(), getCandidate(), getShapeSetId())); if (GraphUtils.hasChildren(getCandidate())) { Graph graph = context.getGraphIndex().getGraph(); List<Edge> clonedEdges = new ArrayList<>(); childrenTraverseProcessor.get() .setRootUUID(getCandidate().getUUID()) .traverse(graph, new AbstractChildrenTraverseCallback<Node<View, Edge>, Edge<Child, Node>>() { @Override public boolean startNodeTraversal(List<Node<View, Edge>> parents, Node<View, Edge> node) { commands.addCommand(createCloneCanvasNodeCommand(getCandidate(), node, getShapeSetId())); clonedEdges.addAll(node.getOutEdges()); return false; } }); clonedEdges.stream() .filter(edge -> edge.getContent() instanceof Dock) .forEach(edge -> commands.addCommand(new CanvasDockNodeCommand(edge.getSourceNode(), edge.getTargetNode()))); clonedEdges .stream() .filter(edge -> edge.getContent() instanceof ViewConnector) .forEach(edge -> commands.addCommand(new AddCanvasConnectorCommand((Edge) edge, getShapeSetId()))); } if (GraphUtils.hasDockedNodes(getCandidate())) { List<Edge> edges = getCandidate().getOutEdges(); edges.stream() .filter(edge -> edge.getContent() instanceof Dock) .map(edge -> edge.getTargetNode()) .forEach(targetNode -> { commands.addCommand(new AddCanvasChildNodeCommand(getParent(), targetNode, getShapeSetId())); commands.addCommand(new CanvasDockNodeCommand(getCandidate(), targetNode)); }); } return commands.execute(context); } }
CloneCanvasNodeCommand extends AbstractCanvasCommand { @Override public CommandResult<CanvasViolation> execute(AbstractCanvasHandler context) { commands = new CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation>() .reverse() .build(); commands.addCommand(createAddCanvasChildNodeCommand(getParent(), getCandidate(), getShapeSetId())); if (GraphUtils.hasChildren(getCandidate())) { Graph graph = context.getGraphIndex().getGraph(); List<Edge> clonedEdges = new ArrayList<>(); childrenTraverseProcessor.get() .setRootUUID(getCandidate().getUUID()) .traverse(graph, new AbstractChildrenTraverseCallback<Node<View, Edge>, Edge<Child, Node>>() { @Override public boolean startNodeTraversal(List<Node<View, Edge>> parents, Node<View, Edge> node) { commands.addCommand(createCloneCanvasNodeCommand(getCandidate(), node, getShapeSetId())); clonedEdges.addAll(node.getOutEdges()); return false; } }); clonedEdges.stream() .filter(edge -> edge.getContent() instanceof Dock) .forEach(edge -> commands.addCommand(new CanvasDockNodeCommand(edge.getSourceNode(), edge.getTargetNode()))); clonedEdges .stream() .filter(edge -> edge.getContent() instanceof ViewConnector) .forEach(edge -> commands.addCommand(new AddCanvasConnectorCommand((Edge) edge, getShapeSetId()))); } if (GraphUtils.hasDockedNodes(getCandidate())) { List<Edge> edges = getCandidate().getOutEdges(); edges.stream() .filter(edge -> edge.getContent() instanceof Dock) .map(edge -> edge.getTargetNode()) .forEach(targetNode -> { commands.addCommand(new AddCanvasChildNodeCommand(getParent(), targetNode, getShapeSetId())); commands.addCommand(new CanvasDockNodeCommand(getCandidate(), targetNode)); }); } return commands.execute(context); } CloneCanvasNodeCommand(Node parent, Node candidate, String shapeSetId, final ManagedInstance<ChildrenTraverseProcessor> childrenTraverseProcessor); }
CloneCanvasNodeCommand extends AbstractCanvasCommand { @Override public CommandResult<CanvasViolation> execute(AbstractCanvasHandler context) { commands = new CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation>() .reverse() .build(); commands.addCommand(createAddCanvasChildNodeCommand(getParent(), getCandidate(), getShapeSetId())); if (GraphUtils.hasChildren(getCandidate())) { Graph graph = context.getGraphIndex().getGraph(); List<Edge> clonedEdges = new ArrayList<>(); childrenTraverseProcessor.get() .setRootUUID(getCandidate().getUUID()) .traverse(graph, new AbstractChildrenTraverseCallback<Node<View, Edge>, Edge<Child, Node>>() { @Override public boolean startNodeTraversal(List<Node<View, Edge>> parents, Node<View, Edge> node) { commands.addCommand(createCloneCanvasNodeCommand(getCandidate(), node, getShapeSetId())); clonedEdges.addAll(node.getOutEdges()); return false; } }); clonedEdges.stream() .filter(edge -> edge.getContent() instanceof Dock) .forEach(edge -> commands.addCommand(new CanvasDockNodeCommand(edge.getSourceNode(), edge.getTargetNode()))); clonedEdges .stream() .filter(edge -> edge.getContent() instanceof ViewConnector) .forEach(edge -> commands.addCommand(new AddCanvasConnectorCommand((Edge) edge, getShapeSetId()))); } if (GraphUtils.hasDockedNodes(getCandidate())) { List<Edge> edges = getCandidate().getOutEdges(); edges.stream() .filter(edge -> edge.getContent() instanceof Dock) .map(edge -> edge.getTargetNode()) .forEach(targetNode -> { commands.addCommand(new AddCanvasChildNodeCommand(getParent(), targetNode, getShapeSetId())); commands.addCommand(new CanvasDockNodeCommand(getCandidate(), targetNode)); }); } return commands.execute(context); } CloneCanvasNodeCommand(Node parent, Node candidate, String shapeSetId, final ManagedInstance<ChildrenTraverseProcessor> childrenTraverseProcessor); AbstractCanvasCommand createAddCanvasChildNodeCommand(Node parent, Node candidate, String shapeSetId); CloneCanvasNodeCommand createCloneCanvasNodeCommand(Node parent, Node candidate, String shapeSetId); @Override CommandResult<CanvasViolation> execute(AbstractCanvasHandler context); @Override CommandResult<CanvasViolation> undo(AbstractCanvasHandler context); ManagedInstance<ChildrenTraverseProcessor> getChildrenTraverseProcessor(); Node getParent(); Node getCandidate(); String getShapeSetId(); @Override String toString(); }
CloneCanvasNodeCommand extends AbstractCanvasCommand { @Override public CommandResult<CanvasViolation> execute(AbstractCanvasHandler context) { commands = new CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation>() .reverse() .build(); commands.addCommand(createAddCanvasChildNodeCommand(getParent(), getCandidate(), getShapeSetId())); if (GraphUtils.hasChildren(getCandidate())) { Graph graph = context.getGraphIndex().getGraph(); List<Edge> clonedEdges = new ArrayList<>(); childrenTraverseProcessor.get() .setRootUUID(getCandidate().getUUID()) .traverse(graph, new AbstractChildrenTraverseCallback<Node<View, Edge>, Edge<Child, Node>>() { @Override public boolean startNodeTraversal(List<Node<View, Edge>> parents, Node<View, Edge> node) { commands.addCommand(createCloneCanvasNodeCommand(getCandidate(), node, getShapeSetId())); clonedEdges.addAll(node.getOutEdges()); return false; } }); clonedEdges.stream() .filter(edge -> edge.getContent() instanceof Dock) .forEach(edge -> commands.addCommand(new CanvasDockNodeCommand(edge.getSourceNode(), edge.getTargetNode()))); clonedEdges .stream() .filter(edge -> edge.getContent() instanceof ViewConnector) .forEach(edge -> commands.addCommand(new AddCanvasConnectorCommand((Edge) edge, getShapeSetId()))); } if (GraphUtils.hasDockedNodes(getCandidate())) { List<Edge> edges = getCandidate().getOutEdges(); edges.stream() .filter(edge -> edge.getContent() instanceof Dock) .map(edge -> edge.getTargetNode()) .forEach(targetNode -> { commands.addCommand(new AddCanvasChildNodeCommand(getParent(), targetNode, getShapeSetId())); commands.addCommand(new CanvasDockNodeCommand(getCandidate(), targetNode)); }); } return commands.execute(context); } CloneCanvasNodeCommand(Node parent, Node candidate, String shapeSetId, final ManagedInstance<ChildrenTraverseProcessor> childrenTraverseProcessor); AbstractCanvasCommand createAddCanvasChildNodeCommand(Node parent, Node candidate, String shapeSetId); CloneCanvasNodeCommand createCloneCanvasNodeCommand(Node parent, Node candidate, String shapeSetId); @Override CommandResult<CanvasViolation> execute(AbstractCanvasHandler context); @Override CommandResult<CanvasViolation> undo(AbstractCanvasHandler context); ManagedInstance<ChildrenTraverseProcessor> getChildrenTraverseProcessor(); Node getParent(); Node getCandidate(); String getShapeSetId(); @Override String toString();  }