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.menu.MHandledMenuItem;
|
12
|
import org.eclipse.e4.ui.services.IServiceConstants;
|
13
|
import org.eclipse.e4.ui.workbench.modeling.EModelService;
|
14
|
import org.eclipse.e4.ui.workbench.modeling.EPartService;
|
15
|
import org.eclipse.swt.widgets.Shell;
|
16
|
|
17
|
public abstract class DefaultOpenHandlerBaseE4 <T> {
|
18
|
|
19
|
protected IEclipseContext context;
|
20
|
|
21
|
protected MApplication application;
|
22
|
|
23
|
protected EModelService modelService;
|
24
|
|
25
|
@Execute
|
26
|
public void execute(@Named(IServiceConstants.ACTIVE_SHELL)Shell shell, MHandledMenuItem menuItem,
|
27
|
EModelService modelService, EPartService partService, MApplication application,
|
28
|
IEclipseContext context) {
|
29
|
this.context = context;
|
30
|
this.modelService = modelService;
|
31
|
this.application = application;
|
32
|
|
33
|
String commandId = menuItem.getCommand().getElementId();
|
34
|
Object transientData = menuItem.getTransientData().get(commandId+".uuid");
|
35
|
if(transientData instanceof UUID){
|
36
|
T entity = getEntity((UUID) transientData);
|
37
|
open(entity, shell, partService);
|
38
|
}
|
39
|
}
|
40
|
|
41
|
@CanExecute
|
42
|
public boolean canExecute(MHandledMenuItem menuItem) {
|
43
|
boolean canExecute = false;
|
44
|
String commandId = menuItem.getCommand().getElementId();
|
45
|
Object transientData = menuItem.getTransientData().get(commandId+".uuid");
|
46
|
if(transientData instanceof UUID){
|
47
|
T entity = getEntity((UUID) transientData);
|
48
|
canExecute = canExecute(entity);
|
49
|
}
|
50
|
menuItem.setVisible(canExecute);
|
51
|
return canExecute;
|
52
|
}
|
53
|
|
54
|
protected abstract T getEntity(UUID uuid);
|
55
|
|
56
|
protected abstract void open(T entity, Shell shell, EPartService partService);
|
57
|
|
58
|
protected abstract boolean canExecute(T entity);
|
59
|
|
60
|
}
|