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
;
15 import eu
.etaxonomy
.cdm
.model
.common
.ICdmBase
;
16 import eu
.etaxonomy
.cdm
.persistence
.dto
.UuidAndTitleCache
;
17 import eu
.etaxonomy
.taxeditor
.bulkeditor
.AppModelId
;
18 import eu
.etaxonomy
.taxeditor
.editor
.IReferencingObjectsView
;
19 import eu
.etaxonomy
.taxeditor
.view
.CdmViewerUtilE4
;
21 public class OpenReferencingObjectsViewHandler
{
23 private List
<UuidAndTitleCache
<?
extends ICdmBase
>> selectedObjectList
;
26 public void execute(EPartService partService
) {
28 MPart part
= partService
.createPart(AppModelId
.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_BULKEDITOR_REFERENCINGOBJECTS_E4_REFERENCINGOBJECTSVIEWE4
);
29 part
= partService
.showPart(part
, PartState
.ACTIVATE
);
30 IReferencingObjectsView view
= (IReferencingObjectsView
)part
.getObject();
32 if (selectedObjectList
!= null && !selectedObjectList
.isEmpty()) {
33 UuidAndTitleCache
<?
extends ICdmBase
> dto
= selectedObjectList
.get(0);
34 view
.handleNewSelection(dto
);
39 public boolean canExecute(EPartService partService
,
40 @Named(IServiceConstants
.ACTIVE_PART
)MPart activePart
,
41 MHandledMenuItem menuItem
) {
43 boolean canExecute
= false;
44 MPart part
= partService
.findPart(AppModelId
.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_BULKEDITOR_REFERENCINGOBJECTS_E4_REFERENCINGOBJECTSVIEWE4
);
45 canExecute
= part
.equals(activePart
) //we explicitly want to allow calling the view recursively
46 || part
.getObject() == null ; //we show the menu item only if the view is not yet open (otherwise by setting the focus data will be shown anyway
47 //but this may change in future for some data where explicitly calling the view is required
49 selectedObjectList
= null;
51 String commandId
= menuItem
.getCommand().getElementId();
52 Object selectedObject
= menuItem
.getTransientData().get(commandId
+".uuid");
53 selectedObjectList
= CdmViewerUtilE4
.transformSelectionToUuidAndTitleCacheList(selectedObject
);
54 canExecute
= selectedObjectList
.size() == 1;
56 menuItem
.setVisible(canExecute
);