1 |
e9116e90
|
Patric Plitzner
|
// $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 |
913c77b4
|
Patric Plitzner
|
package eu.etaxonomy.taxeditor.view.derivateSearch;
|
11 |
e9116e90
|
Patric Plitzner
|
|
12 |
39cbdc2e
|
Patric Plitzner
|
import java.util.Arrays;
|
13 |
|
|
import java.util.LinkedHashMap;
|
14 |
e9116e90
|
Patric Plitzner
|
import java.util.List;
|
15 |
|
|
|
16 |
b2f76600
|
Patric Plitzner
|
import org.eclipse.core.commands.ExecutionException;
|
17 |
|
|
import org.eclipse.core.commands.NotEnabledException;
|
18 |
|
|
import org.eclipse.core.commands.NotHandledException;
|
19 |
|
|
import org.eclipse.core.commands.common.NotDefinedException;
|
20 |
e9116e90
|
Patric Plitzner
|
import org.eclipse.jface.viewers.ArrayContentProvider;
|
21 |
|
|
import org.eclipse.jface.viewers.DoubleClickEvent;
|
22 |
|
|
import org.eclipse.jface.viewers.IDoubleClickListener;
|
23 |
|
|
import org.eclipse.jface.viewers.TableViewer;
|
24 |
|
|
import org.eclipse.swt.SWT;
|
25 |
|
|
import org.eclipse.swt.events.KeyAdapter;
|
26 |
|
|
import org.eclipse.swt.events.KeyEvent;
|
27 |
f6b03570
|
Patric Plitzner
|
import org.eclipse.swt.widgets.Composite;
|
28 |
b2f76600
|
Patric Plitzner
|
import org.eclipse.ui.handlers.IHandlerService;
|
29 |
e9116e90
|
Patric Plitzner
|
|
30 |
b2f76600
|
Patric Plitzner
|
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeCacheStrategy;
|
31 |
e9116e90
|
Patric Plitzner
|
import eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator;
|
32 |
|
|
import eu.etaxonomy.cdm.api.service.config.IdentifiableServiceConfiguratorImpl;
|
33 |
|
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
34 |
39cbdc2e
|
Patric Plitzner
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
|
35 |
b2f76600
|
Patric Plitzner
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
36 |
e9116e90
|
Patric Plitzner
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
37 |
2d8f997f
|
Patric Plitzner
|
import eu.etaxonomy.taxeditor.ui.mvc.combo.EnumTermComboController;
|
38 |
e9116e90
|
Patric Plitzner
|
|
39 |
|
|
/**
|
40 |
fb649daa
|
Patric Plitzner
|
* Controller class for the {@link DerivateSearchComposite}.<br>
|
41 |
|
|
* This controller contains the logic to search the data base for {@link SpecimenOrObservationBase}s
|
42 |
|
|
* and handles GUI events.
|
43 |
e9116e90
|
Patric Plitzner
|
*
|
44 |
|
|
*/
|
45 |
|
|
public class DerivateSearchCompositeController {
|
46 |
|
|
|
47 |
b2f76600
|
Patric Plitzner
|
private final DerivateSearchComposite derivateSearchComposite;
|
48 |
|
|
private IIdentifiableEntityServiceConfigurator<SpecimenOrObservationBase<DerivedUnitFacadeCacheStrategy>> configurator;
|
49 |
2d8f997f
|
Patric Plitzner
|
private EnumTermComboController<SpecimenOrObservationType> enumTermComboController;
|
50 |
e9116e90
|
Patric Plitzner
|
|
51 |
|
|
/**
|
52 |
f6b03570
|
Patric Plitzner
|
* @param parent
|
53 |
e9116e90
|
Patric Plitzner
|
*/
|
54 |
f6b03570
|
Patric Plitzner
|
public DerivateSearchCompositeController(Composite parent) {
|
55 |
|
|
this.derivateSearchComposite = new DerivateSearchComposite(parent, SWT.NONE);
|
56 |
e9116e90
|
Patric Plitzner
|
init();
|
57 |
|
|
}
|
58 |
|
|
|
59 |
|
|
private void init(){
|
60 |
39cbdc2e
|
Patric Plitzner
|
LinkedHashMap<SpecimenOrObservationType, String> orderedTerms = AbstractUtility.orderTerms(Arrays.asList(SpecimenOrObservationType.values()));
|
61 |
|
|
String[] comboItems = new String[orderedTerms.size()];
|
62 |
|
|
int count = 0;
|
63 |
|
|
for(String termMessage:orderedTerms.values()){
|
64 |
|
|
comboItems[count] = termMessage;
|
65 |
|
|
count++;
|
66 |
|
|
}
|
67 |
|
|
|
68 |
2d8f997f
|
Patric Plitzner
|
// derivateSearchComposite.getComboDerivateType().setItems(comboItems);
|
69 |
|
|
enumTermComboController = new EnumTermComboController<SpecimenOrObservationType>(derivateSearchComposite.getComboDerivateType(), null, null, SpecimenOrObservationType.class, 0);
|
70 |
39cbdc2e
|
Patric Plitzner
|
|
71 |
e9116e90
|
Patric Plitzner
|
derivateSearchComposite.getSearchField().addKeyListener(new KeyAdapter() {
|
72 |
|
|
/*
|
73 |
|
|
* (non-Javadoc)
|
74 |
|
|
* @see org.eclipse.swt.events.KeyAdapter#keyPressed(org.eclipse.swt.events.KeyEvent)
|
75 |
|
|
*/
|
76 |
|
|
@Override
|
77 |
|
|
public void keyPressed(KeyEvent e) {
|
78 |
|
|
if (e.keyCode == SWT.CR) {
|
79 |
|
|
String searchString = derivateSearchComposite.getSearchField().getText();
|
80 |
|
|
searchDerivates(searchString);
|
81 |
|
|
}
|
82 |
|
|
}
|
83 |
|
|
});
|
84 |
|
|
|
85 |
|
|
TableViewer resultViewer = derivateSearchComposite.getResultViewer();
|
86 |
|
|
resultViewer.setContentProvider(new ArrayContentProvider());
|
87 |
f0e3bd82
|
Patric Plitzner
|
resultViewer.setLabelProvider(new DerivateLabelProvider());
|
88 |
e9116e90
|
Patric Plitzner
|
resultViewer.addDoubleClickListener(new IDoubleClickListener() {
|
89 |
|
|
@Override
|
90 |
|
|
public void doubleClick(DoubleClickEvent event) {
|
91 |
b2f76600
|
Patric Plitzner
|
String commandId = "eu.etaxonomy.taxeditor.editor.handler.openDerivateView";
|
92 |
|
|
|
93 |
|
|
IHandlerService handlerService = (IHandlerService) AbstractUtility.getService(IHandlerService.class);
|
94 |
|
|
try {
|
95 |
|
|
handlerService.executeCommand(commandId, null);
|
96 |
|
|
} catch (ExecutionException e) {
|
97 |
|
|
AbstractUtility.error(DerivateSearchCompositeController.class, e);
|
98 |
|
|
} catch (NotDefinedException e) {
|
99 |
|
|
AbstractUtility.error(DerivateSearchCompositeController.class, e);
|
100 |
|
|
} catch (NotEnabledException e) {
|
101 |
|
|
AbstractUtility.error(DerivateSearchCompositeController.class, e);
|
102 |
|
|
} catch (NotHandledException e) {
|
103 |
|
|
AbstractUtility.error(DerivateSearchCompositeController.class, e);
|
104 |
|
|
}
|
105 |
|
|
|
106 |
e9116e90
|
Patric Plitzner
|
}
|
107 |
|
|
});
|
108 |
b2f76600
|
Patric Plitzner
|
configurator = new IdentifiableServiceConfiguratorImpl<SpecimenOrObservationBase<DerivedUnitFacadeCacheStrategy>>();
|
109 |
1b2a8f93
|
Patric Plitzner
|
|
110 |
e9116e90
|
Patric Plitzner
|
}
|
111 |
|
|
|
112 |
|
|
private void searchDerivates(String searchString){
|
113 |
|
|
configurator.setTitleSearchString(searchString);
|
114 |
1e3def3e
|
Patric Plitzner
|
List<SpecimenOrObservationBase> results = CdmStore.getSearchManager().findOccurrences(configurator, true);
|
115 |
e9116e90
|
Patric Plitzner
|
derivateSearchComposite.getResultViewer().setInput(results);
|
116 |
|
|
}
|
117 |
|
|
|
118 |
f6b03570
|
Patric Plitzner
|
|
119 |
|
|
/**
|
120 |
|
|
* @return the derivateSearchComposite
|
121 |
|
|
*/
|
122 |
|
|
public DerivateSearchComposite getDerivateSearchComposite() {
|
123 |
|
|
return derivateSearchComposite;
|
124 |
|
|
}
|
125 |
|
|
|
126 |
1b2a8f93
|
Patric Plitzner
|
private void setEnable(boolean enabled){
|
127 |
|
|
derivateSearchComposite.setEnabled(enabled);
|
128 |
|
|
derivateSearchComposite.getResultViewer().getTable().setEnabled(enabled);
|
129 |
|
|
derivateSearchComposite.getSearchField().setEnabled(enabled);
|
130 |
|
|
}
|
131 |
|
|
|
132 |
e9116e90
|
Patric Plitzner
|
}
|