698d7938b41114a5a3c34b28f7fe24ef38c44683
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / view / derivate / handler / OpenDerivativeEditorForDescriptionElement.java
1 package eu.etaxonomy.taxeditor.editor.view.derivate.handler;
2
3 import java.util.Collections;
4 import java.util.UUID;
5
6 import org.eclipse.core.commands.ExecutionEvent;
7 import org.eclipse.ui.PartInitException;
8
9 import eu.etaxonomy.cdm.api.service.IDescriptionService;
10 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
11 import eu.etaxonomy.cdm.model.description.IndividualsAssociation;
12 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
13 import eu.etaxonomy.taxeditor.editor.EditorUtil;
14 import eu.etaxonomy.taxeditor.editor.handler.OpenDerivateViewHandler;
15 import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateViewEditorInput;
16 import eu.etaxonomy.taxeditor.handler.defaultHandler.DefaultOpenHandlerBase;
17 import eu.etaxonomy.taxeditor.model.MessagingUtils;
18 import eu.etaxonomy.taxeditor.store.CdmStore;
19
20 public class OpenDerivativeEditorForDescriptionElement extends DefaultOpenHandlerBase<IndividualsAssociation> {
21
22 @Override
23 protected IndividualsAssociation getEntity(UUID uuid) {
24 DescriptionElementBase descriptionElement = CdmStore.getService(IDescriptionService.class).loadDescriptionElement(uuid, null);
25 if(descriptionElement!=null && descriptionElement.isInstanceOf(IndividualsAssociation.class)){
26 return (IndividualsAssociation) descriptionElement;
27 }
28 return null;
29 }
30
31 @Override
32 protected void open(ExecutionEvent event, IndividualsAssociation entity) {
33 SpecimenOrObservationBase associatedSpecimenOrObservation = entity.getAssociatedSpecimenOrObservation();
34 if(associatedSpecimenOrObservation!=null){
35 UUID specimenUuid = associatedSpecimenOrObservation.getUuid();
36 try {
37 EditorUtil.open(new DerivateViewEditorInput(Collections.singletonList(specimenUuid)));
38 } catch (PartInitException e) {
39 MessagingUtils.error(OpenDerivateViewHandler.class, "Derivative Editor could not be opened", e);
40 }
41 }
42
43 }
44
45 }