*/
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.DefinedTermBase;
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.FeatureTree;
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;
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) {
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);
+ int currentPosition = target.getIndex(droppedNode);
+ if(currentPosition<position){
+ position -= 1;
}
- //copy operation
- else if(getCurrentOperation()==DND.DROP_COPY){
- CdmStore.getService(IFeatureNodeService.class).addChildFeatureNode(target.getUuid(), droppedNode.getFeature().getUuid());
- }
- 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);
+ 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);
+ TermDto termDto = (TermDto) droppedObject;
+ DefinedTermBase term = CdmStore.getService(ITermService.class).load(termDto.getUuid());
+ if(term.isInstanceOf(Feature.class)){
+ AddFeatureOperation operation = new AddFeatureOperation(
+ (Feature)term,
+ target, position, editor, editor);
+ AbstractUtility.executeOperation(operation, sync);
+ }
+ else{
+ MessagingUtils.warningDialog(DefinedTermDropAdapterE4.MOVE_FAILED, this, Messages.FeatureTreeDropAdapter_ONLY_MOVE_FEATURES);
+ }
}
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;
}