Enable remote session support
authorPatrick Plitzner <p.plitzner@bgbm.org>
Wed, 21 Oct 2015 12:19:58 +0000 (14:19 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Wed, 21 Oct 2015 12:19:58 +0000 (14:19 +0200)
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateView.java

index a457b2f91b7efadab231ecc4fb1d0e0d96de3e0d..88c336ff50bbec7acd87c69bd08f1305981f0578 100644 (file)
@@ -1,5 +1,6 @@
 package eu.etaxonomy.taxeditor.editor.view.derivate;
 
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashMap;
@@ -55,6 +56,8 @@ import eu.etaxonomy.taxeditor.model.IPartContentHasFactualData;
 import eu.etaxonomy.taxeditor.model.IPartContentHasMedia;
 import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
+import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
+import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 import eu.etaxonomy.taxeditor.view.derivateSearch.DerivateContentProvider;
 import eu.etaxonomy.taxeditor.view.derivateSearch.DerivateLabelProvider;
@@ -66,7 +69,7 @@ import eu.etaxonomy.taxeditor.view.derivateSearch.DerivateLabelProvider;
 public class DerivateView extends EditorPart implements IPartContentHasFactualData, IDirtyMarkable,
         IConversationEnabled, IPartContentHasDetails, IPartContentHasSupplementalData, IPartContentHasMedia,
 
-        ISelectionChangedListener, IPostOperationEnabled/*, ICdmEntitySessionEnabled*/{
+        ISelectionChangedListener, IPostOperationEnabled, ICdmEntitySessionEnabled{
     public static final String ID = "eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView"; //$NON-NLS-1$
 
     public static final String YOU_NEED_TO_SAVE_BEFORE_PERFORMING_THIS_ACTION = Messages.DerivateView_YOU_NEED_TO_SAVE;
@@ -118,11 +121,12 @@ public class DerivateView extends EditorPart implements IPartContentHasFactualDa
      */
     private Set<SpecimenOrObservationBase<?>> rootElements;
 
+    private ICdmEntitySession cdmEntitySession;
+
     /**
      * Default constructor
      */
     public DerivateView() {
-        conversation = CdmStore.createConversation();
     }
 
     @Override
@@ -229,7 +233,10 @@ public class DerivateView extends EditorPart implements IPartContentHasFactualDa
 
         // commit the conversation and start a new transaction immediately
         conversation.commit(true);
-//      TODO: what does this do?  merge();
+
+        if(CdmStore.getCurrentSessionManager().isRemoting()) {
+            CdmStore.getService(IOccurrenceService.class).merge(new ArrayList(getRootEntities()), true);
+        }
         monitor.worked(1);
 
         this.setDirty(false);
@@ -262,6 +269,13 @@ public class DerivateView extends EditorPart implements IPartContentHasFactualDa
         setInput(input);
         this.derivateToRootEntityMap = new HashMap<SpecimenOrObservationBase<?>, SpecimenOrObservationBase<?>>();
         this.rootElements = new HashSet<SpecimenOrObservationBase<?>>();
+
+        if (CdmStore.isActive() && conversation == null) {
+            conversation = CdmStore.createConversation();
+        }
+        if (CdmStore.isActive()) {
+            cdmEntitySession = CdmStore.getCurrentSessionManager().newSession(this, true);
+        }
     }
 
     @Override
@@ -288,6 +302,9 @@ public class DerivateView extends EditorPart implements IPartContentHasFactualDa
         if(!conversation.isBound()){
             conversation.bind();
         }
+        if(cdmEntitySession != null) {
+            cdmEntitySession.bind();
+        }
     }
 
     @Override
@@ -318,35 +335,28 @@ public class DerivateView extends EditorPart implements IPartContentHasFactualDa
         changed(null);
     }
 
-//    @Override
-//    public Set<SpecimenOrObservationBase<?>> getRootEntities() {
-//        return rootElements;
-//    }
-//
-//    @Override
-//    public void merge() {
-//        if(CdmStore.getCurrentSessionManager().isRemoting()) {
-//            CdmApplicationState.getCurrentAppConfig().getOccurrenceService().merge(new ArrayList(getRootEntities()), true);
-//        }
-//    }
-//
-//    @Override
-//    public Map<Object, List<String>> getPropertyPathsMap() {
-//        List<String> specimenPropertyPaths = Arrays.asList(new String[] {
-//                "descriptions",
-//                "derivationEvents.derivates",
-//                "annotations",
-//                "markers",
-//                "credits",
-//                "extensions",
-//                "rights",
-//                "sources"
-//        });
-//        Map<Object, List<String>> specimenPropertyPathMap =
-//                new HashMap<Object, List<String>>();
-//        specimenPropertyPathMap.put(SpecimenOrObservationBase.class,specimenPropertyPaths);
-//        return specimenPropertyPathMap;
-//    }
+    @Override
+    public Set<SpecimenOrObservationBase<?>> getRootEntities() {
+        return rootElements;
+    }
+
+    @Override
+    public Map<Object, List<String>> getPropertyPathsMap() {
+        List<String> specimenPropertyPaths = Arrays.asList(new String[] {
+                "descriptions",
+                "derivationEvents.derivates",
+                "annotations",
+                "markers",
+                "credits",
+                "extensions",
+                "rights",
+                "sources"
+        });
+        Map<Object, List<String>> specimenPropertyPathMap =
+                new HashMap<Object, List<String>>();
+        specimenPropertyPathMap.put(SpecimenOrObservationBase.class,specimenPropertyPaths);
+        return specimenPropertyPathMap;
+    }
 
     /**
      * Refreshes the derivate hierarchy tree and expands the tree
@@ -437,8 +447,19 @@ public class DerivateView extends EditorPart implements IPartContentHasFactualDa
         derivateToRootEntityMap.put(fieldUnit, fieldUnit);
     }
 
-//    @Override
-//    public ICdmEntitySession getCdmEntitySession() {
-//        return conversation;
-//    }
+    @Override
+    public ICdmEntitySession getCdmEntitySession() {
+        return cdmEntitySession;
+    }
+
+    @Override
+    public void dispose() {
+        super.dispose();
+        if(conversation!=null){
+            conversation.close();
+        }
+        if(cdmEntitySession != null) {
+            cdmEntitySession.dispose();
+        }
+    }
 }