1 package eu
.etaxonomy
.taxeditor
.handler
.defaultHandler
;
5 import javax
.inject
.Named
;
7 import org
.eclipse
.e4
.core
.di
.annotations
.CanExecute
;
8 import org
.eclipse
.e4
.core
.di
.annotations
.Execute
;
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
.EPartService
;
13 import org
.eclipse
.e4
.ui
.workbench
.modeling
.EPartService
.PartState
;
14 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
16 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
17 import eu
.etaxonomy
.cdm
.persistence
.dto
.UuidAndTitleCache
;
18 import eu
.etaxonomy
.taxeditor
.bulkeditor
.AppModelId
;
19 import eu
.etaxonomy
.taxeditor
.editor
.IReferencingObjectsView
;
21 public class OpenReferencingObjectsViewHandler
{
23 Object selectedObject
;
25 public void execute(EPartService partService
) {
26 MPart part
= partService
.createPart(AppModelId
.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_BULKEDITOR_REFERENCINGOBJECTS_E4_REFERENCINGOBJECTSVIEWE4
);
27 part
= partService
.showPart(part
, PartState
.ACTIVATE
);
28 IReferencingObjectsView view
= (IReferencingObjectsView
)part
.getObject();
32 if (selectedObject
instanceof IStructuredSelection
){
33 selectedObject
= ((IStructuredSelection
)selectedObject
).getFirstElement();
35 if (selectedObject
instanceof CdmBase
){
36 uuid
= ((CdmBase
)selectedObject
).getUuid();
37 clazz
= selectedObject
.getClass();
38 } else if (selectedObject
instanceof UuidAndTitleCache
){
39 uuid
= ((UuidAndTitleCache
)selectedObject
).getUuid();
40 clazz
= ((UuidAndTitleCache
)selectedObject
).getType();
42 if (uuid
!= null && clazz
!= null){
43 view
.updateReferencingObjects(uuid
, clazz
);
51 public boolean canExecute(EPartService partService
,
52 @Named(IServiceConstants
.ACTIVE_PART
)MPart activePart
,
53 MHandledMenuItem menuItem
) {
54 boolean canExecute
= false;
55 MPart part
= partService
.findPart(AppModelId
.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_BULKEDITOR_REFERENCINGOBJECTS_E4_REFERENCINGOBJECTSVIEWE4
);
56 canExecute
= !part
.equals(activePart
);
60 String commandId
= menuItem
.getCommand().getElementId();
61 selectedObject
= menuItem
.getTransientData().get(commandId
+".uuid");
62 if (selectedObject
instanceof IStructuredSelection
){
63 canExecute
= ((IStructuredSelection
)selectedObject
).size() == 1;
66 menuItem
.setVisible(canExecute
);