@Test public void execute() { tested.execute(context); verify(tested).executeCommands(eq(context), commandsCapture.capture()); final CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation> commands = commandsCapture.getValue(); assertEquals(commands.size(), 7); final List<Command<AbstractCanvasHandler, CanvasViolation>> commandList = new ArrayList<>(); for (int i = 0; i < commands.size(); i++) { Command<AbstractCanvasHandler, CanvasViolation> cmd = commands.get(i); commandList.add(cmd); } assertEquals(commandList.stream().filter(cmd -> cmd instanceof AddCanvasNodeCommand).count(), 1); assertEquals(commandList.stream().filter(cmd -> cmd instanceof AddCanvasChildNodeCommand).count(), 3); assertEquals(commandList.stream().filter(cmd -> cmd instanceof AddCanvasDockedNodeCommand).count(), 1); assertEquals(commandList.stream().filter(cmd -> cmd instanceof AddCanvasConnectorCommand).count(), 2); }
@Override @SuppressWarnings("unchecked") public CommandResult<CanvasViolation> execute(final AbstractCanvasHandler context) { final Graph graph = context.getGraphIndex().getGraph(); final String shapeSetId = getShapeSetId(context); final CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation> commandBuilder = new CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation>().forward(); childrenTraverseProcessor .traverse(graph, new AbstractChildrenTraverseCallback<Node<View, Edge>, Edge<Child, Node>>() { private Map<String, Boolean> processedNodes = new HashMap<>(); @Override public void startNodeTraversal(final Node<View, Edge> node) { super.startNodeTraversal(node); if (!isCanvasRoot().test(context, node.getUUID())) { addNode(node); } } @Override public boolean startNodeTraversal(final List<Node<View, Edge>> parents, final Node<View, Edge> node) { super.startNodeTraversal(parents, node); final Optional<Edge> dockEdge = node.getInEdges().stream() .filter(e -> e.getContent() instanceof Dock) .findAny(); final Node parent = dockEdge.map(Edge::getSourceNode) .orElseGet(() -> parents.get(parents.size() - 1)); if (dockEdge.isPresent()) { addDockedNode(parent, node); } else if (isCanvasRoot(). test(context, parent.getUUID())) { addNode(node); } else { addChildNode(parent, node); } return true; } private void addNode(final Node node) { if (processedNodes.containsKey(node.getUUID())) { return; } commandBuilder.addCommand(new AddCanvasNodeCommand(node, shapeSetId)); addProcessedNode(node); } private void addChildNode(final Node<View, Edge> parent, final Node<View, Edge> node) { if (processedNodes.containsKey(node.getUUID())) { return; } if (!processedNodes.containsKey(parent.getUUID())) { addNode(parent); } commandBuilder.addCommand(new AddCanvasChildNodeCommand(parent, node, shapeSetId)); addProcessedNode(node); } private void addDockedNode(final Node<View, Edge> parent, final Node<View, Edge> node) { if (!processedNodes.containsKey(parent.getUUID())) { addNode(parent); } commandBuilder.addCommand(new AddCanvasDockedNodeCommand(parent, node, shapeSetId)); addProcessedNode(node); } private void addProcessedNode(Node<View, Edge> node) { processedNodes.put(node.getUUID(), true); } @Override public void endGraphTraversal() { super.endGraphTraversal(); processedNodes.clear(); processedNodes = null; } }); viewTraverseProcessor .traverse(graph, new AbstractContentTraverseCallback<View<?>, Node<View, Edge>, Edge<View<?>, Node>>() { @Override public void startEdgeTraversal(final Edge<View<?>, Node> edge) { super.startEdgeTraversal(edge); commandBuilder.addCommand(new AddCanvasConnectorCommand(edge, shapeSetId)); } }); return executeCommands(context, commandBuilder); }
DrawCanvasCommand extends AbstractCanvasCommand { @Override @SuppressWarnings("unchecked") public CommandResult<CanvasViolation> execute(final AbstractCanvasHandler context) { final Graph graph = context.getGraphIndex().getGraph(); final String shapeSetId = getShapeSetId(context); final CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation> commandBuilder = new CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation>().forward(); childrenTraverseProcessor .traverse(graph, new AbstractChildrenTraverseCallback<Node<View, Edge>, Edge<Child, Node>>() { private Map<String, Boolean> processedNodes = new HashMap<>(); @Override public void startNodeTraversal(final Node<View, Edge> node) { super.startNodeTraversal(node); if (!isCanvasRoot().test(context, node.getUUID())) { addNode(node); } } @Override public boolean startNodeTraversal(final List<Node<View, Edge>> parents, final Node<View, Edge> node) { super.startNodeTraversal(parents, node); final Optional<Edge> dockEdge = node.getInEdges().stream() .filter(e -> e.getContent() instanceof Dock) .findAny(); final Node parent = dockEdge.map(Edge::getSourceNode) .orElseGet(() -> parents.get(parents.size() - 1)); if (dockEdge.isPresent()) { addDockedNode(parent, node); } else if (isCanvasRoot(). test(context, parent.getUUID())) { addNode(node); } else { addChildNode(parent, node); } return true; } private void addNode(final Node node) { if (processedNodes.containsKey(node.getUUID())) { return; } commandBuilder.addCommand(new AddCanvasNodeCommand(node, shapeSetId)); addProcessedNode(node); } private void addChildNode(final Node<View, Edge> parent, final Node<View, Edge> node) { if (processedNodes.containsKey(node.getUUID())) { return; } if (!processedNodes.containsKey(parent.getUUID())) { addNode(parent); } commandBuilder.addCommand(new AddCanvasChildNodeCommand(parent, node, shapeSetId)); addProcessedNode(node); } private void addDockedNode(final Node<View, Edge> parent, final Node<View, Edge> node) { if (!processedNodes.containsKey(parent.getUUID())) { addNode(parent); } commandBuilder.addCommand(new AddCanvasDockedNodeCommand(parent, node, shapeSetId)); addProcessedNode(node); } private void addProcessedNode(Node<View, Edge> node) { processedNodes.put(node.getUUID(), true); } @Override public void endGraphTraversal() { super.endGraphTraversal(); processedNodes.clear(); processedNodes = null; } }); viewTraverseProcessor .traverse(graph, new AbstractContentTraverseCallback<View<?>, Node<View, Edge>, Edge<View<?>, Node>>() { @Override public void startEdgeTraversal(final Edge<View<?>, Node> edge) { super.startEdgeTraversal(edge); commandBuilder.addCommand(new AddCanvasConnectorCommand(edge, shapeSetId)); } }); return executeCommands(context, commandBuilder); } }
DrawCanvasCommand extends AbstractCanvasCommand { @Override @SuppressWarnings("unchecked") public CommandResult<CanvasViolation> execute(final AbstractCanvasHandler context) { final Graph graph = context.getGraphIndex().getGraph(); final String shapeSetId = getShapeSetId(context); final CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation> commandBuilder = new CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation>().forward(); childrenTraverseProcessor .traverse(graph, new AbstractChildrenTraverseCallback<Node<View, Edge>, Edge<Child, Node>>() { private Map<String, Boolean> processedNodes = new HashMap<>(); @Override public void startNodeTraversal(final Node<View, Edge> node) { super.startNodeTraversal(node); if (!isCanvasRoot().test(context, node.getUUID())) { addNode(node); } } @Override public boolean startNodeTraversal(final List<Node<View, Edge>> parents, final Node<View, Edge> node) { super.startNodeTraversal(parents, node); final Optional<Edge> dockEdge = node.getInEdges().stream() .filter(e -> e.getContent() instanceof Dock) .findAny(); final Node parent = dockEdge.map(Edge::getSourceNode) .orElseGet(() -> parents.get(parents.size() - 1)); if (dockEdge.isPresent()) { addDockedNode(parent, node); } else if (isCanvasRoot(). test(context, parent.getUUID())) { addNode(node); } else { addChildNode(parent, node); } return true; } private void addNode(final Node node) { if (processedNodes.containsKey(node.getUUID())) { return; } commandBuilder.addCommand(new AddCanvasNodeCommand(node, shapeSetId)); addProcessedNode(node); } private void addChildNode(final Node<View, Edge> parent, final Node<View, Edge> node) { if (processedNodes.containsKey(node.getUUID())) { return; } if (!processedNodes.containsKey(parent.getUUID())) { addNode(parent); } commandBuilder.addCommand(new AddCanvasChildNodeCommand(parent, node, shapeSetId)); addProcessedNode(node); } private void addDockedNode(final Node<View, Edge> parent, final Node<View, Edge> node) { if (!processedNodes.containsKey(parent.getUUID())) { addNode(parent); } commandBuilder.addCommand(new AddCanvasDockedNodeCommand(parent, node, shapeSetId)); addProcessedNode(node); } private void addProcessedNode(Node<View, Edge> node) { processedNodes.put(node.getUUID(), true); } @Override public void endGraphTraversal() { super.endGraphTraversal(); processedNodes.clear(); processedNodes = null; } }); viewTraverseProcessor .traverse(graph, new AbstractContentTraverseCallback<View<?>, Node<View, Edge>, Edge<View<?>, Node>>() { @Override public void startEdgeTraversal(final Edge<View<?>, Node> edge) { super.startEdgeTraversal(edge); commandBuilder.addCommand(new AddCanvasConnectorCommand(edge, shapeSetId)); } }); return executeCommands(context, commandBuilder); } DrawCanvasCommand(final ChildrenTraverseProcessor childrenTraverseProcessor,
                             final ViewTraverseProcessor viewTraverseProcessor); }
DrawCanvasCommand extends AbstractCanvasCommand { @Override @SuppressWarnings("unchecked") public CommandResult<CanvasViolation> execute(final AbstractCanvasHandler context) { final Graph graph = context.getGraphIndex().getGraph(); final String shapeSetId = getShapeSetId(context); final CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation> commandBuilder = new CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation>().forward(); childrenTraverseProcessor .traverse(graph, new AbstractChildrenTraverseCallback<Node<View, Edge>, Edge<Child, Node>>() { private Map<String, Boolean> processedNodes = new HashMap<>(); @Override public void startNodeTraversal(final Node<View, Edge> node) { super.startNodeTraversal(node); if (!isCanvasRoot().test(context, node.getUUID())) { addNode(node); } } @Override public boolean startNodeTraversal(final List<Node<View, Edge>> parents, final Node<View, Edge> node) { super.startNodeTraversal(parents, node); final Optional<Edge> dockEdge = node.getInEdges().stream() .filter(e -> e.getContent() instanceof Dock) .findAny(); final Node parent = dockEdge.map(Edge::getSourceNode) .orElseGet(() -> parents.get(parents.size() - 1)); if (dockEdge.isPresent()) { addDockedNode(parent, node); } else if (isCanvasRoot(). test(context, parent.getUUID())) { addNode(node); } else { addChildNode(parent, node); } return true; } private void addNode(final Node node) { if (processedNodes.containsKey(node.getUUID())) { return; } commandBuilder.addCommand(new AddCanvasNodeCommand(node, shapeSetId)); addProcessedNode(node); } private void addChildNode(final Node<View, Edge> parent, final Node<View, Edge> node) { if (processedNodes.containsKey(node.getUUID())) { return; } if (!processedNodes.containsKey(parent.getUUID())) { addNode(parent); } commandBuilder.addCommand(new AddCanvasChildNodeCommand(parent, node, shapeSetId)); addProcessedNode(node); } private void addDockedNode(final Node<View, Edge> parent, final Node<View, Edge> node) { if (!processedNodes.containsKey(parent.getUUID())) { addNode(parent); } commandBuilder.addCommand(new AddCanvasDockedNodeCommand(parent, node, shapeSetId)); addProcessedNode(node); } private void addProcessedNode(Node<View, Edge> node) { processedNodes.put(node.getUUID(), true); } @Override public void endGraphTraversal() { super.endGraphTraversal(); processedNodes.clear(); processedNodes = null; } }); viewTraverseProcessor .traverse(graph, new AbstractContentTraverseCallback<View<?>, Node<View, Edge>, Edge<View<?>, Node>>() { @Override public void startEdgeTraversal(final Edge<View<?>, Node> edge) { super.startEdgeTraversal(edge); commandBuilder.addCommand(new AddCanvasConnectorCommand(edge, shapeSetId)); } }); return executeCommands(context, commandBuilder); } DrawCanvasCommand(final ChildrenTraverseProcessor childrenTraverseProcessor,
                             final ViewTraverseProcessor viewTraverseProcessor); @Override @SuppressWarnings("unchecked") CommandResult<CanvasViolation> execute(final AbstractCanvasHandler context); @Override CommandResult<CanvasViolation> undo(final AbstractCanvasHandler context); @Override String toString(); }
DrawCanvasCommand extends AbstractCanvasCommand { @Override @SuppressWarnings("unchecked") public CommandResult<CanvasViolation> execute(final AbstractCanvasHandler context) { final Graph graph = context.getGraphIndex().getGraph(); final String shapeSetId = getShapeSetId(context); final CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation> commandBuilder = new CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation>().forward(); childrenTraverseProcessor .traverse(graph, new AbstractChildrenTraverseCallback<Node<View, Edge>, Edge<Child, Node>>() { private Map<String, Boolean> processedNodes = new HashMap<>(); @Override public void startNodeTraversal(final Node<View, Edge> node) { super.startNodeTraversal(node); if (!isCanvasRoot().test(context, node.getUUID())) { addNode(node); } } @Override public boolean startNodeTraversal(final List<Node<View, Edge>> parents, final Node<View, Edge> node) { super.startNodeTraversal(parents, node); final Optional<Edge> dockEdge = node.getInEdges().stream() .filter(e -> e.getContent() instanceof Dock) .findAny(); final Node parent = dockEdge.map(Edge::getSourceNode) .orElseGet(() -> parents.get(parents.size() - 1)); if (dockEdge.isPresent()) { addDockedNode(parent, node); } else if (isCanvasRoot(). test(context, parent.getUUID())) { addNode(node); } else { addChildNode(parent, node); } return true; } private void addNode(final Node node) { if (processedNodes.containsKey(node.getUUID())) { return; } commandBuilder.addCommand(new AddCanvasNodeCommand(node, shapeSetId)); addProcessedNode(node); } private void addChildNode(final Node<View, Edge> parent, final Node<View, Edge> node) { if (processedNodes.containsKey(node.getUUID())) { return; } if (!processedNodes.containsKey(parent.getUUID())) { addNode(parent); } commandBuilder.addCommand(new AddCanvasChildNodeCommand(parent, node, shapeSetId)); addProcessedNode(node); } private void addDockedNode(final Node<View, Edge> parent, final Node<View, Edge> node) { if (!processedNodes.containsKey(parent.getUUID())) { addNode(parent); } commandBuilder.addCommand(new AddCanvasDockedNodeCommand(parent, node, shapeSetId)); addProcessedNode(node); } private void addProcessedNode(Node<View, Edge> node) { processedNodes.put(node.getUUID(), true); } @Override public void endGraphTraversal() { super.endGraphTraversal(); processedNodes.clear(); processedNodes = null; } }); viewTraverseProcessor .traverse(graph, new AbstractContentTraverseCallback<View<?>, Node<View, Edge>, Edge<View<?>, Node>>() { @Override public void startEdgeTraversal(final Edge<View<?>, Node> edge) { super.startEdgeTraversal(edge); commandBuilder.addCommand(new AddCanvasConnectorCommand(edge, shapeSetId)); } }); return executeCommands(context, commandBuilder); } DrawCanvasCommand(final ChildrenTraverseProcessor childrenTraverseProcessor,
                             final ViewTraverseProcessor viewTraverseProcessor); @Override @SuppressWarnings("unchecked") CommandResult<CanvasViolation> execute(final AbstractCanvasHandler context); @Override CommandResult<CanvasViolation> undo(final AbstractCanvasHandler context); @Override String toString();  }