ref #6596 Add new utility class WorkbenchUtility in workbench plugin
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / model / AbstractUtility.java
index 3d394830b538ceec6c9dab2dce9a9b7d6dd58595..da95042cc0722a262c44401fb1527b6fdfd3db43 100644 (file)
@@ -9,7 +9,6 @@
 
 package eu.etaxonomy.taxeditor.model;
 
-import java.lang.reflect.Field;
 import java.lang.reflect.InvocationTargetException;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -35,7 +34,6 @@ import org.eclipse.core.runtime.Status;
 import org.eclipse.core.runtime.SubProgressMonitor;
 import org.eclipse.core.runtime.jobs.ISchedulingRule;
 import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.e4.ui.model.application.ui.basic.MPart;
 import org.eclipse.jface.action.IStatusLineManager;
 import org.eclipse.jface.operation.IRunnableWithProgress;
 import org.eclipse.jface.resource.ColorRegistry;
@@ -57,7 +55,6 @@ import org.eclipse.ui.PartInitException;
 import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.handlers.IHandlerService;
 import org.eclipse.ui.ide.undo.WorkspaceUndoUtil;
-import org.eclipse.ui.internal.E4PartWrapper;
 import org.eclipse.ui.part.EditorPart;
 import org.eclipse.ui.progress.IProgressConstants;
 import org.eclipse.ui.progress.IProgressService;
@@ -80,6 +77,7 @@ import eu.etaxonomy.taxeditor.ui.dialog.ReportTextDialog;
 import eu.etaxonomy.taxeditor.view.AbstractCdmDataViewer;
 import eu.etaxonomy.taxeditor.view.detail.DetailsViewPart;
 import eu.etaxonomy.taxeditor.view.supplementaldata.SupplementalDataViewPart;
+import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
 
 /**
  *
@@ -143,29 +141,12 @@ public abstract class AbstractUtility {
         IWorkbenchPage activePage = getActivePage();
         if(activePage!=null){
             IWorkbenchPart activePart = activePage.getActivePart();
-            Object e4WrappedPart = getE4WrappedPart(activePart);
+            Object e4WrappedPart = WorkbenchUtility.getE4WrappedPart(activePart);
             return e4WrappedPart!=null?e4WrappedPart:activePart;
         }
         return null;
     }
 
-    public static Object getE4WrappedPart(Object activePart){
-        if(activePart instanceof E4PartWrapper){
-            //FIXME can be removed when E4 migration is complete
-            try {
-                Field field = activePart.getClass().getDeclaredField("wrappedPart");
-                field.setAccessible(true);
-                Object object = field.get(activePart);
-                if(object instanceof MPart){
-                    return ((MPart) object).getObject();
-                }
-            } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
-                e.printStackTrace();
-            }
-        }
-        return null;
-    }
-
     public static IWorkbench getWorkbench() {
         return TaxeditorStorePlugin.getDefault().getWorkbench();
     }
@@ -573,7 +554,7 @@ public abstract class AbstractUtility {
     public static Object getActiveE4Editor() {
         if(getActivePage()!=null){
             IEditorPart activeEditor = getActivePage().getActiveEditor();
-            Object wrappedPart = getE4WrappedPart(getActivePage().getActivePart());
+            Object wrappedPart = WorkbenchUtility.getE4WrappedPart(getActivePage().getActivePart());
             return wrappedPart!=null?wrappedPart:activeEditor;
         }
         return null;