ref #6597 fix selection handling
authorPatrick Plitzner <p.plitzner@bgbm.org>
Wed, 19 Jul 2017 14:33:36 +0000 (16:33 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Wed, 19 Jul 2017 14:33:36 +0000 (16:33 +0200)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/e4/details/DetailsPartE4.java
eu.etaxonomy.taxeditor.workbench/src/main/java/eu/etaxonomy/taxeditor/workbench/WorkbenchUtility.java

index 0717ac5d6e397cc0974939710ac5dfe13893bdb6..6db8d125febd0adf34c89f1f9086279b1de36214 100644 (file)
@@ -29,6 +29,8 @@ import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
 import eu.etaxonomy.taxeditor.l10n.Messages;
 import eu.etaxonomy.taxeditor.model.AbstractUtility;
 import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
+import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
+import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
 
 /**
  * @author pplitzner
@@ -56,15 +58,31 @@ public class DetailsPartE4 implements IConversationEnabled, IDirtyMarkable{
             @Named(IServiceConstants.ACTIVE_SELECTION)Object selection,
             @Named(IServiceConstants.ACTIVE_PART)MPart activePart,
             MPart thisPart){
-        if(activePart==thisPart){
+        if(activePart==thisPart || selection==null){
             return;
         }
-        if(selection instanceof IStructuredSelection){
-            showViewer((IStructuredSelection) selection, activePart, thisPart);
+
+        Object partObject = activePart;
+        Object wrappedPart = WorkbenchUtility.getE4WrappedPart(activePart);
+        if(wrappedPart!=null){
+            partObject = wrappedPart;
+        }
+
+        IStructuredSelection structuredSelection;
+        if(!(selection instanceof IStructuredSelection)){
+            structuredSelection = new StructuredSelection(selection);
         }
         else{
-            showViewer(new StructuredSelection(selection), activePart, thisPart);
+            structuredSelection = (IStructuredSelection) selection;
         }
+        if((partObject instanceof IEditorPart) || (partObject instanceof IPartContentHasDetails)) {
+            showViewer(structuredSelection);
+            selectionProvidingPart = activePart;
+        }
+    }
+
+    public void showEmptyPage() {
+        viewer.setSelection(null);
     }
 
     protected String getViewName(){
@@ -80,12 +98,11 @@ public class DetailsPartE4 implements IConversationEnabled, IDirtyMarkable{
     public void dispose() {
     }
 
-    public void showViewer(IStructuredSelection selection, MPart activePart, MPart thisPart){
+    public void showViewer(IStructuredSelection selection){
         if(getViewer()!=null){
             Object element = selection.getFirstElement();
             if(selection.getFirstElement()!=null){
                 getViewer().setInput(element);
-                selectionProvidingPart = activePart;
             }
         }
     }
index c5024bb2e57ae15f3a51eb6ce2b9665302298eeb..635fe7ff331eeb10f4cef90a96cfb6a3baa016f0 100644 (file)
@@ -12,6 +12,7 @@ import java.lang.reflect.Field;
 
 import org.eclipse.e4.ui.model.application.ui.basic.MPart;
 import org.eclipse.ui.internal.E4PartWrapper;
+import org.eclipse.ui.internal.e4.compatibility.CompatibilityEditor;
 import org.eclipse.ui.internal.e4.compatibility.CompatibilityView;
 
 /**
@@ -30,23 +31,27 @@ public class WorkbenchUtility {
      * @return the wrapped legacy part or <code>null</code>
      */
     public static Object getE4WrappedPart(Object activePart){
-        //FIXME can be removed when E4 migration is complete
+        //FIXME E4 can be removed when E4 migration is complete
 
-        Object object = null;
+        Object object = activePart;
+        if(object instanceof MPart){
+            object = ((MPart) activePart).getObject();
+        }
         try {
-            if(activePart instanceof E4PartWrapper){
-                Field field = activePart.getClass().getDeclaredField("wrappedPart");
+            if(object instanceof E4PartWrapper){
+                Field field = object.getClass().getDeclaredField("wrappedPart");
                 field.setAccessible(true);
-                object = field.get(activePart);
+                object = field.get(object);
             }
-            else if(activePart instanceof CompatibilityView){
-                Field field = activePart.getClass().getSuperclass().getDeclaredField("wrapped");
+            else if(object instanceof CompatibilityView || object instanceof CompatibilityEditor){
+                Field field = object.getClass().getSuperclass().getDeclaredField("wrapped");
                 field.setAccessible(true);
-                object = field.get(activePart);
+                object = field.get(object);
             }
         } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
             e.printStackTrace();
         }
+        //TODO can this still happen??
         if(object instanceof MPart){
             object =((MPart) object).getObject();
         }