Project

General

Profile

Download (1.79 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2017 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.workbench;
10

    
11
import java.lang.reflect.Field;
12

    
13
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
14
import org.eclipse.ui.internal.E4PartWrapper;
15
import org.eclipse.ui.internal.e4.compatibility.CompatibilityView;
16

    
17
/**
18
 * Utility class for e4 workbench related operations
19
 * @author pplitzner
20
 * @since Jun 27, 2017
21
 *
22
 */
23
public class WorkbenchUtility {
24

    
25
    /**
26
     * Checks if the activePart is an E4 wrapper for a legacy part and returns
27
     * that part
28
     *
29
     * @param activePart the e4 wrapper
30
     * @return the wrapped legacy part or <code>null</code>
31
     */
32
    public static Object getE4WrappedPart(Object activePart){
33
        //FIXME can be removed when E4 migration is complete
34

    
35
        Object object = null;
36
        try {
37
            if(activePart instanceof E4PartWrapper){
38
                Field field = activePart.getClass().getDeclaredField("wrappedPart");
39
                field.setAccessible(true);
40
                object = field.get(activePart);
41
            }
42
            else if(activePart instanceof CompatibilityView){
43
                Field field = activePart.getClass().getSuperclass().getDeclaredField("wrapped");
44
                field.setAccessible(true);
45
                object = field.get(activePart);
46
            }
47
        } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
48
            e.printStackTrace();
49
        }
50
        if(object instanceof MPart){
51
            object =((MPart) object).getObject();
52
        }
53
        return object;
54
    }
55
}
(8-8/8)