- fixed possible LazyInitializaitionException in DerivateLabelProvdider
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / view / derivateSearch / DerivateLabelProvider.java
index d628deaaac6e025d30594b0895c2e23e9fb64beb..055880fa63e2e720de579eb22c7036932ba028c6 100644 (file)
@@ -40,12 +40,15 @@ import eu.etaxonomy.taxeditor.store.CdmStore;
  * <b>Note:</b> If you use this label provider you need to assure that you
  * created a {@link ConversationHolder} resp. have an open session because
  * the labels are generated from various fields of the derivate hierarchy which
- * are lazy loaded and could therefore throw a {@link LazyInitializationException}.
+ * are lazy loaded and could therefore throw a {@link LazyInitializationException}.<br>
+ * Use <b>{@link #setConversation(ConversationHolder)}</b> to assign the session to this provider.
  */
 public class DerivateLabelProvider extends ColumnLabelProvider {
 
     private Set<SingleRead> multiLinkSingleReads;
 
+    private ConversationHolder conversation;
+
     private static DefinedTerm photoTerm = null;
     private static DefinedTerm drawingTerm = null;
     private static DefinedTerm specimenScanTerm = null;
@@ -110,22 +113,35 @@ public class DerivateLabelProvider extends ColumnLabelProvider {
         return getDerivateText(element);
     }
 
+    /**
+     * @param conversation the conversation to set
+     */
+    public void setConversation(ConversationHolder conversation) {
+        this.conversation = conversation;
+    }
+
     /**
      *
      * @param element
      * @return
      */
-    public static String getDerivateText(Object element){
+    public String getDerivateText(Object element){
         if(element instanceof TreeNode){
             //unwrap specimen from TreeNode
             element = ((TreeNode) element).getValue();
         }
 
+        conversation.bind();
+
         String label = "";
         if(element instanceof FieldUnit){
             FieldUnit fieldUnit = (FieldUnit)element;
-            GatheringEvent gatheringEvent = fieldUnit.getGatheringEvent();
-            if(gatheringEvent!=null){
+            if(fieldUnit.getGatheringEvent()!=null){
+                GatheringEvent gatheringEvent = fieldUnit.getGatheringEvent();
+                if(!conversation.getSession().contains(gatheringEvent)){
+                    fieldUnit = (FieldUnit) CdmStore.getService(IOccurrenceService.class).load(fieldUnit.getUuid());
+                    gatheringEvent = fieldUnit.getGatheringEvent();
+                }
                 label += gatheringEvent.getCountry()!=null?gatheringEvent.getCountry().getLabel()+", ":"";
                 label += gatheringEvent.getLocality()!=null?gatheringEvent.getLocality().getText()+", ":"";
                 label += gatheringEvent.getGatheringDate()!=null?gatheringEvent.getGatheringDate()+", ":"";