@Test public void testResizeNodes() { final Node stage = createNode(AdHocSubprocess.class, 1.0, 1.0, 25.0, 25.0); final Node task = createNode(UserTask.class, 1.0, 1.0, 5.0, 5.0); final CaseManagementSetChildNodeGraphCommand command = new CaseManagementSetChildNodeGraphCommand(stage, task, index, originalParent, originalIndex); final Edge childEdge = mock(Edge.class); when(childEdge.getContent()).thenReturn(mock(Child.class)); when(childEdge.getTargetNode()).thenReturn(task); when(stage.getOutEdges()).thenReturn(Collections.singletonList(childEdge)); command.resizeNodes(); assertEquals(Optional.of(Bounds.create(1.0, 1.0, 25.0, 25.0)), command.originalParentBounds); assertEquals(1, command.originalBounds.size()); assertEquals(Optional.of(Bounds.create(1.0, 1.0, 5.0, 5.0)), command.originalBounds.get(task.getUUID())); assertEquals(Bounds.create(1.0, 1.0, 1.0 + CHILD_WIDTH + STAGE_GAP * 2, 1.0 + CHILD_HEIGHT + STAGE_GAP * 2), ((View) stage.getContent()).getBounds()); assertEquals(Bounds.create(STAGE_GAP, STAGE_GAP, STAGE_GAP + CHILD_WIDTH, STAGE_GAP + CHILD_HEIGHT), ((View) task.getContent()).getBounds()); command.undoResizeNodes(); assertEquals(Bounds.create(1.0, 1.0, 25.0, 25.0), ((View) stage.getContent()).getBounds()); assertEquals(Bounds.create(1.0, 1.0, 5.0, 5.0), ((View) task.getContent()).getBounds()); }
@SuppressWarnings("unchecked") void resizeNodes() { if (isStageNode(parent) && isSubStageNode(child)) { final List<Node> childNodes = parent.getOutEdges().stream() .filter(childPredicate()).map(Edge::getTargetNode).collect(Collectors.toList()); childNodes.stream().forEach(cNode -> { final Bounds cBounds = ((Node<View, Edge>) cNode).getContent().getBounds(); originalBounds.put(cNode.getUUID(), Optional.of(Bounds.create(cBounds.getUpperLeft().getX(), cBounds.getUpperLeft().getY(), cBounds.getLowerRight().getX(), cBounds.getLowerRight().getY()))); }); IntStream.range(0, childNodes.size()).forEach(i -> { final Node<View, Edge> childNode = childNodes.get(i); final double cx = STAGE_GAP; final double cy = STAGE_GAP + (STAGE_GAP + CHILD_HEIGHT) * i; childNode.getContent().setBounds( Bounds.create(cx, cy, cx + CHILD_WIDTH, cy + CHILD_HEIGHT)); }); Bounds pBounds = parent.getContent().getBounds(); originalParentBounds = Optional.of(Bounds.create(pBounds.getUpperLeft().getX(), pBounds.getUpperLeft().getY(), pBounds.getLowerRight().getX(), pBounds.getLowerRight().getY())); Bounds parentBounds = Bounds.create(pBounds.getUpperLeft().getX(), pBounds.getUpperLeft().getY(), pBounds.getUpperLeft().getX() + CHILD_WIDTH + STAGE_GAP * 2, pBounds.getUpperLeft().getY() + STAGE_GAP + (STAGE_GAP + CHILD_HEIGHT) * childNodes.size()); parent.getContent().setBounds(parentBounds); } }
CaseManagementSetChildNodeGraphCommand extends AbstractGraphCommand { @SuppressWarnings("unchecked") void resizeNodes() { if (isStageNode(parent) && isSubStageNode(child)) { final List<Node> childNodes = parent.getOutEdges().stream() .filter(childPredicate()).map(Edge::getTargetNode).collect(Collectors.toList()); childNodes.stream().forEach(cNode -> { final Bounds cBounds = ((Node<View, Edge>) cNode).getContent().getBounds(); originalBounds.put(cNode.getUUID(), Optional.of(Bounds.create(cBounds.getUpperLeft().getX(), cBounds.getUpperLeft().getY(), cBounds.getLowerRight().getX(), cBounds.getLowerRight().getY()))); }); IntStream.range(0, childNodes.size()).forEach(i -> { final Node<View, Edge> childNode = childNodes.get(i); final double cx = STAGE_GAP; final double cy = STAGE_GAP + (STAGE_GAP + CHILD_HEIGHT) * i; childNode.getContent().setBounds( Bounds.create(cx, cy, cx + CHILD_WIDTH, cy + CHILD_HEIGHT)); }); Bounds pBounds = parent.getContent().getBounds(); originalParentBounds = Optional.of(Bounds.create(pBounds.getUpperLeft().getX(), pBounds.getUpperLeft().getY(), pBounds.getLowerRight().getX(), pBounds.getLowerRight().getY())); Bounds parentBounds = Bounds.create(pBounds.getUpperLeft().getX(), pBounds.getUpperLeft().getY(), pBounds.getUpperLeft().getX() + CHILD_WIDTH + STAGE_GAP * 2, pBounds.getUpperLeft().getY() + STAGE_GAP + (STAGE_GAP + CHILD_HEIGHT) * childNodes.size()); parent.getContent().setBounds(parentBounds); } } }
CaseManagementSetChildNodeGraphCommand extends AbstractGraphCommand { @SuppressWarnings("unchecked") void resizeNodes() { if (isStageNode(parent) && isSubStageNode(child)) { final List<Node> childNodes = parent.getOutEdges().stream() .filter(childPredicate()).map(Edge::getTargetNode).collect(Collectors.toList()); childNodes.stream().forEach(cNode -> { final Bounds cBounds = ((Node<View, Edge>) cNode).getContent().getBounds(); originalBounds.put(cNode.getUUID(), Optional.of(Bounds.create(cBounds.getUpperLeft().getX(), cBounds.getUpperLeft().getY(), cBounds.getLowerRight().getX(), cBounds.getLowerRight().getY()))); }); IntStream.range(0, childNodes.size()).forEach(i -> { final Node<View, Edge> childNode = childNodes.get(i); final double cx = STAGE_GAP; final double cy = STAGE_GAP + (STAGE_GAP + CHILD_HEIGHT) * i; childNode.getContent().setBounds( Bounds.create(cx, cy, cx + CHILD_WIDTH, cy + CHILD_HEIGHT)); }); Bounds pBounds = parent.getContent().getBounds(); originalParentBounds = Optional.of(Bounds.create(pBounds.getUpperLeft().getX(), pBounds.getUpperLeft().getY(), pBounds.getLowerRight().getX(), pBounds.getLowerRight().getY())); Bounds parentBounds = Bounds.create(pBounds.getUpperLeft().getX(), pBounds.getUpperLeft().getY(), pBounds.getUpperLeft().getX() + CHILD_WIDTH + STAGE_GAP * 2, pBounds.getUpperLeft().getY() + STAGE_GAP + (STAGE_GAP + CHILD_HEIGHT) * childNodes.size()); parent.getContent().setBounds(parentBounds); } } CaseManagementSetChildNodeGraphCommand(final Node<View<?>, Edge> parent,
                                                  final Node<View<?>, Edge> child,
                                                  final OptionalInt index,
                                                  final Optional<Node<View<?>, Edge>> originalParent,
                                                  final OptionalInt originalIndex); }
CaseManagementSetChildNodeGraphCommand extends AbstractGraphCommand { @SuppressWarnings("unchecked") void resizeNodes() { if (isStageNode(parent) && isSubStageNode(child)) { final List<Node> childNodes = parent.getOutEdges().stream() .filter(childPredicate()).map(Edge::getTargetNode).collect(Collectors.toList()); childNodes.stream().forEach(cNode -> { final Bounds cBounds = ((Node<View, Edge>) cNode).getContent().getBounds(); originalBounds.put(cNode.getUUID(), Optional.of(Bounds.create(cBounds.getUpperLeft().getX(), cBounds.getUpperLeft().getY(), cBounds.getLowerRight().getX(), cBounds.getLowerRight().getY()))); }); IntStream.range(0, childNodes.size()).forEach(i -> { final Node<View, Edge> childNode = childNodes.get(i); final double cx = STAGE_GAP; final double cy = STAGE_GAP + (STAGE_GAP + CHILD_HEIGHT) * i; childNode.getContent().setBounds( Bounds.create(cx, cy, cx + CHILD_WIDTH, cy + CHILD_HEIGHT)); }); Bounds pBounds = parent.getContent().getBounds(); originalParentBounds = Optional.of(Bounds.create(pBounds.getUpperLeft().getX(), pBounds.getUpperLeft().getY(), pBounds.getLowerRight().getX(), pBounds.getLowerRight().getY())); Bounds parentBounds = Bounds.create(pBounds.getUpperLeft().getX(), pBounds.getUpperLeft().getY(), pBounds.getUpperLeft().getX() + CHILD_WIDTH + STAGE_GAP * 2, pBounds.getUpperLeft().getY() + STAGE_GAP + (STAGE_GAP + CHILD_HEIGHT) * childNodes.size()); parent.getContent().setBounds(parentBounds); } } CaseManagementSetChildNodeGraphCommand(final Node<View<?>, Edge> parent,
                                                  final Node<View<?>, Edge> child,
                                                  final OptionalInt index,
                                                  final Optional<Node<View<?>, Edge>> originalParent,
                                                  final OptionalInt originalIndex); @Override @SuppressWarnings("unchecked") CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context); @Override @SuppressWarnings("unchecked") CommandResult<RuleViolation> undo(final GraphCommandExecutionContext context); OptionalInt getIndex(); OptionalInt getOriginalIndex(); }
CaseManagementSetChildNodeGraphCommand extends AbstractGraphCommand { @SuppressWarnings("unchecked") void resizeNodes() { if (isStageNode(parent) && isSubStageNode(child)) { final List<Node> childNodes = parent.getOutEdges().stream() .filter(childPredicate()).map(Edge::getTargetNode).collect(Collectors.toList()); childNodes.stream().forEach(cNode -> { final Bounds cBounds = ((Node<View, Edge>) cNode).getContent().getBounds(); originalBounds.put(cNode.getUUID(), Optional.of(Bounds.create(cBounds.getUpperLeft().getX(), cBounds.getUpperLeft().getY(), cBounds.getLowerRight().getX(), cBounds.getLowerRight().getY()))); }); IntStream.range(0, childNodes.size()).forEach(i -> { final Node<View, Edge> childNode = childNodes.get(i); final double cx = STAGE_GAP; final double cy = STAGE_GAP + (STAGE_GAP + CHILD_HEIGHT) * i; childNode.getContent().setBounds( Bounds.create(cx, cy, cx + CHILD_WIDTH, cy + CHILD_HEIGHT)); }); Bounds pBounds = parent.getContent().getBounds(); originalParentBounds = Optional.of(Bounds.create(pBounds.getUpperLeft().getX(), pBounds.getUpperLeft().getY(), pBounds.getLowerRight().getX(), pBounds.getLowerRight().getY())); Bounds parentBounds = Bounds.create(pBounds.getUpperLeft().getX(), pBounds.getUpperLeft().getY(), pBounds.getUpperLeft().getX() + CHILD_WIDTH + STAGE_GAP * 2, pBounds.getUpperLeft().getY() + STAGE_GAP + (STAGE_GAP + CHILD_HEIGHT) * childNodes.size()); parent.getContent().setBounds(parentBounds); } } CaseManagementSetChildNodeGraphCommand(final Node<View<?>, Edge> parent,
                                                  final Node<View<?>, Edge> child,
                                                  final OptionalInt index,
                                                  final Optional<Node<View<?>, Edge>> originalParent,
                                                  final OptionalInt originalIndex); @Override @SuppressWarnings("unchecked") CommandResult<RuleViolation> execute(final GraphCommandExecutionContext context); @Override @SuppressWarnings("unchecked") CommandResult<RuleViolation> undo(final GraphCommandExecutionContext context); OptionalInt getIndex(); OptionalInt getOriginalIndex();  }