commit a49808268ab4e0a76254dd8a9592ddec0c1ff2dc
Author: Patrick Plitzner <p.plitzner@bgbm.org>
Date:   Fri Aug 11 11:40:45 2017 +0200

    ref #6905, #6597 refactor selectionChanged() method

diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/e4/AbstractCdmEditorPartE4.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/e4/AbstractCdmEditorPartE4.java
index 97ccf7320..69fe31c24 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/e4/AbstractCdmEditorPartE4.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/e4/AbstractCdmEditorPartE4.java
@@ -13,6 +13,7 @@ import javax.annotation.PreDestroy;
 
 import org.eclipse.e4.ui.model.application.ui.basic.MPart;
 import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.ui.IEditorPart;
 
@@ -21,6 +22,7 @@ import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
 import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
 import eu.etaxonomy.taxeditor.model.AbstractUtility;
 import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
+import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
 import eu.etaxonomy.taxeditor.workbench.part.ISelectionElementEditingPart;
 
 /**
@@ -66,6 +68,29 @@ public abstract class AbstractCdmEditorPartE4 implements IConversationEnabled, I
         }
     }
 
+    protected Object createPartObject(MPart activePart) {
+        Object partObject = activePart;
+        Object wrappedPart = WorkbenchUtility.getE4WrappedPart(activePart);
+        if(wrappedPart!=null){
+            partObject = wrappedPart;
+        }
+        return partObject;
+    }
+
+    protected IStructuredSelection createSelection(Object selection) {
+        if(selection==null){
+            return null;
+        }
+        IStructuredSelection structuredSelection;
+        if(!(selection instanceof IStructuredSelection)){
+            structuredSelection = new StructuredSelection(selection);
+        }
+        else{
+            structuredSelection = (IStructuredSelection) selection;
+        }
+        return structuredSelection;
+    }
+
     public void showEmptyPage() {
         if(viewer!=null){
             viewer.showEmptyPage();
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/e4/details/DetailsPartE4.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/e4/details/DetailsPartE4.java
index 88e0c7fe5..145f3eda4 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/e4/details/DetailsPartE4.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/e4/details/DetailsPartE4.java
@@ -16,7 +16,6 @@ import org.eclipse.e4.core.di.annotations.Optional;
 import org.eclipse.e4.ui.model.application.ui.basic.MPart;
 import org.eclipse.e4.ui.services.IServiceConstants;
 import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.swt.widgets.Composite;
 
 import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
@@ -26,7 +25,6 @@ import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
 import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
 import eu.etaxonomy.taxeditor.view.e4.AbstractCdmDataViewerE4;
 import eu.etaxonomy.taxeditor.view.e4.AbstractCdmEditorPartE4;
-import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
 
 /**
  * @author pplitzner
@@ -56,28 +54,15 @@ public class DetailsPartE4 extends AbstractCdmEditorPartE4{
         if(activePart==thisPart){
             return;
         }
-        if(selection==null){
-            showEmptyPage();
-            return;
-        }
 
-        Object partObject = activePart;
-        Object wrappedPart = WorkbenchUtility.getE4WrappedPart(activePart);
-        if(wrappedPart!=null){
-            partObject = wrappedPart;
-        }
-
-        IStructuredSelection structuredSelection;
-        if(!(selection instanceof IStructuredSelection)){
-            structuredSelection = new StructuredSelection(selection);
-        }
-        else{
-            structuredSelection = (IStructuredSelection) selection;
-        }
+        IStructuredSelection structuredSelection = createSelection(selection);
         if(structuredSelection.isEmpty()){
             showEmptyPage();
             return;
         }
+
+        Object partObject = createPartObject(activePart);
+
         if(partObject instanceof IPartContentHasDetails){
             if(partObject instanceof IConversationEnabled && ((IConversationEnabled) partObject).getConversationHolder()==null) {
                 //TODO show specific message (refactor EmptyElement to allow specific messages)
@@ -87,7 +72,7 @@ public class DetailsPartE4 extends AbstractCdmEditorPartE4{
             // do not show details for feature nodes TODO strange check to avoid having shown the distribution map for every FeatureNodeContainer
             if(structuredSelection.getFirstElement() instanceof FeatureNodeContainer){
                 // do show the map for distributions
-                Feature feature = ((FeatureNodeContainer) ((IStructuredSelection) selection).getFirstElement()).getFeature();
+                Feature feature = ((FeatureNodeContainer) structuredSelection.getFirstElement()).getFeature();
                 if(!feature.equals(Feature.DISTRIBUTION())){
                     showEmptyPage();
                     return;
@@ -102,7 +87,6 @@ public class DetailsPartE4 extends AbstractCdmEditorPartE4{
         }
     }
 
-
     @Override
     protected String getViewName(){
         return Messages.DetailsViewPart_VIEWER_NAME;
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/e4/supplementaldata/SupplementalDataPartE4.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/e4/supplementaldata/SupplementalDataPartE4.java
index a0f2f506d..d43cc72b6 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/e4/supplementaldata/SupplementalDataPartE4.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/e4/supplementaldata/SupplementalDataPartE4.java
@@ -21,7 +21,6 @@ import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.jface.viewers.TreeNode;
 import org.eclipse.swt.widgets.Composite;
-import org.eclipse.ui.part.EditorPart;
 
 import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
 import eu.etaxonomy.cdm.ext.occurrence.gbif.GbifResponse;
@@ -34,7 +33,6 @@ import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
 import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
 import eu.etaxonomy.taxeditor.view.e4.AbstractCdmDataViewerE4;
 import eu.etaxonomy.taxeditor.view.e4.AbstractCdmEditorPartE4;
-import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
 
 
 /**
@@ -63,30 +61,16 @@ public class SupplementalDataPartE4 extends AbstractCdmEditorPartE4 {
 	    if(activePart==thisPart){
 	        return;
 	    }
-	    if(selection==null){
-	        showEmptyPage();
-	        return;
-	    }
-
-	    Object partObject = activePart;
-	    Object wrappedPart = WorkbenchUtility.getE4WrappedPart(partObject);
-	    if(wrappedPart!=null){
-	        partObject = wrappedPart;
-	    }
 
-	    IStructuredSelection structuredSelection;
-	    if(!(selection instanceof IStructuredSelection)){
-	        structuredSelection = new StructuredSelection(selection);
-	    }
-	    else{
-	        structuredSelection = (IStructuredSelection) selection;
-	    }
+	    IStructuredSelection structuredSelection = createSelection(selection);
 	    if(structuredSelection.isEmpty()){
 	        showEmptyPage();
 	        return;
 	    }
 
-	    if((partObject instanceof EditorPart || partObject instanceof IPartContentHasSupplementalData)) {
+        Object partObject = createPartObject(activePart);
+
+	    if(partObject instanceof IPartContentHasSupplementalData) {
 	        if(structuredSelection.size() != 1){
 	            showEmptyPage();
 	            return;
