ref #6905, #6597 refactor selectionChanged() method
authorPatrick Plitzner <p.plitzner@bgbm.org>
Fri, 11 Aug 2017 09:40:45 +0000 (11:40 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Fri, 11 Aug 2017 09:40:45 +0000 (11:40 +0200)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/e4/AbstractCdmEditorPartE4.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/e4/details/DetailsPartE4.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/e4/supplementaldata/SupplementalDataPartE4.java

index 97ccf73205d1f060cde2a54312fb60f14c693078..69fe31c24d4db235c73b64ced4f593f62f64798f 100644 (file)
@@ -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();
index 88e0c7fe58908c9ecbd6adec3009decdf1910854..145f3eda4b2bb6da7acd52c8f77fc7620e7a656a 100644 (file)
@@ -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;
index a0f2f506d4b5e2fef85a46fa9bca5295fbebe323..d43cc72b606b5966908a03d75d8de3f468e77715 100644 (file)
@@ -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;