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.swt.widgets.Composite;
|
26
|
import org.eclipse.ui.handlers.IHandlerService;
|
27
|
|
28
|
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeCacheStrategy;
|
29
|
import eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator;
|
30
|
import eu.etaxonomy.cdm.api.service.config.IdentifiableServiceConfiguratorImpl;
|
31
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
32
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
33
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
34
|
|
35
|
/**
|
36
|
* Controller class for the {@link DerivateSearchComposite}.<br>
|
37
|
* This controller contains the logic to search the data base for {@link SpecimenOrObservationBase}s
|
38
|
* and handles GUI events.
|
39
|
*
|
40
|
*/
|
41
|
public class DerivateSearchCompositeController {
|
42
|
|
43
|
private final DerivateSearchComposite derivateSearchComposite;
|
44
|
private IIdentifiableEntityServiceConfigurator<SpecimenOrObservationBase<DerivedUnitFacadeCacheStrategy>> configurator;
|
45
|
|
46
|
/**
|
47
|
* @param parent
|
48
|
*/
|
49
|
public DerivateSearchCompositeController(Composite parent) {
|
50
|
this.derivateSearchComposite = new DerivateSearchComposite(parent, SWT.NONE);
|
51
|
init();
|
52
|
}
|
53
|
|
54
|
private void init(){
|
55
|
derivateSearchComposite.getSearchField().addKeyListener(new KeyAdapter() {
|
56
|
/*
|
57
|
* (non-Javadoc)
|
58
|
* @see org.eclipse.swt.events.KeyAdapter#keyPressed(org.eclipse.swt.events.KeyEvent)
|
59
|
*/
|
60
|
@Override
|
61
|
public void keyPressed(KeyEvent e) {
|
62
|
if (e.keyCode == SWT.CR) {
|
63
|
String searchString = derivateSearchComposite.getSearchField().getText();
|
64
|
searchDerivates(searchString);
|
65
|
}
|
66
|
}
|
67
|
});
|
68
|
|
69
|
TableViewer resultViewer = derivateSearchComposite.getResultViewer();
|
70
|
resultViewer.setContentProvider(new ArrayContentProvider());
|
71
|
resultViewer.setLabelProvider(new DerivateSearchResultsLabelProvider());
|
72
|
resultViewer.addDoubleClickListener(new IDoubleClickListener() {
|
73
|
@Override
|
74
|
public void doubleClick(DoubleClickEvent event) {
|
75
|
String commandId = "eu.etaxonomy.taxeditor.editor.handler.openDerivateView";
|
76
|
|
77
|
IHandlerService handlerService = (IHandlerService) AbstractUtility.getService(IHandlerService.class);
|
78
|
try {
|
79
|
handlerService.executeCommand(commandId, null);
|
80
|
} catch (ExecutionException e) {
|
81
|
AbstractUtility.error(DerivateSearchCompositeController.class, e);
|
82
|
} catch (NotDefinedException e) {
|
83
|
AbstractUtility.error(DerivateSearchCompositeController.class, e);
|
84
|
} catch (NotEnabledException e) {
|
85
|
AbstractUtility.error(DerivateSearchCompositeController.class, e);
|
86
|
} catch (NotHandledException e) {
|
87
|
AbstractUtility.error(DerivateSearchCompositeController.class, e);
|
88
|
}
|
89
|
|
90
|
}
|
91
|
});
|
92
|
|
93
|
configurator = new IdentifiableServiceConfiguratorImpl<SpecimenOrObservationBase<DerivedUnitFacadeCacheStrategy>>();
|
94
|
|
95
|
}
|
96
|
|
97
|
private void searchDerivates(String searchString){
|
98
|
configurator.setTitleSearchString(searchString);
|
99
|
List<SpecimenOrObservationBase> results = CdmStore.getSearchManager().findOccurrences(configurator);
|
100
|
derivateSearchComposite.getResultViewer().setInput(results);
|
101
|
}
|
102
|
|
103
|
|
104
|
/**
|
105
|
* @return the derivateSearchComposite
|
106
|
*/
|
107
|
public DerivateSearchComposite getDerivateSearchComposite() {
|
108
|
return derivateSearchComposite;
|
109
|
}
|
110
|
|
111
|
private void setEnable(boolean enabled){
|
112
|
derivateSearchComposite.setEnabled(enabled);
|
113
|
derivateSearchComposite.getResultViewer().getTable().setEnabled(enabled);
|
114
|
derivateSearchComposite.getSearchField().setEnabled(enabled);
|
115
|
}
|
116
|
|
117
|
}
|