commit 751c610c7854e0311e38be963bf395ae856d1f85
Author: Katja Luther <k.luther@bgbm.org>
Date:   Thu Jun 9 21:10:01 2016 +0200

    fix save of checklist editor, fix show rank preference

diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/ChecklistEditor.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/ChecklistEditor.java
index 9ae2a675c..6f4d65b28 100644
--- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/ChecklistEditor.java
+++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/ChecklistEditor.java
@@ -12,7 +12,6 @@ package eu.etaxonomy.taxeditor.editor.view.checklist;
 
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
@@ -58,7 +57,6 @@ import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
 import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
 import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
-import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.model.common.DefinedTermBase;
 import eu.etaxonomy.cdm.model.taxon.Classification;
 import eu.etaxonomy.cdm.model.taxon.Taxon;
@@ -77,8 +75,6 @@ import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
 import eu.etaxonomy.taxeditor.model.IPartContentHasFactualData;
 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
 import eu.etaxonomy.taxeditor.preference.Resources;
-import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
-import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 
 /**
@@ -90,8 +86,8 @@ import eu.etaxonomy.taxeditor.store.CdmStore;
  * @created 30.04.2014
  * @version 1.0
  */
-public class ChecklistEditor extends EditorPart implements ISelectionListener, IPartContentHasFactualData,
-        IConversationEnabled, IContextListener, IPartContentHasDetails, IDirtyMarkable, ICdmEntitySessionEnabled {
+public class ChecklistEditor extends EditorPart implements ISelectionListener, IPartContentHasFactualData, IConversationEnabled,
+        IContextListener, IPartContentHasDetails, IDirtyMarkable{//, ICdmEntitySessionEnabled {
 
     private static final Logger logger = Logger.getLogger(ChecklistEditor.class);
     /**
@@ -189,7 +185,7 @@ public class ChecklistEditor extends EditorPart implements ISelectionListener, I
 
     private Label statusLabel;
 
-    private final ICdmEntitySession cdmEntitySession;
+   // private final ICdmEntitySession cdmEntitySession;
 
     private ChecklistLabelProvider labelProvider;
 
@@ -218,7 +214,7 @@ public class ChecklistEditor extends EditorPart implements ISelectionListener, I
      * </p>
      */
     public ChecklistEditor() {
-        cdmEntitySession = CdmStore.getCurrentSessionManager().newSession(this, true);
+        //cdmEntitySession = CdmStore.getCurrentSessionManager().newSession(this, true);
 
     }
 
@@ -472,14 +468,17 @@ public class ChecklistEditor extends EditorPart implements ISelectionListener, I
     /** {@inheritDoc} */
     @Override
     public void dispose() {
-        cdmEntitySession.dispose();
+        this.checklistEditorInput.dispose();
+
+        conversation.unregisterForDataStoreChanges(this);
+        conversation.close();
         super.dispose();
     }
 
     /** {@inheritDoc} */
     @Override
     public void setFocus() {
-        cdmEntitySession.bind();
+
         viewer.getControl().setFocus();
     }
 
@@ -615,8 +614,12 @@ public class ChecklistEditor extends EditorPart implements ISelectionListener, I
     public void doSave(IProgressMonitor monitor) {
         try {
             monitor.beginTask("Saving Editor", 1);
-            getConversationHolder().bind();
-            getConversationHolder().commit(true);
+            if (!conversation.isBound()) {
+                conversation.bind();
+            }
+            CdmStore.getService(ITaxonNodeService.class).merge(selectedTaxonNodes, true);
+            //this.checklistEditorInput.merge();
+            conversation.commit(true);
             setDirty(false);
             monitor.worked(1);
         } finally {
@@ -636,10 +639,12 @@ public class ChecklistEditor extends EditorPart implements ISelectionListener, I
         if (input instanceof ChecklistEditorInput) {
             checklistEditorInput = (ChecklistEditorInput) input;
             setPartName(getPartName() + ": " + checklistEditorInput.getName());
-            conversation = ((ChecklistEditorInput) input).getConversationHolder();
+            conversation = checklistEditorInput.getConversation();
+            conversation.registerForDataStoreChanges(this);
         }
         simpleSelectionProvider = new SimpleSelectionProvider();
         getSite().setSelectionProvider(simpleSelectionProvider);
+
     }
 
     @Override
@@ -657,29 +662,9 @@ public class ChecklistEditor extends EditorPart implements ISelectionListener, I
     public void selectionChanged(IWorkbenchPart part, ISelection selection) {
     }
 
-    /*
-     * (non-Javadoc)
-     *
-     * @see
-     * eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update
-     * (eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
-     */
-    @Override
-    public void update(CdmDataChangeMap changeEvents) {
 
-    }
 
-    /*
-     * (non-Javadoc)
-     *
-     * @see
-     * eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder
-     * ()
-     */
-    @Override
-    public ConversationHolder getConversationHolder() {
-        return conversation;
-    }
+
 
     /*
      * (non-Javadoc)
@@ -755,8 +740,8 @@ public class ChecklistEditor extends EditorPart implements ISelectionListener, I
     private static final List<String> NODE_INIT_STRATEGY = Arrays.asList(new String[] { "descriptions",
             "descriptions.*", "description.state", "feature", "feature.*", "childNodes", "childNodes.taxon",
             "childNodes.taxon.name", "taxonNodes", "taxonNodes.*", "taxonNodes.taxon.*", "taxon.*",
-            "taxon.descriptions", "taxon.sec", "taxon.name.*", "taxon.synonymRelations", "terms", "name.*",
-            "name.rank.representations", "name.status.type.representations", "sources.$", "stateData.$" });
+            "taxon.descriptions", "taxon.sec", "taxon.name.*", "terms", "name.*",
+            "name.rank.representations", "name.status.type.representations", "stateData.$" });
 
     /*
      * (non-Javadoc)
@@ -800,34 +785,48 @@ public class ChecklistEditor extends EditorPart implements ISelectionListener, I
     /* (non-Javadoc)
      * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getCdmEntitySession()
      */
-    @Override
-    public ICdmEntitySession getCdmEntitySession() {
-        // TODO Auto-generated method stub
-        return null;
+
+
+//    /* (non-Javadoc)
+//     * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getRootEntities()
+//     */
+//    @Override
+//    public <T extends CdmBase> Collection<T> getRootEntities() {
+//        // TODO Auto-generated method stub
+//        return null;
+//    }
+//
+//    /* (non-Javadoc)
+//     * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getPropertyPathsMap()
+//     */
+//    @Override
+//    public Map<Object, List<String>> getPropertyPathsMap() {
+//        // TODO Auto-generated method stub
+//        return null;
+//    }
+
+    /**
+     * @return the labelProvider
+     */
+    public ChecklistLabelProvider getLabelProvider() {
+        return labelProvider;
     }
 
     /* (non-Javadoc)
-     * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getRootEntities()
+     * @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
      */
     @Override
-    public <T extends CdmBase> Collection<T> getRootEntities() {
+    public void update(CdmDataChangeMap arg0) {
         // TODO Auto-generated method stub
-        return null;
+
     }
 
     /* (non-Javadoc)
-     * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getPropertyPathsMap()
+     * @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder()
      */
     @Override
-    public Map<Object, List<String>> getPropertyPathsMap() {
-        // TODO Auto-generated method stub
-        return null;
-    }
+    public ConversationHolder getConversationHolder() {
 
-    /**
-     * @return the labelProvider
-     */
-    public ChecklistLabelProvider getLabelProvider() {
-        return labelProvider;
+        return conversation;
     }
 }
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/ChecklistEditorInput.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/ChecklistEditorInput.java
index 0bc2b2459..e92264617 100644
--- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/ChecklistEditorInput.java
+++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/ChecklistEditorInput.java
@@ -9,6 +9,9 @@
 */
 package eu.etaxonomy.taxeditor.editor.view.checklist;
 
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
 import java.util.UUID;
 
 import org.eclipse.jface.resource.ImageDescriptor;
@@ -18,8 +21,11 @@ import org.eclipse.ui.IPersistable;
 import org.eclipse.ui.IPersistableElement;
 
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
+import eu.etaxonomy.cdm.api.service.ITaxonService;
 import eu.etaxonomy.cdm.model.taxon.Classification;
+import eu.etaxonomy.cdm.model.taxon.TaxonBase;
 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
+import eu.etaxonomy.taxeditor.editor.CdmEntitySessionInput;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 
 /**
@@ -28,16 +34,18 @@ import eu.etaxonomy.taxeditor.store.CdmStore;
  * @date 25.04.2014
  *
  */
-public class ChecklistEditorInput implements IEditorInput, IPersistable {
+public class ChecklistEditorInput extends CdmEntitySessionInput implements IEditorInput, IPersistable {
 
     /**
      * The selected classification
      */
     private TaxonNode taxonNode = null;
 
+    private final List<TaxonBase> taxa = new ArrayList<TaxonBase>();
+
     private Classification classification = null;
 
-    private final ConversationHolder conversationHolder;
+    private final ConversationHolder conversation;
 
 
     /**
@@ -46,19 +54,35 @@ public class ChecklistEditorInput implements IEditorInput, IPersistable {
      * @param taxonNode
      */
     public ChecklistEditorInput(TaxonNode taxonNode){
-        super();
-        this.conversationHolder = CdmStore.createConversation();
+        super(true);
+        this.conversation = CdmStore.createConversation();
         this.taxonNode = CdmStore.getCurrentApplicationConfiguration().getTaxonNodeService().load(taxonNode.getUuid());
+       // getChildTaxa(taxonNode);
         classification = taxonNode.getClassification();
     }
 
+    /**
+     * @param taxonNode2
+     */
+    private void getChildTaxa(TaxonNode taxonNode2) {
+       taxonNode2.removeNullValueFromChildren();
+       if (taxonNode2.hasChildNodes()){
+           for (TaxonNode node: taxonNode2.getChildNodes()){
+               taxa.add(node.getTaxon());
+               getChildTaxa(node);
+           }
+       }
+
+
+    }
+
     /**
      * Creates an editor input for the {@link ChecklistView} with the currently selected classification.
      * @param classificationUuid
      */
     public ChecklistEditorInput(Classification classification) {
-        super();
-        this.conversationHolder = CdmStore.createConversation();
+        super(true);
+        this.conversation = CdmStore.createConversation();
         this.classification = CdmStore.getCurrentApplicationConfiguration().getClassificationService().load(classification.getUuid());
 
     }
@@ -133,12 +157,12 @@ public class ChecklistEditorInput implements IEditorInput, IPersistable {
     	return classification;
     }
 
-    /**
-     * @return the conversationHolder
-     */
-    public ConversationHolder getConversationHolder() {
-        return conversationHolder;
-    }
+//    /**
+//     * @return the conversationHolder
+//     */
+//    public ConversationHolder getConversationHolder() {
+//        return conversationHolder;
+//    }
 
 
 
@@ -194,4 +218,28 @@ public class ChecklistEditorInput implements IEditorInput, IPersistable {
         UUID uuid = classification.getUuid();
     }
 
+    @Override
+    public void merge() {
+        for (TaxonBase taxon:taxa){
+            CdmStore.getService(ITaxonService.class).merge(taxon, true);
+        }
+
+    //    CdmStore.getService(ITaxonNodeService.class).merge(taxonNode, true);
+    }
+
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getRootEntities()
+     */
+    @Override
+    public List<TaxonNode> getRootEntities() {
+        return Arrays.asList(taxonNode);
+    }
+
+    /**
+     * @return the conversation
+     */
+    public ConversationHolder getConversation() {
+        return conversation;
+    }
+
 }
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/ChecklistEditorGeneralPreference.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/ChecklistEditorGeneralPreference.java
index d7a342c62..b807510bc 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/ChecklistEditorGeneralPreference.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/ChecklistEditorGeneralPreference.java
@@ -94,7 +94,7 @@ public class ChecklistEditorGeneralPreference extends PreferencePage implements
             @Override
             public void widgetSelected(SelectionEvent e) {
                 boolean isShowRank = activateRankButton.getSelection();
-                PreferencesUtil.setShowRankInChecklistEditor(isEditorActivated);
+                PreferencesUtil.setShowRankInChecklistEditor(isShowRank);
             }
         });
 
