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.Collection;
|
13
|
import java.util.Comparator;
|
14
|
import java.util.List;
|
15
|
|
16
|
import org.eclipse.swt.SWT;
|
17
|
import org.eclipse.swt.widgets.Composite;
|
18
|
|
19
|
import eu.etaxonomy.cdm.api.service.ITermService;
|
20
|
import eu.etaxonomy.cdm.model.common.TermType;
|
21
|
import eu.etaxonomy.cdm.persistence.dto.TermDto;
|
22
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
23
|
import eu.etaxonomy.taxeditor.store.StoreUtil;
|
24
|
import eu.etaxonomy.taxeditor.view.search.facet.SearchComposite;
|
25
|
import eu.etaxonomy.taxeditor.view.search.facet.SearchController;
|
26
|
|
27
|
/**
|
28
|
* @author pplitzner
|
29
|
* @since Jan 22, 2019
|
30
|
*
|
31
|
*/
|
32
|
public class TermSearchController extends SearchController<TermSearchResult, TermDto> {
|
33
|
|
34
|
public TermSearchController(SearchComposite composite) {
|
35
|
super(composite);
|
36
|
}
|
37
|
|
38
|
@Override
|
39
|
protected Comparator<TermSearchResult> getResultComparator(String searchString) {
|
40
|
return new Comparator<TermSearchResult>() {
|
41
|
@Override
|
42
|
public int compare(TermSearchResult o1, TermSearchResult o2) {
|
43
|
String label1 = o1.getContent().getRepresentation_L10n();
|
44
|
String label2 = o2.getContent().getRepresentation_L10n();
|
45
|
return StoreUtil.compareBySearchString(searchString, label1, label2);
|
46
|
}
|
47
|
|
48
|
};
|
49
|
}
|
50
|
|
51
|
@Override
|
52
|
protected List<TermSearchResult> searchResults(String searchString){
|
53
|
List<TermSearchResult> searchResults = new ArrayList<>();
|
54
|
Collection<TermDto> dtos = CdmStore.getService(ITermService.class).findByTitleAsDto(searchString, TermType.Feature);
|
55
|
dtos.stream().forEach(dto->searchResults.add(new TermSearchResult(dto)));
|
56
|
return searchResults;
|
57
|
}
|
58
|
|
59
|
@Override
|
60
|
protected TermSearchResultComposite createResultComposite(TermSearchResult result, Composite parent) {
|
61
|
return new TermSearchResultComposite(result, parent, SWT.NONE);
|
62
|
}
|
63
|
|
64
|
@Override
|
65
|
protected List<TermSearchResult> getSelectedResults() {
|
66
|
return null;
|
67
|
}
|
68
|
|
69
|
}
|