Revision 3be6ef3e
Added by Niels Hoffmann over 13 years ago
taxeditor-navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/search/SearchResultView.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2007 EDIT |
|
3 |
* European Distributed Institute of Taxonomy |
|
4 |
* http://www.e-taxonomy.eu |
|
5 |
* |
|
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. |
|
8 |
*/ |
|
9 |
|
|
10 |
package eu.etaxonomy.taxeditor.navigation.search; |
|
11 |
|
|
12 |
import java.util.ArrayList; |
|
13 |
import java.util.List; |
|
14 |
|
|
15 |
import org.eclipse.core.runtime.IProgressMonitor; |
|
16 |
import org.eclipse.core.runtime.IStatus; |
|
17 |
import org.eclipse.core.runtime.Status; |
|
18 |
import org.eclipse.core.runtime.jobs.Job; |
|
19 |
import org.eclipse.jface.action.GroupMarker; |
|
20 |
import org.eclipse.jface.action.MenuManager; |
|
21 |
import org.eclipse.jface.viewers.ArrayContentProvider; |
|
22 |
import org.eclipse.jface.viewers.DoubleClickEvent; |
|
23 |
import org.eclipse.jface.viewers.IDoubleClickListener; |
|
24 |
import org.eclipse.jface.viewers.TableViewer; |
|
25 |
import org.eclipse.swt.SWT; |
|
26 |
import org.eclipse.swt.layout.GridData; |
|
27 |
import org.eclipse.swt.layout.GridLayout; |
|
28 |
import org.eclipse.swt.widgets.Composite; |
|
29 |
import org.eclipse.swt.widgets.Control; |
|
30 |
import org.eclipse.swt.widgets.Display; |
|
31 |
import org.eclipse.swt.widgets.Label; |
|
32 |
import org.eclipse.swt.widgets.Menu; |
|
33 |
import org.eclipse.swt.widgets.Text; |
|
34 |
import org.eclipse.ui.IMemento; |
|
35 |
import org.eclipse.ui.IWorkbenchActionConstants; |
|
36 |
import org.eclipse.ui.part.ViewPart; |
|
37 |
|
|
38 |
import eu.etaxonomy.cdm.api.conversation.ConversationHolder; |
|
39 |
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled; |
|
40 |
import eu.etaxonomy.cdm.api.service.config.ITaxonServiceConfigurator; |
|
41 |
import eu.etaxonomy.cdm.model.common.IdentifiableEntity; |
|
42 |
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap; |
|
43 |
import eu.etaxonomy.taxeditor.model.ContextListenerAdapter; |
|
44 |
import eu.etaxonomy.taxeditor.model.IContextListener; |
|
45 |
import eu.etaxonomy.taxeditor.navigation.NavigationUtil; |
|
46 |
import eu.etaxonomy.taxeditor.navigation.search.SearchBar.SearchOption; |
|
47 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
|
48 |
|
|
49 |
/** |
|
50 |
* @author p.ciardelli |
|
51 |
* @created 19.01.2009 |
|
52 |
* @version 1.0 |
|
53 |
* @author n.hoffmann |
|
54 |
*/ |
|
55 |
public class SearchResultView extends ViewPart implements IConversationEnabled{ |
|
56 |
|
|
57 |
private class ContextListener extends ContextListenerAdapter{ |
|
58 |
/* (non-Javadoc) |
|
59 |
* @see eu.etaxonomy.taxeditor.model.IContextListener#contextStop(org.eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor) |
|
60 |
*/ |
|
61 |
@Override |
|
62 |
public void contextStop(IMemento memento, IProgressMonitor monitor) { |
|
63 |
NavigationUtil.hideView(SearchResultView.this); |
|
64 |
} |
|
65 |
} |
|
66 |
|
|
67 |
public static final String ID = |
|
68 |
"eu.etaxonomy.taxeditor.navigation.search.searchResultView"; //$NON-NLS-1$ |
|
69 |
|
|
70 |
private TableViewer resultViewer; |
|
71 |
|
|
72 |
private ConversationHolder conversation; |
|
73 |
|
|
74 |
private Text searchString; |
|
75 |
|
|
76 |
private Text configurationLabel; |
|
77 |
|
|
78 |
private Text status; |
|
79 |
|
|
80 |
private SearchJob searchJob; |
|
81 |
|
|
82 |
private IContextListener contextListener; |
|
83 |
|
|
84 |
/* (non-Javadoc) |
|
85 |
* @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite) |
|
86 |
*/ |
|
87 |
@Override |
|
88 |
public void createPartControl(Composite parent) { |
|
89 |
|
|
90 |
conversation = CdmStore.createConversation(); |
|
91 |
contextListener = new ContextListener(); |
|
92 |
CdmStore.getContextManager().addContextListener(contextListener); |
|
93 |
|
|
94 |
GridLayout layout = new GridLayout(); |
|
95 |
layout.marginWidth = 0; |
|
96 |
layout.marginHeight = 0; |
|
97 |
|
|
98 |
parent.setLayout(layout); |
|
99 |
|
|
100 |
Composite infoComposite = createInfoComposite(parent); |
|
101 |
infoComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); |
|
102 |
|
|
103 |
resultViewer = new TableViewer(parent, SWT.NONE); |
|
104 |
resultViewer.setContentProvider(new ArrayContentProvider()); |
|
105 |
resultViewer.setLabelProvider(new SearchResultLabelProvider()); |
|
106 |
resultViewer.addDoubleClickListener(new IDoubleClickListener() { |
|
107 |
public void doubleClick(DoubleClickEvent event) { |
|
108 |
NavigationUtil.executeEditHandler(); |
|
109 |
} |
|
110 |
}); |
|
111 |
|
|
112 |
resultViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); |
|
113 |
|
|
114 |
getSite().setSelectionProvider(resultViewer); |
|
115 |
|
|
116 |
// register context menu |
|
117 |
MenuManager menuMgr = new MenuManager(); |
|
118 |
menuMgr.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS)); |
|
119 |
getSite().registerContextMenu(menuMgr, resultViewer); |
|
120 |
|
|
121 |
Control control = resultViewer.getControl(); |
|
122 |
Menu menu = menuMgr.createContextMenu(control); |
|
123 |
control.setMenu(menu); |
|
124 |
} |
|
125 |
|
|
126 |
private Composite createInfoComposite(Composite parent){ |
|
127 |
Composite composite = new Composite(parent, SWT.NULL); |
|
128 |
|
|
129 |
composite.setLayout(new GridLayout(2, false)); |
|
130 |
|
|
131 |
Label searchStringLabel = new Label(composite, SWT.NULL); |
|
132 |
searchStringLabel.setText("Search String:"); |
|
133 |
|
|
134 |
searchString = new Text(composite, SWT.NULL); |
|
135 |
searchString.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); |
|
136 |
searchString.setEditable(false); |
|
137 |
// searchString.setText(" "); |
|
138 |
|
|
139 |
Label configurationDescriptionLabel = new Label(composite, SWT.NULL); |
|
140 |
configurationDescriptionLabel.setText("Search for:"); |
|
141 |
|
|
142 |
configurationLabel = new Text(composite, SWT.WRAP); |
|
143 |
configurationLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); |
|
144 |
configurationLabel.setEditable(false); |
|
145 |
|
|
146 |
Label statusLabel = new Label(composite, SWT.NULL); |
|
147 |
statusLabel.setText("Status:"); |
|
148 |
|
|
149 |
status = new Text(composite, SWT.NULL); |
|
150 |
status.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); |
|
151 |
status.setEditable(false); |
|
152 |
|
|
153 |
return composite; |
|
154 |
} |
|
155 |
|
|
156 |
public void performSearch(ITaxonServiceConfigurator configurator){ |
|
157 |
setPartName("Search: '" + configurator.getSearchString() + "'"); |
|
158 |
|
|
159 |
searchString.setText(configurator.getSearchString()); |
|
160 |
|
|
161 |
List<String> includedEntities = new ArrayList<String>(); |
|
162 |
if(configurator.isDoTaxa()) |
|
163 |
includedEntities.add(SearchOption.TAXON.getLabel()); |
|
164 |
if(configurator.isDoSynonyms()) |
|
165 |
includedEntities.add(SearchOption.SYNONYM.getLabel()); |
|
166 |
if(configurator.isDoNamesWithoutTaxa()) |
|
167 |
includedEntities.add(SearchOption.NAME.getLabel()); |
|
168 |
if(configurator.isDoTaxaByCommonNames()){ |
|
169 |
includedEntities.add(SearchOption.COMMON_NAME.getLabel()); |
|
170 |
} |
|
171 |
|
|
172 |
String includedEntitiesString = ""; |
|
173 |
for (int i = 0; i < includedEntities.size(); i++){ |
|
174 |
includedEntitiesString += includedEntities.get(i); |
|
175 |
if(i < includedEntities.size() -1){ |
|
176 |
includedEntitiesString += ", "; |
|
177 |
} |
|
178 |
} |
|
179 |
|
|
180 |
configurationLabel.setText(includedEntitiesString); |
|
181 |
|
|
182 |
status.setText("Searching..."); |
|
183 |
|
|
184 |
searchJob = new SearchJob(Display.getCurrent(), configurator); |
|
185 |
searchJob.schedule(); |
|
186 |
|
|
187 |
} |
|
188 |
|
|
189 |
protected void displaySearchResult(List<IdentifiableEntity> result) { |
|
190 |
if(result.size() > 0){ |
|
191 |
resultViewer.setInput(result); |
|
192 |
status.setText(result.size() + " entities found"); |
|
193 |
}else{ |
|
194 |
status.setText("Search returned no results"); |
|
195 |
} |
|
196 |
} |
|
197 |
|
|
198 |
/* (non-Javadoc) |
|
199 |
* @see org.eclipse.ui.part.WorkbenchPart#setFocus() |
|
200 |
*/ |
|
201 |
@Override |
|
202 |
public void setFocus() { |
|
203 |
//logger.warn("Setting focus to search result viewer"); |
|
204 |
conversation.bind(); |
|
205 |
// pass focus to resultViewer |
|
206 |
resultViewer.getControl().setFocus(); |
|
207 |
} |
|
208 |
|
|
209 |
/* (non-Javadoc) |
|
210 |
* @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder() |
|
211 |
*/ |
|
212 |
public ConversationHolder getConversationHolder() { |
|
213 |
return this.conversation; |
|
214 |
} |
|
215 |
|
|
216 |
/* (non-Javadoc) |
|
217 |
* @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap) |
|
218 |
*/ |
|
219 |
public void update(CdmDataChangeMap changeEvents) { |
|
220 |
// TODO Auto-generated method stub |
|
221 |
|
|
222 |
} |
|
223 |
|
|
224 |
/* (non-Javadoc) |
|
225 |
* @see org.eclipse.ui.part.WorkbenchPart#dispose() |
|
226 |
*/ |
|
227 |
@Override |
|
228 |
public void dispose() { |
|
229 |
super.dispose(); |
|
230 |
conversation.close(); |
|
231 |
if(searchJob != null) |
|
232 |
searchJob.cancel(); |
|
233 |
CdmStore.getContextManager().removeContextListener(contextListener); |
|
234 |
} |
|
235 |
|
|
236 |
/** |
|
237 |
* |
|
238 |
* @author n.hoffmann |
|
239 |
* @created Feb 2, 2010 |
|
240 |
* @version 1.0 |
|
241 |
*/ |
|
242 |
class SearchJob extends Job{ |
|
243 |
|
|
244 |
private ITaxonServiceConfigurator configurator; |
|
245 |
|
|
246 |
private Display display; |
|
247 |
|
|
248 |
/** |
|
249 |
* @param name |
|
250 |
*/ |
|
251 |
public SearchJob(Display display, ITaxonServiceConfigurator configurator) { |
|
252 |
super("Performing Search"); |
|
253 |
this.display = display; |
|
254 |
this.configurator = configurator; |
|
255 |
} |
|
256 |
|
|
257 |
/* (non-Javadoc) |
|
258 |
* @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor) |
|
259 |
*/ |
|
260 |
@Override |
|
261 |
protected IStatus run(IProgressMonitor monitor) { |
|
262 |
monitor.beginTask("", 100); |
|
263 |
monitor.worked(20); |
|
264 |
|
|
265 |
final List<IdentifiableEntity> searchResult = CdmStore.findTaxaAndNames(configurator); |
|
266 |
monitor.worked(40); |
|
267 |
|
|
268 |
if(! monitor.isCanceled()){ |
|
269 |
display.asyncExec(new Runnable() { |
|
270 |
public void run() { |
|
271 |
displaySearchResult(searchResult); |
|
272 |
} |
|
273 |
}); |
|
274 |
}else{ |
|
275 |
display.asyncExec(new Runnable() { |
|
276 |
public void run() { |
|
277 |
status.setText("Cancelled"); |
|
278 |
} |
|
279 |
}); |
|
280 |
} |
|
281 |
monitor.done(); |
|
282 |
return Status.OK_STATUS; |
|
283 |
} |
|
284 |
|
|
285 |
} |
|
286 |
} |
|
1 |
/** |
|
2 |
* Copyright (C) 2007 EDIT |
|
3 |
* European Distributed Institute of Taxonomy |
|
4 |
* http://www.e-taxonomy.eu |
|
5 |
* |
|
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. |
|
8 |
*/ |
|
9 |
|
|
10 |
package eu.etaxonomy.taxeditor.navigation.search; |
|
11 |
|
|
12 |
import java.util.ArrayList; |
|
13 |
import java.util.List; |
|
14 |
|
|
15 |
import org.eclipse.core.runtime.IProgressMonitor; |
|
16 |
import org.eclipse.core.runtime.IStatus; |
|
17 |
import org.eclipse.core.runtime.Status; |
|
18 |
import org.eclipse.core.runtime.jobs.Job; |
|
19 |
import org.eclipse.jface.action.GroupMarker; |
|
20 |
import org.eclipse.jface.action.MenuManager; |
|
21 |
import org.eclipse.jface.viewers.ArrayContentProvider; |
|
22 |
import org.eclipse.jface.viewers.DoubleClickEvent; |
|
23 |
import org.eclipse.jface.viewers.IDoubleClickListener; |
|
24 |
import org.eclipse.jface.viewers.TableViewer; |
|
25 |
import org.eclipse.swt.SWT; |
|
26 |
import org.eclipse.swt.layout.GridData; |
|
27 |
import org.eclipse.swt.layout.GridLayout; |
|
28 |
import org.eclipse.swt.widgets.Composite; |
|
29 |
import org.eclipse.swt.widgets.Control; |
|
30 |
import org.eclipse.swt.widgets.Display; |
|
31 |
import org.eclipse.swt.widgets.Label; |
|
32 |
import org.eclipse.swt.widgets.Menu; |
|
33 |
import org.eclipse.swt.widgets.Text; |
|
34 |
import org.eclipse.ui.IMemento; |
|
35 |
import org.eclipse.ui.IWorkbenchActionConstants; |
|
36 |
import org.eclipse.ui.part.ViewPart; |
|
37 |
|
|
38 |
import eu.etaxonomy.cdm.api.conversation.ConversationHolder; |
|
39 |
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled; |
|
40 |
import eu.etaxonomy.cdm.api.service.config.ITaxonServiceConfigurator; |
|
41 |
import eu.etaxonomy.cdm.model.common.IdentifiableEntity; |
|
42 |
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap; |
|
43 |
import eu.etaxonomy.taxeditor.model.ContextListenerAdapter; |
|
44 |
import eu.etaxonomy.taxeditor.model.IContextListener; |
|
45 |
import eu.etaxonomy.taxeditor.navigation.NavigationUtil; |
|
46 |
import eu.etaxonomy.taxeditor.navigation.search.SearchBar.SearchOption; |
|
47 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
|
48 |
|
|
49 |
/** |
|
50 |
* <p>SearchResultView class.</p> |
|
51 |
* |
|
52 |
* @author p.ciardelli |
|
53 |
* @author n.hoffmann |
|
54 |
* @created 19.01.2009 |
|
55 |
* @version 1.0 |
|
56 |
*/ |
|
57 |
public class SearchResultView extends ViewPart implements IConversationEnabled{ |
|
58 |
|
|
59 |
private class ContextListener extends ContextListenerAdapter{ |
|
60 |
/* (non-Javadoc) |
|
61 |
* @see eu.etaxonomy.taxeditor.model.IContextListener#contextStop(org.eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor) |
|
62 |
*/ |
|
63 |
@Override |
|
64 |
public void contextStop(IMemento memento, IProgressMonitor monitor) { |
|
65 |
NavigationUtil.hideView(SearchResultView.this); |
|
66 |
} |
|
67 |
} |
|
68 |
|
|
69 |
/** Constant <code>ID="eu.etaxonomy.taxeditor.navigation.searc"{trunked}</code> */ |
|
70 |
public static final String ID = |
|
71 |
"eu.etaxonomy.taxeditor.navigation.search.searchResultView"; //$NON-NLS-1$ |
|
72 |
|
|
73 |
private TableViewer resultViewer; |
|
74 |
|
|
75 |
private ConversationHolder conversation; |
|
76 |
|
|
77 |
private Text searchString; |
|
78 |
|
|
79 |
private Text configurationLabel; |
|
80 |
|
|
81 |
private Text status; |
|
82 |
|
|
83 |
private SearchJob searchJob; |
|
84 |
|
|
85 |
private IContextListener contextListener; |
|
86 |
|
|
87 |
/* (non-Javadoc) |
|
88 |
* @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite) |
|
89 |
*/ |
|
90 |
/** {@inheritDoc} */ |
|
91 |
@Override |
|
92 |
public void createPartControl(Composite parent) { |
|
93 |
|
|
94 |
conversation = CdmStore.createConversation(); |
|
95 |
contextListener = new ContextListener(); |
|
96 |
CdmStore.getContextManager().addContextListener(contextListener); |
|
97 |
|
|
98 |
GridLayout layout = new GridLayout(); |
|
99 |
layout.marginWidth = 0; |
|
100 |
layout.marginHeight = 0; |
|
101 |
|
|
102 |
parent.setLayout(layout); |
|
103 |
|
|
104 |
Composite infoComposite = createInfoComposite(parent); |
|
105 |
infoComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); |
|
106 |
|
|
107 |
resultViewer = new TableViewer(parent, SWT.NONE); |
|
108 |
resultViewer.setContentProvider(new ArrayContentProvider()); |
|
109 |
resultViewer.setLabelProvider(new SearchResultLabelProvider()); |
|
110 |
resultViewer.addDoubleClickListener(new IDoubleClickListener() { |
|
111 |
public void doubleClick(DoubleClickEvent event) { |
|
112 |
NavigationUtil.executeEditHandler(); |
|
113 |
} |
|
114 |
}); |
|
115 |
|
|
116 |
resultViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); |
|
117 |
|
|
118 |
getSite().setSelectionProvider(resultViewer); |
|
119 |
|
|
120 |
// register context menu |
|
121 |
MenuManager menuMgr = new MenuManager(); |
|
122 |
menuMgr.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS)); |
|
123 |
getSite().registerContextMenu(menuMgr, resultViewer); |
|
124 |
|
|
125 |
Control control = resultViewer.getControl(); |
|
126 |
Menu menu = menuMgr.createContextMenu(control); |
|
127 |
control.setMenu(menu); |
|
128 |
} |
|
129 |
|
|
130 |
private Composite createInfoComposite(Composite parent){ |
|
131 |
Composite composite = new Composite(parent, SWT.NULL); |
|
132 |
|
|
133 |
composite.setLayout(new GridLayout(2, false)); |
|
134 |
|
|
135 |
Label searchStringLabel = new Label(composite, SWT.NULL); |
|
136 |
searchStringLabel.setText("Search String:"); |
|
137 |
|
|
138 |
searchString = new Text(composite, SWT.NULL); |
|
139 |
searchString.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); |
|
140 |
searchString.setEditable(false); |
|
141 |
// searchString.setText(" "); |
|
142 |
|
|
143 |
Label configurationDescriptionLabel = new Label(composite, SWT.NULL); |
|
144 |
configurationDescriptionLabel.setText("Search for:"); |
|
145 |
|
|
146 |
configurationLabel = new Text(composite, SWT.WRAP); |
|
147 |
configurationLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); |
|
148 |
configurationLabel.setEditable(false); |
|
149 |
|
|
150 |
Label statusLabel = new Label(composite, SWT.NULL); |
|
151 |
statusLabel.setText("Status:"); |
|
152 |
|
|
153 |
status = new Text(composite, SWT.NULL); |
|
154 |
status.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); |
|
155 |
status.setEditable(false); |
|
156 |
|
|
157 |
return composite; |
|
158 |
} |
|
159 |
|
|
160 |
/** |
|
161 |
* <p>performSearch</p> |
|
162 |
* |
|
163 |
* @param configurator a {@link eu.etaxonomy.cdm.api.service.config.ITaxonServiceConfigurator} object. |
|
164 |
*/ |
|
165 |
public void performSearch(ITaxonServiceConfigurator configurator){ |
|
166 |
setPartName("Search: '" + configurator.getSearchString() + "'"); |
|
167 |
|
|
168 |
searchString.setText(configurator.getSearchString()); |
|
169 |
|
|
170 |
List<String> includedEntities = new ArrayList<String>(); |
|
171 |
if(configurator.isDoTaxa()) |
|
172 |
includedEntities.add(SearchOption.TAXON.getLabel()); |
|
173 |
if(configurator.isDoSynonyms()) |
|
174 |
includedEntities.add(SearchOption.SYNONYM.getLabel()); |
|
175 |
if(configurator.isDoNamesWithoutTaxa()) |
|
176 |
includedEntities.add(SearchOption.NAME.getLabel()); |
|
177 |
if(configurator.isDoTaxaByCommonNames()){ |
|
178 |
includedEntities.add(SearchOption.COMMON_NAME.getLabel()); |
|
179 |
} |
|
180 |
|
|
181 |
String includedEntitiesString = ""; |
|
182 |
for (int i = 0; i < includedEntities.size(); i++){ |
|
183 |
includedEntitiesString += includedEntities.get(i); |
|
184 |
if(i < includedEntities.size() -1){ |
|
185 |
includedEntitiesString += ", "; |
|
186 |
} |
|
187 |
} |
|
188 |
|
|
189 |
configurationLabel.setText(includedEntitiesString); |
|
190 |
|
|
191 |
status.setText("Searching..."); |
|
192 |
|
|
193 |
searchJob = new SearchJob(Display.getCurrent(), configurator); |
|
194 |
searchJob.schedule(); |
|
195 |
|
|
196 |
} |
|
197 |
|
|
198 |
/** |
|
199 |
* <p>displaySearchResult</p> |
|
200 |
* |
|
201 |
* @param result a {@link java.util.List} object. |
|
202 |
*/ |
|
203 |
protected void displaySearchResult(List<IdentifiableEntity> result) { |
|
204 |
if(result.size() > 0){ |
|
205 |
resultViewer.setInput(result); |
|
206 |
status.setText(result.size() + " entities found"); |
|
207 |
}else{ |
|
208 |
status.setText("Search returned no results"); |
|
209 |
} |
|
210 |
} |
|
211 |
|
|
212 |
/* (non-Javadoc) |
|
213 |
* @see org.eclipse.ui.part.WorkbenchPart#setFocus() |
|
214 |
*/ |
|
215 |
/** {@inheritDoc} */ |
|
216 |
@Override |
|
217 |
public void setFocus() { |
|
218 |
//logger.warn("Setting focus to search result viewer"); |
|
219 |
conversation.bind(); |
|
220 |
// pass focus to resultViewer |
|
221 |
resultViewer.getControl().setFocus(); |
|
222 |
} |
|
223 |
|
|
224 |
/* (non-Javadoc) |
|
225 |
* @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder() |
|
226 |
*/ |
|
227 |
/** |
|
228 |
* <p>getConversationHolder</p> |
|
229 |
* |
|
230 |
* @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object. |
|
231 |
*/ |
|
232 |
public ConversationHolder getConversationHolder() { |
|
233 |
return this.conversation; |
|
234 |
} |
|
235 |
|
|
236 |
/* (non-Javadoc) |
|
237 |
* @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap) |
|
238 |
*/ |
|
239 |
/** {@inheritDoc} */ |
|
240 |
public void update(CdmDataChangeMap changeEvents) { |
|
241 |
// TODO Auto-generated method stub |
|
242 |
|
|
243 |
} |
|
244 |
|
|
245 |
/* (non-Javadoc) |
|
246 |
* @see org.eclipse.ui.part.WorkbenchPart#dispose() |
|
247 |
*/ |
|
248 |
/** {@inheritDoc} */ |
|
249 |
@Override |
|
250 |
public void dispose() { |
|
251 |
super.dispose(); |
|
252 |
conversation.close(); |
|
253 |
if(searchJob != null) |
|
254 |
searchJob.cancel(); |
|
255 |
CdmStore.getContextManager().removeContextListener(contextListener); |
|
256 |
} |
|
257 |
|
|
258 |
/** |
|
259 |
* |
|
260 |
* @author n.hoffmann |
|
261 |
* @created Feb 2, 2010 |
|
262 |
* @version 1.0 |
|
263 |
*/ |
|
264 |
class SearchJob extends Job{ |
|
265 |
|
|
266 |
private ITaxonServiceConfigurator configurator; |
|
267 |
|
|
268 |
private Display display; |
|
269 |
|
|
270 |
/** |
|
271 |
* @param name |
|
272 |
*/ |
|
273 |
public SearchJob(Display display, ITaxonServiceConfigurator configurator) { |
|
274 |
super("Performing Search"); |
|
275 |
this.display = display; |
|
276 |
this.configurator = configurator; |
|
277 |
} |
|
278 |
|
|
279 |
/* (non-Javadoc) |
|
280 |
* @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor) |
|
281 |
*/ |
|
282 |
@Override |
|
283 |
protected IStatus run(IProgressMonitor monitor) { |
|
284 |
monitor.beginTask("", 100); |
|
285 |
monitor.worked(20); |
|
286 |
|
|
287 |
final List<IdentifiableEntity> searchResult = CdmStore.findTaxaAndNames(configurator); |
|
288 |
monitor.worked(40); |
|
289 |
|
|
290 |
if(! monitor.isCanceled()){ |
|
291 |
display.asyncExec(new Runnable() { |
|
292 |
public void run() { |
|
293 |
displaySearchResult(searchResult); |
|
294 |
} |
|
295 |
}); |
|
296 |
}else{ |
|
297 |
display.asyncExec(new Runnable() { |
|
298 |
public void run() { |
|
299 |
status.setText("Cancelled"); |
|
300 |
} |
|
301 |
}); |
|
302 |
} |
|
303 |
monitor.done(); |
|
304 |
return Status.OK_STATUS; |
|
305 |
} |
|
306 |
|
|
307 |
} |
|
308 |
} |
Also available in: Unified diff
performed javacscript:fix and worked on documentation