Revision 924cc33b
Added by Katja Luther about 4 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/defaultHandler/OpenReferencingObjectsViewHandler.java | ||
---|---|---|
1 | 1 |
package eu.etaxonomy.taxeditor.handler.defaultHandler; |
2 | 2 |
|
3 |
import java.util.UUID; |
|
4 |
|
|
3 | 5 |
import javax.inject.Named; |
4 | 6 |
|
5 | 7 |
import org.eclipse.e4.core.di.annotations.CanExecute; |
... | ... | |
9 | 11 |
import org.eclipse.e4.ui.services.IServiceConstants; |
10 | 12 |
import org.eclipse.e4.ui.workbench.modeling.EPartService; |
11 | 13 |
import org.eclipse.e4.ui.workbench.modeling.EPartService.PartState; |
14 |
import org.eclipse.jface.viewers.IStructuredSelection; |
|
12 | 15 |
|
16 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
|
17 |
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache; |
|
13 | 18 |
import eu.etaxonomy.taxeditor.bulkeditor.AppModelId; |
19 |
import eu.etaxonomy.taxeditor.editor.IReferencingObjectsView; |
|
14 | 20 |
|
15 | 21 |
public class OpenReferencingObjectsViewHandler { |
16 | 22 |
|
23 |
Object selectedObject; |
|
17 | 24 |
@Execute |
18 | 25 |
public void execute(EPartService partService) { |
19 | 26 |
MPart part = partService.createPart(AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_BULKEDITOR_REFERENCINGOBJECTS_E4_REFERENCINGOBJECTSVIEWE4); |
20 | 27 |
part = partService.showPart(part, PartState.ACTIVATE); |
28 |
IReferencingObjectsView view = (IReferencingObjectsView)part.getObject(); |
|
29 |
UUID uuid = null; |
|
30 |
Class clazz = null; |
|
31 |
|
|
32 |
if (selectedObject instanceof IStructuredSelection){ |
|
33 |
selectedObject = ((IStructuredSelection)selectedObject).getFirstElement(); |
|
34 |
} |
|
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(); |
|
41 |
} |
|
42 |
if (uuid != null && clazz != null){ |
|
43 |
view.updateReferencingObjects(uuid, clazz); |
|
44 |
} |
|
45 |
|
|
46 |
|
|
47 |
|
|
21 | 48 |
} |
22 | 49 |
|
23 | 50 |
@CanExecute |
... | ... | |
27 | 54 |
boolean canExecute = false; |
28 | 55 |
MPart part = partService.findPart(AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_BULKEDITOR_REFERENCINGOBJECTS_E4_REFERENCINGOBJECTSVIEWE4); |
29 | 56 |
canExecute = !part.equals(activePart); |
57 |
|
|
58 |
|
|
59 |
if (canExecute){ |
|
60 |
String commandId = menuItem.getCommand().getElementId(); |
|
61 |
selectedObject = menuItem.getTransientData().get(commandId+".uuid"); |
|
62 |
if (selectedObject instanceof IStructuredSelection){ |
|
63 |
canExecute = ((IStructuredSelection)selectedObject).size() == 1; |
|
64 |
} |
|
65 |
} |
|
30 | 66 |
menuItem.setVisible(canExecute); |
31 | 67 |
return canExecute; |
32 | 68 |
} |
Also available in: Unified diff
ref #8890: handle dynamic menu for ref objects view and taxonnode wizard correctly