Project

General

Profile

Download (2.53 KB) Statistics
| Branch: | Tag: | Revision:
1
package eu.etaxonomy.taxeditor.handler.defaultHandler.e4;
2

    
3
import java.util.UUID;
4

    
5
import javax.inject.Named;
6

    
7
import org.eclipse.e4.core.contexts.IEclipseContext;
8
import org.eclipse.e4.core.di.annotations.CanExecute;
9
import org.eclipse.e4.core.di.annotations.Execute;
10
import org.eclipse.e4.ui.model.application.MApplication;
11
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
12
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
13
import org.eclipse.e4.ui.services.IServiceConstants;
14
import org.eclipse.e4.ui.workbench.modeling.EModelService;
15
import org.eclipse.e4.ui.workbench.modeling.EPartService;
16
import org.eclipse.swt.widgets.Shell;
17

    
18
public abstract class DefaultOpenHandlerBaseE4 <T> {
19

    
20
    protected IEclipseContext context;
21

    
22
    protected MApplication application;
23

    
24
    protected EModelService modelService;
25

    
26
    @Execute
27
    public void execute(@Named(IServiceConstants.ACTIVE_SHELL)Shell shell, MHandledMenuItem menuItem,
28
            EModelService modelService, EPartService partService, MApplication application,
29
            IEclipseContext context) {
30
        this.context = context;
31
        this.modelService = modelService;
32
        this.application = application;
33

    
34

    
35
        String commandId = menuItem.getCommand().getElementId();
36
        Object transientData = menuItem.getTransientData().get(commandId+".uuid");
37
        if(transientData instanceof UUID){
38
            T entity = getEntity((UUID) transientData);
39
            open(entity, shell, partService);
40
        }
41
    }
42

    
43
    @CanExecute
44
    public boolean canExecute(MHandledMenuItem menuItem,
45
            @Named(IServiceConstants.ACTIVE_PART) MPart activePart) {
46
        boolean canExecute = false;
47

    
48
        //check if same part
49
        String partId = getPartId();
50
        //check for correct entity
51
        String commandId = menuItem.getCommand().getElementId();
52
        Object transientData = menuItem.getTransientData().get(commandId+".uuid");
53
        if(transientData instanceof UUID){
54
            T entity = getEntity((UUID) transientData);
55
            canExecute = canExecute(entity)
56
                    && (partId!=null?!partId.equals(activePart.getElementId()):true);
57
        }
58
        menuItem.setVisible(canExecute);
59
        return canExecute;
60
    }
61

    
62
    protected abstract T getEntity(UUID uuid);
63

    
64
    protected abstract void open(T entity, Shell shell, EPartService partService);
65

    
66
    protected abstract boolean canExecute(T entity);
67

    
68
    /**
69
     * Returns the part id for the part this handler opens.<br>
70
     */
71
    protected String getPartId(){
72
        return null;
73
    }
74

    
75
}
(2-2/3)