adding the operation and handler files
authorKatja Luther <k.luther@bgbm.org>
Thu, 6 Feb 2014 12:45:47 +0000 (12:45 +0000)
committerKatja Luther <k.luther@bgbm.org>
Thu, 6 Feb 2014 12:45:47 +0000 (12:45 +0000)
.gitattributes
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/ChangeAcceptedTaxonToSynonymHandler.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/ChangeAcceptedTaxonToSynonymOperation.java [new file with mode: 0644]

index a8ee33899da7538e1e2e11e0b5cbea942656cc29..2388d9c2ac28779d5fba7f62d07c3aa6bfbbdc8c 100644 (file)
@@ -872,6 +872,7 @@ eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigatio
 eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonNodePropertyTester.java -text
 eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TreeNodeDropAdapterAssistant.java -text
 eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/dnd/TaxonNavigatorDragAdapterAssistant.java -text
+eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/ChangeAcceptedTaxonToSynonymHandler.java -text
 eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/CopyHandler.java -text
 eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/DeleteHandler.java -text
 eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/EditHandler.java -text
@@ -879,6 +880,7 @@ eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigatio
 eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/NewClassificationHandler.java -text
 eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/NewTaxonNodeHandler.java -text
 eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/RefreshTreeHandler.java -text
+eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/ChangeAcceptedTaxonToSynonymOperation.java -text
 eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/CopyOperation.java -text
 eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/DeleteOperation.java -text
 eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/EditClassificationOperation.java -text
diff --git a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/ChangeAcceptedTaxonToSynonymHandler.java b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/ChangeAcceptedTaxonToSynonymHandler.java
new file mode 100644 (file)
index 0000000..c376a50
--- /dev/null
@@ -0,0 +1,193 @@
+/**
+ * 
+ */
+package eu.etaxonomy.taxeditor.navigation.navigator.handler;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.UUID;
+
+import org.apache.log4j.Logger;
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.IHandler;
+import org.eclipse.core.commands.common.NotDefinedException;
+import org.eclipse.core.commands.operations.IUndoContext;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.TreeSelection;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
+import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;
+import eu.etaxonomy.cdm.model.common.CdmBase;
+import eu.etaxonomy.cdm.model.taxon.Classification;
+import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
+import eu.etaxonomy.cdm.model.taxon.TaxonNode;
+import eu.etaxonomy.taxeditor.editor.EditorUtil;
+import eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor;
+import eu.etaxonomy.taxeditor.editor.Page;
+import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
+import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor;
+import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
+import eu.etaxonomy.taxeditor.navigation.navigator.operation.ChangeAcceptedTaxonToSynonymOperation;
+import eu.etaxonomy.taxeditor.navigation.navigator.operation.DeleteOperation;
+import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
+import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
+import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonNodeSelectionDialog;
+
+/**
+ * <p>ChangeAcceptedTaxonToSynonymHandler class.</p>
+ *
+ * @author n.hoffmann
+ * @created Jan 4, 2010
+ * @version 1.0
+ */
+public class ChangeAcceptedTaxonToSynonymHandler extends DeleteHandler
+               implements IHandler, IPostOperationEnabled {
+       private static final Logger logger = Logger
+                       .getLogger(ChangeAcceptedTaxonToSynonymHandler.class);
+       private ChangeAcceptedTaxonToSynonymOperation operation;
+
+       private UUID newAcceptedTaxonNodeUuid;
+       private TaxonNameEditor editor;
+       
+       /* (non-Javadoc)
+        * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+        */
+       /** {@inheritDoc} */
+       public Object execute(ExecutionEvent event) throws ExecutionException {
+               
+               
+                activePage = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();
+
+               taxonNavigator = NavigationUtil.showNavigator();
+
+               TreeSelection selection = (TreeSelection) HandlerUtil.getCurrentSelection(event);
+
+               String plural = selection.size() > 1 ? "s" : "";
+               // Prompt user for confirmation
+               
+               
+
+               Iterator selectionIterator = selection.iterator();
+               Set<ITaxonTreeNode> treeNodes = new HashSet<ITaxonTreeNode>();
+
+               while (selectionIterator.hasNext()){
+                       Object object = selectionIterator.next();
+                       if(object instanceof ITaxonTreeNode) {
+                treeNodes.add((ITaxonTreeNode) object);
+            }
+               }
+               boolean allEditorsClosed = true;
+               for (ITaxonTreeNode treeNode : treeNodes){
+                       if(treeNode instanceof TaxonNode) {
+                               allEditorsClosed &= closeObsoleteEditor((TaxonNode) treeNode);
+                       }
+               }
+               AbstractPostOperation operation = null;
+               if (treeNodes.size() == 1 ){
+                       try {
+                               
+                               ITaxonTreeNode treeNode = treeNodes.iterator().next();
+                               ITaxonTreeNode oldAcceptedTaxonNode =treeNode;
+                               
+                               // check if taxon has no children
+                               if(((TaxonNode)oldAcceptedTaxonNode).getCountChildren() > 0) {
+                                       EditorUtil.warningDialog("Prerequisite not met", this, 
+                                                       "The accepted taxon must not have any childen. You need to move all childen to " +
+                                                       "another taxon node in the TaxonNavigator before attempting to turn the accepted " +
+                                                       "taxon into a synonym.");
+                                       return null;
+                               }
+                               /*if(((TaxonNode)oldAcceptedTaxonNode).getTaxon().hasSynonyms()) {
+                                       EditorUtil.warningDialog("Prerequisite not met", this, 
+                                                       "The accepted taxon must not have any synonyms. You need to move all synonyms to " +
+                                                       "another taxon before attempting to turn the accepted " +
+                                                       "taxon into a synonym.");
+                                       return null;
+                               }*/
+                               
+                               List<UUID> excludeTaxa = new ArrayList<UUID>();
+                               excludeTaxa.add(oldAcceptedTaxonNode.getUuid());
+                               TaxonNode newAcceptedTaxonNode = TaxonNodeSelectionDialog.select(HandlerUtil.getActiveShell(event), 
+                                               taxonNavigator.getConversationHolder(), 
+                                               "Choose the accepted taxon", 
+                                               excludeTaxa, 
+                                               null, 
+                                               ((TaxonNode)oldAcceptedTaxonNode).getClassification());                 
+
+                               if (newAcceptedTaxonNode == null) {
+                                       return null;
+                               }
+       
+                               if (allEditorsClosed){
+                                       
+                                               operation = new ChangeAcceptedTaxonToSynonymOperation(event.getCommand().getName(), NavigationUtil.getUndoContext(), oldAcceptedTaxonNode, newAcceptedTaxonNode,
+                                                               taxonNavigator, taxonNavigator);
+                       
+                                               NavigationUtil.executeOperation(operation);
+                                               //}
+                               }
+       
+               
+       
+                       } catch (NotDefinedException e) {
+                               NavigationUtil.warn(getClass(), "Command name not set");
+                       }
+               } else{
+                       if( MessageDialog.openConfirm(HandlerUtil.getActiveShell(event), "Moving to synonymy", "The operation move accepted taxon to synonymy is available only for a single taxon.")){
+                               return null;
+                       }
+               }
+               
+               
+               return null;
+               
+       }
+
+       /* (non-Javadoc)
+        * @see eu.etaxonomy.taxeditor.operations.IPostOperationEnabled#postOperation(eu.etaxonomy.cdm.model.common.CdmBase)
+        */
+       /** {@inheritDoc} */
+       public boolean postOperation(CdmBase objectAffectedByOperation) {
+               Display.getDefault().asyncExec(new Runnable(){
+
+                       public void run() {
+                               EditorUtil.close(editor.getMultiPageTaxonEditor());
+                               
+                               try {
+                                       MultiPageTaxonEditor possibleOpenEditor = (MultiPageTaxonEditor) EditorUtil.findEditorByTaxonNodeUuid(newAcceptedTaxonNodeUuid);
+                                       if(possibleOpenEditor != null){
+                                               EditorUtil.close(possibleOpenEditor);
+                                       }
+                                       EditorUtil.openTaxonNode(newAcceptedTaxonNodeUuid);
+                               } catch (PartInitException e) {
+                                       EditorUtil.error(this.getClass(), e);
+                                       throw new RuntimeException(e);
+                               } catch (Exception e) {
+                                       EditorUtil.warningDialog("Could not create Taxon", this, e.getMessage());
+                               }
+                       }
+                       
+               });
+               
+               
+               return true;
+       }
+
+       /**
+        * <p>onComplete</p>
+        *
+        * @return a boolean.
+        */
+       public boolean onComplete() {
+               // TODO Auto-generated method stub
+               return false;
+       }       
+}
diff --git a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/ChangeAcceptedTaxonToSynonymOperation.java b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/ChangeAcceptedTaxonToSynonymOperation.java
new file mode 100644 (file)
index 0000000..680a2d3
--- /dev/null
@@ -0,0 +1,109 @@
+// $Id$
+/**
+* Copyright (C) 2007 EDIT
+* 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.
+*/
+
+package eu.etaxonomy.taxeditor.navigation.navigator.operation;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.operations.IUndoContext;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+
+import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
+import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
+import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;
+import eu.etaxonomy.cdm.api.service.exception.DataChangeNoRollbackException;
+import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
+import eu.etaxonomy.cdm.model.common.ITreeNode;
+import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
+import eu.etaxonomy.cdm.model.taxon.Synonym;
+import eu.etaxonomy.cdm.model.taxon.Taxon;
+import eu.etaxonomy.cdm.model.taxon.TaxonNode;
+import eu.etaxonomy.taxeditor.operation.AbstractPersistentPostOperation;
+import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+
+/**
+ * <p>ChangeAcceptedTaxonToSynonymOperation class.</p>
+ *
+ * @author n.hoffmann
+ * @created Jan 4, 2010
+ * @version 1.0
+ */
+public class ChangeAcceptedTaxonToSynonymOperation extends
+       DeleteOperation {
+       
+       private TaxonNode newAcceptedTaxonNode;
+
+       //private TaxonNode oldTaxonNode;
+       
+       /**
+        * <p>Constructor for ChangeAcceptedTaxonToSynonymOperation.</p>
+        *
+        * @param label a {@link java.lang.String} object.
+        * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object.
+        * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object.
+        * @param oldTaxonNode a {@link eu.etaxonomy.cdm.model.taxon.TaxonNode} object.
+        * @param newAcceptedTaxonNode a {@link eu.etaxonomy.cdm.model.taxon.TaxonNode} object.
+        * @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object.
+        */
+       public ChangeAcceptedTaxonToSynonymOperation(String label,
+                       IUndoContext undoContext, ITaxonTreeNode oldTaxonNode, TaxonNode newAcceptedTaxonNode,
+                       IPostOperationEnabled postOperationEnabled, IConversationEnabled conversationEnabled) {
+               super(label, undoContext, oldTaxonNode, new TaxonDeletionConfigurator(),postOperationEnabled, conversationEnabled);
+               this.newAcceptedTaxonNode = newAcceptedTaxonNode;
+       }
+
+
+       /* (non-Javadoc)
+        * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
+        */
+       /** {@inheritDoc} */
+       @Override
+       public IStatus execute(IProgressMonitor monitor, IAdaptable info)
+                       throws ExecutionException {
+
+               monitor.worked(20);
+               bind();
+       Synonym synonym = null;
+       Taxon oldTaxon = (Taxon) HibernateProxyHelper.deproxy(((TaxonNode) taxonNode).getTaxon());
+               try {
+                       synonym = CdmStore.getService(ITaxonNodeService.class).makeTaxonNodeASynonymOfAnotherTaxonNode((TaxonNode) taxonNode, newAcceptedTaxonNode, null, null, null);
+               } catch (DataChangeNoRollbackException e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               }
+               monitor.worked(40);
+        
+               return postExecute(oldTaxon);
+       }
+
+       /* (non-Javadoc)
+        * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
+        */
+       /** {@inheritDoc} */
+       @Override
+       public IStatus redo(IProgressMonitor monitor, IAdaptable info)
+                       throws ExecutionException {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       /* (non-Javadoc)
+        * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
+        */
+       /** {@inheritDoc} */
+       @Override
+       public IStatus undo(IProgressMonitor monitor, IAdaptable info)
+                       throws ExecutionException {
+               // TODO Auto-generated method stub
+               return null;
+       }
+}