import java.util.Collection;
import java.util.Collections;
+import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.e4.ui.model.application.ui.MDirtyable;
import org.eclipse.jface.util.LocalSelectionTransfer;
import org.eclipse.jface.viewers.IStructuredSelection;
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.taxeditor.store.CdmStore;
import eu.etaxonomy.taxeditor.ui.dialog.selection.TermVocabularySelectionDialog;
import eu.etaxonomy.taxeditor.view.webimport.termimport.wrapper.OntologyTermWrapper;
+import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart;
public class FeatureNodeDropAdapter extends ViewerDropAdapter {
+ public static final String SAVE_CHANGES_TITLE = "Unsaved changes";
+ public static final String SAVE_CHANGES_MESSAGE = "The editor has unsaved changes. You need to save before performind this operation. Save now?";
+
private MDirtyable dirtyable;
+ private IE4SavablePart savablePart;
- public FeatureNodeDropAdapter(MDirtyable dirtyable, Viewer viewer) {
+ public FeatureNodeDropAdapter(MDirtyable dirtyable, IE4SavablePart savablePart, Viewer viewer) {
super(viewer);
this.dirtyable = dirtyable;
+ this.savablePart = savablePart;
}
@Override
public boolean performDrop(Object data) {
+ if(dirtyable.isDirty()){
+ if(MessagingUtils.confirmDialog(SAVE_CHANGES_TITLE, SAVE_CHANGES_MESSAGE)){
+ savablePart.save(new NullProgressMonitor());
+ }
+ else{
+ return false;
+ }
+ }
Object currentTarget = getCurrentTarget();
FeatureNode target = null;
if(currentTarget instanceof FeatureTree){
if (target != null) {
int location = getCurrentLocation();
FeatureNode parent = target.getParent();
- if (location == LOCATION_BEFORE) {
- position = Math.max(0, parent.getIndex(target) - 1);
- target = parent;
- }
+ if(parent!=null){
+ if (location == LOCATION_BEFORE) {
+ position = Math.max(0, parent.getIndex(target) - 1);
+ target = parent;
+ }
- if (location == LOCATION_AFTER) {
- position = parent.getIndex(target);
- target = parent;
+ if (location == LOCATION_AFTER) {
+ position = parent.getIndex(target);
+ target = parent;
+ }
}
}
MessagingUtils.warningDialog(Messages.FeatureNodeDropAdapter_INVALID_TARGET, this, Messages.FeatureNodeDropAdapter_INVALID_TARGET_MESSAGE);
return false;
}
-
Collection<Object> droppedObjects = Collections.emptyList();
if(data instanceof Object[]){
droppedObjects = Arrays.asList((Object[])data);
// 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.");
+ return false;
+ }
if (droppedObject.equals(target)) {
return false;
}
for (Object droppedObject : droppedObjects) {
if(droppedObject instanceof FeatureNode){
FeatureNode droppedNode = (FeatureNode) droppedObject;
- CdmStore.getService(IFeatureNodeService.class).moveFeatureNode(droppedNode.getUuid(), target.getUuid(), position);
+ //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());
+ }
viewer.reveal(droppedNode);
}
else if(droppedObject instanceof Feature){
}
else if(droppedObject instanceof OntologyTermWrapper){
OntologyTermWrapper wrapper = (OntologyTermWrapper)droppedObject;
- TermVocabulary vocabulary = TermVocabularySelectionDialog.select(
- "Choose vocabulary for import", 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.");
+ TermVocabulary vocabulary = wrapper.getTermVocabulary();
+ if(vocabulary==null){
+ vocabulary = TermVocabularySelectionDialog.select(
+ "Choose vocabulary for import", 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.");
+ return false;
+ }
+ }
+ if(vocabulary==null){
return false;
}
- if(vocabulary!=null){
+ else{
Feature feature = Feature.NewInstance(wrapper.getDescription(), wrapper.getLabel(), null);
feature.setUri(URI.create(wrapper.getUri()));
vocabulary.addTerm(feature);
}
}
}
- dirtyable.setDirty(true);
viewer.refresh();
return true;
}