1 package eu
.etaxonomy
.taxeditor
.handler
.defaultHandler
.e4
;
3 import javax
.inject
.Named
;
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
;
17 import eu
.etaxonomy
.cdm
.persistence
.dto
.UuidAndTitleCache
;
19 public abstract class DefaultOpenHandlerBaseE4
<T
> {
21 protected IEclipseContext context
;
23 protected MApplication application
;
25 protected EModelService modelService
;
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
;
36 String commandId
= menuItem
.getCommand().getElementId();
37 Object transientData
= menuItem
.getTransientData().get(commandId
+".uuid");
39 if (transientData
instanceof IStructuredSelection
){
41 for (Object element
: ((IStructuredSelection
)transientData
).toArray()) {
42 open((T
)element
, shell
, partService
);
44 }else if (transientData
instanceof UuidAndTitleCache
){
45 // T entity = getEntity(((UuidAndTitleCache)transientData).getUuid());
46 open((T
)transientData
, shell
, partService
);
53 public boolean canExecute(MHandledMenuItem menuItem
,
54 @Named(IServiceConstants
.ACTIVE_PART
) MPart activePart
) {
55 boolean canExecute
= false;
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
){
67 canExecute
= canExecute(transientData
)
68 && (partId
!=null?
!partId
.equals(activePart
.getElementId()):true);
71 menuItem
.setVisible(canExecute
);
75 // protected abstract T getEntity(UUID uuid);
77 protected abstract void open(T entity
, Shell shell
, EPartService partService
);
79 protected abstract boolean canExecute(Object entity
);
82 * Returns the part id for the part this handler opens.<br>
84 protected String
getPartId(){