commit dd35c5fd3d7527995d9282dd0b0c38c3a62a1092
Author: Patrick Plitzner <p.plitzner@bgbm.org>
Date:   Wed Oct 21 08:36:44 2015 +0200

    Implement taxon assignment filter and refactor DerivativeEditor
     - Input no longer needs session
     - editor itself keeps track of its root elements
     - taxon assignment filter allows filtering specimens with/without taxon
    assignment or both

diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateView.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateView.java
index 1b82c9f8d..a457b2f91 100644
--- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateView.java
+++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateView.java
@@ -1,7 +1,11 @@
 package eu.etaxonomy.taxeditor.editor.view.derivate;
 
+import java.util.Arrays;
 import java.util.Collection;
+import java.util.HashMap;
 import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
 import java.util.UUID;
@@ -34,12 +38,15 @@ import org.eclipse.ui.part.EditorPart;
 
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
 import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
+import eu.etaxonomy.cdm.api.service.IOccurrenceService;
 import eu.etaxonomy.cdm.api.service.molecular.ISequenceService;
 import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.model.molecular.Sequence;
 import eu.etaxonomy.cdm.model.molecular.SingleRead;
+import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
 import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
+import eu.etaxonomy.taxeditor.editor.EditorUtil;
 import eu.etaxonomy.taxeditor.editor.Messages;
 import eu.etaxonomy.taxeditor.editor.view.derivate.searchFilter.DerivateSearchCompositeController;
 import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
@@ -58,13 +65,29 @@ import eu.etaxonomy.taxeditor.view.derivateSearch.DerivateLabelProvider;
  */
 public class DerivateView extends EditorPart implements IPartContentHasFactualData, IDirtyMarkable,
         IConversationEnabled, IPartContentHasDetails, IPartContentHasSupplementalData, IPartContentHasMedia,
-        ISelectionChangedListener, IPostOperationEnabled{
 
+        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;
     public static final String VIEW_HAS_UNSAVED_CHANGES = Messages.DerivateView_UNSAVED_CHANGES;
 
+    private static final List<String> SPECIMEN_INIT_STRATEGY = Arrays.asList(new String[] {
+            "descriptions",
+            "annotations",
+            "markers",
+            "credits",
+            "extensions",
+            "rights",
+            "sources",
+            "derivationEvents.derivatives.annotations",
+            "derivationEvents.derivatives.markers",
+            "derivationEvents.derivatives.credits",
+            "derivationEvents.derivatives.extensions",
+            "derivationEvents.derivatives.rights",
+            "derivationEvents.derivatives.sources"
+    });
+
 	private ConversationHolder conversation;
 
 	private TreeViewer viewer;
@@ -84,10 +107,22 @@ public class DerivateView extends EditorPart implements IPartContentHasFactualDa
 
     private DerivateSearchCompositeController derivateSearchCompositeController;
 
+    /**
+     * A map with keys being the derivative entities belonging to the {@link UUID}s passed to the constructor
+     * and values being the root elements of the hierarchy (may be the same objects as the derivative entities)
+     */
+    private Map<SpecimenOrObservationBase<?>, SpecimenOrObservationBase<?>> derivateToRootEntityMap;
+
+    /**
+     * The set of root elements
+     */
+    private Set<SpecimenOrObservationBase<?>> rootElements;
+
     /**
      * Default constructor
      */
     public DerivateView() {
+        conversation = CdmStore.createConversation();
     }
 
     @Override
@@ -129,19 +164,17 @@ public class DerivateView extends EditorPart implements IPartContentHasFactualDa
         Menu menu = menuManager.createContextMenu(control);
         control.setMenu(menu);
 
+        //single read multi links
         generateMultiLinkSingleReads();
         labelProvider.setMultiLinkSingleReads(multiLinkSingleReads);
-        IEditorInput editorInput = getEditorInput();
-        viewer.setInput(((DerivateViewEditorInput) editorInput).getRootEntities());
-        //set selection to selected derivate if only one was selected
-        if(editorInput instanceof DerivateViewEditorInput){
-            Set<SpecimenOrObservationBase<?>> derivateEntities = ((DerivateViewEditorInput) editorInput).getDerivateEntities();
-            if(derivateEntities.size()==1){
-                SpecimenOrObservationBase<?> specimen = derivateEntities.iterator().next();
-                if(specimen != null){
-                    viewer.setSelection(new StructuredSelection(new TreeNode(specimen)));
-                }
-            }
+
+        //init tree
+        DerivateViewEditorInput editorInput = (DerivateViewEditorInput) getEditorInput();
+        if(editorInput.getDerivativeUUIDs()!=null){
+            updateRootEntities(editorInput.getDerivativeUUIDs());
+        }
+        else{
+            updateRootEntities();
         }
 
         //add drag'n'drop support
@@ -150,6 +183,37 @@ public class DerivateView extends EditorPart implements IPartContentHasFactualDa
         viewer.addDropSupport(dndOperations, transfers, new DerivateDropListener(this));
     }
 
+    public void updateRootEntities() {
+        updateRootEntities(null);
+    }
+
+    public void updateRootEntities(Collection<UUID> derivativeUuids) {
+        if(derivativeUuids!=null){
+            this.derivateToRootEntityMap = new HashMap<SpecimenOrObservationBase<?>, SpecimenOrObservationBase<?>>();
+            this.rootElements = new HashSet<SpecimenOrObservationBase<?>>();
+            for (UUID uuid : derivativeUuids) {
+                SpecimenOrObservationBase<?> derivate = CdmStore.getService(IOccurrenceService.class).load(uuid, SPECIMEN_INIT_STRATEGY);
+                if(derivate instanceof FieldUnit){
+                    derivateToRootEntityMap.put(derivate, derivate);
+                }
+                else {
+                    SpecimenOrObservationBase<?> topMostDerivate = EditorUtil.getTopMostDerivate(derivate);
+                    if(topMostDerivate!=null){
+                        derivateToRootEntityMap.put(derivate, topMostDerivate);
+                    }
+                    else{
+                        derivateToRootEntityMap.put(derivate, derivate);
+                    }
+                }
+            }
+            for (SpecimenOrObservationBase<?> specimen : derivateToRootEntityMap.values()) {
+                rootElements.add(specimen);
+            }
+        }
+        viewer.setInput(rootElements);
+        refreshTree();
+    }
+
     @Override
     public void doSave(IProgressMonitor monitor) {
         String taskName = Messages.DerivateView_SAVING_HIERARCHY;
@@ -165,7 +229,7 @@ public class DerivateView extends EditorPart implements IPartContentHasFactualDa
 
         // commit the conversation and start a new transaction immediately
         conversation.commit(true);
-        ((DerivateViewEditorInput) getEditorInput()).merge();
+//      TODO: what does this do?  merge();
         monitor.worked(1);
 
         this.setDirty(false);
@@ -179,6 +243,10 @@ public class DerivateView extends EditorPart implements IPartContentHasFactualDa
     public void doSaveAs() {
     }
 
+    public Set<SpecimenOrObservationBase<?>> getRootElements() {
+        return rootElements;
+    }
+
     @Override
     public String getTitleToolTip() {
         if(getEditorInput() instanceof DerivateViewEditorInput){
@@ -192,11 +260,8 @@ public class DerivateView extends EditorPart implements IPartContentHasFactualDa
     public void init(IEditorSite site, IEditorInput input) throws PartInitException {
         setSite(site);
         setInput(input);
-        if(input instanceof DerivateViewEditorInput){
-            DerivateViewEditorInput derivateViewEditorInput = (DerivateViewEditorInput) input;
-            conversation = derivateViewEditorInput.getConversationHolder();
-            setPartName(derivateViewEditorInput.getName());
-        }
+        this.derivateToRootEntityMap = new HashMap<SpecimenOrObservationBase<?>, SpecimenOrObservationBase<?>>();
+        this.rootElements = new HashSet<SpecimenOrObservationBase<?>>();
     }
 
     @Override
@@ -223,7 +288,6 @@ public class DerivateView extends EditorPart implements IPartContentHasFactualDa
         if(!conversation.isBound()){
             conversation.bind();
         }
-        ((DerivateViewEditorInput) getEditorInput()).bind();
     }
 
     @Override
@@ -254,9 +318,35 @@ public class DerivateView extends EditorPart implements IPartContentHasFactualDa
         changed(null);
     }
 
-    protected void setRootEntities(Collection<UUID> rootEntityUuids){
-        ((DerivateViewEditorInput)getEditorInput()).updateRootEntities(rootEntityUuids);
-    }
+//    @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;
+//    }
 
     /**
      * Refreshes the derivate hierarchy tree and expands the tree
@@ -283,9 +373,8 @@ public class DerivateView extends EditorPart implements IPartContentHasFactualDa
     //FIXME:Remoting hack to make this work for remoting
     //This should actually be resolved using remoting post operations
     public void remove(Object obj) {
-        Set<SpecimenOrObservationBase<?>> rootEntities = ((DerivateViewEditorInput) getEditorInput()).getRootEntities();
-        rootEntities.remove(obj);
-        viewer.setInput(rootEntities);
+        rootElements.remove(obj);
+        viewer.setInput(rootElements);
     }
 
     private void generateMultiLinkSingleReads() {
@@ -332,15 +421,24 @@ public class DerivateView extends EditorPart implements IPartContentHasFactualDa
         return true;
     }
 
-    @Override
-    public void dispose() {
-        ((DerivateViewEditorInput) getEditorInput()).dispose();
-        super.dispose();
-    }
-
 
     @Override
     public boolean canAttachMedia() {
         return true;
     }
+
+    public void removeHierarchy(SpecimenOrObservationBase<?> specimenOrObservationBase) {
+        SpecimenOrObservationBase<?> rootElement = derivateToRootEntityMap.remove(specimenOrObservationBase);
+        rootElements.remove(rootElement);
+    }
+
+    public void addHierarchy(FieldUnit fieldUnit) {
+        rootElements.add(fieldUnit);
+        derivateToRootEntityMap.put(fieldUnit, fieldUnit);
+    }
+
+//    @Override
+//    public ICdmEntitySession getCdmEntitySession() {
+//        return conversation;
+//    }
 }
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateViewEditorInput.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateViewEditorInput.java
index 4c66f5536..950533d11 100644
--- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateViewEditorInput.java
+++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateViewEditorInput.java
@@ -9,13 +9,6 @@
 */
 package eu.etaxonomy.taxeditor.editor.view.derivate;
 
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
 import java.util.Set;
 import java.util.UUID;
 
@@ -23,16 +16,8 @@ import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.ui.IEditorInput;
 import org.eclipse.ui.IPersistableElement;
 
-import eu.etaxonomy.cdm.api.application.CdmApplicationState;
-import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
-import eu.etaxonomy.cdm.api.service.IOccurrenceService;
-import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
 import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
-import eu.etaxonomy.taxeditor.editor.CdmEntitySessionInput;
-import eu.etaxonomy.taxeditor.editor.EditorUtil;
-import eu.etaxonomy.taxeditor.store.CdmStore;
-import eu.etaxonomy.taxeditor.view.derivateSearch.DerivateLabelProvider;
 
 /**
  * Editor input for the {@link DerivateView} which holds the currently selected derivate for which
@@ -42,53 +27,21 @@ import eu.etaxonomy.taxeditor.view.derivateSearch.DerivateLabelProvider;
  * @date 25.11.2013
  *
  */
-public class DerivateViewEditorInput extends CdmEntitySessionInput implements IEditorInput {
+public class DerivateViewEditorInput implements IEditorInput {
 
     /**
-     * The selected derivate {@link UUID}s
+     * The {@link UUID}s of the derivative entities
      */
-    private Set<SpecimenOrObservationBase<?>> derivateEntities;
-    /**
-     * List of the {@link UUID}s of the root elements of the hierarchy (may be the same objects as the derivates)
-     */
-    private Set<SpecimenOrObservationBase<?>> rootEntities;
-    private Set<UUID> rootUUIDs;
-
-    private final ConversationHolder conversationHolder;
-
-    private static final List<String> SPECIMEN_INIT_STRATEGY = Arrays.asList(new String[] {
-            "descriptions",
-            "annotations",
-            "markers",
-            "credits",
-            "extensions",
-            "rights",
-            "sources",
-            "derivationEvents.derivatives.annotations",
-            "derivationEvents.derivatives.markers",
-            "derivationEvents.derivatives.credits",
-            "derivationEvents.derivatives.extensions",
-            "derivationEvents.derivatives.rights",
-            "derivationEvents.derivatives.sources"
-    });
+    private Set<UUID> derivativeUUIDs;
 
     /**
      * Creates an editor input for the {@link DerivateView} with the currently selected derivates and the
      * corresponding {@link FieldUnit}s (both may be the same object).
      * @param derivateUuids the {@link UUID}s of the derivates for which the derivate hierarchy should be shown
-     * @param rootUUIDs the root of the hierarchy
+     * @param derivativeUUIDs the root of the hierarchy
      */
     public DerivateViewEditorInput(Set<UUID> derivateUuids) {
-        super(false);
-        rootUUIDs = derivateUuids;
-        //FIXME:Remoting temporary hack for making the sessions work
-        //This should ideally be changed to initializing the
-        //super class with a collection of (id) objects which can
-        //then be used for the hashCode, equals methods
-        initSession();
-        this.conversationHolder = CdmStore.createConversation();
-        updateRootEntities(derivateUuids);
-
+        this.derivativeUUIDs = derivateUuids;
     }
 
     /* (non-Javadoc)
@@ -142,46 +95,21 @@ public class DerivateViewEditorInput extends CdmEntitySessionInput implements IE
     }
 
     private String getEditorName() {
-        String name = null;
-        for( SpecimenOrObservationBase<?> specimen : rootEntities){
-            if(specimen!=null){
-                if(name==null){
-                    name = DerivateLabelProvider.getDerivateText(specimen, conversationHolder);
-                }
-                else{
-                    name += " + "+DerivateLabelProvider.getDerivateText(specimen, conversationHolder); //$NON-NLS-1$
-                }
-            }
-        }
-        if(name==null){
-            name = "Derivative Editor";
-        }
-        return name;
+            return "Derivative Editor";
     }
 
-    @Override
-    public Set<SpecimenOrObservationBase<?>> getRootEntities() {
-        return rootEntities;
-    }
-
-    public Set<SpecimenOrObservationBase<?>> getDerivateEntities() {
-        return derivateEntities;
-    }
-
-    public void addRootEntity(SpecimenOrObservationBase<?> root){
-        rootEntities.add(root);
-    }
-
-
-    public ConversationHolder getConversationHolder() {
-        return conversationHolder;
+    /**
+     * @return the derivativeUUIDs
+     */
+    public Set<UUID> getDerivativeUUIDs() {
+        return derivativeUUIDs;
     }
 
     @Override
     public int hashCode() {
         final int prime = 31;
         int result = 1;
-        result = prime * result + ((rootUUIDs == null) ? 0 : rootUUIDs.hashCode());
+        result = prime * result + ((derivativeUUIDs == null) ? 0 : derivativeUUIDs.hashCode());
         return result;
     }
 
@@ -197,61 +125,14 @@ public class DerivateViewEditorInput extends CdmEntitySessionInput implements IE
             return false;
         }
         DerivateViewEditorInput other = (DerivateViewEditorInput) obj;
-        if (rootUUIDs == null) {
-            if (other.rootUUIDs != null) {
+        if (derivativeUUIDs == null) {
+            if (other.derivativeUUIDs != null) {
                 return false;
             }
-        } else if (!rootUUIDs.equals(other.rootUUIDs)) {
+        } else if (!derivativeUUIDs.equals(other.derivativeUUIDs)) {
             return false;
         }
         return true;
     }
 
-    @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;
-    }
-
-    public void updateRootEntities(Collection<UUID> derivateUuids) {
-        this.derivateEntities = new HashSet<SpecimenOrObservationBase<?>>();
-        this.rootEntities = new HashSet<SpecimenOrObservationBase<?>>();
-        for (UUID uuid : derivateUuids) {
-            SpecimenOrObservationBase<?> derivate = CdmStore.getService(IOccurrenceService.class).load(uuid, SPECIMEN_INIT_STRATEGY);
-            derivateEntities.add(derivate);
-            if(derivate instanceof FieldUnit){
-                rootEntities.add(derivate);
-            }
-            else if(derivate instanceof DerivedUnit){
-                SpecimenOrObservationBase<?> topMostDerivate = EditorUtil.getTopMostDerivate(derivate);
-                if(topMostDerivate!=null){
-                    rootEntities.add(topMostDerivate);
-                }
-            }
-        }
-        if(rootEntities.isEmpty()){
-            rootEntities = derivateEntities;
-        }
-    }
-
 }
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/handler/CreateFieldUnitHandler.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/handler/CreateFieldUnitHandler.java
index 5129e44c5..7f9905742 100644
--- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/handler/CreateFieldUnitHandler.java
+++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/handler/CreateFieldUnitHandler.java
@@ -8,7 +8,6 @@ import eu.etaxonomy.cdm.api.service.IOccurrenceService;
 import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
 import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView;
-import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateViewEditorInput;
 import eu.etaxonomy.taxeditor.model.AbstractUtility;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.store.CdmStore;
@@ -26,8 +25,7 @@ public class CreateFieldUnitHandler extends AbstractHandler {
             FieldUnit fieldUnit = FieldUnit.NewInstance();
             fieldUnit = CdmBase.deproxy(CdmStore.getService(IOccurrenceService.class).save(fieldUnit), FieldUnit.class);
             derivateView.getConversationHolder().commit();
-            DerivateViewEditorInput input = (DerivateViewEditorInput) derivateView.getEditorInput();
-            input.addRootEntity(fieldUnit);
+            derivateView.addHierarchy(fieldUnit);
             derivateView.refreshTree();
         }
         return null;
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/searchFilter/DerivateSearchComposite.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/searchFilter/DerivateSearchComposite.java
index bd940eef6..c7b4d4e08 100644
--- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/searchFilter/DerivateSearchComposite.java
+++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/searchFilter/DerivateSearchComposite.java
@@ -76,7 +76,7 @@ public class DerivateSearchComposite extends Composite {
         lblNewLabel.setText("Taxon assignment");
 
         comboTaxonAssignment = new Combo(this, SWT.NONE);
-        comboTaxonAssignment.setItems(new String[] { "Yes", "No", "All" });
+        comboTaxonAssignment.setItems(new String[] { "All", "Yes", "No" });
         comboTaxonAssignment.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
         formToolkit.adapt(comboTaxonAssignment);
         formToolkit.paintBordersFor(comboTaxonAssignment);
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/searchFilter/DerivateSearchCompositeController.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/searchFilter/DerivateSearchCompositeController.java
index 6eb5444b6..af08275f3 100644
--- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/searchFilter/DerivateSearchCompositeController.java
+++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/searchFilter/DerivateSearchCompositeController.java
@@ -101,32 +101,33 @@ public class DerivateSearchCompositeController implements Listener{
         }
 
         //filter out (un-)assigned specimens
+        DerivateViewEditorInput editorInput = (DerivateViewEditorInput)derivativeEditor.getEditorInput();
         int selectionIndex = derivateSearchComposite.getComboTaxonAssignment().getSelectionIndex();
-        List<SpecimenOrObservationBase> specimensWithAssociations = new ArrayList<SpecimenOrObservationBase>();
+        List<SpecimenOrObservationBase<?>> specimenWithAssociations = new ArrayList<SpecimenOrObservationBase<?>>();
         if(selectionIndex!=DerivateSearchComposite.ALL_SPECIMENS){
             for (SpecimenOrObservationBase specimenOrObservationBase : occurrences) {
                 Collection<TaxonBase<?>> associatedTaxa = CdmStore.getService(IOccurrenceService.class).listAssociatedTaxa(specimenOrObservationBase, null, null, null, null);
                 if(!associatedTaxa.isEmpty()){
-                    specimensWithAssociations.add(specimenOrObservationBase);
+                    specimenWithAssociations.add(specimenOrObservationBase);
                 }
             }
         }
-        if(selectionIndex==DerivateSearchComposite.ASSIGNED_SPECIMENS){
-            occurrences = specimensWithAssociations;
-        }
-        else if(selectionIndex==DerivateSearchComposite.UNASSIGNED_SPECIMENS){
-            occurrences.retainAll(specimensWithAssociations);
+        if(selectionIndex==DerivateSearchComposite.UNASSIGNED_SPECIMENS){
+            for (SpecimenOrObservationBase<?> specimenOrObservationBase : specimenWithAssociations) {
+                derivativeEditor.removeHierarchy(specimenOrObservationBase);
+            }
+            derivativeEditor.updateRootEntities();
         }
-
-        List<UUID> derivateUuids = new ArrayList<UUID>();
-        for (SpecimenOrObservationBase specimenOrObservationBase : occurrences) {
-            derivateUuids.add(specimenOrObservationBase.getUuid());
+        else{
+            if(selectionIndex==DerivateSearchComposite.ASSIGNED_SPECIMENS){
+                occurrences = new ArrayList<SpecimenOrObservationBase>(specimenWithAssociations);
+            }
+            List<UUID> derivateUuids = new ArrayList<UUID>();
+            for (SpecimenOrObservationBase specimenOrObservationBase : occurrences) {
+                derivateUuids.add(specimenOrObservationBase.getUuid());
+            }
+            derivativeEditor.updateRootEntities(derivateUuids);
         }
-        //update tree
-        DerivateViewEditorInput editorInput = (DerivateViewEditorInput)derivativeEditor.getEditorInput();
-        editorInput.updateRootEntities(derivateUuids);
-        derivativeEditor.getViewer().setInput(editorInput.getRootEntities());
-        derivativeEditor.refreshTree();
     }
 
     @Override
