@Test public void testNewGraphCommand() { final Command graphCommand = command.newGraphCommand(canvasHandler); assertTrue(graphCommand instanceof CaseManagementSetChildNodeGraphCommand); final CaseManagementSetChildNodeGraphCommand cmGraphCommand = (CaseManagementSetChildNodeGraphCommand) graphCommand; assertTrue(cmGraphCommand.getIndex().isPresent()); assertEquals(0, cmGraphCommand.getIndex().getAsInt()); assertFalse(cmGraphCommand.getOriginalIndex().isPresent()); }
@Override @SuppressWarnings("unchecked") protected Command<GraphCommandExecutionContext, RuleViolation> newGraphCommand(final AbstractCanvasHandler context) { OptionalInt originalIndex = originalParent .map(p -> OptionalInt.of(getChildGraphIndex(p, getCandidate()))) .orElseGet(OptionalInt::empty); OptionalInt index = last.map(s -> { int i = getChildGraphIndex(parent, s); if (originalIndex.isPresent() && originalIndex.getAsInt() < i) { return OptionalInt.of(i); } else { return OptionalInt.of(i + 1); } }).orElseGet(() -> { if (canvasIndex.isPresent() && canvasIndex.getAsInt() == 0 ) { if (isStage(parent, getCandidate())) { List<Node<View<?>, Edge>> childNodes = ((Node<View<?>, Edge>) parent).getOutEdges().stream() .map(e -> (Node<View<?>, Edge>) e.getTargetNode()).collect(Collectors.toList()); for (int i = 0, n = childNodes.size(); i < n; i++) { if (childNodes.get(i).getContent().getDefinition() instanceof StartNoneEvent) { return OptionalInt.of(++i); } } return OptionalInt.of(0); } else { return canvasIndex; } } else { return OptionalInt.empty(); } }); return new CaseManagementSetChildNodeGraphCommand(parent, getCandidate(), index, originalParent, originalIndex); }
CaseManagementSetChildCommand extends org.kie.workbench.common.stunner.core.client.canvas.command.SetChildrenCommand { @Override @SuppressWarnings("unchecked") protected Command<GraphCommandExecutionContext, RuleViolation> newGraphCommand(final AbstractCanvasHandler context) { OptionalInt originalIndex = originalParent .map(p -> OptionalInt.of(getChildGraphIndex(p, getCandidate()))) .orElseGet(OptionalInt::empty); OptionalInt index = last.map(s -> { int i = getChildGraphIndex(parent, s); if (originalIndex.isPresent() && originalIndex.getAsInt() < i) { return OptionalInt.of(i); } else { return OptionalInt.of(i + 1); } }).orElseGet(() -> { if (canvasIndex.isPresent() && canvasIndex.getAsInt() == 0 ) { if (isStage(parent, getCandidate())) { List<Node<View<?>, Edge>> childNodes = ((Node<View<?>, Edge>) parent).getOutEdges().stream() .map(e -> (Node<View<?>, Edge>) e.getTargetNode()).collect(Collectors.toList()); for (int i = 0, n = childNodes.size(); i < n; i++) { if (childNodes.get(i).getContent().getDefinition() instanceof StartNoneEvent) { return OptionalInt.of(++i); } } return OptionalInt.of(0); } else { return canvasIndex; } } else { return OptionalInt.empty(); } }); return new CaseManagementSetChildNodeGraphCommand(parent, getCandidate(), index, originalParent, originalIndex); } }
CaseManagementSetChildCommand extends org.kie.workbench.common.stunner.core.client.canvas.command.SetChildrenCommand { @Override @SuppressWarnings("unchecked") protected Command<GraphCommandExecutionContext, RuleViolation> newGraphCommand(final AbstractCanvasHandler context) { OptionalInt originalIndex = originalParent .map(p -> OptionalInt.of(getChildGraphIndex(p, getCandidate()))) .orElseGet(OptionalInt::empty); OptionalInt index = last.map(s -> { int i = getChildGraphIndex(parent, s); if (originalIndex.isPresent() && originalIndex.getAsInt() < i) { return OptionalInt.of(i); } else { return OptionalInt.of(i + 1); } }).orElseGet(() -> { if (canvasIndex.isPresent() && canvasIndex.getAsInt() == 0 ) { if (isStage(parent, getCandidate())) { List<Node<View<?>, Edge>> childNodes = ((Node<View<?>, Edge>) parent).getOutEdges().stream() .map(e -> (Node<View<?>, Edge>) e.getTargetNode()).collect(Collectors.toList()); for (int i = 0, n = childNodes.size(); i < n; i++) { if (childNodes.get(i).getContent().getDefinition() instanceof StartNoneEvent) { return OptionalInt.of(++i); } } return OptionalInt.of(0); } else { return canvasIndex; } } else { return OptionalInt.empty(); } }); return new CaseManagementSetChildNodeGraphCommand(parent, getCandidate(), index, originalParent, originalIndex); } CaseManagementSetChildCommand(final Node<View<?>, Edge> parent,
                                         final Node<View<?>, Edge> child);  CaseManagementSetChildCommand(final Node<View<?>, Edge> parent,
                                         final Node<View<?>, Edge> child,
                                         final Optional<Node<View<?>, Edge>> last,
                                         final OptionalInt canvasIndex,
                                         final Optional<Node<View<?>, Edge>> originalParent,
                                         final OptionalInt originaCanvaslIndex); }
CaseManagementSetChildCommand extends org.kie.workbench.common.stunner.core.client.canvas.command.SetChildrenCommand { @Override @SuppressWarnings("unchecked") protected Command<GraphCommandExecutionContext, RuleViolation> newGraphCommand(final AbstractCanvasHandler context) { OptionalInt originalIndex = originalParent .map(p -> OptionalInt.of(getChildGraphIndex(p, getCandidate()))) .orElseGet(OptionalInt::empty); OptionalInt index = last.map(s -> { int i = getChildGraphIndex(parent, s); if (originalIndex.isPresent() && originalIndex.getAsInt() < i) { return OptionalInt.of(i); } else { return OptionalInt.of(i + 1); } }).orElseGet(() -> { if (canvasIndex.isPresent() && canvasIndex.getAsInt() == 0 ) { if (isStage(parent, getCandidate())) { List<Node<View<?>, Edge>> childNodes = ((Node<View<?>, Edge>) parent).getOutEdges().stream() .map(e -> (Node<View<?>, Edge>) e.getTargetNode()).collect(Collectors.toList()); for (int i = 0, n = childNodes.size(); i < n; i++) { if (childNodes.get(i).getContent().getDefinition() instanceof StartNoneEvent) { return OptionalInt.of(++i); } } return OptionalInt.of(0); } else { return canvasIndex; } } else { return OptionalInt.empty(); } }); return new CaseManagementSetChildNodeGraphCommand(parent, getCandidate(), index, originalParent, originalIndex); } CaseManagementSetChildCommand(final Node<View<?>, Edge> parent,
                                         final Node<View<?>, Edge> child);  CaseManagementSetChildCommand(final Node<View<?>, Edge> parent,
                                         final Node<View<?>, Edge> child,
                                         final Optional<Node<View<?>, Edge>> last,
                                         final OptionalInt canvasIndex,
                                         final Optional<Node<View<?>, Edge>> originalParent,
                                         final OptionalInt originaCanvaslIndex); Node getCandidate(); }
CaseManagementSetChildCommand extends org.kie.workbench.common.stunner.core.client.canvas.command.SetChildrenCommand { @Override @SuppressWarnings("unchecked") protected Command<GraphCommandExecutionContext, RuleViolation> newGraphCommand(final AbstractCanvasHandler context) { OptionalInt originalIndex = originalParent .map(p -> OptionalInt.of(getChildGraphIndex(p, getCandidate()))) .orElseGet(OptionalInt::empty); OptionalInt index = last.map(s -> { int i = getChildGraphIndex(parent, s); if (originalIndex.isPresent() && originalIndex.getAsInt() < i) { return OptionalInt.of(i); } else { return OptionalInt.of(i + 1); } }).orElseGet(() -> { if (canvasIndex.isPresent() && canvasIndex.getAsInt() == 0 ) { if (isStage(parent, getCandidate())) { List<Node<View<?>, Edge>> childNodes = ((Node<View<?>, Edge>) parent).getOutEdges().stream() .map(e -> (Node<View<?>, Edge>) e.getTargetNode()).collect(Collectors.toList()); for (int i = 0, n = childNodes.size(); i < n; i++) { if (childNodes.get(i).getContent().getDefinition() instanceof StartNoneEvent) { return OptionalInt.of(++i); } } return OptionalInt.of(0); } else { return canvasIndex; } } else { return OptionalInt.empty(); } }); return new CaseManagementSetChildNodeGraphCommand(parent, getCandidate(), index, originalParent, originalIndex); } CaseManagementSetChildCommand(final Node<View<?>, Edge> parent,
                                         final Node<View<?>, Edge> child);  CaseManagementSetChildCommand(final Node<View<?>, Edge> parent,
                                         final Node<View<?>, Edge> child,
                                         final Optional<Node<View<?>, Edge>> last,
                                         final OptionalInt canvasIndex,
                                         final Optional<Node<View<?>, Edge>> originalParent,
                                         final OptionalInt originaCanvaslIndex); Node getCandidate();  }