-// $Id$
/**
* Copyright (C) 2014 EDIT
* European Distributed Institute of Taxonomy
*/
package eu.etaxonomy.taxeditor.editor.view.derivate;
+import org.eclipse.core.runtime.Status;
import org.eclipse.jface.util.LocalSelectionTransfer;
-import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TreeNode;
import org.eclipse.jface.viewers.ViewerDropAdapter;
+import org.eclipse.swt.dnd.DND;
+import org.eclipse.swt.dnd.DropTargetEvent;
import org.eclipse.swt.dnd.TransferData;
-import eu.etaxonomy.cdm.api.service.IOccurrenceService;
-import eu.etaxonomy.cdm.api.service.molecular.IAmplificationService;
-import eu.etaxonomy.cdm.api.service.molecular.ISequenceService;
-import eu.etaxonomy.cdm.model.molecular.Amplification;
-import eu.etaxonomy.cdm.model.molecular.DnaSample;
-import eu.etaxonomy.cdm.model.molecular.Sequence;
-import eu.etaxonomy.cdm.model.molecular.SingleRead;
-import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
-import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
+import eu.etaxonomy.taxeditor.editor.EditorUtil;
+import eu.etaxonomy.taxeditor.editor.l10n.Messages;
+import eu.etaxonomy.taxeditor.editor.view.derivate.operation.MoveDerivateOperation;
import eu.etaxonomy.taxeditor.model.AbstractUtility;
-import eu.etaxonomy.taxeditor.store.CdmStore;
+import eu.etaxonomy.taxeditor.model.MessagingUtils;
/**
* @author pplitzner
private final DerivateView derivateView;
- /**
- * @param derivateView
- */
protected DerivateDropListener(DerivateView derivateView) {
- super(derivateView.viewer);
+ super(derivateView.getViewer());
this.derivateView = derivateView;
}
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.ViewerDropAdapter#performDrop(java.lang.Object)
- */
@Override
public boolean performDrop(Object data) {
if(derivateView.isDirty()){
- AbstractUtility.warningDialog("View has unsaved changes", this, "You need to save before performing this action");
+ MessagingUtils.warningDialog(DerivateView.VIEW_HAS_UNSAVED_CHANGES, this, DerivateView.YOU_NEED_TO_SAVE_BEFORE_PERFORMING_THIS_ACTION);
return false;
}
Object target = getCurrentTarget();
- if(target instanceof TreeNode && data instanceof IStructuredSelection && ((IStructuredSelection) data).size()==1 && ((IStructuredSelection) data).getFirstElement() instanceof TreeNode){
+ if(target instanceof TreeNode && data instanceof DerivateViewSelection){
+ DerivateViewSelection derivateViewSelection = (DerivateViewSelection)data;
TreeNode targetNode = (TreeNode) target;
- TreeNode draggednode = (TreeNode) ((IStructuredSelection) data).getFirstElement();
- if(moveDropTarget(draggednode, targetNode)){
- derivateView.viewer.setInput(derivateView.getEditorInput());
- return true;
+ TreeNode draggedNode = EditorUtil.getTreeNodeOfSelection(derivateViewSelection.getSelection());
+ if(draggedNode!=null){
+ MoveDerivateOperation moveDerivateOperation = new MoveDerivateOperation(String.format(Messages.DerivateDropListener_MOVE_TO, derivateView.getLabelProvider().getDerivateText(draggedNode), derivateView.getLabelProvider().getDerivateText(targetNode)), EditorUtil.getUndoContext(), derivateView, draggedNode, targetNode);
+ return AbstractUtility.executeOperation(moveDerivateOperation).equals(Status.OK_STATUS)?true:false;
}
}
return false;
}
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.ViewerDropAdapter#validateDrop(java.lang.Object, int, org.eclipse.swt.dnd.TransferData)
- */
@Override
public boolean validateDrop(Object target, int operation, TransferData transferType) {
- System.out.println("VAL");
return LocalSelectionTransfer.getTransfer().isSupportedType(transferType) && target instanceof TreeNode;
}
/**
- * @param value
- * @return
+ * {@inheritDoc}
*/
- private boolean moveDropTarget(TreeNode draggedObject, TreeNode target) {
- Object dragValue = draggedObject.getValue();
- Object targetValue = target.getValue();
- TreeNode dragParentNode = draggedObject.getParent();
- Object dragParentSpecimen = dragParentNode.getValue();
-
- // drag'n'drop for SpecimenOrObservationBase
- if(dragValue instanceof DerivedUnit && targetValue instanceof SpecimenOrObservationBase<?>){
- DerivedUnit draggedSpecimen = (DerivedUnit) dragValue;
- SpecimenOrObservationBase<?> targetSpecimen = (SpecimenOrObservationBase<?>) targetValue;
- //check if type is a sub derivate type
- if(!dragParentNode.equals(target)//don't drag on direct parent node
- && dragParentSpecimen instanceof SpecimenOrObservationBase<?>){
- CdmStore.getService(IOccurrenceService.class).moveDerivate((SpecimenOrObservationBase<?>)dragParentSpecimen, targetSpecimen, draggedSpecimen);
- return true;
- }
- }
-
- // drag'n'drop for SingleRead
- else if(dragValue instanceof SingleRead && (targetValue instanceof Amplification || targetValue instanceof Sequence)){
- SingleRead singleRead = (SingleRead) dragValue;
- //amplification -> amplification
- if(dragParentSpecimen instanceof Amplification && targetValue instanceof Amplification){
- if(((Amplification) dragParentSpecimen).getSingleReads().size()>1){
- CdmStore.getService(IAmplificationService.class).moveSingleRead((Amplification)dragParentSpecimen, (Amplification)targetValue, singleRead);
- }
- }
- //amplification -> sequence
- else if(dragParentSpecimen instanceof Amplification && targetValue instanceof Sequence){
- //TODO: what does the user expect?
- }
- //sequence -> sequence
- else if(dragParentSpecimen instanceof Sequence && targetValue instanceof Sequence){
- CdmStore.getService(ISequenceService.class).moveSingleRead((Sequence)dragParentSpecimen, (Sequence)targetValue, singleRead);
- }
- //sequence -> amplification
- else if(dragParentSpecimen instanceof Sequence && targetValue instanceof Amplification){
- //TODO: what does the user expect?
- }
- return true;
- }
-
- // drag'n'drop for Sequence
- else if(dragValue instanceof Sequence && targetValue instanceof DnaSample ){
- Sequence sequence = (Sequence)dragValue;
- if(dragParentSpecimen instanceof DnaSample){
- CdmStore.getService(IOccurrenceService.class).moveSequence((DnaSample)dragParentSpecimen, (DnaSample)targetValue, sequence);
- return true;
- }
- }
- return false;
+ @Override
+ public void dragOver(DropTargetEvent event) {
+ super.dragOver(event);
+ event.feedback = DND.FEEDBACK_SELECT | DND.FEEDBACK_SCROLL;
}
}