1
|
package eu.etaxonomy.taxeditor.handler.defaultHandler;
|
2
|
|
3
|
import java.util.UUID;
|
4
|
|
5
|
import javax.inject.Named;
|
6
|
|
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;
|
15
|
|
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;
|
20
|
|
21
|
public class OpenReferencingObjectsViewHandler {
|
22
|
|
23
|
Object selectedObject;
|
24
|
@Execute
|
25
|
public void execute(EPartService partService) {
|
26
|
|
27
|
MPart part = partService.createPart(AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_BULKEDITOR_REFERENCINGOBJECTS_E4_REFERENCINGOBJECTSVIEWE4);
|
28
|
part = partService.showPart(part, PartState.ACTIVATE);
|
29
|
IReferencingObjectsView view = (IReferencingObjectsView)part.getObject();
|
30
|
UUID uuid = null;
|
31
|
Class clazz = null;
|
32
|
|
33
|
if (selectedObject instanceof IStructuredSelection){
|
34
|
selectedObject = ((IStructuredSelection)selectedObject).getFirstElement();
|
35
|
}
|
36
|
if (selectedObject instanceof CdmBase){
|
37
|
uuid = ((CdmBase)selectedObject).getUuid();
|
38
|
clazz = selectedObject.getClass();
|
39
|
} else if (selectedObject instanceof UuidAndTitleCache){
|
40
|
uuid = ((UuidAndTitleCache)selectedObject).getUuid();
|
41
|
clazz = ((UuidAndTitleCache)selectedObject).getType();
|
42
|
}
|
43
|
if (uuid != null && clazz != null){
|
44
|
view.updateReferencingObjects(uuid, clazz);
|
45
|
}
|
46
|
}
|
47
|
|
48
|
@CanExecute
|
49
|
public boolean canExecute(EPartService partService,
|
50
|
@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
|
51
|
MHandledMenuItem menuItem) {
|
52
|
boolean canExecute = false;
|
53
|
MPart part = partService.findPart(AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_BULKEDITOR_REFERENCINGOBJECTS_E4_REFERENCINGOBJECTSVIEWE4);
|
54
|
canExecute = !part.equals(activePart);
|
55
|
|
56
|
|
57
|
if (canExecute){
|
58
|
String commandId = menuItem.getCommand().getElementId();
|
59
|
selectedObject = menuItem.getTransientData().get(commandId+".uuid");
|
60
|
if (selectedObject instanceof IStructuredSelection){
|
61
|
canExecute = ((IStructuredSelection)selectedObject).size() == 1;
|
62
|
}
|
63
|
}
|
64
|
menuItem.setVisible(canExecute);
|
65
|
return canExecute;
|
66
|
}
|
67
|
}
|