changes for move descriptions and description elements
authorU-BGBM\k.luther <k.luther@BGBM11732.bgbm.fu-berlin.de>
Tue, 18 Aug 2015 11:40:45 +0000 (13:40 +0200)
committerjenkins <jenkins-int@bgbm.org>
Tue, 18 Aug 2015 14:11:27 +0000 (16:11 +0200)
eu.etaxonomy.taxeditor.editor/plugin.xml
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/handler/MoveDescriptionElementsHandler.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/handler/MoveDescriptionToOtherTaxonHandler.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/operation/MoveDescriptionElementsOperation.java

index d06b782..b9a3d50 100644 (file)
                   checkEnabled="true">
                <or>
                   <reference
-                        definitionId="isDescriptionElement">
-                  </reference>
-                  <reference
                         definitionId="isFeatureNodeContainer">
                   </reference>
                </or>
             id="eu.etaxonomy.taxeditor.editor.media.command.delete"
             name="%command.name.49">
       </command>
+      
       <category
             id="eu.etaxonomy.taxeditor.editor.new.category"
             name="%category.name.4">
       <command
             categoryId="eu.etaxonomy.taxeditor.editor.view.descriptive.command.category"
             defaultHandler="eu.etaxonomy.taxeditor.editor.view.descriptive.handler.MoveDescriptionToOtherTaxonHandler"
-            id="eu.etaxonomy.taxeditor.editor.commands.description.moveDescriptionToTaxon"
+            id="eu.etaxonomy.taxeditor.editor.view.descriptive.command.moveDescriptionToTaxon"
             name="%command.name.13">
       </command>
+       
       <command
             categoryId="eu.etaxonomy.taxeditor.editor.view.descriptive.command.category"
             defaultHandler="eu.etaxonomy.taxeditor.editor.view.descriptive.handler.MoveDescriptionElementsHandler"
-            id="eu.etaxonomy.taxeditor.description.commands.moveDescriptionElements"
+            id="eu.etaxonomy.taxeditor.editor.view.descriptive.command.moveDescriptionElements"
             name="%command.name.12">
       </command>
         
index 0c2306b..9a801a4 100644 (file)
@@ -20,25 +20,36 @@ import org.eclipse.core.commands.ExecutionException;
 import org.eclipse.core.commands.common.NotDefinedException;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.PartInitException;
 import org.eclipse.ui.handlers.HandlerUtil;
 
 import eu.etaxonomy.cdm.api.service.IDescriptionService;
 import eu.etaxonomy.cdm.api.service.ITaxonService;
+import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
 import eu.etaxonomy.cdm.model.common.Annotation;
 import eu.etaxonomy.cdm.model.common.AnnotationType;
+import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.model.common.Language;
+import eu.etaxonomy.cdm.model.description.DescriptionBase;
 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
 import eu.etaxonomy.cdm.model.description.TaxonDescription;
 import eu.etaxonomy.cdm.model.taxon.Taxon;
+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.name.TaxonNameEditor;
 import eu.etaxonomy.taxeditor.editor.view.descriptive.DescriptiveViewPart;
 import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.MoveDescriptionElementsOperation;
+import eu.etaxonomy.taxeditor.model.AbstractUtility;
 import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
 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.TaxonBaseSelectionDialog;
+import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonNodeSelectionDialog;
 
 
 /**
@@ -46,8 +57,9 @@ import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonBaseSelectionDialog;
  * @created Feb 8, 2011
  * @version 1.0
  */
-public class MoveDescriptionElementsHandler extends AbstractHandler {
-
+public class MoveDescriptionElementsHandler extends AbstractHandler implements IPostOperationEnabled{
+       private UUID newAcceptedTaxonNodeUuid;
+       private TaxonNameEditor editor;
        /* (non-Javadoc)
         * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
         */
@@ -55,7 +67,7 @@ public class MoveDescriptionElementsHandler extends AbstractHandler {
        public Object execute(ExecutionEvent event) throws ExecutionException {
                
 //             ConversationHolder conversation = CdmStore.createConversation();
-               
+               editor = (TaxonNameEditor) EditorUtil.getActiveEditorPage(Page.NAME);
                ISelection selection = HandlerUtil.getCurrentSelection(event);
                
                if(selection instanceof IStructuredSelection){
@@ -81,14 +93,28 @@ public class MoveDescriptionElementsHandler extends AbstractHandler {
                        if(elements.size() == 0){
                                return null;
                        }
+                       DescriptionBase description = elements.get(0).getInDescription();
+                       List<UUID> excludeTaxa = new ArrayList<UUID>();
+                       if (description.isInstanceOf(TaxonDescription.class)){
+                               TaxonDescription taxonDescription = HibernateProxyHelper.deproxy(description, TaxonDescription.class);
+                               Taxon actualTaxon = taxonDescription.getTaxon();
+                               excludeTaxa.add(actualTaxon.getUuid());
+                       }
                        
-                       Taxon targetTaxon = TaxonBaseSelectionDialog.selectTaxon(HandlerUtil.getActiveShell(event), EditorUtil.getActiveMultiPageTaxonEditor().getConversationHolder(), null);
+                       
+                       TaxonNode newAcceptedTaxonNode = TaxonNodeSelectionDialog.select(HandlerUtil.getActiveShell(event),
+                                       editor.getConversationHolder(),
+                                       "Choose the accepted taxon",
+                                       excludeTaxa,
+                                       null,
+                                       null);
+                       Taxon targetTaxon = newAcceptedTaxonNode.getTaxon();
                        
                        if(targetTaxon == null){
                                // canceled
                                return null;
                        }
-                                               
+                       newAcceptedTaxonNodeUuid = newAcceptedTaxonNode.getUuid();                      
                        TaxonDescription targetDescription = TaxonDescription.NewInstance(targetTaxon);
                        String moveMessage = String.format("Elements moved from %s", EditorUtil.getActiveMultiPageTaxonEditor().getTaxon());
                        targetDescription.setTitleCache(moveMessage, true);
@@ -99,10 +125,11 @@ public class MoveDescriptionElementsHandler extends AbstractHandler {
                        try {
                                AbstractPostOperation operation = new MoveDescriptionElementsOperation(
                                                event.getCommand().getName(), EditorUtil.getUndoContext(), 
-                                               targetDescription, elements, false, (IPostOperationEnabled) EditorUtil.getView(DescriptiveViewPart.ID, true));
+                                               targetDescription, elements, false, this);
+                               
                                EditorUtil.executeOperation(operation);
-//                             conversation.commit(true);
-                               CdmStore.getService(ITaxonService.class).saveOrUpdate(targetTaxon);
+                               
+                               //CdmStore.getService(ITaxonService.class).saveOrUpdate(targetTaxon);
                                
                        } catch (NotDefinedException e) {
                                MessagingUtils.error(getClass(), e);
@@ -112,4 +139,44 @@ public class MoveDescriptionElementsHandler extends AbstractHandler {
                return null;
        }
 
+       /* (non-Javadoc)
+        * @see eu.etaxonomy.taxeditor.operations.IPostOperationEnabled#postOperation(eu.etaxonomy.cdm.model.common.CdmBase)
+        */
+       /** {@inheritDoc} */
+       @Override
+    public boolean postOperation(CdmBase objectAffectedByOperation) {
+               
+               editor.getConversationHolder().bind();
+               editor.getConversationHolder().commit(true);
+               Display.getDefault().asyncExec(new Runnable(){
+                       
+            public void run() {
+                               //AbstractUtility.close(editor.getMultiPageTaxonEditor());
+
+                               try {
+                                       MultiPageTaxonEditor possibleOpenEditor = (MultiPageTaxonEditor) EditorUtil.findEditorByTaxonNodeUuid(newAcceptedTaxonNodeUuid);
+                                       if(possibleOpenEditor != null){
+                                               AbstractUtility.close(possibleOpenEditor);
+                                       }
+                                       EditorUtil.openTaxonNode(newAcceptedTaxonNodeUuid);
+                               } catch (PartInitException e) {
+                                       MessagingUtils.error(this.getClass(), e);
+                                       throw new RuntimeException(e);
+                               } catch (Exception e) {
+                                       MessagingUtils.warningDialog("Could not create Taxon", this, e.getMessage());
+                               }
+                       }
+
+               });
+
+
+               return true;
+       }
+
+       @Override
+       public boolean onComplete() {
+               // TODO Auto-generated method stub
+               return false;
+       }
+       
 }
index ab67cf8..c4b57e9 100644 (file)
@@ -20,6 +20,7 @@ import org.eclipse.ui.handlers.HandlerUtil;
 
 import eu.etaxonomy.cdm.api.service.IDescriptionService;
 import eu.etaxonomy.cdm.model.common.CdmBase;
+import eu.etaxonomy.cdm.model.description.DescriptionBase;
 import eu.etaxonomy.cdm.model.description.TaxonDescription;
 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
 import eu.etaxonomy.taxeditor.editor.EditorUtil;
@@ -28,6 +29,7 @@ import eu.etaxonomy.taxeditor.editor.Page;
 import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor;
 import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.MoveDescriptionToOtherTaxonOperation;
 import eu.etaxonomy.taxeditor.model.AbstractUtility;
+import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
 import eu.etaxonomy.taxeditor.store.CdmStore;
@@ -66,8 +68,14 @@ public class MoveDescriptionToOtherTaxonHandler extends AbstractHandler
                        IStructuredSelection structuredSelection = (IStructuredSelection) selection;
 
                        for(Object element : structuredSelection.toArray()){
-                               if (element instanceof TaxonDescription){
-                                       UUID uuid = ((TaxonDescription)element).getUuid();
+                               UUID uuid = null;
+                               if (element instanceof FeatureNodeContainer){
+                                       uuid = ((FeatureNodeContainer)element).getDescription().getUuid();
+                               }       else if (element instanceof DescriptionBase){
+                                       uuid = ((DescriptionBase)element).getUuid();
+                               }
+                               
+                               if (uuid != null){
                                        descriptions.add((TaxonDescription) CdmStore.getService(IDescriptionService.class).load(uuid, null));
                                }
                        }
index 5b4b005..fd74d72 100644 (file)
@@ -17,10 +17,17 @@ 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 org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.PartInitException;
 
 import eu.etaxonomy.cdm.api.service.IDescriptionService;
+import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.model.description.DescriptionBase;
 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
+import eu.etaxonomy.taxeditor.editor.EditorUtil;
+import eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor;
+import eu.etaxonomy.taxeditor.model.AbstractUtility;
+import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation;
 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
 import eu.etaxonomy.taxeditor.store.CdmStore;
@@ -30,7 +37,7 @@ import eu.etaxonomy.taxeditor.store.CdmStore;
  * @created Feb 8, 2011
  * @version 1.0
  */
-public class MoveDescriptionElementsOperation extends AbstractPostTaxonOperation {
+public class MoveDescriptionElementsOperation extends AbstractPostTaxonOperation{
 
        private Collection<DescriptionElementBase> descriptionElements;
        private DescriptionBase targetDescription;
@@ -68,6 +75,7 @@ public class MoveDescriptionElementsOperation extends AbstractPostTaxonOperation
                
                service.moveDescriptionElementsToDescription(descriptionElements, targetDescription, isCopy);
                
+               
                return postExecute(targetDescription);
        }
 
@@ -90,5 +98,7 @@ public class MoveDescriptionElementsOperation extends AbstractPostTaxonOperation
                // TODO Auto-generated method stub
                return null;
        }
+       
+       
 
 }