Project

General

Profile

« Previous | Next » 

Revision 180fef01

Added by Patrick Plitzner about 5 years ago

ref #8011 Refactored package structure

  • extracted abstract classes
  • implemented term specific implementation

View differences:

eu.etaxonomy.taxeditor.store/fragment.e4xmi
81 81
    </elements>
82 82
    <elements xsi:type="basic:PartDescriptor" xmi:id="_aT37QM3UEeeznb_sS6rfAQ" elementId="eu.etaxonomy.taxeditor.store.partdescriptor.SearchDialog" label="%view.name.9" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.ui.dialog.selection.SearchDialog"/>
83 83
    <elements xsi:type="basic:PartDescriptor" xmi:id="_XV6gkEbOEeiER_VRS0L7wA" elementId="eu.etaxonomy.taxeditor.view.webimport.termimport.GfBioTerminologyImportPart" label="%partdescriptor.label.1" tooltip="%partdescriptor.tooltip.1" closeable="true" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.view.webimport.termimport.GfBioTerminologyImportPart"/>
84
    <elements xsi:type="basic:PartDescriptor" xmi:id="_namYwB7xEemDKJyLc5CJfQ" elementId="eu.etaxonomy.taxeditor.store.partdescriptor.termsearch" label="Term Search" closeable="true" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.view.search.term.TermSearch"/>
84
    <elements xsi:type="basic:PartDescriptor" xmi:id="_namYwB7xEemDKJyLc5CJfQ" elementId="eu.etaxonomy.taxeditor.store.partdescriptor.termsearch" label="Term Search" closeable="true" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.view.search.facet.term.TermSearch"/>
85 85
  </fragments>
86 86
  <fragments xsi:type="fragment:StringModelFragment" xmi:id="_3rW8wCXaEeex9MwMOgUeWw" featurename="children" parentElementId="eu.etaxonomy.taxeditor.menu.showView" positionInList="after:eu.etaxonomy.taxeditor.workbench.menuseparator.afterConcept">
87 87
    <elements xsi:type="menu:HandledMenuItem" xmi:id="_TlufMCaGEeeTEd_pKXBflg" elementId="eu.etaxonomy.taxeditor.store.showViewMenu.supplemental" label="%command.label.1" iconURI="platform:/plugin/eu.etaxonomy.taxeditor.store/icons/applications-office.png" tooltip="%command.label.1" command="_bnVKsCZxEeeQLpuomSmVoQ">
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/search/facet/Facet.java
1
/**
2
* Copyright (C) 2019 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.view.search.facet;
10

  
11
/**
12
 * @author pplitzner
13
 * @since Jan 24, 2019
14
 *
15
 */
16
public class Facet {
17

  
18
    private String category;
19
    private String facet;
20

  
21
    public Facet(String facet) {
22
        this(facet, null);
23
    }
24

  
25
    public Facet(String facet, String category) {
26
        this.category = category;
27
        this.facet = facet;
28
    }
29

  
30
    public String getCategory() {
31
        return category;
32
    }
33

  
34
    public String getFacet() {
35
        return facet;
36
    }
37

  
38
    @Override
39
    public int hashCode() {
40
        final int prime = 31;
41
        int result = 1;
42
        result = prime * result + ((category == null) ? 0 : category.hashCode());
43
        result = prime * result + ((facet == null) ? 0 : facet.hashCode());
44
        return result;
45
    }
46

  
47
    @Override
48
    public boolean equals(Object obj) {
49
        if (this == obj) {
50
            return true;
51
        }
52
        if (obj == null) {
53
            return false;
54
        }
55
        if (getClass() != obj.getClass()) {
56
            return false;
57
        }
58
        Facet other = (Facet) obj;
59
        if (category == null) {
60
            if (other.category != null) {
61
                return false;
62
            }
63
        } else if (!category.equals(other.category)) {
64
            return false;
65
        }
66
        if (facet == null) {
67
            if (other.facet != null) {
68
                return false;
69
            }
70
        } else if (!facet.equals(other.facet)) {
71
            return false;
72
        }
73
        return true;
74
    }
75

  
76
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/search/facet/FilterComposite.java
1
/**
2
* Copyright (C) 2019 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.view.search.facet;
10

  
11
import org.eclipse.jface.layout.GridDataFactory;
12
import org.eclipse.swt.SWT;
13
import org.eclipse.swt.events.SelectionAdapter;
14
import org.eclipse.swt.events.SelectionEvent;
15
import org.eclipse.swt.layout.GridLayout;
16
import org.eclipse.swt.widgets.Button;
17
import org.eclipse.swt.widgets.Composite;
18
import org.eclipse.swt.widgets.Label;
19

  
20
/**
21
 * @author pplitzner
22
 * @since Jan 23, 2019
23
 *
24
 */
25
public class FilterComposite extends Composite{
26
    private Button btnCheck;
27
    private Facet facet;
28

  
29
    public FilterComposite(Facet facet, SearchController controller, Composite parent, int style) {
30
        super(parent, style);
31
        this.facet = facet;
32
        GridDataFactory.fillDefaults().applyTo(this);
33
        setLayout(new GridLayout(2, false));
34

  
35
        btnCheck = new Button(this, SWT.CHECK);
36
        btnCheck.addSelectionListener(new SelectionAdapter() {
37
            @Override
38
            public void widgetSelected(SelectionEvent e) {
39
                controller.applyFilter(FilterComposite.this);
40
            }
41
        });
42
        btnCheck.setSelection(true);
43

  
44
        Composite content = new Composite(this, SWT.NONE);
45
        GridDataFactory.fillDefaults().applyTo(content);
46
        content.setLayout(new GridLayout());
47

  
48
        Label label = new Label(content, SWT.NONE);
49
        label.setText(facet.getFacet());
50
        GridDataFactory.fillDefaults().applyTo(label);
51

  
52
    }
53

  
54
    public boolean isFilterActive() {
55
        return btnCheck.getSelection();
56
    }
57

  
58
    public Facet getFacet() {
59
        return facet;
60
    }
61

  
62
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/search/facet/SearchComposite.java
1
// $Id$
2
/**
3
* Copyright (C) 2019 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10
package eu.etaxonomy.taxeditor.view.search.facet;
11

  
12
import org.eclipse.swt.SWT;
13
import org.eclipse.swt.custom.ScrolledComposite;
14
import org.eclipse.swt.layout.GridData;
15
import org.eclipse.swt.layout.GridLayout;
16
import org.eclipse.swt.widgets.Composite;
17
import org.eclipse.swt.widgets.Text;
18

  
19
/**
20
 * @author pplitzner
21
 * @date 22.01.2019
22
 *
23
 */
24
public class SearchComposite extends Composite {
25
    private Text txtSearch;
26
    private ScrolledComposite filterScrolledComposite;
27
    private Composite filterListComposite;
28
    private Composite searchResultComposite;
29
    private ScrolledComposite resultScrolledComposite;
30

  
31
    /**
32
     * Create the composite.
33
     * @param parent
34
     * @param style
35
     */
36
    public SearchComposite(Composite parent, int style) {
37
        super(parent, style);
38
        setLayout(new GridLayout(2, false));
39

  
40
        Composite filterComposite = new Composite(this, SWT.NONE);
41
        filterComposite.setLayout(new GridLayout(1, false));
42
        GridData gd_filterComposite = new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1);
43
        gd_filterComposite.widthHint = 170;
44
        filterComposite.setLayoutData(gd_filterComposite);
45

  
46
        txtSearch = new Text(filterComposite, SWT.BORDER);
47
        txtSearch.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
48

  
49
        filterScrolledComposite = new ScrolledComposite(filterComposite, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
50
        filterScrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
51
        filterScrolledComposite.setExpandHorizontal(true);
52
        filterScrolledComposite.setExpandVertical(true);
53

  
54
        initFilterList();
55

  
56
        Composite composite_1 = new Composite(this, SWT.NONE);
57
        composite_1.setLayout(new GridLayout(1, false));
58
        composite_1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
59

  
60
        resultScrolledComposite = new ScrolledComposite(composite_1, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
61
        resultScrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
62
        resultScrolledComposite.setExpandHorizontal(true);
63
        resultScrolledComposite.setExpandVertical(true);
64

  
65
        initSearchResultList();
66

  
67
    }
68

  
69
    private void initSearchResultList() {
70
        searchResultComposite = new Composite(resultScrolledComposite, SWT.NONE);
71
        searchResultComposite.setLayout(new GridLayout(1, false));
72
        resultScrolledComposite.setContent(searchResultComposite);
73
        resultScrolledComposite.setMinSize(searchResultComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
74
    }
75

  
76
    private void initFilterList() {
77
        filterListComposite = new Composite(filterScrolledComposite, SWT.NONE);
78
        filterListComposite.setLayout(new GridLayout(1, false));
79
        filterScrolledComposite.setContent(filterListComposite);
80
        filterScrolledComposite.setMinSize(filterListComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
81
    }
82

  
83
    @Override
84
    protected void checkSubclass() {
85
        // Disable the check that prevents subclassing of SWT components
86
    }
87
    public Text getTxtSearch() {
88
        return txtSearch;
89
    }
90

  
91
    public Composite getFilterListComposite() {
92
        return filterListComposite;
93
    }
94

  
95
    public void clear(){
96
        filterListComposite.dispose();
97
        initFilterList();
98

  
99
        clearResults();
100
    }
101

  
102
    public void clearResults() {
103
        searchResultComposite.dispose();
104
        initSearchResultList();
105
    }
106

  
107
    public void refresh(){
108
        filterScrolledComposite.layout(true, true);
109
        filterScrolledComposite.setMinSize(filterListComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
110
        resultScrolledComposite.layout(true, true);
111
        resultScrolledComposite.setMinSize(searchResultComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
112
    }
113
    public Composite getSearchResultComposite() {
114
        return searchResultComposite;
115
    }
116
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/search/facet/SearchController.java
1
/**
2
* Copyright (C) 2019 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.view.search.facet;
10

  
11
import java.util.ArrayList;
12
import java.util.HashSet;
13
import java.util.List;
14
import java.util.Set;
15

  
16
import org.eclipse.swt.SWT;
17
import org.eclipse.swt.events.KeyEvent;
18
import org.eclipse.swt.events.KeyListener;
19

  
20
/**
21
 * @author pplitzner
22
 * @since Jan 22, 2019
23
 *
24
 */
25
public abstract class SearchController implements KeyListener{
26

  
27
    private SearchComposite composite;
28
    private List<SearchResult> searchResults = new ArrayList<>();
29
    private Set<Facet> appliedFacets = new HashSet<>();
30

  
31
    public SearchController(SearchComposite composite) {
32
        this.composite = composite;
33
        composite.getTxtSearch().addKeyListener(this);
34
    }
35

  
36
    protected abstract List<SearchResult> searchResults(String searchString);
37

  
38
    private void search(String searchString){
39
        searchResults.clear();
40

  
41
        searchResults = searchResults(searchString);
42

  
43
        Set<Facet> facets = createResults(searchResults);
44

  
45
        createFilterButtons(facets);
46

  
47
        composite.refresh();
48
    }
49

  
50
    private void createFilterButtons(Set<Facet> facets) {
51
        for (Facet facet : facets) {
52
            FilterComposite filterComposite = new FilterComposite(facet, this, composite.getFilterListComposite(), SWT.NONE);
53
            appliedFacets.add(facet);
54
        }
55
    }
56

  
57
    private Set<Facet> createResults(List<SearchResult> results) {
58
        Set<Facet> facets = new HashSet<>();
59
        for (SearchResult result : results) {
60
            createResultComposite(result);
61
            facets.addAll(result.getFacets());
62
        }
63
        return facets;
64
    }
65

  
66
    private void createResultComposite(SearchResult result) {
67
        new SearchResultComposite(result, composite.getSearchResultComposite(), SWT.NONE);
68
    }
69

  
70
    @Override
71
    public void keyPressed(KeyEvent e) {
72
        if(e.keyCode==SWT.CR && e.widget==composite.getTxtSearch()){
73
            composite.clear();
74
            search(composite.getTxtSearch().getText());
75
        }
76
    }
77

  
78
    @Override
79
    public void keyReleased(KeyEvent e) {
80
    }
81

  
82
    public void applyFilter(FilterComposite filterComposite) {
83

  
84
        composite.clearResults();
85

  
86
        Facet facet = filterComposite.getFacet();
87
        if(filterComposite.isFilterActive()){
88
            appliedFacets.add(facet);
89
        }
90
        else{
91
            appliedFacets.remove(facet);
92
        }
93

  
94
        for (SearchResult searchResult : searchResults) {
95
            if(searchResult.hasAnyFacet(appliedFacets)){
96
                createResultComposite(searchResult);
97
            }
98
        }
99

  
100
        composite.refresh();
101
    }
102

  
103
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/search/facet/SearchResult.java
1
/**
2
* Copyright (C) 2019 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.view.search.facet;
10

  
11
import java.util.HashSet;
12
import java.util.Set;
13

  
14
/**
15
 * @author pplitzner
16
 * @since Jan 23, 2019
17
 *
18
 * @param <T> The type of the search result
19
 */
20
public abstract class SearchResult<T> {
21

  
22
    private Set<Facet> facets = new HashSet<>();
23
    private T content;
24

  
25
    public SearchResult(T content) {
26
        super();
27
        this.content = content;
28
        facets = initFacets(content);
29
    }
30

  
31
    protected abstract Set<Facet> initFacets(T content);
32

  
33
    public boolean hasFacet(Facet facet){
34
        return facets.contains(facet);
35
    }
36

  
37
    public boolean hasAnyFacet(Set<Facet> facets){
38
        return facets.stream().anyMatch(facet->this.facets.contains(facet));
39
    }
40

  
41
    public T getContent() {
42
        return content;
43
    }
44

  
45
    public Set<Facet> getFacets() {
46
        return facets;
47
    }
48

  
49
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/search/facet/SearchResultComposite.java
1
/**
2
* Copyright (C) 2019 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.view.search.facet;
10

  
11
import org.eclipse.jface.layout.GridDataFactory;
12
import org.eclipse.swt.SWT;
13
import org.eclipse.swt.layout.GridData;
14
import org.eclipse.swt.layout.GridLayout;
15
import org.eclipse.swt.widgets.Composite;
16
import org.eclipse.swt.widgets.Label;
17

  
18
/**
19
 * @author pplitzner
20
 * @since Jan 23, 2019
21
 *
22
 */
23
public class SearchResultComposite extends Composite {
24

  
25
    /**
26
     * Create the composite.
27
     * @param result
28
     * @param parent
29
     * @param style
30
     */
31
    public SearchResultComposite(SearchResult result, Composite parent, int style) {
32
        super(parent, style);
33
        setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
34
        setLayout(new GridLayout());
35
        Label label = new Label(parent, SWT.NONE);
36
        label.setText(result.getContent().toString());
37
        GridDataFactory.fillDefaults().applyTo(label);
38
    }
39

  
40
    @Override
41
    protected void checkSubclass() {
42
        // Disable the check that prevents subclassing of SWT components
43
    }
44

  
45
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/search/facet/term/TermFilter.java
1
/**
2
* Copyright (C) 2019 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.view.search.facet.term;
10

  
11
import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;
12

  
13
/**
14
 * @author pplitzner
15
 * @since Jan 22, 2019
16
 *
17
 */
18
public class TermFilter {
19

  
20
    private TermVocabularyDto vocabulary;
21

  
22
    /**
23
     * @param vocabulary
24
     */
25
    public TermFilter(TermVocabularyDto vocabulary) {
26
        super();
27
        this.vocabulary = vocabulary;
28
    }
29

  
30
    /**
31
     * @return the vocabulary
32
     */
33
    public TermVocabularyDto getVocabulary() {
34
        return vocabulary;
35
    }
36

  
37
    /**
38
     * @param vocabulary the vocabulary to set
39
     */
40
    public void setVocabulary(TermVocabularyDto vocabulary) {
41
        this.vocabulary = vocabulary;
42
    }
43

  
44

  
45

  
46
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/search/facet/term/TermSearch.java
1
/**
2
* Copyright (C) 2019 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.view.search.facet.term;
10

  
11
import javax.annotation.PostConstruct;
12
import javax.inject.Named;
13

  
14
import org.eclipse.e4.core.contexts.IEclipseContext;
15
import org.eclipse.e4.ui.services.EMenuService;
16
import org.eclipse.e4.ui.services.IServiceConstants;
17
import org.eclipse.swt.SWT;
18
import org.eclipse.swt.widgets.Composite;
19
import org.eclipse.swt.widgets.Shell;
20

  
21
import eu.etaxonomy.taxeditor.view.search.facet.SearchComposite;
22

  
23
/**
24
 * @author pplitzner
25
 * @since Jan 22, 2019
26
 *
27
 */
28
public class TermSearch {
29

  
30
    @PostConstruct
31
    public void create(Composite parent, IEclipseContext context, @Named(IServiceConstants.ACTIVE_SHELL)Shell shell,
32
            EMenuService menuService){
33
        new TermSearchController(new SearchComposite(parent, SWT.NONE));
34
    }
35
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/search/facet/term/TermSearchController.java
1
/**
2
* Copyright (C) 2019 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.view.search.facet.term;
10

  
11
import java.util.ArrayList;
12
import java.util.List;
13

  
14
import eu.etaxonomy.cdm.model.common.Language;
15
import eu.etaxonomy.cdm.model.description.Feature;
16
import eu.etaxonomy.taxeditor.view.search.facet.SearchComposite;
17
import eu.etaxonomy.taxeditor.view.search.facet.SearchController;
18
import eu.etaxonomy.taxeditor.view.search.facet.SearchResult;
19

  
20
/**
21
 * @author pplitzner
22
 * @since Jan 22, 2019
23
 *
24
 */
25
public class TermSearchController extends SearchController {
26

  
27
    public TermSearchController(SearchComposite composite) {
28
        super(composite);
29
    }
30

  
31
    @Override
32
    protected List<SearchResult> searchResults(String searchString){
33
        List<SearchResult> searchResults = new ArrayList<>();
34
        searchResults.add(new TermSearchResult(Language.ABKHAZIAN()));
35
        searchResults.add(new TermSearchResult(Language.WAKASHANS()));
36
        searchResults.add(new TermSearchResult(Feature.ADDITIONAL_PUBLICATION()));
37
        return searchResults;
38
    }
39

  
40
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/search/facet/term/TermSearchResult.java
1
/**
2
* Copyright (C) 2019 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.view.search.facet.term;
10

  
11
import java.util.HashSet;
12
import java.util.Set;
13

  
14
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
15
import eu.etaxonomy.taxeditor.view.search.facet.Facet;
16
import eu.etaxonomy.taxeditor.view.search.facet.SearchResult;
17

  
18
/**
19
 * @author pplitzner
20
 * @since Jan 24, 2019
21
 *
22
 */
23
public class TermSearchResult extends SearchResult<DefinedTermBase> {
24

  
25
    public TermSearchResult(DefinedTermBase content) {
26
        super(content);
27
    }
28

  
29
    @Override
30
    protected Set<Facet> initFacets(DefinedTermBase content) {
31
        Set<Facet> facets = new HashSet<>();
32
        facets.add(new Facet(content.getVocabulary().getLabel()));
33
        return facets;
34
    }
35

  
36
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/search/term/Facet.java
1
/**
2
* Copyright (C) 2019 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.view.search.term;
10

  
11
/**
12
 * @author pplitzner
13
 * @since Jan 24, 2019
14
 *
15
 */
16
public class Facet {
17

  
18
    private String category;
19
    private String facet;
20

  
21
    public Facet(String facet) {
22
        this(facet, null);
23
    }
24

  
25
    public Facet(String facet, String category) {
26
        this.category = category;
27
        this.facet = facet;
28
    }
29

  
30
    public String getCategory() {
31
        return category;
32
    }
33

  
34
    public String getFacet() {
35
        return facet;
36
    }
37

  
38
    @Override
39
    public int hashCode() {
40
        final int prime = 31;
41
        int result = 1;
42
        result = prime * result + ((category == null) ? 0 : category.hashCode());
43
        result = prime * result + ((facet == null) ? 0 : facet.hashCode());
44
        return result;
45
    }
46

  
47
    @Override
48
    public boolean equals(Object obj) {
49
        if (this == obj) {
50
            return true;
51
        }
52
        if (obj == null) {
53
            return false;
54
        }
55
        if (getClass() != obj.getClass()) {
56
            return false;
57
        }
58
        Facet other = (Facet) obj;
59
        if (category == null) {
60
            if (other.category != null) {
61
                return false;
62
            }
63
        } else if (!category.equals(other.category)) {
64
            return false;
65
        }
66
        if (facet == null) {
67
            if (other.facet != null) {
68
                return false;
69
            }
70
        } else if (!facet.equals(other.facet)) {
71
            return false;
72
        }
73
        return true;
74
    }
75

  
76
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/search/term/Filter.java
1
/**
2
* Copyright (C) 2019 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.view.search.term;
10

  
11
/**
12
 * @author pplitzner
13
 * @since Jan 23, 2019
14
 *
15
 */
16
public class Filter {
17

  
18
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/search/term/FilterComposite.java
1
/**
2
* Copyright (C) 2019 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.view.search.term;
10

  
11
import org.eclipse.jface.layout.GridDataFactory;
12
import org.eclipse.swt.SWT;
13
import org.eclipse.swt.events.SelectionAdapter;
14
import org.eclipse.swt.events.SelectionEvent;
15
import org.eclipse.swt.layout.GridLayout;
16
import org.eclipse.swt.widgets.Button;
17
import org.eclipse.swt.widgets.Composite;
18
import org.eclipse.swt.widgets.Label;
19

  
20
/**
21
 * @author pplitzner
22
 * @since Jan 23, 2019
23
 *
24
 */
25
public class FilterComposite extends Composite{
26
    private Button btnCheck;
27
    private Facet facet;
28

  
29
    public FilterComposite(Facet facet, TermSearchController controller, Composite parent, int style) {
30
        super(parent, style);
31
        this.facet = facet;
32
        GridDataFactory.fillDefaults().applyTo(this);
33
        setLayout(new GridLayout(2, false));
34

  
35
        btnCheck = new Button(this, SWT.CHECK);
36
        btnCheck.addSelectionListener(new SelectionAdapter() {
37
            @Override
38
            public void widgetSelected(SelectionEvent e) {
39
                controller.applyFilter(FilterComposite.this);
40
            }
41
        });
42

  
43
        Composite content = new Composite(this, SWT.NONE);
44
        GridDataFactory.fillDefaults().applyTo(content);
45
        content.setLayout(new GridLayout());
46

  
47
        Label label = new Label(content, SWT.NONE);
48
        label.setText(facet.getFacet());
49
        GridDataFactory.fillDefaults().applyTo(label);
50

  
51
    }
52

  
53
    public boolean isFilterActive() {
54
        return btnCheck.getSelection();
55
    }
56

  
57
    public Facet getFacet() {
58
        return facet;
59
    }
60

  
61
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/search/term/SearchResult.java
1
/**
2
* Copyright (C) 2019 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.view.search.term;
10

  
11
import java.util.HashSet;
12
import java.util.Set;
13

  
14
/**
15
 * @author pplitzner
16
 * @since Jan 23, 2019
17
 *
18
 */
19
public class SearchResult {
20

  
21
    private Set<Facet> facets = new HashSet<>();
22
    private Object content;
23

  
24
    public SearchResult(Object content) {
25
        super();
26
        this.content = content;
27
        initFacets(content);
28
    }
29

  
30
    private void initFacets(Object content){
31
        facets.add(new Facet(content.toString()));
32
    }
33

  
34
    public boolean hasFacet(Facet facet){
35
        return facets.contains(facet);
36
    }
37

  
38
    public boolean hasAnyFacet(Set<Facet> facets){
39
        return facets.stream().anyMatch(facet->this.facets.contains(facet));
40
    }
41

  
42
    public Object getContent() {
43
        return content;
44
    }
45

  
46
    public Set<Facet> getFacets() {
47
        return facets;
48
    }
49

  
50
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/search/term/SearchResultComposite.java
1
/**
2
* Copyright (C) 2019 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.view.search.term;
10

  
11
import org.eclipse.jface.layout.GridDataFactory;
12
import org.eclipse.swt.SWT;
13
import org.eclipse.swt.layout.GridData;
14
import org.eclipse.swt.layout.GridLayout;
15
import org.eclipse.swt.widgets.Composite;
16
import org.eclipse.swt.widgets.Label;
17

  
18
/**
19
 * @author pplitzner
20
 * @since Jan 23, 2019
21
 *
22
 */
23
public class SearchResultComposite extends Composite {
24

  
25
    /**
26
     * Create the composite.
27
     * @param result
28
     * @param parent
29
     * @param style
30
     */
31
    public SearchResultComposite(SearchResult result, Composite parent, int style) {
32
        super(parent, style);
33
        setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
34
        setLayout(new GridLayout());
35
        Label label = new Label(parent, SWT.NONE);
36
        label.setText(result.getContent().toString());
37
        GridDataFactory.fillDefaults().applyTo(label);
38
    }
39

  
40
    @Override
41
    protected void checkSubclass() {
42
        // Disable the check that prevents subclassing of SWT components
43
    }
44

  
45
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/search/term/TermFilter.java
1
/**
2
* Copyright (C) 2019 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.view.search.term;
10

  
11
import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;
12

  
13
/**
14
 * @author pplitzner
15
 * @since Jan 22, 2019
16
 *
17
 */
18
public class TermFilter {
19

  
20
    private TermVocabularyDto vocabulary;
21

  
22
    /**
23
     * @param vocabulary
24
     */
25
    public TermFilter(TermVocabularyDto vocabulary) {
26
        super();
27
        this.vocabulary = vocabulary;
28
    }
29

  
30
    /**
31
     * @return the vocabulary
32
     */
33
    public TermVocabularyDto getVocabulary() {
34
        return vocabulary;
35
    }
36

  
37
    /**
38
     * @param vocabulary the vocabulary to set
39
     */
40
    public void setVocabulary(TermVocabularyDto vocabulary) {
41
        this.vocabulary = vocabulary;
42
    }
43

  
44

  
45

  
46
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/search/term/TermSearch.java
1
/**
2
* Copyright (C) 2019 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.view.search.term;
10

  
11
import javax.annotation.PostConstruct;
12
import javax.inject.Named;
13

  
14
import org.eclipse.e4.core.contexts.IEclipseContext;
15
import org.eclipse.e4.ui.services.EMenuService;
16
import org.eclipse.e4.ui.services.IServiceConstants;
17
import org.eclipse.swt.SWT;
18
import org.eclipse.swt.widgets.Composite;
19
import org.eclipse.swt.widgets.Shell;
20

  
21
/**
22
 * @author pplitzner
23
 * @since Jan 22, 2019
24
 *
25
 */
26
public class TermSearch {
27

  
28
    @PostConstruct
29
    public void create(Composite parent, IEclipseContext context, @Named(IServiceConstants.ACTIVE_SHELL)Shell shell,
30
            EMenuService menuService){
31
        new TermSearchController(new TermSearchComposite(parent, SWT.NONE));
32
    }
33
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/search/term/TermSearchComposite.java
1
// $Id$
2
/**
3
* Copyright (C) 2019 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10
package eu.etaxonomy.taxeditor.view.search.term;
11

  
12
import org.eclipse.swt.SWT;
13
import org.eclipse.swt.custom.ScrolledComposite;
14
import org.eclipse.swt.layout.GridData;
15
import org.eclipse.swt.layout.GridLayout;
16
import org.eclipse.swt.widgets.Composite;
17
import org.eclipse.swt.widgets.Text;
18

  
19
/**
20
 * @author pplitzner
21
 * @date 22.01.2019
22
 *
23
 */
24
public class TermSearchComposite extends Composite {
25
    private Text txtSearch;
26
    private ScrolledComposite filterScrolledComposite;
27
    private Composite filterListComposite;
28
    private Composite searchResultComposite;
29
    private ScrolledComposite resultScrolledComposite;
30

  
31
    /**
32
     * Create the composite.
33
     * @param parent
34
     * @param style
35
     */
36
    public TermSearchComposite(Composite parent, int style) {
37
        super(parent, style);
38
        setLayout(new GridLayout(2, false));
39

  
40
        Composite filterComposite = new Composite(this, SWT.NONE);
41
        filterComposite.setLayout(new GridLayout(1, false));
42
        GridData gd_filterComposite = new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1);
43
        gd_filterComposite.widthHint = 134;
44
        filterComposite.setLayoutData(gd_filterComposite);
45

  
46
        txtSearch = new Text(filterComposite, SWT.BORDER);
47
        txtSearch.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
48

  
49
        filterScrolledComposite = new ScrolledComposite(filterComposite, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
50
        filterScrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
51
        filterScrolledComposite.setExpandHorizontal(true);
52
        filterScrolledComposite.setExpandVertical(true);
53

  
54
        initFilterList();
55

  
56
        Composite composite_1 = new Composite(this, SWT.NONE);
57
        composite_1.setLayout(new GridLayout(1, false));
58
        composite_1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
59

  
60
        resultScrolledComposite = new ScrolledComposite(composite_1, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
61
        resultScrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
62
        resultScrolledComposite.setExpandHorizontal(true);
63
        resultScrolledComposite.setExpandVertical(true);
64

  
65
        initSearchResultList();
66

  
67
    }
68

  
69
    private void initSearchResultList() {
70
        searchResultComposite = new Composite(resultScrolledComposite, SWT.NONE);
71
        searchResultComposite.setLayout(new GridLayout(1, false));
72
        resultScrolledComposite.setContent(searchResultComposite);
73
        resultScrolledComposite.setMinSize(searchResultComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
74
    }
75

  
76
    private void initFilterList() {
77
        filterListComposite = new Composite(filterScrolledComposite, SWT.NONE);
78
        filterListComposite.setLayout(new GridLayout(1, false));
79
        filterScrolledComposite.setContent(filterListComposite);
80
        filterScrolledComposite.setMinSize(filterListComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
81
    }
82

  
83
    @Override
84
    protected void checkSubclass() {
85
        // Disable the check that prevents subclassing of SWT components
86
    }
87
    public Text getTxtSearch() {
88
        return txtSearch;
89
    }
90

  
91
    public Composite getFilterListComposite() {
92
        return filterListComposite;
93
    }
94

  
95
    public void clear(){
96
        filterListComposite.dispose();
97
        initFilterList();
98

  
99
        clearResults();
100
    }
101

  
102
    public void clearResults() {
103
        searchResultComposite.dispose();
104
        initSearchResultList();
105
    }
106

  
107
    public void refresh(){
108
        filterScrolledComposite.layout(true, true);
109
        filterScrolledComposite.setMinSize(filterListComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
110
        resultScrolledComposite.layout(true, true);
111
        resultScrolledComposite.setMinSize(searchResultComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
112
    }
113
    public Composite getSearchResultComposite() {
114
        return searchResultComposite;
115
    }
116
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/search/term/TermSearchController.java
1
/**
2
* Copyright (C) 2019 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.view.search.term;
10

  
11
import java.util.ArrayList;
12
import java.util.HashSet;
13
import java.util.List;
14
import java.util.Set;
15

  
16
import org.eclipse.swt.SWT;
17
import org.eclipse.swt.events.KeyEvent;
18
import org.eclipse.swt.events.KeyListener;
19

  
20
/**
21
 * @author pplitzner
22
 * @since Jan 22, 2019
23
 *
24
 */
25
public class TermSearchController implements KeyListener{
26

  
27
    private TermSearchComposite composite;
28
    private List<SearchResult> searchResults = new ArrayList<>();
29
    private Set<Facet> appliedFacets = new HashSet<>();
30

  
31
    public TermSearchController(TermSearchComposite composite) {
32
        this.composite = composite;
33
        composite.getTxtSearch().addKeyListener(this);
34
    }
35

  
36
    private void search(String searchString){
37
        searchResults.clear();
38

  
39
        searchResults.add(new SearchResult("Refffffffffffffffffffffffffffffffffffffffffffffffs2"));
40
        searchResults.add(new SearchResult("Res3"));
41
        searchResults.add(new SearchResult("Cas2"));
42

  
43
        Set<Facet> facets = createResults(searchResults);
44

  
45
        createFilterButtons(facets);
46

  
47
        composite.refresh();
48
    }
49

  
50
    private void createFilterButtons(Set<Facet> facets) {
51
        for (Facet facet : facets) {
52
            FilterComposite filterComposite = new FilterComposite(facet, this, composite.getFilterListComposite(), SWT.NONE);
53
        }
54
    }
55

  
56
    private Set<Facet> createResults(List<SearchResult> results) {
57
        Set<Facet> facets = new HashSet<>();
58
        for (SearchResult result : results) {
59
            createResultComposite(result);
60
            facets.addAll(result.getFacets());
61
        }
62
        return facets;
63
    }
64

  
65
    private void createResultComposite(SearchResult result) {
66
        new SearchResultComposite(result, composite.getSearchResultComposite(), SWT.NONE);
67
    }
68

  
69
    @Override
70
    public void keyPressed(KeyEvent e) {
71
        if(e.keyCode==SWT.CR && e.widget==composite.getTxtSearch()){
72
            composite.clear();
73
            search(composite.getTxtSearch().getText());
74
        }
75
    }
76

  
77
    @Override
78
    public void keyReleased(KeyEvent e) {
79
    }
80

  
81
    public void applyFilter(FilterComposite filterComposite) {
82

  
83
        composite.clearResults();
84

  
85
        Facet facet = filterComposite.getFacet();
86
        if(filterComposite.isFilterActive()){
87
            appliedFacets.add(facet);
88
        }
89
        else{
90
            appliedFacets.remove(facet);
91
        }
92

  
93
        for (SearchResult searchResult : searchResults) {
94
            if(!searchResult.hasAnyFacet(appliedFacets)){
95
                createResultComposite(searchResult);
96
            }
97
        }
98

  
99
        composite.refresh();
100
    }
101

  
102
}

Also available in: Unified diff