Project

General

Profile

Revision f0973bb3

IDf0973bb39b8c70687f48f2d3908e0928339b51eb
Parent 14ae9d24
Child 3dd178b8

Added by Patrick Plitzner almost 3 years ago

ref #8011 Enhance term search framework

  • added menu to open term search
  • filter facets now have an effect on search results

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 85
  </fragments>
85 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">
86 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">
......
187 188
  </fragments>
188 189
  <fragments xsi:type="fragment:StringModelFragment" xmi:id="_qT4hgIfTEeecZ4F2Y9Z0Og" featurename="children" parentElementId="eu.etaxonomy.taxeditor.workbench.menu.window" positionInList="before:eu.etaxonomy.taxeditor.application.windowMenu.last">
189 190
    <elements xsi:type="menu:Menu" xmi:id="_LT3P8IfcEeecZ4F2Y9Z0Og" elementId="eu.etaxonomy.taxeditor.store.menu.termeditor" label="%menu.label.1">
190
      <visibleWhen xsi:type="ui:CoreExpression" xmi:id="_gVhOIEb1EeiER_VRS0L7wA" coreExpressionId="isCdmStoreConnected"/>
191 191
      <children xsi:type="menu:DynamicMenuContribution" xmi:id="_HIptYIfUEeecZ4F2Y9Z0Og" elementId="eu.etaxonomy.taxeditor.store.dynamicmenucontribution.0" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.editor.definedterm.e4.DefinedTermMenuE4"/>
192 192
      <children xsi:type="menu:MenuSeparator" xmi:id="_yRINcIfqEeecZ4F2Y9Z0Og" elementId="eu.etaxonomy.taxeditor.store.menuseparator.3"/>
193 193
      <children xsi:type="menu:HandledMenuItem" xmi:id="_rwfDkIftEeecZ4F2Y9Z0Og" elementId="eu.etaxonomy.taxeditor.store.termEditorMenu.featureTreeEditor" label="%handledmenuitem.label.8" tooltip="%handledmenuitem.tooltip.1" command="_bnVKsCZxEeeQLpuomSmVoQ">
......
198 198
        <visibleWhen xsi:type="ui:CoreExpression" xmi:id="_h15bwEb1EeiER_VRS0L7wA" coreExpressionId="isCdmStoreConnectedAndShowExperimental"/>
199 199
        <parameters xmi:id="_eU0zcUbOEeiER_VRS0L7wA" elementId="eu.etaxonomy.taxeditor.store.showView.parameter.gfbioTermImport" name="eu.etaxonomy.taxeditor.workbench.commandparameter.partName" value="eu.etaxonomy.taxeditor.view.webimport.termimport.GfBioTerminologyImportPart"/>
200 200
      </children>
201
      <children xsi:type="menu:HandledMenuItem" xmi:id="_fbZtkB7xEemDKJyLc5CJfQ" elementId="eu.etaxonomy.taxeditor.store.handledmenuitem.termsearch" label="TermSearch" command="_bnVKsCZxEeeQLpuomSmVoQ">
202
        <parameters xmi:id="_jnbCEB7xEemDKJyLc5CJfQ" elementId="eu.etaxonomy.taxeditor.store.showView.parameter.termsearch" name="eu.etaxonomy.taxeditor.workbench.commandparameter.partName" value="eu.etaxonomy.taxeditor.store.partdescriptor.termsearch"/>
203
      </children>
201 204
    </elements>
202 205
  </fragments>
203 206
  <fragments xsi:type="fragment:StringModelFragment" xmi:id="_pVVyEJFJEeeDJpjGQES7gw" featurename="addons" parentElementId="xpath:/">
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 String facet;
28

  
29
    public FilterComposite(String 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
        Composite content = new Composite(this, SWT.NONE);
36
        GridDataFactory.fillDefaults().applyTo(content);
37
        content.setLayout(new GridLayout());
38

  
39
        Label label = new Label(content, SWT.NONE);
40
        label.setText(facet);
41
        GridDataFactory.fillDefaults().applyTo(label);
42

  
43
        btnCheck = new Button(this, SWT.CHECK);
44
        btnCheck.addSelectionListener(new SelectionAdapter() {
45
            @Override
46
            public void widgetSelected(SelectionEvent e) {
47
                controller.applyFilter(FilterComposite.this);
48
            }
49
        });
50
    }
51

  
52
    public Button getBtnCheck() {
53
        return btnCheck;
54
    }
55

  
56
    public String getFacet() {
57
        return facet;
58
    }
59

  
60
}
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<String> 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(content.toString().substring(0, 3));
32
    }
33

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

  
38
    public Object getContent() {
39
        return content;
40
    }
41

  
42
    public Set<String> getFacets() {
43
        return facets;
44
    }
45

  
46
}
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/TermSearchComposite.java
14 14
import org.eclipse.swt.layout.GridData;
15 15
import org.eclipse.swt.layout.GridLayout;
16 16
import org.eclipse.swt.widgets.Composite;
17
import org.eclipse.swt.widgets.ExpandBar;
18
import org.eclipse.swt.widgets.ExpandItem;
19
import org.eclipse.swt.widgets.Label;
20 17
import org.eclipse.swt.widgets.Text;
21 18

  
22 19
/**
......
26 23
 */
27 24
public class TermSearchComposite extends Composite {
28 25
    private Text txtSearch;
26
    private ScrolledComposite filterScrolledComposite;
27
    private Composite filterListComposite;
29 28
    private Composite searchResultComposite;
29
    private ScrolledComposite resultScrolledComposite;
30 30

  
31 31
    /**
32 32
     * Create the composite.
......
40 40
        Composite filterComposite = new Composite(this, SWT.NONE);
41 41
        filterComposite.setLayout(new GridLayout(1, false));
42 42
        filterComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
43
        filterComposite.setBounds(0, 0, 64, 64);
44 43

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

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

  
53
        searchResultComposite = new Composite(this, SWT.NONE);
54
        searchResultComposite.setLayout(new GridLayout(1, false));
55
        searchResultComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
56
        searchResultComposite.setBounds(0, 0, 64, 64);
52
        initFilterList();
57 53

  
58
        ScrolledComposite resultComposite = new ScrolledComposite(searchResultComposite, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
59
        resultComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
60
        resultComposite.setExpandHorizontal(true);
61
        resultComposite.setExpandVertical(true);
54
        Composite composite_1 = new Composite(this, SWT.NONE);
55
        composite_1.setLayout(new GridLayout(1, false));
56
        composite_1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
62 57

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

  
65
        ExpandItem xpndtmNewExpanditem = new ExpandItem(expandBar, SWT.NONE);
66
        xpndtmNewExpanditem.setExpanded(true);
67
        xpndtmNewExpanditem.setText("New ExpandItem");
63
        initSearchResultList();
68 64

  
69
        Label lblNewLabel = new Label(expandBar, SWT.NONE);
70
        xpndtmNewExpanditem.setControl(lblNewLabel);
71
        lblNewLabel.setText("New Label");
72
        xpndtmNewExpanditem.setHeight(xpndtmNewExpanditem.getControl().computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
65
    }
73 66

  
74
        ExpandItem xpndtmNewExpanditem_1 = new ExpandItem(expandBar, SWT.NONE);
75
        xpndtmNewExpanditem_1.setText("New ExpandItem");
76
        resultComposite.setContent(expandBar);
77
        resultComposite.setMinSize(expandBar.computeSize(SWT.DEFAULT, SWT.DEFAULT));
67
    private void initSearchResultList() {
68
        searchResultComposite = new Composite(resultScrolledComposite, SWT.NONE);
69
        searchResultComposite.setLayout(new GridLayout(1, false));
70
        resultScrolledComposite.setContent(searchResultComposite);
71
        resultScrolledComposite.setMinSize(searchResultComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
72
    }
78 73

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

  
81 81
    @Override
......
85 85
    public Text getTxtSearch() {
86 86
        return txtSearch;
87 87
    }
88

  
89
    public Composite getFilterListComposite() {
90
        return filterListComposite;
91
    }
92

  
93
    public void clear(){
94
        filterListComposite.dispose();
95
        initFilterList();
96

  
97
        clearResults();
98
    }
99

  
100
    public void clearResults() {
101
        searchResultComposite.dispose();
102
        initSearchResultList();
103
    }
104

  
105
    public void refresh(){
106
        filterScrolledComposite.layout(true, true);
107
        filterScrolledComposite.setMinSize(filterListComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
108
        resultScrolledComposite.layout(true, true);
109
        resultScrolledComposite.setMinSize(searchResultComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
110
    }
88 111
    public Composite getSearchResultComposite() {
89 112
        return searchResultComposite;
90 113
    }
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/search/term/TermSearchController.java
9 9
package eu.etaxonomy.taxeditor.view.search.term;
10 10

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

  
14 16
import org.eclipse.swt.SWT;
15 17
import org.eclipse.swt.events.KeyEvent;
16 18
import org.eclipse.swt.events.KeyListener;
17
import org.eclipse.swt.widgets.Label;
18

  
19
import eu.etaxonomy.cdm.model.common.Language;
20
import eu.etaxonomy.cdm.model.description.Feature;
21
import eu.etaxonomy.cdm.model.location.Country;
22
import eu.etaxonomy.cdm.persistence.dto.TermDto;
23
import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;
24
import eu.etaxonomy.cdm.remote.l10n.TermRepresentation_L10n;
25 19

  
26 20
/**
27 21
 * @author pplitzner
......
38 32
    }
39 33

  
40 34
    private void search(String searchString){
41
        //search terms via term service
42
        List<TermDto> terms = new ArrayList<>();
43
        terms.add(TermDto.fromTerm(Feature.ANATOMY()));
44
        terms.add(TermDto.fromTerm(Feature.BIOLOGY_ECOLOGY()));
45
        terms.add(TermDto.fromTerm(Country.AFGHANISTAN()));
46
        terms.add(TermDto.fromTerm(Country.DENMARKKINGDOMOF()));
47
        terms.add(TermDto.fromTerm(Language.ENGLISH()));
48
        terms.add(TermDto.fromTerm(Language.SUKUMA()));
49

  
50
        List<TermFilter> filters = createResultsAndFilters(terms);
51

  
52
        createFilterButtons(filters);
35
        List<SearchResult> results = new ArrayList<>();
36
        results.add(new SearchResult("Res2"));
37
        results.add(new SearchResult("Res3"));
38
        results.add(new SearchResult("Cas2"));
53 39

  
54
    }
40
        Set<String> facets = createResultsAndFilters(results);
55 41

  
56
    private void createFilterButtons(List<TermFilter> filters) {
42
        createFilterButtons(facets);
57 43

  
44
        composite.refresh();
58 45
    }
59 46

  
60
    private void extractFilters(List<TermDto> terms) {
47
    private void createFilterButtons(Set<String> facets) {
48
        for (String facet : facets) {
49
            FilterComposite filterComposite = new FilterComposite(facet, this, composite.getFilterListComposite(), SWT.NONE);
50
        }
61 51
    }
62 52

  
63
    private List<TermFilter> createResultsAndFilters(List<TermDto> terms) {
64
        List<TermVocabularyDto> vocabularyDtos = new ArrayList<>();
65
        for (TermDto term : terms) {
66
            term.localize(new TermRepresentation_L10n());
67
            createResultComposite(term);
68
            if(!vocabularyDtos.contains(term.getVocabularyUuid())){
69
                vocabularyDtos.add(term.getVocabularyDto());
70
            }
71
        }
72
        List<TermFilter> filters = new ArrayList<>();
73
        for (TermVocabularyDto termVocabularyDto : vocabularyDtos) {
74
            filters.add(new TermFilter(termVocabularyDto));
53
    private Set<String> createResultsAndFilters(List<SearchResult> results) {
54
        Set<String> facets = new HashSet<>();
55
        for (SearchResult result : results) {
56
            createResultComposite(result);
57
            facets.addAll(result.getFacets());
75 58
        }
76
        return filters;
59
        return facets;
77 60
    }
78 61

  
79
    private void createResultComposite(TermDto term) {
80
        Label label = new Label(composite.getSearchResultComposite(), SWT.NONE);
81
        label.setText(term.getRepresentation_L10n());
62
    private void createResultComposite(SearchResult result) {
63
        new SearchResultComposite(result, composite.getSearchResultComposite(), SWT.NONE);
82 64
    }
83 65

  
84 66
    @Override
85 67
    public void keyPressed(KeyEvent e) {
86
        if(e.widget==composite.getTxtSearch()){
68
        if(e.keyCode==SWT.CR && e.widget==composite.getTxtSearch()){
69
            composite.clear();
87 70
            search(composite.getTxtSearch().getText());
88 71
        }
89 72
    }
......
92 75
    public void keyReleased(KeyEvent e) {
93 76
    }
94 77

  
78
    public void applyFilter(FilterComposite filterComposite) {
79

  
80
        composite.clearResults();
81

  
82
        List<SearchResult> results = new ArrayList<>();
83
        results.add(new SearchResult("Des2"));
84
        results.add(new SearchResult("PPs3"));
85
        results.add(new SearchResult("PPs2"));
86

  
87
        createResultsAndFilters(results);
88

  
89
        composite.refresh();
90
    }
91

  
95 92
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)