Simplify selectionChanged method
authorPatrick Plitzner <p.plitzner@bgbm.org>
Tue, 17 Nov 2015 15:34:09 +0000 (16:34 +0100)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Tue, 17 Nov 2015 15:34:09 +0000 (16:34 +0100)
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateView.java

index ba2b316..95d3b93 100644 (file)
@@ -52,6 +52,7 @@ import eu.etaxonomy.cdm.model.taxon.TaxonNode;
 import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
 import eu.etaxonomy.taxeditor.editor.EditorUtil;
 import eu.etaxonomy.taxeditor.editor.Messages;
+import eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor;
 import eu.etaxonomy.taxeditor.editor.view.derivate.searchFilter.DerivateSearchCompositeController;
 import eu.etaxonomy.taxeditor.model.IContextListener;
 import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
@@ -462,23 +463,28 @@ public class DerivateView extends EditorPart implements IPartContentHasFactualDa
         if(viewer.getTree().isDisposed()){
             return;
         }
-        if(listenToSelectionChange && selection instanceof IStructuredSelection){
-            Object selectedElement = ((IStructuredSelection) selection).getFirstElement();
-            if(selectedElement instanceof CdmBase){
-                if(((CdmBase) selectedElement).isInstanceOf(TaxonNode.class)){
-                    selectedTaxon = HibernateProxyHelper.deproxy(selectedElement, TaxonNode.class).getTaxon();
-                }
-                else if(((CdmBase) selectedElement).isInstanceOf(Taxon.class)){
-                    selectedTaxon = HibernateProxyHelper.deproxy(selectedElement, Taxon.class);
-                }
-                Collection<SpecimenOrObservationBase> fieldUnits = CdmStore.getService(IOccurrenceService.class).listFieldUnitsByAssociatedTaxon(selectedTaxon, null, null);
-                Collection<UUID> uuids = new HashSet<UUID>();
-                for (SpecimenOrObservationBase specimenOrObservationBase : fieldUnits) {
-                    uuids.add(specimenOrObservationBase.getUuid());
+        if(listenToSelectionChange){
+            if(part instanceof MultiPageTaxonEditor){
+                selectedTaxon = ((MultiPageTaxonEditor) part).getTaxon();
+            }
+            else if(selection instanceof IStructuredSelection){
+                Object selectedElement = ((IStructuredSelection) selection).getFirstElement();
+                if(selectedElement instanceof CdmBase){
+                    if(((CdmBase) selectedElement).isInstanceOf(TaxonNode.class)){
+                        selectedTaxon = HibernateProxyHelper.deproxy(selectedElement, TaxonNode.class).getTaxon();
+                    }
+                    else if(((CdmBase) selectedElement).isInstanceOf(Taxon.class)){
+                        selectedTaxon = HibernateProxyHelper.deproxy(selectedElement, Taxon.class);
+                    }
                 }
-                updateRootEntities(uuids);
-                setPartName("Derivative Editor: " + selectedTaxon.getName());
             }
+            Collection<SpecimenOrObservationBase> fieldUnits = CdmStore.getService(IOccurrenceService.class).listFieldUnitsByAssociatedTaxon(selectedTaxon, null, null);
+            Collection<UUID> uuids = new HashSet<UUID>();
+            for (SpecimenOrObservationBase specimenOrObservationBase : fieldUnits) {
+                uuids.add(specimenOrObservationBase.getUuid());
+            }
+            updateRootEntities(uuids);
+            setPartName("Derivative Editor: " + selectedTaxon.getName());
         }
     }