- added conversation/session support to DerivateLabelProvider
authorPatric Plitzner <p.plitzner@bgbm.org>
Wed, 11 Jun 2014 07:23:48 +0000 (07:23 +0000)
committerPatric Plitzner <p.plitzner@bgbm.org>
Wed, 11 Jun 2014 07:23:48 +0000 (07:23 +0000)
  - GUI widgets using the provider need to provide a conversation/session to avoid LazyInitializationException

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateView.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/derivateSearch/DerivateLabelProvider.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/derivateSearch/DerivateSearchView.java

index ff919dfca756439b4493a023000b3e91e4d2fe05..4b0a5bad1071a7a8a3426031105b15ec669a5508 100644 (file)
@@ -301,6 +301,7 @@ public class DerivateView extends EditorPart implements IPartContentHasFactualDa
      */
     @Override
     public void workbenchShutdown(IMemento memento, IProgressMonitor monitor) {
+        conversation.close();
 //        if(memento == null){
 //            return;
 //        }
index 260854f859bdc8dd12a21ca9164975854f6d8089..13c6f8dfbba7ad7cca67d754366c6ac3183e46b3 100644 (file)
@@ -16,7 +16,9 @@ import java.util.UUID;
 import org.eclipse.jface.viewers.ColumnLabelProvider;
 import org.eclipse.jface.viewers.TreeNode;
 import org.eclipse.swt.graphics.Image;
+import org.hibernate.LazyInitializationException;
 
+import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
 import eu.etaxonomy.cdm.model.common.DefinedTerm;
 import eu.etaxonomy.cdm.model.molecular.DnaSample;
 import eu.etaxonomy.cdm.model.molecular.Sequence;
@@ -32,7 +34,12 @@ import eu.etaxonomy.taxeditor.model.ImageResources;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 
 /**
- * Label provider for the views to show {@link SpecimenOrObservationBase}s.
+ * Label provider for the views to show {@link SpecimenOrObservationBase}s.<br>
+ * <br>
+ * <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}.
  */
 public class DerivateLabelProvider extends ColumnLabelProvider {
 
@@ -111,7 +118,7 @@ public class DerivateLabelProvider extends ColumnLabelProvider {
             if(gatheringEvent!=null){
                 label += gatheringEvent.getCountry()!=null?gatheringEvent.getCountry().getLabel()+", ":"";
                 label += gatheringEvent.getLocality()!=null?gatheringEvent.getLocality().getText()+", ":"";
-//                label += gatheringEvent.getGatheringDate()!=null?gatheringEvent.getGatheringDate()+", ":"";
+                label += gatheringEvent.getGatheringDate()!=null?gatheringEvent.getGatheringDate()+", ":"";
                 label += gatheringEvent.getCollector()!=null?gatheringEvent.getCollector()+", ":"";
             }
             label += fieldUnit.getFieldNumber()!=null?fieldUnit.getFieldNumber():"";
@@ -136,7 +143,7 @@ public class DerivateLabelProvider extends ColumnLabelProvider {
                 label += derivedUnit.getBarcode()!=null?derivedUnit.getBarcode():"";
             }
             else if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.TissueSample){
-
+//                kindofTissue + SampleDesignation
             }
         }
         else if(element instanceof MediaSpecimen){
index 38853d0b9f5ebebfe1f7b7d2c73f10c54bcb9072..142bdbdb8722aaa2cd35e8ffb1a80f531798814e 100644 (file)
@@ -14,6 +14,7 @@ import org.eclipse.swt.widgets.Composite;
 import org.eclipse.ui.IMemento;
 import org.eclipse.ui.part.ViewPart;
 
+import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
 import eu.etaxonomy.taxeditor.model.IContextListener;
 import eu.etaxonomy.taxeditor.store.CdmStore;
@@ -26,6 +27,7 @@ public class DerivateSearchView extends ViewPart implements IContextListener {
 
     public static final String ID = "eu.etaxonomy.taxeditor.view.derivateSearch.DerivateSearchView";
     private DerivateSearchCompositeController derivateSearchCompositeController;
+    private ConversationHolder conversationHolder;
 
     /**
      * Constructs a new DerivateSearchView and registers it to listen to context changes
@@ -50,6 +52,10 @@ public class DerivateSearchView extends ViewPart implements IContextListener {
     @Override
     public void setFocus() {
         derivateSearchCompositeController.setFocus();
+        //make sure to bind again if maybe in another view the conversation was unbound
+        if(getConversationHolder()!=null && !getConversationHolder().isBound()){
+            getConversationHolder().bind();
+        }
     }
 
     /* (non-Javadoc)
@@ -81,6 +87,13 @@ public class DerivateSearchView extends ViewPart implements IContextListener {
      */
     @Override
     public void contextRefresh(IProgressMonitor monitor) {
+        initConversation();
+    }
+
+    private void initConversation(){
+        if(conversationHolder==null){
+            conversationHolder = CdmStore.createConversation();
+        }
     }
 
     /* (non-Javadoc)
@@ -88,5 +101,18 @@ public class DerivateSearchView extends ViewPart implements IContextListener {
      */
     @Override
     public void workbenchShutdown(IMemento memento, IProgressMonitor monitor) {
+        if(getConversationHolder()!=null){
+            getConversationHolder().close();
+        }
+    }
+
+    /**
+     * @return the conversationHolder
+     */
+    public ConversationHolder getConversationHolder() {
+        if(CdmStore.isActive() && conversationHolder==null){
+            initConversation();
+        }
+        return conversationHolder;
     }
 }