Project

General

Profile

« Previous | Next » 

Revision ea1b3d44

Added by Patrick Plitzner almost 7 years ago

ref #6596 Add new utility class WorkbenchUtility in workbench plugin

  • move getE4WrappedPart() method to that class

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/AbstractUtility.java
9 9

  
10 10
package eu.etaxonomy.taxeditor.model;
11 11

  
12
import java.lang.reflect.Field;
13 12
import java.lang.reflect.InvocationTargetException;
14 13
import java.util.ArrayList;
15 14
import java.util.Collection;
......
35 34
import org.eclipse.core.runtime.SubProgressMonitor;
36 35
import org.eclipse.core.runtime.jobs.ISchedulingRule;
37 36
import org.eclipse.core.runtime.jobs.Job;
38
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
39 37
import org.eclipse.jface.action.IStatusLineManager;
40 38
import org.eclipse.jface.operation.IRunnableWithProgress;
41 39
import org.eclipse.jface.resource.ColorRegistry;
......
57 55
import org.eclipse.ui.PlatformUI;
58 56
import org.eclipse.ui.handlers.IHandlerService;
59 57
import org.eclipse.ui.ide.undo.WorkspaceUndoUtil;
60
import org.eclipse.ui.internal.E4PartWrapper;
61 58
import org.eclipse.ui.part.EditorPart;
62 59
import org.eclipse.ui.progress.IProgressConstants;
63 60
import org.eclipse.ui.progress.IProgressService;
......
80 77
import eu.etaxonomy.taxeditor.view.AbstractCdmDataViewer;
81 78
import eu.etaxonomy.taxeditor.view.detail.DetailsViewPart;
82 79
import eu.etaxonomy.taxeditor.view.supplementaldata.SupplementalDataViewPart;
80
import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
83 81

  
84 82
/**
85 83
 *
......
143 141
        IWorkbenchPage activePage = getActivePage();
144 142
        if(activePage!=null){
145 143
            IWorkbenchPart activePart = activePage.getActivePart();
146
            Object e4WrappedPart = getE4WrappedPart(activePart);
144
            Object e4WrappedPart = WorkbenchUtility.getE4WrappedPart(activePart);
147 145
            return e4WrappedPart!=null?e4WrappedPart:activePart;
148 146
        }
149 147
        return null;
150 148
    }
151 149

  
152
    public static Object getE4WrappedPart(Object activePart){
153
        if(activePart instanceof E4PartWrapper){
154
            //FIXME can be removed when E4 migration is complete
155
            try {
156
                Field field = activePart.getClass().getDeclaredField("wrappedPart");
157
                field.setAccessible(true);
158
                Object object = field.get(activePart);
159
                if(object instanceof MPart){
160
                    return ((MPart) object).getObject();
161
                }
162
            } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
163
                e.printStackTrace();
164
            }
165
        }
166
        return null;
167
    }
168

  
169 150
    public static IWorkbench getWorkbench() {
170 151
        return TaxeditorStorePlugin.getDefault().getWorkbench();
171 152
    }
......
573 554
    public static Object getActiveE4Editor() {
574 555
        if(getActivePage()!=null){
575 556
            IEditorPart activeEditor = getActivePage().getActiveEditor();
576
            Object wrappedPart = getE4WrappedPart(getActivePage().getActivePart());
557
            Object wrappedPart = WorkbenchUtility.getE4WrappedPart(getActivePage().getActivePart());
577 558
            return wrappedPart!=null?wrappedPart:activeEditor;
578 559
        }
579 560
        return null;

Also available in: Unified diff