@Override public void execute() { state.getGhost().ifPresent(ghost -> state.getOriginalParent().ifPresent(originalParent -> reparentDraggedShape(ghost, originalParent) ) ); clearState(); batch(); }
@Override public boolean accept() { if (null == getParent() || getParent() instanceof WiresLayer) { return false; } if (!(state.getOriginalParent().isPresent() || state.getOriginalIndex().isPresent())) { return false; } // Execute. return getWiresManager() .getContainmentAcceptor() .acceptContainment(getParent(), new WiresShape[]{getShape()}); }
OptionalInt getShapeIndex() { if ((getShape() instanceof CaseManagementDiagramShapeView)) { return OptionalInt.of(0); } if (!(getParent() instanceof CaseManagementShapeView) || getShape() == null) { return OptionalInt.empty(); } int index = ((CaseManagementShapeView) getParent()).getIndex(getShape()); return index >= 0 ? OptionalInt.of(index) : OptionalInt.empty(); }
@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()); } }
@Test public void testGetShapeIndex_diagram() throws Exception { when(containmentControl.getShape()).thenReturn(mock(CaseManagementDiagramShapeView.class)); OptionalInt result = control.getShapeIndex(); assertEquals(0, result.getAsInt()); }
public CaseManagementShapeControl(final WiresShape shape, final CaseManagementContainmentStateHolder state) { final ColorMapBackedPicker.PickerOptions pickerOptions = new ColorMapBackedPicker.PickerOptions(false, 0); final WiresParentPickerCachedControl parentPicker = new WiresParentPickerCachedControl(new CaseManagementShapeLocationControl(shape), new CaseManagementColorMapBackedPickerProvider(pickerOptions)); shapeControl = new WiresShapeControlImpl(parentPicker, new WiresMagnetsControlImpl(shape), null, new CaseManagementContainmentControl(parentPicker, state)); }
@Override public void reset() { state.getGhost().ifPresent(this::restore); clearState(); }
@Test public void testReparentDraggedShape() { when(state.getOriginalParent()).thenReturn(Optional.of(mock(WiresContainer.class))); final CaseManagementShapeView ghostParent = mock(CaseManagementShapeView.class); when(ghost.getParent()).thenReturn(ghostParent); when(ghostParent.getIndex(eq(ghost))).thenReturn(1); control.execute(); verify(containmentControl, times(1)).execute(); verify(ghost, atLeast(1)).removeFromParent(); verify(ghostParent, times(1)).addShape(eq(shape), eq(1)); }
@Test public void testAccept() { control.accept(); verify(containmentAcceptor, never()).containmentAllowed(any(WiresContainer.class), any(WiresShape[].class)); verify(containmentAcceptor, times(1)).acceptContainment(eq(parent), eq(new WiresShape[]{shape})); }
@Test public void testClear() { control.clear(); verify(ghost, times(1)).destroy(); verify(state, times(1)).setGhost(Optional.empty()); verify(state, times(1)).setOriginalParent(Optional.empty()); verify(state, times(1)).setOriginalIndex(OptionalInt.empty()); }
@Test public void testAdjust() { Point2D adjust = new Point2D(0d, 1d); when(containmentControl.getAdjust()).thenReturn(adjust); assertEquals(adjust, control.getAdjust()); }
@Test public void testCandidateLocation() { Point2D location = new Point2D(0d, 1d); when(containmentControl.getCandidateLocation()).thenReturn(location); assertEquals(location, control.getCandidateLocation()); }
@Test public void testGetShapeIndex_noShape() throws Exception { when(containmentControl.getShape()).thenReturn(null); OptionalInt result = control.getShapeIndex(); assertFalse(result.isPresent()); }
@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 void clear() { clearState(); containmentControl.clear(); }
@Test public void testExecuteAndRestoreGhost() { control.execute(); verify(parent, never()).logicallyReplace(eq(ghost), eq(shape)); verify(ghost, times(1)).destroy(); verify(state, times(1)).setGhost(Optional.empty()); verify(state, times(1)).setOriginalParent(Optional.empty()); verify(state, times(1)).setOriginalIndex(OptionalInt.empty()); verify(layer, times(1)).batch(); }
@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; }
@Test public void testGetShapeIndex_noParent() throws Exception { when(containmentControl.getParent()).thenReturn(null); OptionalInt result = control.getShapeIndex(); assertFalse(result.isPresent()); } }
@Override public void destroy() { clearState(); containmentControl.destroy(); }