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
|
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
|
|
34
|
String commandId = menuItem.getCommand().getElementId();
|
35
|
Object transientData = menuItem.getTransientData().get(commandId+".uuid");
|
36
|
// if(transientData instanceof UUID){
|
37
|
// T entity = getEntity((UUID) transientData);
|
38
|
open((T)((IStructuredSelection)transientData).getFirstElement(), shell, partService);
|
39
|
// }
|
40
|
}
|
41
|
|
42
|
@CanExecute
|
43
|
public boolean canExecute(MHandledMenuItem menuItem,
|
44
|
@Named(IServiceConstants.ACTIVE_PART) MPart activePart) {
|
45
|
boolean canExecute = false;
|
46
|
|
47
|
//check if same part
|
48
|
String partId = getPartId();
|
49
|
//check for correct entity
|
50
|
String commandId = menuItem.getCommand().getElementId();
|
51
|
Object transientData = menuItem.getTransientData().get(commandId+".uuid");
|
52
|
if(transientData instanceof IStructuredSelection){
|
53
|
//TODO: is it necessary to get the entity? This handler is only available for the navigator and there are all objects are transient, this also needs several db calls, not necessary
|
54
|
// T entity = getEntity((UUID) transientData);
|
55
|
|
56
|
canExecute = canExecute((IStructuredSelection)transientData)
|
57
|
&& (partId!=null?!partId.equals(activePart.getElementId()):true);
|
58
|
}
|
59
|
menuItem.setVisible(canExecute);
|
60
|
return canExecute;
|
61
|
}
|
62
|
|
63
|
//protected abstract T getEntity(UUID uuid);
|
64
|
|
65
|
protected abstract void open(T entity, Shell shell, EPartService partService);
|
66
|
|
67
|
protected abstract boolean canExecute(IStructuredSelection entity);
|
68
|
|
69
|
/**
|
70
|
* Returns the part id for the part this handler opens.<br>
|
71
|
*/
|
72
|
protected String getPartId(){
|
73
|
return null;
|
74
|
}
|
75
|
|
76
|
}
|