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.core.commands.ExecutionException;
|
15
|
import org.eclipse.core.commands.NotEnabledException;
|
16
|
import org.eclipse.core.commands.NotHandledException;
|
17
|
import org.eclipse.core.commands.common.NotDefinedException;
|
18
|
import org.eclipse.jface.viewers.ArrayContentProvider;
|
19
|
import org.eclipse.jface.viewers.DoubleClickEvent;
|
20
|
import org.eclipse.jface.viewers.IDoubleClickListener;
|
21
|
import org.eclipse.jface.viewers.TableViewer;
|
22
|
import org.eclipse.swt.SWT;
|
23
|
import org.eclipse.swt.events.KeyAdapter;
|
24
|
import org.eclipse.swt.events.KeyEvent;
|
25
|
import org.eclipse.ui.handlers.IHandlerService;
|
26
|
|
27
|
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeCacheStrategy;
|
28
|
import eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator;
|
29
|
import eu.etaxonomy.cdm.api.service.config.IdentifiableServiceConfiguratorImpl;
|
30
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
31
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
32
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
33
|
|
34
|
/**
|
35
|
* @author pplitzner
|
36
|
* @date 25.11.2013
|
37
|
*
|
38
|
*/
|
39
|
public class DerivateSearchCompositeController {
|
40
|
|
41
|
private final DerivateSearchComposite derivateSearchComposite;
|
42
|
private IIdentifiableEntityServiceConfigurator<SpecimenOrObservationBase<DerivedUnitFacadeCacheStrategy>> configurator;
|
43
|
|
44
|
/**
|
45
|
* @param derivateSearchComposite
|
46
|
*/
|
47
|
public DerivateSearchCompositeController(DerivateSearchComposite derivateSearchComposite) {
|
48
|
this.derivateSearchComposite = derivateSearchComposite;
|
49
|
init();
|
50
|
}
|
51
|
|
52
|
private void init(){
|
53
|
derivateSearchComposite.getSearchField().addKeyListener(new KeyAdapter() {
|
54
|
/*
|
55
|
* (non-Javadoc)
|
56
|
* @see org.eclipse.swt.events.KeyAdapter#keyPressed(org.eclipse.swt.events.KeyEvent)
|
57
|
*/
|
58
|
@Override
|
59
|
public void keyPressed(KeyEvent e) {
|
60
|
if (e.keyCode == SWT.CR) {
|
61
|
String searchString = derivateSearchComposite.getSearchField().getText();
|
62
|
searchDerivates(searchString);
|
63
|
}
|
64
|
}
|
65
|
});
|
66
|
|
67
|
TableViewer resultViewer = derivateSearchComposite.getResultViewer();
|
68
|
resultViewer.setContentProvider(new ArrayContentProvider());
|
69
|
resultViewer.setLabelProvider(new DerivateSearchResultsLabelProvider());
|
70
|
resultViewer.addDoubleClickListener(new IDoubleClickListener() {
|
71
|
@Override
|
72
|
public void doubleClick(DoubleClickEvent event) {
|
73
|
String commandId = "eu.etaxonomy.taxeditor.editor.handler.openDerivateView";
|
74
|
|
75
|
IHandlerService handlerService = (IHandlerService) AbstractUtility.getService(IHandlerService.class);
|
76
|
try {
|
77
|
handlerService.executeCommand(commandId, null);
|
78
|
} catch (ExecutionException e) {
|
79
|
AbstractUtility.error(DerivateSearchCompositeController.class, e);
|
80
|
} catch (NotDefinedException e) {
|
81
|
AbstractUtility.error(DerivateSearchCompositeController.class, e);
|
82
|
} catch (NotEnabledException e) {
|
83
|
AbstractUtility.error(DerivateSearchCompositeController.class, e);
|
84
|
} catch (NotHandledException e) {
|
85
|
AbstractUtility.error(DerivateSearchCompositeController.class, e);
|
86
|
}
|
87
|
|
88
|
}
|
89
|
});
|
90
|
|
91
|
configurator = new IdentifiableServiceConfiguratorImpl<SpecimenOrObservationBase<DerivedUnitFacadeCacheStrategy>>();
|
92
|
}
|
93
|
|
94
|
private void searchDerivates(String searchString){
|
95
|
configurator.setTitleSearchString(searchString);
|
96
|
List<SpecimenOrObservationBase> results = CdmStore.getSearchManager().findOccurrences(configurator);
|
97
|
derivateSearchComposite.getResultViewer().setInput(results);
|
98
|
}
|
99
|
|
100
|
}
|