Enable referencing objects view for descriptions and description
authorPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 21 Mar 2016 10:45:42 +0000 (11:45 +0100)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 21 Mar 2016 10:45:42 +0000 (11:45 +0100)
elements #5656

eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/referencingobjects/ReferencingObjectsView.java

index 6c76b43..d1645a7 100644 (file)
@@ -43,17 +43,21 @@ import org.eclipse.ui.IWorkbenchPart;
 
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
 import eu.etaxonomy.cdm.api.service.IAgentService;
+import eu.etaxonomy.cdm.api.service.IDescriptionService;
 import eu.etaxonomy.cdm.api.service.IGroupService;
 import eu.etaxonomy.cdm.api.service.INameService;
 import eu.etaxonomy.cdm.api.service.IOccurrenceService;
 import eu.etaxonomy.cdm.api.service.IReferenceService;
 import eu.etaxonomy.cdm.api.service.ITaxonService;
 import eu.etaxonomy.cdm.api.service.IUserService;
+import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
 import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
 import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.model.common.Group;
 import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
 import eu.etaxonomy.cdm.model.common.User;
+import eu.etaxonomy.cdm.model.description.DescriptionBase;
+import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
 import eu.etaxonomy.cdm.model.name.NonViralName;
 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
 import eu.etaxonomy.cdm.model.reference.Reference;
@@ -219,12 +223,24 @@ public class ReferencingObjectsView extends AbstractCdmViewPart {
                        referencedObject = CdmStore.getService(IUserService.class).load(entity);
                } else if (objectClass.isAssignableFrom(Group.class)){
                        referencedObject = CdmStore.getService(IGroupService.class).load(entity);
-               }
+               } else if (DescriptionBase.class.isAssignableFrom(objectClass)){
+                   referencedObject = CdmStore.getService(IDescriptionService.class).load(entity);
+               } else if (DescriptionElementBase.class.isAssignableFrom(objectClass)){
+                referencedObject = CdmStore.getService(IDescriptionService.class).loadDescriptionElement(entity, null);
+            }
                        //referencedObject =(CdmBase) CdmStore.getService(IIdentifiableEntityService.class).load(referencedObject.getUuid());
                Set<CdmBase> setOfReferencingObjects = null;
 
                if (referencedObject != null){
-                       referencedObjectTitleCache = ((IdentifiableEntity)referencedObject).getTitleCache();
+                   if(referencedObject.isInstanceOf(IdentifiableEntity.class)){
+                       referencedObjectTitleCache = (HibernateProxyHelper.deproxy(referencedObject, IdentifiableEntity.class)).getTitleCache();
+                   }
+                   else if(referencedObject.isInstanceOf(DescriptionElementBase.class)){
+                       referencedObjectTitleCache = DescriptionHelper.getLabel(referencedObject);
+                   }
+                   else{
+                       referencedObjectTitleCache = null;
+                   }
                        setOfReferencingObjects = CdmStore.getCommonService().getReferencingObjects(referencedObject);
                }
                if (setOfReferencingObjects != null){
@@ -296,10 +312,11 @@ public class ReferencingObjectsView extends AbstractCdmViewPart {
                if(firstElement instanceof TreeNode){
                    firstElement = ((TreeNode) firstElement).getValue();
                }
-               if(firstElement instanceof IdentifiableEntity){
-                   updateReferencingObjects(((IdentifiableEntity) firstElement).getUuid(),firstElement.getClass() );
+               if(firstElement instanceof CdmBase){
+                   updateReferencingObjects(((CdmBase) firstElement).getUuid(),firstElement.getClass() );
                }
                else{
+                   updateView(null);
             setContentDescription("");
                }
        }