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.CompatibilityEditor;
|
16
|
import org.eclipse.ui.internal.e4.compatibility.CompatibilityView;
|
17
|
|
18
|
/**
|
19
|
* Utility class for e4 workbench related operations
|
20
|
* @author pplitzner
|
21
|
* @since Jun 27, 2017
|
22
|
*
|
23
|
*/
|
24
|
public class WorkbenchUtility {
|
25
|
|
26
|
/**
|
27
|
* Checks if the activePart is an E4 wrapper for a legacy part and returns
|
28
|
* that part
|
29
|
*
|
30
|
* @param activePart the e4 wrapper
|
31
|
* @return the wrapped legacy part or <code>null</code>
|
32
|
*/
|
33
|
public static Object getE4WrappedPart(Object activePart){
|
34
|
//FIXME E4 can be removed when E4 migration is complete
|
35
|
|
36
|
Object object = activePart;
|
37
|
if(object instanceof MPart){
|
38
|
object = ((MPart) activePart).getObject();
|
39
|
}
|
40
|
try {
|
41
|
if(object instanceof E4PartWrapper){
|
42
|
Field field = object.getClass().getDeclaredField("wrappedPart");
|
43
|
field.setAccessible(true);
|
44
|
object = field.get(object);
|
45
|
}
|
46
|
else if(object instanceof CompatibilityView || object instanceof CompatibilityEditor){
|
47
|
Field field = object.getClass().getSuperclass().getDeclaredField("wrapped");
|
48
|
field.setAccessible(true);
|
49
|
object = field.get(object);
|
50
|
}
|
51
|
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
|
52
|
e.printStackTrace();
|
53
|
}
|
54
|
//TODO can this still happen??
|
55
|
if(object instanceof MPart){
|
56
|
object =((MPart) object).getObject();
|
57
|
}
|
58
|
return object;
|
59
|
}
|
60
|
}
|