merged/implemented cdm3.3 model adaptations
[taxeditor.git] / eu.etaxonomy.taxeditor.navigation / src / main / java / eu / etaxonomy / taxeditor / navigation / navigator / TreeNodeDropAdapterAssistant.java
index b0d7bb74f6297ecd44fbb02f2b186383790cc739..dd7c51520345b8bd71e85b361868f3619841d82e 100644 (file)
@@ -1,9 +1,9 @@
 // $Id$
 /**
 * Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy 
+* European Distributed Institute of Taxonomy
 * http://www.e-taxonomy.eu
-* 
+*
 * The contents of this file are subject to the Mozilla Public License Version 1.1
 * See LICENSE.TXT at the top of this package for the full license terms.
 */
@@ -28,7 +28,7 @@ import org.eclipse.ui.navigator.CommonDropAdapter;
 import org.eclipse.ui.navigator.CommonDropAdapterAssistant;
 
 import eu.etaxonomy.cdm.model.common.CdmBase;
-import eu.etaxonomy.cdm.model.taxon.ITreeNode;
+import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
 import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
 import eu.etaxonomy.taxeditor.navigation.navigator.operation.MoveTaxonOperation;
@@ -48,7 +48,7 @@ public class TreeNodeDropAdapterAssistant extends CommonDropAdapterAssistant imp
 
        /** Constant <code>ID="eu.etaxonomy.taxeditor.navigation.navig"{trunked}</code> */
        public static final String ID = "eu.etaxonomy.taxeditor.navigation.navigator.dropassistant"; //$NON-NLS-1$
-       
+
        /* (non-Javadoc)
         * @see org.eclipse.ui.navigator.CommonDropAdapterAssistant#handleDrop(org.eclipse.ui.navigator.CommonDropAdapter, org.eclipse.swt.dnd.DropTargetEvent, java.lang.Object)
         */
@@ -56,25 +56,26 @@ public class TreeNodeDropAdapterAssistant extends CommonDropAdapterAssistant imp
        @Override
        public IStatus handleDrop(CommonDropAdapter dropAdapter,
                        DropTargetEvent dropTargetEvent, Object target) {
-                       
-               if (target instanceof ITreeNode) {
+
+               if (target instanceof ITaxonTreeNode) {
                        Set<TaxonNode> taxonNodes = getSelectedTaxa();
-                       ITreeNode targetTreeNode = (ITreeNode) target;
-                       if(taxonNodes != null)
-                               return moveTaxon(taxonNodes, targetTreeNode);
+                       ITaxonTreeNode targetTreeNode = (ITaxonTreeNode) target;
+                       if(taxonNodes != null) {
+                return moveTaxon(taxonNodes, targetTreeNode);
+            }
                }
-                                                       
+
                return Status.CANCEL_STATUS;
        }
-       
+
        private Set<TaxonNode> getSelectedTaxa(){
-               HashSet<TaxonNode> taxonNodes = new HashSet<TaxonNode>();               
-               
+               HashSet<TaxonNode> taxonNodes = new HashSet<TaxonNode>();
+
                ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
                if (selection instanceof TreeSelection) {
-               
+
                        Iterator selectionIterator = ((TreeSelection) selection).iterator();
-                               
+
                        while (selectionIterator.hasNext()){
                                Object object = selectionIterator.next();
                                if(object instanceof TaxonNode){
@@ -92,8 +93,8 @@ public class TreeNodeDropAdapterAssistant extends CommonDropAdapterAssistant imp
        /** {@inheritDoc} */
        @Override
        public IStatus validateDrop(Object target, int operation,
-                       TransferData transferType) {    
-               if (target instanceof ITreeNode) {
+                       TransferData transferType) {
+               if (target instanceof ITaxonTreeNode) {
                        // do not allow to drop onto itself
                        for(TaxonNode taxonNode : getSelectedTaxa()){
                                if (taxonNode.equals(target)) {
@@ -101,53 +102,53 @@ public class TreeNodeDropAdapterAssistant extends CommonDropAdapterAssistant imp
                                }
                        }
                        return Status.OK_STATUS;
-               }               
+               }
                return Status.CANCEL_STATUS;
        }
-       
+
 
        /**
         * @param childTaxonNode
         * @param parentTaxon
         * @return
         */
-       private IStatus moveTaxon(Set<TaxonNode> taxonNodes, ITreeNode targetITreeNode) {
-               
+       private IStatus moveTaxon(Set<TaxonNode> taxonNodes, ITaxonTreeNode targetITaxonTreeNode) {
+
                TaxonNavigator taxonNavigator;
                taxonNavigator = (TaxonNavigator) NavigationUtil.showView(TaxonNavigator.ID);
-               
-               if(targetITreeNode instanceof TaxonNode){
-               
-                       TaxonNode targetTaxonNode = (TaxonNode) targetITreeNode;
-                       
+
+               if(targetITaxonTreeNode instanceof TaxonNode){
+
+                       TaxonNode targetTaxonNode = (TaxonNode) targetITaxonTreeNode;
+
 //                     for(TaxonNode taxonNode : taxonNodes){
 //                             if (taxonNode.equals(targetTaxonNode)) {
 //                                     return Status.CANCEL_STATUS;
 //                             }
 //                     }
-                       
+
                        // Make sure parent taxon does not have unsaved changes
                        if (NavigationUtil.isDirty(targetTaxonNode)){
                                MessageDialog.openWarning(NavigationUtil.getShell(), "Unsaved Parent Taxon", "There are unsaved " +
                                "changes in the parent taxon. Pleas save first.");
                                return Status.CANCEL_STATUS;
                        }
-                       
-                       
+
+
                        // Make sure parentTaxon is not the drop target
 //                     if (!childTaxonNode.isTopmostNode() && childTaxonNode.getParent().equals(targetTaxonNode)){
 //                             return Status.CANCEL_STATUS;
 //                     }
-                       
+
                        // Make sure taxon is not being dropped onto itself
 //                     if (childTaxonNode.equals(targetTaxonNode)) {
 //                             return Status.CANCEL_STATUS;
 //                     }
-                       
-                       
 
-               }       
-               
+
+
+               }
+
                IUndoContext workspaceUndoContext = NavigationUtil.getWorkbenchUndoContext();
                if (workspaceUndoContext == null) {
                        logger.error("Workspace undo context is null. DND operation cancelled");
@@ -155,10 +156,10 @@ public class TreeNodeDropAdapterAssistant extends CommonDropAdapterAssistant imp
                }
 
                AbstractPostOperation operation = new MoveTaxonOperation
-                               ("Move Taxon", workspaceUndoContext, taxonNodes, targetITreeNode, this, taxonNavigator);
-               NavigationUtil.executeOperation(operation);     
-               
-               logger.info("Moved taxa to new parent " + targetITreeNode);
+                               ("Move Taxon", workspaceUndoContext, taxonNodes, targetITaxonTreeNode, this, taxonNavigator);
+               NavigationUtil.executeOperation(operation);
+
+               logger.info("Moved taxa to new parent " + targetITaxonTreeNode);
                return Status.OK_STATUS;
        }
 
@@ -166,7 +167,8 @@ public class TreeNodeDropAdapterAssistant extends CommonDropAdapterAssistant imp
         * @see eu.etaxonomy.taxeditor.operations.IPostOperationEnabled#postOperation(eu.etaxonomy.cdm.model.common.CdmBase)
         */
        /** {@inheritDoc} */
-       public boolean postOperation(CdmBase objectAffectedByOperation) {
+       @Override
+    public boolean postOperation(CdmBase objectAffectedByOperation) {
                return true;
        }
 
@@ -175,7 +177,8 @@ public class TreeNodeDropAdapterAssistant extends CommonDropAdapterAssistant imp
         *
         * @return a boolean.
         */
-       public boolean onComplete() {
+       @Override
+    public boolean onComplete() {
                // TODO Auto-generated method stub
                return false;
        }