2 * Copyright (C) 2019 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.view
.search
.facet
.occurrence
;
11 import java
.util
.ArrayList
;
12 import java
.util
.Collection
;
13 import java
.util
.Comparator
;
14 import java
.util
.List
;
16 import org
.eclipse
.swt
.SWT
;
17 import org
.eclipse
.swt
.widgets
.Composite
;
19 import eu
.etaxonomy
.cdm
.api
.service
.IOccurrenceService
;
20 import eu
.etaxonomy
.cdm
.api
.service
.config
.FindOccurrencesConfigurator
;
21 import eu
.etaxonomy
.cdm
.api
.service
.dto
.DerivedUnitDTO
;
22 import eu
.etaxonomy
.cdm
.persistence
.query
.MatchMode
;
23 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
24 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
25 import eu
.etaxonomy
.taxeditor
.view
.search
.facet
.SearchComposite
;
26 import eu
.etaxonomy
.taxeditor
.view
.search
.facet
.SearchController
;
33 public class OccurrenceSearchController
extends SearchController
<OccurrenceSearchResult
, DerivedUnitDTO
> {
35 public OccurrenceSearchController(SearchComposite composite
) {
40 protected Comparator
<OccurrenceSearchResult
> getResultComparator(String searchString
) {
41 return new Comparator
<OccurrenceSearchResult
>() {
43 public int compare(OccurrenceSearchResult o1
, OccurrenceSearchResult o2
) {
44 String label1
= o1
.getContent().getLabel();
45 String label2
= o2
.getContent().getLabel();
46 return StoreUtil
.compareBySearchString(searchString
, label1
, label2
);
53 protected List
<OccurrenceSearchResult
> searchResults(String searchString
){
54 List
<OccurrenceSearchResult
> searchResults
= new ArrayList
<>();
55 FindOccurrencesConfigurator config
= new FindOccurrencesConfigurator();
56 config
.setTitleSearchString(searchString
);
57 config
.setMatchMode(MatchMode
.ANYWHERE
);
58 Collection
<DerivedUnitDTO
> dtos
= CdmStore
.getService(IOccurrenceService
.class).findByTitleDerivedUnitDTO(config
);
59 dtos
.stream().forEach(dto
->searchResults
.add(new OccurrenceSearchResult(dto
)));
64 protected OccurrenceSearchResultComposite
createResultComposite(OccurrenceSearchResult result
, Composite parent
) {
65 return new OccurrenceSearchResultComposite(result
, parent
, SWT
.NONE
);
69 protected List
<OccurrenceSearchResult
> getSelectedResults() {