(no commit message)
authorKatja Luther <k.luther@bgbm.org>
Thu, 12 Mar 2015 11:50:20 +0000 (11:50 +0000)
committerKatja Luther <k.luther@bgbm.org>
Thu, 12 Mar 2015 11:50:20 +0000 (11:50 +0000)
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/MoveTaxonHandler.java

index 02f6a6659ce850958a82cf74cbe711b84a8ba6da..ba681d70c4affeae78491497ba7ebeebf04c73a0 100644 (file)
@@ -19,17 +19,29 @@ import java.util.UUID;
 import org.eclipse.core.commands.AbstractHandler;
 import org.eclipse.core.commands.ExecutionEvent;
 import org.eclipse.core.commands.ExecutionException;
 import org.eclipse.core.commands.AbstractHandler;
 import org.eclipse.core.commands.ExecutionEvent;
 import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.expressions.EvaluationContext;
 import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.viewers.TreeSelection;
 import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.viewers.TreeSelection;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorReference;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PartInitException;
 import org.eclipse.ui.handlers.HandlerUtil;
 
 import org.eclipse.ui.handlers.HandlerUtil;
 
+import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
+import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
+import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
 import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.model.common.CdmBase;
+import eu.etaxonomy.cdm.model.common.ITreeNode;
+import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
+import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
 import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
 import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigator;
 import eu.etaxonomy.taxeditor.navigation.navigator.operation.MoveTaxonOperation;
 import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
 import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
 import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigator;
 import eu.etaxonomy.taxeditor.navigation.navigator.operation.MoveTaxonOperation;
 import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
+import eu.etaxonomy.taxeditor.store.CdmStore;
 import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonNodeSelectionDialog;
 
 /**
 import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonNodeSelectionDialog;
 
 /**
@@ -42,49 +54,56 @@ import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonNodeSelectionDialog;
 public class MoveTaxonHandler extends AbstractHandler implements IPostOperationEnabled {
 
        private TaxonNode parentTaxonNode;
 public class MoveTaxonHandler extends AbstractHandler implements IPostOperationEnabled {
 
        private TaxonNode parentTaxonNode;
-
+       protected IWorkbenchPage activePage;
        /* (non-Javadoc)
         * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
         */
        /** {@inheritDoc} */
        public Object execute(ExecutionEvent event) throws ExecutionException {
        /* (non-Javadoc)
         * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
         */
        /** {@inheritDoc} */
        public Object execute(ExecutionEvent event) throws ExecutionException {
-               TaxonNavigator taxonNavigator = NavigationUtil.showNavigator();
+               activePage = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();
+               TaxonNavigator taxonNavigator = (TaxonNavigator)NavigationUtil.showView(TaxonNavigator.ID);
                
                TreeSelection selection = (TreeSelection) HandlerUtil.getCurrentSelection(event);
                
                Iterator selectionIterator = selection.iterator();
                
                TreeSelection selection = (TreeSelection) HandlerUtil.getCurrentSelection(event);
                
                Iterator selectionIterator = selection.iterator();
-               Set<TaxonNode> taxonNodes = new HashSet<TaxonNode>();
+               TaxonNode taxonNode = null;
+               UUID taxonNodeUUID = null;
                // do not show the current selection
                List<UUID> excludeTaxa = new ArrayList<UUID>();
                
                // do not show the current selection
                List<UUID> excludeTaxa = new ArrayList<UUID>();
                
-       
-               while (selectionIterator.hasNext()){
+               if (selection.size() == 1){
                        Object object = selectionIterator.next();
                        if(object instanceof TaxonNode){
                        Object object = selectionIterator.next();
                        if(object instanceof TaxonNode){
-                               TaxonNode taxonNode = (TaxonNode) object;
-                               taxonNodes.add(taxonNode);
+                               taxonNode = HibernateProxyHelper.deproxy(object,TaxonNode.class);
+                               taxonNodeUUID = taxonNode.getUuid();
                                excludeTaxa.add(taxonNode.getTaxon().getUuid());
                        }
                                excludeTaxa.add(taxonNode.getTaxon().getUuid());
                        }
+               } else{
+                       if( MessageDialog.openConfirm(HandlerUtil.getActiveShell(event), "Moving taxon", "The operation move accepted taxon to other parent is available only for a single taxon.")){
+                               return null;
+                       }
                }
                
                }
                
-//             TaxonNode taxonNode = (TaxonNode) selection.getFirstElement();
                
                
-               parentTaxonNode = TaxonNodeSelectionDialog.select(HandlerUtil.getActiveShell(event), taxonNavigator.getConversationHolder(), "Choose new parent", excludeTaxa, null, null);
+//             TaxonNode taxonNode = (TaxonNode) selection.getFirstElement();
+               if (taxonNode != null){
+                       parentTaxonNode = TaxonNodeSelectionDialog.select(HandlerUtil.getActiveShell(event), taxonNavigator.getConversationHolder(), "Choose new parent", excludeTaxa, null, null);
+                       
+                       if(parentTaxonNode != null){
+                               if(NavigationUtil.isDirty(parentTaxonNode)){
+                                       MessageDialog.openWarning(HandlerUtil.getActiveShell(event), "Unsaved Parent Taxon", "There are unsaved " +
+                                                       "changes in the parent taxon. Please save first.");
+                                       return null;
+                               }
                                
                                
-               if(parentTaxonNode != null){
-                       if(NavigationUtil.isDirty(parentTaxonNode)){
-                               MessageDialog.openWarning(HandlerUtil.getActiveShell(event), "Unsaved Parent Taxon", "There are unsaved " +
-                                               "changes in the parent taxon. Please save first.");
-                               return null;
-                       }
+                               AbstractPostOperation operation = new MoveTaxonOperation
+                                               ("Move taxon to new parent", NavigationUtil.getUndoContext(),
+                                                               taxonNode, parentTaxonNode, taxonNavigator, taxonNavigator); //$NON-NLS-1$
+                               NavigationUtil.executeOperation(operation);
+                               taxonNavigator.refresh();
                        
                        
-                       AbstractPostOperation operation = new MoveTaxonOperation
-                                       ("Move taxon to new parent", NavigationUtil.getUndoContext(), 
-                                                       taxonNodes, parentTaxonNode, this, taxonNavigator); //$NON-NLS-1$
-                       NavigationUtil.executeOperation(operation);
-               
+                       }
                }
                }
-               
                return null;
        }
 
                return null;
        }
 
@@ -105,4 +124,6 @@ public class MoveTaxonHandler extends AbstractHandler implements IPostOperationE
                return false;
        }
        
                return false;
        }
        
+       
+       
 }
 }