for (Object droppedObject : droppedObjects) {
//check term type compatibility
TermType targetType = target.getType();
+
TermType droppedType = null;
if(droppedObject instanceof IHasTermType){
droppedType = ((IHasTermType)droppedObject).getTermType();
}
TermNodeDto droppedNode = editor.getNodeDtoForUuid(((TermNodeDto) droppedObject).getUuid());
TermNodeDto oldParent = editor.getNodeDtoForUuid(droppedNode.getParentUuid());
+ boolean isCircle = checkCircle(droppedNode, target);
+ if (isCircle){
+ return false;
+ }
int currentPosition = oldParent.getIndex(droppedNode);
if(currentPosition<position && target.equals(oldParent)){
MoveFeatureOperation operation = new MoveFeatureOperation(droppedNode.getUuid(), droppedNode.getTerm().getUuid(), target.getUuid(), position, getCurrentOperation(), editor, editor);
Object o = oldParent.getChildren().remove(currentPosition);
+
target.getChildren().add(position, droppedNode);
droppedNode.setParentUuid(target.getUuid());
editor.setNodeDtoForUuid(droppedNode);
return true;
}
+ /**
+ * @param droppedNode
+ * @param target
+ */
+ private boolean checkCircle(TermNodeDto droppedNode, TermNodeDto newParent) {
+ boolean result = false;
+ if (droppedNode.getChildren().contains(newParent)){
+ return true;
+ }
+
+ if (newParent.getParentUuid() != null){
+ result = checkCircle(droppedNode, editor.getNodeDtoForUuid(newParent.getParentUuid()));
+
+ }
+ return result;
+
+ }
+
@Override
public boolean validateDrop(Object target, int operation, TransferData transferData) {
boolean
isSupported |= TermTransfer.getInstance().isSupportedType(transferData);
isSupported |= LocalSelectionTransfer.getTransfer().isSupportedType(transferData);
isSupported &= getViewer().getInput()!=null;
+
if(target instanceof TermTreeDto && getCurrentLocation()!=ViewerDropAdapter.LOCATION_ON){
isSupported = false;
}