-// $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.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.ISequenceService;
-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.view.derivateSearch.DerivateLabelProvider;
+import eu.etaxonomy.taxeditor.model.MessagingUtils;
/**
* @author pplitzner
private final DerivateView derivateView;
- /**
- * @param derivateView
- */
protected DerivateDropListener(DerivateView derivateView) {
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 DerivateViewSelection){
DerivateViewSelection derivateViewSelection = (DerivateViewSelection)data;
TreeNode targetNode = (TreeNode) target;
- TreeNode draggednode = EditorUtil.getTreeNodeOfSelection(derivateViewSelection.getSelection());
- if(draggednode!=null){
- if(moveTreeNode(draggednode, targetNode)){
- //update DerivateView
- derivateView.getConversationHolder().commit();
- derivateView.refreshTree();
-
- // update source DerivateView if dragging between different views occured
- DerivateView sourceDerivateView = derivateViewSelection.getDerivateView();
- if(sourceDerivateView!=derivateView){
- sourceDerivateView.getConversationHolder().commit();
- sourceDerivateView.refreshTree();
- }
-
- //FIXME: way too much overhead for just refreshing the other DerivateView
-// CdmStore.getContextManager().notifyContextRefresh();
- LocalSelectionTransfer.getTransfer().setSelection(null);
- return true;
- }
- else{
- AbstractUtility.warningDialog("Moving derivate not possible!", derivateView, "Moving \""+DerivateLabelProvider.getDerivateText(draggednode)+"\" to \""+DerivateLabelProvider.getDerivateText(targetNode)+"\" is not possible!");
- }
+ 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) {
return LocalSelectionTransfer.getTransfer().isSupportedType(transferType) && target instanceof TreeNode;
}
/**
- * @param value
- * @return
+ * {@inheritDoc}
*/
- private boolean moveTreeNode(TreeNode draggedNode, TreeNode targetNode) {
- Object draggedNodeValue = draggedNode.getValue();
- Object targetNodeValue = targetNode.getValue();
- TreeNode fromParentNode = draggedNode.getParent();
- Object fromParentSpecimen = fromParentNode.getValue();
-
- // drag'n'drop for SpecimenOrObservationBase
- IOccurrenceService occurrenceService = CdmStore.getService(IOccurrenceService.class);
- if(draggedNodeValue instanceof DerivedUnit && targetNodeValue instanceof SpecimenOrObservationBase<?>){
- DerivedUnit draggedSpecimen = (DerivedUnit) draggedNodeValue;
- SpecimenOrObservationBase<?> targetSpecimen = (SpecimenOrObservationBase<?>) targetNodeValue;
- //check if type is a sub derivate type
- if(!fromParentNode.equals(targetNode)//don't drag on direct parent node
- && fromParentSpecimen instanceof SpecimenOrObservationBase<?>){
- return occurrenceService.moveDerivate((SpecimenOrObservationBase<?>)fromParentSpecimen, targetSpecimen, draggedSpecimen);
- }
- }
-
- // drag'n'drop for SingleRead
- else if(draggedNodeValue instanceof SingleRead && targetNodeValue instanceof Sequence){
- SingleRead singleRead = (SingleRead) draggedNodeValue;
- if(fromParentSpecimen instanceof Sequence){
- return CdmStore.getService(ISequenceService.class).moveSingleRead((Sequence)fromParentSpecimen, (Sequence)targetNodeValue, singleRead);
- }
- }
-
- // drag'n'drop for Sequence
- else if(draggedNodeValue instanceof Sequence && targetNodeValue instanceof DnaSample ){
- Sequence sequence = (Sequence)draggedNodeValue;
- if(fromParentSpecimen instanceof DnaSample){
- return occurrenceService.moveSequence((DnaSample)fromParentSpecimen, (DnaSample)targetNodeValue, sequence);
- }
- }
- return false;
+ @Override
+ public void dragOver(DropTargetEvent event) {
+ super.dragOver(event);
+ event.feedback = DND.FEEDBACK_SELECT | DND.FEEDBACK_SCROLL;
}
}