Project

General

Profile

Download (1.66 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 org.eclipse.e4.ui.model.application.ui.basic.MPart;
12

    
13
import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart;
14
import eu.etaxonomy.taxeditor.workbench.part.ISelectionElementEditingPart;
15

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

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

    
34
        Object object = activePart;
35
        if(object instanceof MPart){
36
            object = ((MPart) activePart).getObject();
37
        }
38
        return object;
39
    }
40

    
41
    public static Object findSavablePart(ISelectionElementEditingPart part){
42
        Object selectionProvidingPart = getE4WrappedPart(part.getSelectionProvidingPart());
43
        if(selectionProvidingPart instanceof ISelectionElementEditingPart){
44
            return findSavablePart((ISelectionElementEditingPart) selectionProvidingPart);
45
        }
46
        else if(selectionProvidingPart instanceof IE4SavablePart || selectionProvidingPart instanceof MPart){
47
            return selectionProvidingPart;
48
        }
49
        return null;
50
    }
51
}
(8-8/8)