Revision 2ff53a7f
Added by Patrick Plitzner over 6 years ago
eu.etaxonomy.taxeditor.navigation/META-INF/MANIFEST.MF | ||
---|---|---|
25 | 25 |
javax.inject, |
26 | 26 |
org.eclipse.e4.ui.services, |
27 | 27 |
org.eclipse.e4.ui.workbench, |
28 |
org.eclipse.e4.core.di.annotations |
|
28 |
org.eclipse.e4.core.di.annotations, |
|
29 |
org.eclipse.e4.core.contexts;bundle-version="1.5.1" |
|
29 | 30 |
Bundle-RequiredExecutionEnvironment: JavaSE-1.8 |
30 | 31 |
Import-Package: org.eclipse.core.resources, |
31 | 32 |
org.eclipse.core.runtime, |
eu.etaxonomy.taxeditor.navigation/fragment.e4xmi | ||
---|---|---|
48 | 48 |
<children xsi:type="menu:HandledMenuItem" xmi:id="_1JIbQJIwEeeJAdt8ZUxyaw" elementId="eu.etaxonomy.taxeditor.navigation.handledmenuitem.copy" label="%command.label.12" command="_EJ-u0JIyEeeJAdt8ZUxyaw"/> |
49 | 49 |
</menus> |
50 | 50 |
</elements> |
51 |
<elements xsi:type="basic:PartDescriptor" xmi:id="_AcycAKOkEee6lJH578buGg" elementId="eu.etaxonomy.taxeditor.navigation.search.e4.SearchResultViewE4" label="%view.name" iconURI="platform:/plugin/eu.etaxonomy.taxeditor.navigation/icons/system-search.png" allowMultiple="true" closeable="true" contributionURI="bundleclass://eu.etaxonomy.taxeditor.navigation/eu.etaxonomy.taxeditor.navigation.search.e4.SearchResultViewE4"> |
|
52 |
<menus xsi:type="menu:PopupMenu" xmi:id="_A-rBEKOkEee6lJH578buGg" elementId="eu.etaxonomy.taxeditor.navigation.popupmenu.searchresults"> |
|
53 |
<children xsi:type="menu:DynamicMenuContribution" xmi:id="_tVmTQKOkEee6lJH578buGg" elementId="eu.etaxonomy.taxeditor.navigation.dynamicmenucontribution.searchResult.cdmViewer" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.view.CdmViewerContextMenuE4"/> |
|
54 |
</menus> |
|
55 |
</elements> |
|
51 | 56 |
</fragments> |
52 | 57 |
<fragments xsi:type="fragment:StringModelFragment" xmi:id="_wITZ8JIVEeeJAdt8ZUxyaw" featurename="children" parentElementId="eu.etaxonomy.taxeditor.menu.showView" positionInList=""> |
53 | 58 |
<elements xsi:type="menu:HandledMenuItem" xmi:id="_wITZ8ZIVEeeJAdt8ZUxyaw" elementId="eu.etaxonomy.taxeditor.navigator.showViewMenu.navigator" label="%command.label" iconURI="platform:/plugin/eu.etaxonomy.taxeditor.navigation/icons/edit_16x16.gif"> |
eu.etaxonomy.taxeditor.navigation/plugin.xml | ||
---|---|---|
12 | 12 |
</extension> |
13 | 13 |
<extension |
14 | 14 |
point="org.eclipse.ui.views"> |
15 |
<view |
|
16 |
allowMultiple="true" |
|
17 |
class="eu.etaxonomy.taxeditor.navigation.search.SearchResultView" |
|
18 |
icon="icons/system-search.png" |
|
19 |
id="eu.etaxonomy.taxeditor.navigation.search.searchResultView" |
|
20 |
name="%view.name" |
|
21 |
restorable="false"> |
|
22 |
</view> |
|
23 | 15 |
<view |
24 | 16 |
allowMultiple="false" |
25 | 17 |
class="eu.etaxonomy.taxeditor.navigation.key.polytomous.PolytomousKeyViewPart" |
... | ... | |
65 | 57 |
</visibleWhen> |
66 | 58 |
</command> |
67 | 59 |
</menuContribution> |
68 |
<menuContribution |
|
69 |
locationURI="popup:eu.etaxonomy.taxeditor.navigation.search.searchResultView"> |
|
70 |
<dynamic |
|
71 |
class="eu.etaxonomy.taxeditor.view.CdmViewerContextMenu" |
|
72 |
id="eu.etaxonomy.taxeditor.navigation.cdmViewerContextMenu"> |
|
73 |
</dynamic> |
|
74 |
<separator |
|
75 |
name="eu.etaxonomy.taxeditor.navigation.separator2"> |
|
76 |
</separator> |
|
77 |
</menuContribution> |
|
78 | 60 |
<menuContribution |
79 | 61 |
locationURI="menu:eu.etaxonomy.navigation.menu.new"> |
80 | 62 |
<command |
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/search/SearchBar.java | ||
---|---|---|
10 | 10 |
package eu.etaxonomy.taxeditor.navigation.search; |
11 | 11 |
|
12 | 12 |
import javax.annotation.PostConstruct; |
13 |
import javax.inject.Inject; |
|
13 | 14 |
|
14 | 15 |
import org.eclipse.core.runtime.IProgressMonitor; |
16 |
import org.eclipse.e4.ui.model.application.ui.basic.MPart; |
|
17 |
import org.eclipse.e4.ui.workbench.modeling.EPartService; |
|
18 |
import org.eclipse.e4.ui.workbench.modeling.EPartService.PartState; |
|
15 | 19 |
import org.eclipse.swt.SWT; |
16 | 20 |
import org.eclipse.swt.events.FocusEvent; |
17 | 21 |
import org.eclipse.swt.events.FocusListener; |
... | ... | |
30 | 34 |
import org.eclipse.swt.widgets.ToolBar; |
31 | 35 |
import org.eclipse.swt.widgets.ToolItem; |
32 | 36 |
import org.eclipse.ui.IMemento; |
33 |
import org.eclipse.ui.IViewPart; |
|
34 |
import org.eclipse.ui.IWorkbenchPage; |
|
35 |
import org.eclipse.ui.PartInitException; |
|
36 | 37 |
import org.eclipse.ui.PlatformUI; |
37 | 38 |
import org.eclipse.ui.swt.IFocusService; |
38 | 39 |
|
... | ... | |
40 | 41 |
import eu.etaxonomy.taxeditor.model.AbstractUtility; |
41 | 42 |
import eu.etaxonomy.taxeditor.model.IContextListener; |
42 | 43 |
import eu.etaxonomy.taxeditor.model.MessagingUtils; |
43 |
import eu.etaxonomy.taxeditor.navigation.internal.TaxeditorNavigationPlugin; |
|
44 | 44 |
import eu.etaxonomy.taxeditor.navigation.l10n.Messages; |
45 |
import eu.etaxonomy.taxeditor.navigation.search.e4.SearchResultViewE4; |
|
45 | 46 |
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys; |
46 | 47 |
import eu.etaxonomy.taxeditor.preference.PreferencesUtil; |
47 | 48 |
import eu.etaxonomy.taxeditor.preference.Resources; |
... | ... | |
55 | 56 |
*/ |
56 | 57 |
public class SearchBar implements IContextListener{ |
57 | 58 |
private Text text_search; |
58 |
private String secondaryId; |
|
59 | 59 |
private ToolBar toolBar; |
60 | 60 |
|
61 | 61 |
private final String defaultText = Messages.SearchBar_0; |
62 | 62 |
|
63 |
@Inject |
|
64 |
private EPartService partService; |
|
65 |
|
|
63 | 66 |
final private ConfigurationSelectionListener configurationListener = new ConfigurationSelectionListener(); |
64 | 67 |
|
65 | 68 |
/** {@inheritDoc} */ |
... | ... | |
210 | 213 |
*/ |
211 | 214 |
private void openSearchResultsView(IFindTaxaAndNamesConfigurator configurator) { |
212 | 215 |
boolean openResultInSeparateWindows = PreferencesUtil.getPreferenceStore().getBoolean((IPreferenceKeys.SEARCH_OPEN_RESULTS_IN_SEPARATE_WINDOWS)); |
213 |
if(openResultInSeparateWindows){ |
|
214 |
//increment change secondary id so it is unique |
|
215 |
secondaryId += "1"; |
|
216 |
} |
|
217 | 216 |
|
218 |
try { |
|
219 |
IViewPart resultsView = TaxeditorNavigationPlugin.getDefault() |
|
220 |
.getWorkbench().getActiveWorkbenchWindow() |
|
221 |
.getActivePage().showView(SearchResultView.ID, secondaryId, |
|
222 |
IWorkbenchPage.VIEW_ACTIVATE); |
|
223 |
((SearchResultView) resultsView).performSearch(configurator); |
|
224 |
} catch (PartInitException e) { |
|
225 |
MessagingUtils.error(this.getClass(), Messages.SearchBar_4, e); |
|
226 |
} |
|
217 |
MPart part = partService.createPart("eu.etaxonomy.taxeditor.navigation.search.e4.SearchResultViewE4"); |
|
218 |
part = partService.showPart(part, PartState.ACTIVATE); |
|
219 |
SearchResultViewE4 resultView = (SearchResultViewE4)part.getObject(); |
|
220 |
resultView.performSearch(configurator); |
|
227 | 221 |
} |
228 | 222 |
|
229 | 223 |
/** |
... | ... | |
306 | 300 |
} |
307 | 301 |
} |
308 | 302 |
|
309 |
/** |
|
310 |
* Available search options. |
|
311 |
* |
|
312 |
* @author n.hoffmann |
|
313 |
* @created Feb 2, 2010 |
|
314 |
* @version 1.0 |
|
315 |
*/ |
|
316 |
enum SearchOption { |
|
317 |
TAXON(Messages.SearchBar_6), |
|
318 |
SYNONYM(Messages.SearchBar_7), |
|
319 |
NAME(Messages.SearchBar_8), |
|
320 |
COMMON_NAME(Messages.SearchBar_9); |
|
321 |
|
|
322 |
private final String label; |
|
323 |
|
|
324 |
private SearchOption(String label) { |
|
325 |
this.label = label; |
|
326 |
} |
|
327 |
|
|
328 |
public String getLabel() { |
|
329 |
return label; |
|
330 |
} |
|
331 |
|
|
332 |
public boolean getPreference() { |
|
333 |
if (!PreferencesUtil.getPreferenceStore().contains( |
|
334 |
IPreferenceKeys.TAXON_SERVICE_CONFIGURATOR_TAXA)) { |
|
335 |
// initializes the search configurator |
|
336 |
PreferencesUtil.initializeSearchConfigurator(); |
|
337 |
} |
|
338 |
|
|
339 |
switch (this) { |
|
340 |
case TAXON: |
|
341 |
boolean result = PreferencesUtil.getPreferenceStore().getBoolean( |
|
342 |
IPreferenceKeys.TAXON_SERVICE_CONFIGURATOR_TAXA); |
|
343 |
return result; |
|
344 |
case SYNONYM: |
|
345 |
return PreferencesUtil.getPreferenceStore().getBoolean( |
|
346 |
IPreferenceKeys.TAXON_SERVICE_CONFIGURATOR_SYNONYMS); |
|
347 |
case NAME: |
|
348 |
return PreferencesUtil.getPreferenceStore().getBoolean( |
|
349 |
IPreferenceKeys.TAXON_SERVICE_CONFIGURATOR_NAMES); |
|
350 |
case COMMON_NAME: |
|
351 |
return PreferencesUtil.getPreferenceStore().getBoolean( |
|
352 |
IPreferenceKeys.TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES); |
|
353 |
} |
|
354 |
|
|
355 |
return true; |
|
356 |
} |
|
357 |
|
|
358 |
} |
|
359 |
|
|
360 | 303 |
@Override |
361 | 304 |
public void contextAboutToStop(IMemento memento, IProgressMonitor monitor) { |
362 | 305 |
} |
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/search/SearchOption.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2017 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 |
package eu.etaxonomy.taxeditor.navigation.search; |
|
10 |
|
|
11 |
import eu.etaxonomy.taxeditor.navigation.l10n.Messages; |
|
12 |
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys; |
|
13 |
import eu.etaxonomy.taxeditor.preference.PreferencesUtil; |
|
14 |
|
|
15 |
/** |
|
16 |
* @author pplitzner |
|
17 |
* @since Sep 27, 2017 |
|
18 |
* |
|
19 |
*/ |
|
20 |
public enum SearchOption { |
|
21 |
TAXON(Messages.SearchBar_6), |
|
22 |
SYNONYM(Messages.SearchBar_7), |
|
23 |
NAME(Messages.SearchBar_8), |
|
24 |
COMMON_NAME(Messages.SearchBar_9); |
|
25 |
|
|
26 |
private final String label; |
|
27 |
|
|
28 |
private SearchOption(String label) { |
|
29 |
this.label = label; |
|
30 |
} |
|
31 |
|
|
32 |
public String getLabel() { |
|
33 |
return label; |
|
34 |
} |
|
35 |
|
|
36 |
public boolean getPreference() { |
|
37 |
if (!PreferencesUtil.getPreferenceStore().contains( |
|
38 |
IPreferenceKeys.TAXON_SERVICE_CONFIGURATOR_TAXA)) { |
|
39 |
// initializes the search configurator |
|
40 |
PreferencesUtil.initializeSearchConfigurator(); |
|
41 |
} |
|
42 |
|
|
43 |
switch (this) { |
|
44 |
case TAXON: |
|
45 |
boolean result = PreferencesUtil.getPreferenceStore().getBoolean( |
|
46 |
IPreferenceKeys.TAXON_SERVICE_CONFIGURATOR_TAXA); |
|
47 |
return result; |
|
48 |
case SYNONYM: |
|
49 |
return PreferencesUtil.getPreferenceStore().getBoolean( |
|
50 |
IPreferenceKeys.TAXON_SERVICE_CONFIGURATOR_SYNONYMS); |
|
51 |
case NAME: |
|
52 |
return PreferencesUtil.getPreferenceStore().getBoolean( |
|
53 |
IPreferenceKeys.TAXON_SERVICE_CONFIGURATOR_NAMES); |
|
54 |
case COMMON_NAME: |
|
55 |
return PreferencesUtil.getPreferenceStore().getBoolean( |
|
56 |
IPreferenceKeys.TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES); |
|
57 |
} |
|
58 |
|
|
59 |
return true; |
|
60 |
} |
|
61 |
|
|
62 |
} |
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/search/SearchResultView.java | ||
---|---|---|
49 | 49 |
import eu.etaxonomy.taxeditor.model.IContextListener; |
50 | 50 |
import eu.etaxonomy.taxeditor.navigation.NavigationUtil; |
51 | 51 |
import eu.etaxonomy.taxeditor.navigation.l10n.Messages; |
52 |
import eu.etaxonomy.taxeditor.navigation.search.SearchBar.SearchOption; |
|
53 | 52 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
54 | 53 |
|
55 | 54 |
/** |
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/search/e4/SearchResultViewE4.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.e4; |
|
11 |
|
|
12 |
import java.util.ArrayList; |
|
13 |
import java.util.List; |
|
14 |
|
|
15 |
import javax.annotation.PostConstruct; |
|
16 |
import javax.annotation.PreDestroy; |
|
17 |
import javax.inject.Inject; |
|
18 |
|
|
19 |
import org.eclipse.core.runtime.IProgressMonitor; |
|
20 |
import org.eclipse.core.runtime.IStatus; |
|
21 |
import org.eclipse.core.runtime.Status; |
|
22 |
import org.eclipse.core.runtime.jobs.Job; |
|
23 |
import org.eclipse.e4.ui.di.Focus; |
|
24 |
import org.eclipse.e4.ui.model.application.ui.basic.MPart; |
|
25 |
import org.eclipse.e4.ui.services.EMenuService; |
|
26 |
import org.eclipse.e4.ui.workbench.modeling.EPartService; |
|
27 |
import org.eclipse.e4.ui.workbench.modeling.ESelectionService; |
|
28 |
import org.eclipse.jface.viewers.ArrayContentProvider; |
|
29 |
import org.eclipse.jface.viewers.DoubleClickEvent; |
|
30 |
import org.eclipse.jface.viewers.IDoubleClickListener; |
|
31 |
import org.eclipse.jface.viewers.ISelection; |
|
32 |
import org.eclipse.jface.viewers.ISelectionChangedListener; |
|
33 |
import org.eclipse.jface.viewers.IStructuredSelection; |
|
34 |
import org.eclipse.jface.viewers.TableViewer; |
|
35 |
import org.eclipse.swt.SWT; |
|
36 |
import org.eclipse.swt.layout.GridData; |
|
37 |
import org.eclipse.swt.layout.GridLayout; |
|
38 |
import org.eclipse.swt.widgets.Composite; |
|
39 |
import org.eclipse.swt.widgets.Display; |
|
40 |
import org.eclipse.swt.widgets.Label; |
|
41 |
import org.eclipse.swt.widgets.Text; |
|
42 |
import org.eclipse.ui.IMemento; |
|
43 |
|
|
44 |
import eu.etaxonomy.cdm.api.conversation.ConversationHolder; |
|
45 |
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled; |
|
46 |
import eu.etaxonomy.cdm.api.service.config.IFindTaxaAndNamesConfigurator; |
|
47 |
import eu.etaxonomy.cdm.model.common.IdentifiableEntity; |
|
48 |
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache; |
|
49 |
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap; |
|
50 |
import eu.etaxonomy.cdm.persistence.query.MatchMode; |
|
51 |
import eu.etaxonomy.taxeditor.model.AbstractUtility; |
|
52 |
import eu.etaxonomy.taxeditor.model.ContextListenerAdapter; |
|
53 |
import eu.etaxonomy.taxeditor.model.IContextListener; |
|
54 |
import eu.etaxonomy.taxeditor.navigation.NavigationUtil; |
|
55 |
import eu.etaxonomy.taxeditor.navigation.l10n.Messages; |
|
56 |
import eu.etaxonomy.taxeditor.navigation.search.SearchOption; |
|
57 |
import eu.etaxonomy.taxeditor.navigation.search.SearchResultLabelProvider; |
|
58 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
|
59 |
|
|
60 |
/** |
|
61 |
* |
|
62 |
* @author pplitzner |
|
63 |
* @since Sep 27, 2017 |
|
64 |
* |
|
65 |
*/ |
|
66 |
public class SearchResultViewE4 implements IConversationEnabled{ |
|
67 |
|
|
68 |
private static Object[] EMPTY = new Object[0]; |
|
69 |
|
|
70 |
@Inject |
|
71 |
private MPart thisPart; |
|
72 |
|
|
73 |
private class ContextListener extends ContextListenerAdapter{ |
|
74 |
@Override |
|
75 |
public void contextStop(IMemento memento, IProgressMonitor monitor) { |
|
76 |
//close view when workbench closes |
|
77 |
try{ |
|
78 |
thisPart.getContext().get(EPartService.class).hidePart(thisPart); |
|
79 |
} |
|
80 |
catch(Exception e){ |
|
81 |
//nothing |
|
82 |
} |
|
83 |
} |
|
84 |
} |
|
85 |
|
|
86 |
/** Constant <code>ID="eu.etaxonomy.taxeditor.navigation.searc"{trunked}</code> */ |
|
87 |
public static final String ID = |
|
88 |
"eu.etaxonomy.taxeditor.navigation.search.searchResultView"; //$NON-NLS-1$ |
|
89 |
|
|
90 |
private TableViewer resultViewer; |
|
91 |
|
|
92 |
private ConversationHolder conversation; |
|
93 |
|
|
94 |
private Text searchString; |
|
95 |
|
|
96 |
private Text configurationLabel; |
|
97 |
|
|
98 |
private Text status; |
|
99 |
|
|
100 |
private SearchJob searchJob; |
|
101 |
|
|
102 |
private IContextListener contextListener; |
|
103 |
|
|
104 |
@Inject |
|
105 |
private ESelectionService selService; |
|
106 |
|
|
107 |
private ISelectionChangedListener selectionChangedListener; |
|
108 |
|
|
109 |
/** {@inheritDoc} */ |
|
110 |
@PostConstruct |
|
111 |
public void createPartControl(Composite parent, EMenuService menuService) { |
|
112 |
if (CdmStore.isActive()){ |
|
113 |
if(conversation == null){ |
|
114 |
conversation = getConversation_internal(); |
|
115 |
} |
|
116 |
} |
|
117 |
else{ |
|
118 |
return; |
|
119 |
} |
|
120 |
contextListener = new ContextListener(); |
|
121 |
CdmStore.getContextManager().addContextListener(contextListener); |
|
122 |
|
|
123 |
GridLayout layout = new GridLayout(); |
|
124 |
layout.marginWidth = 0; |
|
125 |
layout.marginHeight = 0; |
|
126 |
|
|
127 |
parent.setLayout(layout); |
|
128 |
|
|
129 |
Composite infoComposite = createInfoComposite(parent); |
|
130 |
infoComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); |
|
131 |
|
|
132 |
resultViewer = new TableViewer(parent, SWT.NONE); |
|
133 |
resultViewer.setContentProvider(new ArrayContentProvider()); |
|
134 |
resultViewer.setLabelProvider(new SearchResultLabelProvider()); |
|
135 |
resultViewer.addDoubleClickListener(new IDoubleClickListener() { |
|
136 |
@Override |
|
137 |
public void doubleClick(DoubleClickEvent event) { |
|
138 |
ISelection selection = event.getSelection(); |
|
139 |
if(selection instanceof IStructuredSelection){ |
|
140 |
Object firstElement = ((IStructuredSelection) selection).getFirstElement(); |
|
141 |
if(firstElement instanceof UuidAndTitleCache){ |
|
142 |
NavigationUtil.openEditor((UuidAndTitleCache) firstElement); |
|
143 |
} |
|
144 |
} |
|
145 |
} |
|
146 |
}); |
|
147 |
|
|
148 |
resultViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); |
|
149 |
|
|
150 |
//propagate selection |
|
151 |
selectionChangedListener = (event -> selService.setSelection(AbstractUtility.getElementsFromSelectionChangedEvent(event))); |
|
152 |
resultViewer.addSelectionChangedListener(selectionChangedListener); |
|
153 |
|
|
154 |
//create context menu |
|
155 |
menuService.registerContextMenu(resultViewer.getControl(), "eu.etaxonomy.taxeditor.navigation.popupmenu.searchresults"); |
|
156 |
|
|
157 |
} |
|
158 |
|
|
159 |
private Composite createInfoComposite(Composite parent){ |
|
160 |
Composite composite = new Composite(parent, SWT.NULL); |
|
161 |
|
|
162 |
composite.setLayout(new GridLayout(2, false)); |
|
163 |
|
|
164 |
Label searchStringLabel = new Label(composite, SWT.NULL); |
|
165 |
searchStringLabel.setText(Messages.SearchResultView_SEARCH_STRING); |
|
166 |
|
|
167 |
searchString = new Text(composite, SWT.NULL); |
|
168 |
searchString.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); |
|
169 |
searchString.setEditable(false); |
|
170 |
// searchString.setText(" "); |
|
171 |
|
|
172 |
Label configurationDescriptionLabel = new Label(composite, SWT.NULL); |
|
173 |
configurationDescriptionLabel.setText(Messages.SearchResultView_SEARCH_FOR); |
|
174 |
|
|
175 |
configurationLabel = new Text(composite, SWT.WRAP); |
|
176 |
configurationLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); |
|
177 |
configurationLabel.setEditable(false); |
|
178 |
|
|
179 |
Label statusLabel = new Label(composite, SWT.NULL); |
|
180 |
statusLabel.setText(Messages.SearchResultView_STATUS); |
|
181 |
|
|
182 |
status = new Text(composite, SWT.NULL); |
|
183 |
status.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); |
|
184 |
status.setEditable(false); |
|
185 |
|
|
186 |
return composite; |
|
187 |
} |
|
188 |
|
|
189 |
/** |
|
190 |
* <p>performSearch</p> |
|
191 |
* |
|
192 |
* @param configurator a {@link eu.etaxonomy.cdm.api.service.config.ITaxonServiceConfigurator} object. |
|
193 |
*/ |
|
194 |
public void performSearch(IFindTaxaAndNamesConfigurator configurator){ |
|
195 |
thisPart.setLabel(String.format(Messages.SearchResultView_SEARCH, configurator.getTitleSearchString())); |
|
196 |
|
|
197 |
searchString.setText(configurator.getTitleSearchString()); |
|
198 |
|
|
199 |
List<String> includedEntities = new ArrayList<String>(); |
|
200 |
if(configurator.isDoTaxa()) { |
|
201 |
includedEntities.add(SearchOption.TAXON.getLabel()); |
|
202 |
} |
|
203 |
if(configurator.isDoSynonyms()) { |
|
204 |
includedEntities.add(SearchOption.SYNONYM.getLabel()); |
|
205 |
} |
|
206 |
if(configurator.isDoNamesWithoutTaxa()) { |
|
207 |
includedEntities.add(SearchOption.NAME.getLabel()); |
|
208 |
} |
|
209 |
if(configurator.isDoTaxaByCommonNames()){ |
|
210 |
includedEntities.add(SearchOption.COMMON_NAME.getLabel()); |
|
211 |
} |
|
212 |
configurator.setMatchMode(MatchMode.LIKE); |
|
213 |
|
|
214 |
String includedEntitiesString = ""; //$NON-NLS-1$ |
|
215 |
for (int i = 0; i < includedEntities.size(); i++){ |
|
216 |
includedEntitiesString += includedEntities.get(i); |
|
217 |
if(i < includedEntities.size() -1){ |
|
218 |
includedEntitiesString += ", "; //$NON-NLS-1$ |
|
219 |
} |
|
220 |
} |
|
221 |
|
|
222 |
configurationLabel.setText(includedEntitiesString); |
|
223 |
|
|
224 |
status.setText(Messages.SearchResultView_SEARCHING); |
|
225 |
|
|
226 |
searchJob = new SearchJob(Display.getCurrent(), configurator); |
|
227 |
searchJob.schedule(); |
|
228 |
|
|
229 |
} |
|
230 |
|
|
231 |
/** |
|
232 |
* <p>displaySearchResult</p> |
|
233 |
* |
|
234 |
* @param result a {@link java.util.List} object. |
|
235 |
*/ |
|
236 |
protected void displaySearchResult(List<UuidAndTitleCache<IdentifiableEntity>> result) { |
|
237 |
if(result.size() > 0){ |
|
238 |
resultViewer.setInput(result); |
|
239 |
status.setText(String.format(Messages.SearchResultView_CNT_ENTITIES_FOUND, result.size())); |
|
240 |
}else{ |
|
241 |
resultViewer.setInput(EMPTY); |
|
242 |
status.setText(Messages.SearchResultView_NO_RESULTS); |
|
243 |
} |
|
244 |
} |
|
245 |
|
|
246 |
/** {@inheritDoc} */ |
|
247 |
@Focus |
|
248 |
public void setFocus() { |
|
249 |
//logger.warn("Setting focus to search result viewer"); |
|
250 |
ConversationHolder conversation_internal = getConversation_internal(); |
|
251 |
if(conversation_internal!=null){ |
|
252 |
conversation_internal.bind(); |
|
253 |
} |
|
254 |
// pass focus to resultViewer |
|
255 |
resultViewer.getControl().setFocus(); |
|
256 |
} |
|
257 |
|
|
258 |
/** |
|
259 |
* <p>getConversationHolder</p> |
|
260 |
* |
|
261 |
* @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object. |
|
262 |
*/ |
|
263 |
@Override |
|
264 |
public ConversationHolder getConversationHolder() { |
|
265 |
return this.conversation; |
|
266 |
} |
|
267 |
|
|
268 |
/** {@inheritDoc} */ |
|
269 |
@Override |
|
270 |
public void update(CdmDataChangeMap changeEvents) { |
|
271 |
// TODO Auto-generated method stub |
|
272 |
|
|
273 |
} |
|
274 |
|
|
275 |
/** {@inheritDoc} */ |
|
276 |
@PreDestroy |
|
277 |
public void dispose() { |
|
278 |
if(conversation!=null){ |
|
279 |
conversation.close(); |
|
280 |
} |
|
281 |
if(searchJob != null) { |
|
282 |
searchJob.cancel(); |
|
283 |
} |
|
284 |
CdmStore.getContextManager().removeContextListener(contextListener); |
|
285 |
} |
|
286 |
|
|
287 |
private ConversationHolder getConversation_internal(){ |
|
288 |
if(conversation==null && CdmStore.isActive()){ |
|
289 |
try { |
|
290 |
conversation = CdmStore.createConversation(); |
|
291 |
} catch (Exception e) { |
|
292 |
//nothing |
|
293 |
} |
|
294 |
} |
|
295 |
return conversation; |
|
296 |
} |
|
297 |
|
|
298 |
/** |
|
299 |
* |
|
300 |
* @author n.hoffmann |
|
301 |
* @created Feb 2, 2010 |
|
302 |
* @version 1.0 |
|
303 |
*/ |
|
304 |
class SearchJob extends Job{ |
|
305 |
|
|
306 |
private final IFindTaxaAndNamesConfigurator configurator; |
|
307 |
|
|
308 |
private final Display display; |
|
309 |
|
|
310 |
/** |
|
311 |
* @param name |
|
312 |
*/ |
|
313 |
public SearchJob(Display display, IFindTaxaAndNamesConfigurator configurator) { |
|
314 |
super(Messages.SearchResultView_PERFORMING_SEARCH); |
|
315 |
this.display = display; |
|
316 |
this.configurator = configurator; |
|
317 |
} |
|
318 |
|
|
319 |
@Override |
|
320 |
protected IStatus run(IProgressMonitor monitor) { |
|
321 |
monitor.beginTask("", 100); //$NON-NLS-1$ |
|
322 |
monitor.worked(20); |
|
323 |
|
|
324 |
final List<UuidAndTitleCache<IdentifiableEntity>> searchResult = CdmStore.getSearchManager().findTaxaAndNames(configurator); |
|
325 |
monitor.worked(40); |
|
326 |
|
|
327 |
if(! monitor.isCanceled()){ |
|
328 |
display.asyncExec(new Runnable() { |
|
329 |
@Override |
|
330 |
public void run() { |
|
331 |
displaySearchResult(searchResult); |
|
332 |
} |
|
333 |
}); |
|
334 |
}else{ |
|
335 |
display.asyncExec(new Runnable() { |
|
336 |
@Override |
|
337 |
public void run() { |
|
338 |
status.setText(Messages.SearchResultView_CANCELLED); |
|
339 |
} |
|
340 |
}); |
|
341 |
} |
|
342 |
monitor.done(); |
|
343 |
return Status.OK_STATUS; |
|
344 |
} |
|
345 |
|
|
346 |
} |
|
347 |
} |
Also available in: Unified diff
fix #6990 Migrate search result view