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()); } }
private WiresManager getWiresManager() { return getShape().getWiresManager(); }
private void restore(final CaseManagementShapeView ghost, final CaseManagementShapeView parent, final int index) { ghost.removeFromParent(); parent.addShape(getShape(), index); }
private void batch() { getShape().getGroup().getLayer().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()}); }
@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; }