1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2013 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.ui.campanula.derivatesearch;
|
11
|
|
12
|
import java.util.List;
|
13
|
|
14
|
import org.eclipse.jface.viewers.ArrayContentProvider;
|
15
|
import org.eclipse.jface.viewers.DoubleClickEvent;
|
16
|
import org.eclipse.jface.viewers.IDoubleClickListener;
|
17
|
import org.eclipse.jface.viewers.TableViewer;
|
18
|
import org.eclipse.swt.SWT;
|
19
|
import org.eclipse.swt.events.KeyAdapter;
|
20
|
import org.eclipse.swt.events.KeyEvent;
|
21
|
|
22
|
import eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator;
|
23
|
import eu.etaxonomy.cdm.api.service.config.IdentifiableServiceConfiguratorImpl;
|
24
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
25
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
26
|
|
27
|
/**
|
28
|
* @author pplitzner
|
29
|
* @date 25.11.2013
|
30
|
*
|
31
|
*/
|
32
|
public class DerivateSearchCompositeController {
|
33
|
|
34
|
private DerivateSearchComposite derivateSearchComposite;
|
35
|
private IIdentifiableEntityServiceConfigurator<SpecimenOrObservationBase<?>> configurator;
|
36
|
|
37
|
/**
|
38
|
* @param derivateSearchComposite
|
39
|
*/
|
40
|
public DerivateSearchCompositeController(DerivateSearchComposite derivateSearchComposite) {
|
41
|
this.derivateSearchComposite = derivateSearchComposite;
|
42
|
init();
|
43
|
}
|
44
|
|
45
|
private void init(){
|
46
|
derivateSearchComposite.getSearchField().addKeyListener(new KeyAdapter() {
|
47
|
/*
|
48
|
* (non-Javadoc)
|
49
|
* @see org.eclipse.swt.events.KeyAdapter#keyPressed(org.eclipse.swt.events.KeyEvent)
|
50
|
*/
|
51
|
@Override
|
52
|
public void keyPressed(KeyEvent e) {
|
53
|
if (e.keyCode == SWT.CR) {
|
54
|
String searchString = derivateSearchComposite.getSearchField().getText();
|
55
|
searchDerivates(searchString);
|
56
|
}
|
57
|
}
|
58
|
});
|
59
|
|
60
|
TableViewer resultViewer = derivateSearchComposite.getResultViewer();
|
61
|
resultViewer.setContentProvider(new ArrayContentProvider());
|
62
|
resultViewer.setLabelProvider(new DerivateSearchResultsLabelProvider());
|
63
|
resultViewer.addDoubleClickListener(new IDoubleClickListener() {
|
64
|
@Override
|
65
|
public void doubleClick(DoubleClickEvent event) {
|
66
|
// PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input, editorId);
|
67
|
}
|
68
|
});
|
69
|
|
70
|
configurator = new IdentifiableServiceConfiguratorImpl<SpecimenOrObservationBase<?>>();
|
71
|
}
|
72
|
|
73
|
private void searchDerivates(String searchString){
|
74
|
configurator.setTitleSearchString(searchString);
|
75
|
List<SpecimenOrObservationBase> results = CdmStore.getSearchManager().findOccurrences(configurator);
|
76
|
derivateSearchComposite.getResultViewer().setInput(results);
|
77
|
}
|
78
|
|
79
|
}
|