*/
package eu.etaxonomy.taxeditor.featuretree.e4;
-import java.net.URI;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerDropAdapter;
-import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.dnd.TransferData;
-import eu.etaxonomy.cdm.api.service.IFeatureNodeService;
-import eu.etaxonomy.cdm.api.service.ITermService;
-import eu.etaxonomy.cdm.model.common.OrderedTermVocabulary;
-import eu.etaxonomy.cdm.model.common.TermVocabulary;
import eu.etaxonomy.cdm.model.description.Feature;
-import eu.etaxonomy.cdm.model.description.FeatureNode;
-import eu.etaxonomy.cdm.model.description.FeatureTree;
+import eu.etaxonomy.cdm.model.term.FeatureNode;
+import eu.etaxonomy.cdm.model.term.FeatureTree;
+import eu.etaxonomy.cdm.model.term.IHasTermType;
+import eu.etaxonomy.cdm.model.term.OrderedTermVocabulary;
+import eu.etaxonomy.cdm.model.term.TermType;
+import eu.etaxonomy.cdm.model.term.TermVocabulary;
import eu.etaxonomy.cdm.persistence.dto.TermDto;
import eu.etaxonomy.taxeditor.editor.definedterm.TermTransfer;
+import eu.etaxonomy.taxeditor.editor.definedterm.e4.DefinedTermDropAdapterE4;
import eu.etaxonomy.taxeditor.featuretree.FeatureNodeTransfer;
import eu.etaxonomy.taxeditor.featuretree.e4.operation.AddFeatureOperation;
+import eu.etaxonomy.taxeditor.featuretree.e4.operation.AddOntologyTermOperation;
+import eu.etaxonomy.taxeditor.featuretree.e4.operation.MoveFeatureOperation;
import eu.etaxonomy.taxeditor.l10n.Messages;
import eu.etaxonomy.taxeditor.model.AbstractUtility;
import eu.etaxonomy.taxeditor.model.MessagingUtils;
-import eu.etaxonomy.taxeditor.store.CdmStore;
import eu.etaxonomy.taxeditor.store.StoreUtil;
import eu.etaxonomy.taxeditor.ui.dialog.selection.TermVocabularySelectionDialog;
import eu.etaxonomy.taxeditor.view.webimport.termimport.wrapper.OntologyTermWrapper;
FeatureNode parent = target.getParent();
if(parent!=null){
if (location == LOCATION_BEFORE) {
- position = Math.max(0, parent.getIndex(target) - 1);
+ position = Math.max(0, parent.getIndex(target));
target = parent;
}
if (location == LOCATION_AFTER) {
- position = parent.getIndex(target);
+ position = parent.getIndex(target)+1;
target = parent;
}
}
}
if(target==null){
- MessagingUtils.warningDialog(Messages.FeatureNodeDropAdapter_INVALID_TARGET, this, Messages.FeatureNodeDropAdapter_INVALID_TARGET_MESSAGE);
+ MessagingUtils.warningDialog("", this, ""); //$NON-NLS-1$ //$NON-NLS-1$
return false;
}
Collection<Object> droppedObjects = Collections.emptyList();
// cannot drop a feature node onto itself
for (Object droppedObject : droppedObjects) {
if(droppedObject==null){
- MessagingUtils.warningDialog("Move failed", this.getClass(),
- "Moving the feature node failed. Try saving before.");
+ MessagingUtils.warningDialog(DefinedTermDropAdapterE4.MOVE_FAILED, this.getClass(),
+ Messages.FeatureTreeDropAdapter_MOVE_FAILED_SAVE_MESSAGE);
return false;
}
if (droppedObject.equals(target)) {
}
}
for (Object droppedObject : droppedObjects) {
+ //check term type compatibility
+ TermType targetType = target.getTermType();
+ TermType droppedType = null;
+ if(droppedObject instanceof IHasTermType){
+ droppedType = ((IHasTermType)droppedObject).getTermType();
+ if(droppedType!=null && !droppedType.equals(targetType)){
+ MessagingUtils.warningDialog(DefinedTermDropAdapterE4.TERM_TYPE_ERROR_TITLE, this, DefinedTermDropAdapterE4.TERM_TYPE_ERROR_MESSAGE);
+ continue;
+ }
+ }
+ else if(droppedObject instanceof TermDto){
+ droppedType = ((TermDto)droppedObject).getTermType();
+ if(droppedType!=null && !droppedType.equals(targetType) && !droppedType.isKindOf(targetType)){
+ MessagingUtils.warningDialog(DefinedTermDropAdapterE4.TERM_TYPE_ERROR_TITLE, this, DefinedTermDropAdapterE4.TERM_TYPE_ERROR_MESSAGE);
+ continue;
+ }
+ }
if(droppedObject instanceof FeatureNode){
FeatureNode droppedNode = (FeatureNode) droppedObject;
- //move operation
- if(getCurrentOperation()==DND.DROP_MOVE){
- CdmStore.getService(IFeatureNodeService.class).moveFeatureNode(droppedNode.getUuid(), target.getUuid(), position);
- }
- //copy operation
- else if(getCurrentOperation()==DND.DROP_COPY){
- CdmStore.getService(IFeatureNodeService.class).addChildFeatureNode(target.getUuid(), droppedNode.getFeature().getUuid());
+ int currentPosition = target.getIndex(droppedNode);
+ if(currentPosition<position){
+ position -= 1;
}
- viewer.reveal(droppedNode);
+ MoveFeatureOperation operation = new MoveFeatureOperation(droppedNode, target, position, getCurrentOperation(), editor, editor);
+ AbstractUtility.executeOperation(operation, sync);
}
else if(droppedObject instanceof Feature){
Feature droppedFeature = (Feature) droppedObject;
AddFeatureOperation operation = new AddFeatureOperation(
- (Feature) CdmStore.getService(ITermService.class).load(droppedFeature.getUuid()),
- target, editor, editor);
+ droppedFeature.getUuid(),
+ target, position, editor, editor);
AbstractUtility.executeOperation(operation, sync);
}
else if(droppedObject instanceof TermDto){
TermDto termDto = (TermDto) droppedObject;
- AddFeatureOperation operation = new AddFeatureOperation(
- (Feature) CdmStore.getService(ITermService.class).load(termDto.getUuid()),
- target, editor, editor);
- AbstractUtility.executeOperation(operation, sync);
+ // check if target feature tree has the same type as the dropped term
+ if(!termDto.getTermType().equals(targetType)){
+ MessagingUtils.warningDialog(DefinedTermDropAdapterE4.TERM_TYPE_ERROR_TITLE, this, DefinedTermDropAdapterE4.TERM_TYPE_ERROR_MESSAGE);
+ continue;
+ }
+ AddFeatureOperation operation = new AddFeatureOperation(
+ termDto.getUuid(),
+ target, position, editor, editor);
+ AbstractUtility.executeOperation(operation, sync);
}
else if(droppedObject instanceof OntologyTermWrapper){
OntologyTermWrapper wrapper = (OntologyTermWrapper)droppedObject;
TermVocabulary vocabulary = wrapper.getTermVocabulary();
if(vocabulary==null){
vocabulary = TermVocabularySelectionDialog.select(
- "Choose vocabulary for import", viewer.getControl().getShell(), null);
+ Messages.FeatureTreeDropAdapter_CHOOSE_VOC, viewer.getControl().getShell(), null);
if(vocabulary instanceof OrderedTermVocabulary){
- MessagingUtils.warningDialog("Import not possible", this,
- "The chosen vocabulary is an ordered vocabulary.\n"
- + "Importing into ordered vocabularies is currently not supported.");
+ MessagingUtils.warningDialog(Messages.FeatureTreeDropAdapter_IMPORT_NOT_POSSIBLE, this,
+ Messages.FeatureTreeDropAdapter_ORDER_VOC_NOT_POSSIBLE);
return false;
}
}
return false;
}
else{
- Feature feature = Feature.NewInstance(wrapper.getDescription(), wrapper.getLabel(), null);
- feature.setUri(URI.create(wrapper.getUri()));
- vocabulary.addTerm(feature);
- CdmStore.getService(IFeatureNodeService.class).createChildFeatureNode(target, feature);
+ AddOntologyTermOperation operation = new AddOntologyTermOperation(wrapper, target, vocabulary, editor, editor);
+ AbstractUtility.executeOperation(operation, sync);
}
}
}
@Override
public boolean validateDrop(Object target, int operation, TransferData transferData) {
- boolean isSupported = FeatureNodeTransfer.getInstance().isSupportedType(transferData);
+ boolean
+ isSupported = FeatureNodeTransfer.getInstance().isSupportedType(transferData);
isSupported |= TermTransfer.getInstance().isSupportedType(transferData);
isSupported |= LocalSelectionTransfer.getTransfer().isSupportedType(transferData);
- isSupported |= TermTransfer.getInstance().isSupportedType(transferData);
isSupported &= getViewer().getInput()!=null;
+ if(target instanceof FeatureTree && getCurrentLocation()!=ViewerDropAdapter.LOCATION_ON){
+ isSupported = false;
+ }
return isSupported;
}