Revision 77e3fddf
Added by Patrick Plitzner about 5 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/search/facet/SearchController.java | ||
---|---|---|
16 | 16 |
import org.eclipse.swt.SWT; |
17 | 17 |
import org.eclipse.swt.events.KeyEvent; |
18 | 18 |
import org.eclipse.swt.events.KeyListener; |
19 |
import org.eclipse.swt.widgets.Composite; |
|
19 | 20 |
|
20 | 21 |
/** |
21 | 22 |
* @author pplitzner |
22 | 23 |
* @since Jan 22, 2019 |
23 | 24 |
* |
24 | 25 |
*/ |
25 |
public abstract class SearchController implements KeyListener{ |
|
26 |
public abstract class SearchController<S extends SearchResult<T>, T> implements KeyListener{
|
|
26 | 27 |
|
27 | 28 |
private SearchComposite composite; |
28 |
private List<SearchResult> searchResults = new ArrayList<>();
|
|
29 |
private List<S> searchResults = new ArrayList<>(); |
|
29 | 30 |
private Set<Facet> appliedFacets = new HashSet<>(); |
30 | 31 |
|
31 | 32 |
public SearchController(SearchComposite composite) { |
... | ... | |
33 | 34 |
composite.getTxtSearch().addKeyListener(this); |
34 | 35 |
} |
35 | 36 |
|
36 |
protected abstract List<SearchResult> searchResults(String searchString); |
|
37 |
protected abstract List<S> searchResults(String searchString); |
|
38 |
|
|
39 |
protected abstract void createResultComposite(S result, Composite parent); |
|
37 | 40 |
|
38 | 41 |
private void search(String searchString){ |
39 | 42 |
searchResults.clear(); |
... | ... | |
49 | 52 |
|
50 | 53 |
private void createFilterButtons(Set<Facet> facets) { |
51 | 54 |
for (Facet facet : facets) { |
52 |
FilterComposite filterComposite = new FilterComposite(facet, this, composite.getFilterListComposite(), SWT.NONE); |
|
53 |
appliedFacets.add(facet); |
|
55 |
if(facet.getFacet()!=null){ |
|
56 |
FilterComposite filterComposite = new FilterComposite(facet, this, composite.getFilterListComposite(), SWT.NONE); |
|
57 |
appliedFacets.add(facet); |
|
58 |
} |
|
54 | 59 |
} |
55 | 60 |
} |
56 | 61 |
|
57 |
private Set<Facet> createResults(List<SearchResult> results) {
|
|
62 |
private Set<Facet> createResults(List<S> results) { |
|
58 | 63 |
Set<Facet> facets = new HashSet<>(); |
59 |
for (SearchResult result : results) {
|
|
60 |
createResultComposite(result); |
|
64 |
for (S result : results) { |
|
65 |
createResultComposite(result, composite.getSearchResultComposite());
|
|
61 | 66 |
facets.addAll(result.getFacets()); |
62 | 67 |
} |
63 | 68 |
return facets; |
64 | 69 |
} |
65 | 70 |
|
66 |
private void createResultComposite(SearchResult result) { |
|
67 |
new SearchResultComposite(result, composite.getSearchResultComposite(), SWT.NONE); |
|
68 |
} |
|
69 |
|
|
70 | 71 |
@Override |
71 | 72 |
public void keyPressed(KeyEvent e) { |
72 | 73 |
if(e.keyCode==SWT.CR && e.widget==composite.getTxtSearch()){ |
... | ... | |
91 | 92 |
appliedFacets.remove(facet); |
92 | 93 |
} |
93 | 94 |
|
94 |
for (SearchResult searchResult : searchResults) {
|
|
95 |
for (S searchResult : searchResults) { |
|
95 | 96 |
if(searchResult.hasAnyFacet(appliedFacets)){ |
96 |
createResultComposite(searchResult); |
|
97 |
createResultComposite(searchResult, composite.getSearchResultComposite());
|
|
97 | 98 |
} |
98 | 99 |
} |
99 | 100 |
|
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/TermSearchController.java | ||
---|---|---|
9 | 9 |
package eu.etaxonomy.taxeditor.view.search.facet.term; |
10 | 10 |
|
11 | 11 |
import java.util.ArrayList; |
12 |
import java.util.Collection; |
|
12 | 13 |
import java.util.List; |
13 | 14 |
|
14 |
import eu.etaxonomy.cdm.model.common.Language; |
|
15 |
import eu.etaxonomy.cdm.model.description.Feature; |
|
15 |
import org.eclipse.swt.SWT; |
|
16 |
import org.eclipse.swt.widgets.Composite; |
|
17 |
|
|
18 |
import eu.etaxonomy.cdm.api.service.ITermService; |
|
19 |
import eu.etaxonomy.cdm.persistence.dto.TermDto; |
|
20 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
|
16 | 21 |
import eu.etaxonomy.taxeditor.view.search.facet.SearchComposite; |
17 | 22 |
import eu.etaxonomy.taxeditor.view.search.facet.SearchController; |
18 |
import eu.etaxonomy.taxeditor.view.search.facet.SearchResult; |
|
19 | 23 |
|
20 | 24 |
/** |
21 | 25 |
* @author pplitzner |
22 | 26 |
* @since Jan 22, 2019 |
23 | 27 |
* |
24 | 28 |
*/ |
25 |
public class TermSearchController extends SearchController { |
|
29 |
public class TermSearchController extends SearchController<TermSearchResult, TermDto> {
|
|
26 | 30 |
|
27 | 31 |
public TermSearchController(SearchComposite composite) { |
28 | 32 |
super(composite); |
29 | 33 |
} |
30 | 34 |
|
31 | 35 |
@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())); |
|
36 |
protected List<TermSearchResult> searchResults(String searchString){ |
|
37 |
List<TermSearchResult> searchResults = new ArrayList<>(); |
|
38 |
Collection<TermDto> dtos = CdmStore.getService(ITermService.class).findByTitleAsDto(searchString); |
|
39 |
dtos.stream().forEach(dto->searchResults.add(new TermSearchResult(dto))); |
|
37 | 40 |
return searchResults; |
38 | 41 |
} |
39 | 42 |
|
43 |
@Override |
|
44 |
protected void createResultComposite(TermSearchResult result, Composite parent) { |
|
45 |
new TermSearchResultComposite(result, parent, SWT.NONE); |
|
46 |
} |
|
47 |
|
|
40 | 48 |
} |
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/search/facet/term/TermSearchResult.java | ||
---|---|---|
11 | 11 |
import java.util.HashSet; |
12 | 12 |
import java.util.Set; |
13 | 13 |
|
14 |
import eu.etaxonomy.cdm.model.common.DefinedTermBase; |
|
14 |
import eu.etaxonomy.cdm.persistence.dto.TermDto; |
|
15 |
import eu.etaxonomy.cdm.remote.l10n.TermRepresentation_L10n; |
|
15 | 16 |
import eu.etaxonomy.taxeditor.view.search.facet.Facet; |
16 | 17 |
import eu.etaxonomy.taxeditor.view.search.facet.SearchResult; |
17 | 18 |
|
... | ... | |
20 | 21 |
* @since Jan 24, 2019 |
21 | 22 |
* |
22 | 23 |
*/ |
23 |
public class TermSearchResult extends SearchResult<DefinedTermBase> {
|
|
24 |
public class TermSearchResult extends SearchResult<TermDto> {
|
|
24 | 25 |
|
25 |
public TermSearchResult(DefinedTermBase content) {
|
|
26 |
public TermSearchResult(TermDto content) {
|
|
26 | 27 |
super(content); |
27 | 28 |
} |
28 | 29 |
|
29 | 30 |
@Override |
30 |
protected Set<Facet> initFacets(DefinedTermBase content) {
|
|
31 |
protected Set<Facet> initFacets(TermDto content) {
|
|
31 | 32 |
Set<Facet> facets = new HashSet<>(); |
32 |
facets.add(new Facet(content.getVocabulary().getLabel())); |
|
33 |
content.localize(new TermRepresentation_L10n()); |
|
34 |
facets.add(new Facet(content.getVocRepresentation_L10n())); |
|
33 | 35 |
return facets; |
34 | 36 |
} |
35 | 37 |
|
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/search/facet/term/TermSearchResultComposite.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 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 TermSearchResultComposite extends Composite { |
|
24 |
|
|
25 |
/** |
|
26 |
* Create the composite. |
|
27 |
* @param result |
|
28 |
* @param parent |
|
29 |
* @param style |
|
30 |
*/ |
|
31 |
public TermSearchResultComposite(TermSearchResult 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().getRepresentation_L10n()); |
|
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 |
} |
Also available in: Unified diff
ref #8011 Add generics for search results