@Override public void reset() { state.getGhost().ifPresent(this::restore); clearState(); }
private void clearState() { state.getGhost().ifPresent(WiresShapeViewExt::destroy); state.setGhost(Optional.empty()); state.setOriginalIndex(OptionalInt.empty()); state.setOriginalParent(Optional.empty()); }
@Override public void execute() { state.getGhost().ifPresent(ghost -> state.getOriginalParent().ifPresent(originalParent -> reparentDraggedShape(ghost, originalParent) ) ); clearState(); batch(); }
@Override public boolean acceptContainment(final WiresContainer wiresContainer, final WiresShape[] wiresShapes) { if (state.getGhost().isPresent() && containmentAllowed(wiresContainer, wiresShapes)) { final CaseManagementShapeView container = (CaseManagementShapeView) wiresContainer; final CaseManagementShapeView ghost = state.getGhost().get(); final int index = container.getIndex(ghost); if (index >= 0) { final OptionalInt newIndex = OptionalInt.of(index); final Optional<WiresContainer> originalContainer = state.getOriginalParent(); final OptionalInt originalIndex = state.getOriginalIndex(); final CommandResult<CanvasViolation> result = getCommandManager().execute(getCanvasHandler(), makeAddMutationCommand(wiresShapes[0], wiresContainer, newIndex, originalContainer, originalIndex)); return !CommandUtils.isError(result); } } return false; }
@Override public void onMoveStart(double x, double y) { containmentControl.onMoveStart(x, y); if (!(getShape() instanceof CaseManagementShapeView)) { state.setGhost(Optional.empty()); state.setOriginalIndex(OptionalInt.empty()); state.setOriginalParent(Optional.empty()); return; } state.setOriginalParent(Optional.ofNullable(getParent())); state.setOriginalIndex(getShapeIndex()); state.setGhost(Optional.ofNullable(((CaseManagementShapeView) getShape()).getGhost())); final WiresParentPickerControl.Index index = containmentControl.getParentPickerControl().getIndex(); index.clear(); if (state.getGhost().isPresent()) { index.exclude(state.getGhost().get()); } if ((getParent() instanceof CaseManagementShapeView)) { ((CaseManagementShapeView) getParent()).logicallyReplace((CaseManagementShapeView) getShape(), state.getGhost().get()); } }
@Before public void setup() { layer = spy(new Layer()); final Group shapeGroup = mock(Group.class); when(shapeGroup.getLayer()).thenReturn(layer); when(shape.getGroup()).thenReturn(shapeGroup); when(shape.getWiresManager()).thenReturn(wiresManager); doReturn(ghost).when(shape).getGhost(); when(wiresManager.getContainmentAcceptor()).thenReturn(containmentAcceptor); when(parentPickerControl.getPickerOptions()).thenReturn(PICKER_OPTIONS); when(parentPickerControl.getShapeLocationControl()).thenReturn(shapeLocationControl); when(parentPickerControl.getIndex()).thenReturn(index); when(containmentControl.getParentPickerControl()).thenReturn(parentPickerControl); when(containmentControl.getShape()).thenReturn(shape); when(containmentControl.getParent()).thenReturn(parent); final NFastArrayList<WiresShape> children = new NFastArrayList<>(); children.add(shape); children.add(ghost); when(parent.getChildShapes()).thenReturn(children); when(parent.getLayoutHandler()).thenReturn(parentLayoutHandler); when(parent.getIndex(eq(shape))).thenReturn(0); when(parent.getGroup()).thenReturn(new Group()); when(state.getGhost()).thenReturn(Optional.of(ghost)); when(state.getOriginalParent()).thenReturn(Optional.of(parent)); when(state.getOriginalIndex()).thenReturn(OptionalInt.of(0)); control = new CaseManagementContainmentControl(containmentControl, state); }
@Override public boolean onMove(double dx, double dy) { containmentControl.onMove(dx, dy); //Handle moving ghost from one container to another final Optional<CaseManagementShapeView> ghost = state.getGhost(); if (ghost.isPresent() && null != getParent() && null != getParent().getGroup()) { if (getWiresManager().getContainmentAcceptor().containmentAllowed(getParent(), new WiresShape[]{getShape()})) { final double mouseX = containmentControl.getParentPickerControl().getShapeLocationControl().getMouseStartX() + dx; final double mouseY = containmentControl.getParentPickerControl().getShapeLocationControl().getMouseStartY() + dy; final Point2D parentAbsLoc = getParent().getGroup().getComputedLocation(); final Point2D mouseRelativeLoc = new Point2D(mouseX - parentAbsLoc.getX(), mouseY - parentAbsLoc.getY()); //Children contains m_ghost and others excluding m_shape. This therefore moves m_ghost within children. getParent().getLayoutHandler().add(ghost.get(), getParent(), mouseRelativeLoc); containmentControl.getParentPickerControl().rebuildPicker(); } } return false; }