fixing #5150
authorU-BGBM\k.luther <k.luther@BGBM11732.bgbm.fu-berlin.de>
Wed, 2 Sep 2015 12:54:03 +0000 (14:54 +0200)
committerU-BGBM\k.luther <k.luther@BGBM11732.bgbm.fu-berlin.de>
Wed, 2 Sep 2015 12:54:03 +0000 (14:54 +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.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/TaxonNodeSelectionDialog.java

index 4d30784b6a7bd14bceb845e1bae0dd287a3ad92a..66def47309837982fcbfaea4fa1efb79fc917fc0 100644 (file)
                   <reference
                         definitionId="isFeatureNodeContainer">
                   </reference>
-               </or>
+                   <reference
+                        definitionId="isDescriptionElement">
+                  </reference>
+              </or>
             </visibleWhen>
          </command>
          <separator
index 9a801a4d412797995c6899f6ae3f8c6045152438..3c1fee4fb25fe4fedafaefdb96797c876f3bb951 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.
 */
@@ -25,7 +25,6 @@ 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;
@@ -34,13 +33,13 @@ 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.Classification;
 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;
@@ -48,7 +47,6 @@ 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;
 
 
@@ -65,31 +63,31 @@ public class MoveDescriptionElementsHandler extends AbstractHandler implements I
         */
        @Override
        public Object execute(ExecutionEvent event) throws ExecutionException {
-               
+
 //             ConversationHolder conversation = CdmStore.createConversation();
                editor = (TaxonNameEditor) EditorUtil.getActiveEditorPage(Page.NAME);
                ISelection selection = HandlerUtil.getCurrentSelection(event);
-               
+               Taxon actualTaxon= null;
                if(selection instanceof IStructuredSelection){
 
                        IStructuredSelection structuredSelection = (IStructuredSelection) selection;
-                       
+
                        List<DescriptionElementBase> elements = new ArrayList<DescriptionElementBase>();
-                       
+
                        for(Object element : structuredSelection.toArray()){
                                if(element instanceof DescriptionElementBase){
                                        UUID uuid = ((DescriptionElementBase) element).getUuid();
-                                       
+
                                        elements.add(CdmStore.getService(IDescriptionService.class).loadDescriptionElement(uuid, null));
                                } else if(element instanceof FeatureNodeContainer){
                                        for(DescriptionElementBase de : ((FeatureNodeContainer)element).getDescriptionElements()){
                                                elements.add(
-                                                               (DescriptionElementBase)CdmStore.getService(IDescriptionService.class).loadDescriptionElement(de.getUuid(), null)
+                                                               CdmStore.getService(IDescriptionService.class).loadDescriptionElement(de.getUuid(), null)
                                                        );
                                        }
                                }
                        }
-                       
+
                        if(elements.size() == 0){
                                return null;
                        }
@@ -97,45 +95,51 @@ public class MoveDescriptionElementsHandler extends AbstractHandler implements I
                        List<UUID> excludeTaxa = new ArrayList<UUID>();
                        if (description.isInstanceOf(TaxonDescription.class)){
                                TaxonDescription taxonDescription = HibernateProxyHelper.deproxy(description, TaxonDescription.class);
-                               Taxon actualTaxon = taxonDescription.getTaxon();
+                               actualTaxon = taxonDescription.getTaxon();
                                excludeTaxa.add(actualTaxon.getUuid());
                        }
-                       
-                       
+                       Classification classification = null;
+                       if (actualTaxon != null){
+                           if (!actualTaxon.getTaxonNodes().isEmpty() && actualTaxon.getTaxonNodes().size() ==1){
+                               classification = actualTaxon.getTaxonNodes().iterator().next().getClassification();
+                           }
+                       }
                        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);
-                       Annotation annotation = Annotation.NewInstance(moveMessage, Language.getDefaultLanguage());
-                       annotation.setAnnotationType(AnnotationType.TECHNICAL());
-                       targetDescription.addAnnotation(annotation);
-                       
-                       try {
-                               AbstractPostOperation operation = new MoveDescriptionElementsOperation(
-                                               event.getCommand().getName(), EditorUtil.getUndoContext(), 
-                                               targetDescription, elements, false, this);
-                               
-                               EditorUtil.executeOperation(operation);
-                               
-                               //CdmStore.getService(ITaxonService.class).saveOrUpdate(targetTaxon);
-                               
-                       } catch (NotDefinedException e) {
-                               MessagingUtils.error(getClass(), e);
+                                       null,classification
+                                       );
+                       if (newAcceptedTaxonNode != 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);
+                       Annotation annotation = Annotation.NewInstance(moveMessage, Language.getDefaultLanguage());
+                       annotation.setAnnotationType(AnnotationType.TECHNICAL());
+                       targetDescription.addAnnotation(annotation);
+
+                       try {
+                               AbstractPostOperation operation = new MoveDescriptionElementsOperation(
+                                               event.getCommand().getName(), EditorUtil.getUndoContext(),
+                                               targetDescription, elements, false, this);
+
+                               EditorUtil.executeOperation(operation);
+
+                               //CdmStore.getService(ITaxonService.class).saveOrUpdate(targetTaxon);
+
+                       } catch (NotDefinedException e) {
+                               MessagingUtils.error(getClass(), e);
+                       }
                        }
                }
-               
+
                return null;
        }
 
@@ -145,11 +149,12 @@ public class MoveDescriptionElementsHandler extends AbstractHandler implements I
        /** {@inheritDoc} */
        @Override
     public boolean postOperation(CdmBase objectAffectedByOperation) {
-               
+
                editor.getConversationHolder().bind();
                editor.getConversationHolder().commit(true);
                Display.getDefault().asyncExec(new Runnable(){
-                       
+
+            @Override
             public void run() {
                                //AbstractUtility.close(editor.getMultiPageTaxonEditor());
 
@@ -178,5 +183,5 @@ public class MoveDescriptionElementsHandler extends AbstractHandler implements I
                // TODO Auto-generated method stub
                return false;
        }
-       
+
 }
index e2e864bceb5333cfeadf8bea5f2734f12d3accff..a5a3ba167148fc74c4b2b8f07fdfc31fc3fcba42 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * 
+ *
  */
 package eu.etaxonomy.taxeditor.ui.dialog.selection;
 
@@ -31,8 +31,8 @@ import eu.etaxonomy.taxeditor.store.CdmStore;
  * @author p.ciardelli
  * @version $Id: $
  */
-public class TaxonNodeSelectionDialog extends AbstractFilteredCdmResourceSelectionDialog<TaxonNode> implements SelectionListener{      
-       
+public class TaxonNodeSelectionDialog extends AbstractFilteredCdmResourceSelectionDialog<TaxonNode> implements SelectionListener{
+
        /**
         * <p>select</p>
         *
@@ -44,7 +44,7 @@ public class TaxonNodeSelectionDialog extends AbstractFilteredCdmResourceSelecti
         * @return a {@link eu.etaxonomy.cdm.model.taxon.TaxonNode} object.
         */
        public static TaxonNode select(Shell shell, ConversationHolder conversation, String title, List<UUID> excludeTaxa, TaxonNode node, Classification classification) {
-               TaxonNodeSelectionDialog dialog = new TaxonNodeSelectionDialog(shell, 
+               TaxonNodeSelectionDialog dialog = new TaxonNodeSelectionDialog(shell,
                                conversation,
                                title,
                                excludeTaxa,
@@ -57,8 +57,8 @@ public class TaxonNodeSelectionDialog extends AbstractFilteredCdmResourceSelecti
        private Combo classificationSelectionCombo;
 
        private List<Classification> classifications;
-       
-       private Classification selectedClassification;  
+
+       private Classification selectedClassification;
 
        /**
         * <p>Constructor for FilteredTaxonNodeSelectionDialog.</p>
@@ -72,12 +72,12 @@ public class TaxonNodeSelectionDialog extends AbstractFilteredCdmResourceSelecti
         */
        protected TaxonNodeSelectionDialog(Shell shell, ConversationHolder conversation, String title, List<UUID> excludeTaxa, boolean multi, TaxonNode node, Classification classification) {
                super(shell, conversation, title, multi, TaxonNodeSelectionDialog.class.getCanonicalName(), node);
-               
+
                ILabelProvider labelProvider = new FilteredCdmResourceLabelProvider();
 
                setListLabelProvider(labelProvider);
                setDetailsLabelProvider(labelProvider);
-               
+
                if(classification != null){
                        selectedClassification = classification;
                }
@@ -92,36 +92,37 @@ public class TaxonNodeSelectionDialog extends AbstractFilteredCdmResourceSelecti
        protected Control createExtendedContentArea(Composite parent) {
                return createClassificationSelectionCombo(parent);
        }
-       
+
        /*
         * currently disabled tree selection composite
         */
        private Control createClassificationSelectionCombo(Composite parent){
 //             classifications = CdmStore.getTaxonTreeService().list(null, null, null, null, null);
-               
+
                Composite classificationSelection = new Composite(parent, SWT.NULL);
                classificationSelection.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
-               
+
                GridLayout layout = new GridLayout();
                classificationSelection.setLayout(layout);
-               
+
                Label label = new Label(classificationSelection, SWT.NULL);
                // TODO not working is not really true but leave it here to remind everyone that this is under construction
-               label.setText("Select Classification (experimental)");
+               label.setText("Select Classification");
                classificationSelectionCombo = new Combo(classificationSelection, SWT.BORDER | SWT.READ_ONLY);
                classificationSelectionCombo.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, true));
-               
+
                for(Classification tree : classifications){
                        classificationSelectionCombo.add(tree.getName().getText(), classifications.indexOf(tree));
+
                }
-               
+
                classificationSelectionCombo.select(classifications.indexOf(selectedClassification));
-               
+
                // TODO remember last selection
                classificationSelectionCombo.addSelectionListener(this);
-               
-               
-               
+
+
+
                return classificationSelection;
        }
 
@@ -131,10 +132,10 @@ public class TaxonNodeSelectionDialog extends AbstractFilteredCdmResourceSelecti
                if(taxonNode != null && taxonNode.getTaxon() != null){
                        return taxonNode.getTaxon().getTitleCache();
                }
-               
+
                return "";
        }
-       
+
        /* (non-Javadoc)
         * @see eu.etaxonomy.taxeditor.dialogs.AbstractFilteredCdmResourceSelectionDialog#getPersistentObject(java.util.UUID)
         */
@@ -150,15 +151,15 @@ public class TaxonNodeSelectionDialog extends AbstractFilteredCdmResourceSelecti
        /** {@inheritDoc} */
        @Override
        protected void initModel() {
-               // default to first tree 
-               // TODO this will be problematic and can only be seen as workaround 
-               
-               
+               // default to first tree
+               // TODO this will be problematic and can only be seen as workaround
+
+
                if(classifications == null){
                        classifications = CdmStore.getService(IClassificationService.class).list(null, null, null, null, null);
                        selectedClassification = classifications.iterator().next();
                }
-               
+
                model = CdmStore.getService(IClassificationService.class).getTaxonNodeUuidAndTitleCacheOfAcceptedTaxaByClassification(selectedClassification);
        }
 
@@ -173,17 +174,19 @@ public class TaxonNodeSelectionDialog extends AbstractFilteredCdmResourceSelecti
        protected String getNewWizardLinkText() {
                return null;
        }
-       
+
        /** {@inheritDoc} */
-       public void widgetSelected(SelectionEvent e) {
+       @Override
+    public void widgetSelected(SelectionEvent e) {
                selectedClassification = classifications.get(classificationSelectionCombo.getSelectionIndex());
-               
+
 //             refresh();
                setPattern(null);
        }
 
        /** {@inheritDoc} */
-       public void widgetDefaultSelected(SelectionEvent e) {}
+       @Override
+    public void widgetDefaultSelected(SelectionEvent e) {}
 
 
 }