- added conversation/session support to DerivateLabelProvider
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / view / derivateSearch / DerivateSearchView.java
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;
     }
 }