commit 3dd178b831bf4bd02fc8e83a86f6469256e8e23a
Author: Patrick Plitzner <p.plitzner@bgbm.org>
Date:   Thu Jan 24 08:25:10 2019 +0100

    ref #8011 Implement filter by facets

diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/search/term/Facet.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/search/term/Facet.java
new file mode 100644
index 000000000..57b79fa38
--- /dev/null
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/search/term/Facet.java
@@ -0,0 +1,76 @@
+/**
+* Copyright (C) 2019 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.taxeditor.view.search.term;
+
+/**
+ * @author pplitzner
+ * @since Jan 24, 2019
+ *
+ */
+public class Facet {
+
+    private String category;
+    private String facet;
+
+    public Facet(String facet) {
+        this(facet, null);
+    }
+
+    public Facet(String facet, String category) {
+        this.category = category;
+        this.facet = facet;
+    }
+
+    public String getCategory() {
+        return category;
+    }
+
+    public String getFacet() {
+        return facet;
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((category == null) ? 0 : category.hashCode());
+        result = prime * result + ((facet == null) ? 0 : facet.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        Facet other = (Facet) obj;
+        if (category == null) {
+            if (other.category != null) {
+                return false;
+            }
+        } else if (!category.equals(other.category)) {
+            return false;
+        }
+        if (facet == null) {
+            if (other.facet != null) {
+                return false;
+            }
+        } else if (!facet.equals(other.facet)) {
+            return false;
+        }
+        return true;
+    }
+
+}
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/search/term/FilterComposite.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/search/term/FilterComposite.java
index ec98b748b..d0c07bee5 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/search/term/FilterComposite.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/search/term/FilterComposite.java
@@ -24,22 +24,14 @@ import org.eclipse.swt.widgets.Label;
  */
 public class FilterComposite extends Composite{
     private Button btnCheck;
-    private String facet;
+    private Facet facet;
 
-    public FilterComposite(String facet, TermSearchController controller, Composite parent, int style) {
+    public FilterComposite(Facet facet, TermSearchController controller, Composite parent, int style) {
         super(parent, style);
         this.facet = facet;
         GridDataFactory.fillDefaults().applyTo(this);
         setLayout(new GridLayout(2, false));
 
-        Composite content = new Composite(this, SWT.NONE);
-        GridDataFactory.fillDefaults().applyTo(content);
-        content.setLayout(new GridLayout());
-
-        Label label = new Label(content, SWT.NONE);
-        label.setText(facet);
-        GridDataFactory.fillDefaults().applyTo(label);
-
         btnCheck = new Button(this, SWT.CHECK);
         btnCheck.addSelectionListener(new SelectionAdapter() {
             @Override
@@ -47,13 +39,22 @@ public class FilterComposite extends Composite{
                 controller.applyFilter(FilterComposite.this);
             }
         });
+
+        Composite content = new Composite(this, SWT.NONE);
+        GridDataFactory.fillDefaults().applyTo(content);
+        content.setLayout(new GridLayout());
+
+        Label label = new Label(content, SWT.NONE);
+        label.setText(facet.getFacet());
+        GridDataFactory.fillDefaults().applyTo(label);
+
     }
 
-    public Button getBtnCheck() {
-        return btnCheck;
+    public boolean isFilterActive() {
+        return btnCheck.getSelection();
     }
 
-    public String getFacet() {
+    public Facet getFacet() {
         return facet;
     }
 
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/search/term/SearchResult.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/search/term/SearchResult.java
index e56bca946..c637c5b8f 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/search/term/SearchResult.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/search/term/SearchResult.java
@@ -18,7 +18,7 @@ import java.util.Set;
  */
 public class SearchResult {
 
-    private Set<String> facets = new HashSet<>();
+    private Set<Facet> facets = new HashSet<>();
     private Object content;
 
     public SearchResult(Object content) {
@@ -28,18 +28,22 @@ public class SearchResult {
     }
 
     private void initFacets(Object content){
-        facets.add(content.toString().substring(0, 3));
+        facets.add(new Facet(content.toString()));
     }
 
-    public boolean hasFacet(String facet){
+    public boolean hasFacet(Facet facet){
         return facets.contains(facet);
     }
 
+    public boolean hasAnyFacet(Set<Facet> facets){
+        return facets.stream().anyMatch(facet->this.facets.contains(facet));
+    }
+
     public Object getContent() {
         return content;
     }
 
-    public Set<String> getFacets() {
+    public Set<Facet> getFacets() {
         return facets;
     }
 
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/search/term/TermSearchComposite.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/search/term/TermSearchComposite.java
index 2796c7d44..df0c5034e 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/search/term/TermSearchComposite.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/search/term/TermSearchComposite.java
@@ -39,7 +39,9 @@ public class TermSearchComposite extends Composite {
 
         Composite filterComposite = new Composite(this, SWT.NONE);
         filterComposite.setLayout(new GridLayout(1, false));
-        filterComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
+        GridData gd_filterComposite = new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1);
+        gd_filterComposite.widthHint = 134;
+        filterComposite.setLayoutData(gd_filterComposite);
 
         txtSearch = new Text(filterComposite, SWT.BORDER);
         txtSearch.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/search/term/TermSearchController.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/search/term/TermSearchController.java
index 7f5be5e92..2084ffd50 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/search/term/TermSearchController.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/search/term/TermSearchController.java
@@ -25,6 +25,8 @@ import org.eclipse.swt.events.KeyListener;
 public class TermSearchController implements KeyListener{
 
     private TermSearchComposite composite;
+    private List<SearchResult> searchResults = new ArrayList<>();
+    private Set<Facet> appliedFacets = new HashSet<>();
 
     public TermSearchController(TermSearchComposite composite) {
         this.composite = composite;
@@ -32,26 +34,27 @@ public class TermSearchController implements KeyListener{
     }
 
     private void search(String searchString){
-        List<SearchResult> results = new ArrayList<>();
-        results.add(new SearchResult("Res2"));
-        results.add(new SearchResult("Res3"));
-        results.add(new SearchResult("Cas2"));
+        searchResults.clear();
 
-        Set<String> facets = createResultsAndFilters(results);
+        searchResults.add(new SearchResult("Refffffffffffffffffffffffffffffffffffffffffffffffs2"));
+        searchResults.add(new SearchResult("Res3"));
+        searchResults.add(new SearchResult("Cas2"));
+
+        Set<Facet> facets = createResults(searchResults);
 
         createFilterButtons(facets);
 
         composite.refresh();
     }
 
-    private void createFilterButtons(Set<String> facets) {
-        for (String facet : facets) {
+    private void createFilterButtons(Set<Facet> facets) {
+        for (Facet facet : facets) {
             FilterComposite filterComposite = new FilterComposite(facet, this, composite.getFilterListComposite(), SWT.NONE);
         }
     }
 
-    private Set<String> createResultsAndFilters(List<SearchResult> results) {
-        Set<String> facets = new HashSet<>();
+    private Set<Facet> createResults(List<SearchResult> results) {
+        Set<Facet> facets = new HashSet<>();
         for (SearchResult result : results) {
             createResultComposite(result);
             facets.addAll(result.getFacets());
@@ -79,12 +82,19 @@ public class TermSearchController implements KeyListener{
 
         composite.clearResults();
 
-        List<SearchResult> results = new ArrayList<>();
-        results.add(new SearchResult("Des2"));
-        results.add(new SearchResult("PPs3"));
-        results.add(new SearchResult("PPs2"));
+        Facet facet = filterComposite.getFacet();
+        if(filterComposite.isFilterActive()){
+            appliedFacets.add(facet);
+        }
+        else{
+            appliedFacets.remove(facet);
+        }
 
-        createResultsAndFilters(results);
+        for (SearchResult searchResult : searchResults) {
+            if(!searchResult.hasAnyFacet(appliedFacets)){
+                createResultComposite(searchResult);
+            }
+        }
 
         composite.refresh();
     }
