Project

General

Profile

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

    
3
import javax.inject.Named;
4

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

    
17
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
18

    
19
public abstract class DefaultOpenHandlerBaseE4 <T> {
20

    
21
    protected IEclipseContext context;
22

    
23
    protected MApplication application;
24

    
25
    protected EModelService modelService;
26

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

    
35

    
36
        String commandId = menuItem.getCommand().getElementId();
37
        Object transientData = menuItem.getTransientData().get(commandId+".uuid");
38

    
39
        if (transientData instanceof IStructuredSelection){
40

    
41
            for (Object element: ((IStructuredSelection)transientData).toArray()) {
42
               open((T)element, shell, partService);
43
            }
44
        }else if (transientData instanceof UuidAndTitleCache){
45
//            T entity = getEntity(((UuidAndTitleCache)transientData).getUuid());
46
            open((T)transientData, shell, partService);
47
        }
48

    
49

    
50
    }
51

    
52
    @CanExecute
53
    public boolean canExecute(MHandledMenuItem menuItem,
54
            @Named(IServiceConstants.ACTIVE_PART) MPart activePart) {
55
        boolean canExecute = false;
56

    
57
        //check if same part
58
        String partId = getPartId();
59
        //check for correct entity
60
        String commandId = menuItem.getCommand().getElementId();
61
        Object transientData = menuItem.getTransientData().get(commandId+".uuid");
62
        if(transientData instanceof IStructuredSelection){
63
            canExecute = canExecute(transientData)
64
                    && (partId!=null?!partId.equals(activePart.getElementId()):true);
65
        }else if (transientData instanceof UuidAndTitleCache){
66

    
67
            canExecute = canExecute(transientData)
68
                    && (partId!=null?!partId.equals(activePart.getElementId()):true);
69
        }
70

    
71
        menuItem.setVisible(canExecute);
72
        return canExecute;
73
    }
74

    
75
//    protected abstract T getEntity(UUID uuid);
76

    
77
    protected abstract void open(T entity, Shell shell, EPartService partService);
78

    
79
    protected abstract boolean canExecute(Object entity);
80

    
81
    /**
82
     * Returns the part id for the part this handler opens.<br>
83
     */
84
    protected String getPartId(){
85
        return null;
86
    }
87

    
88
}
(2-2/4)