Revision fe515a88
Added by Patrick Plitzner over 8 years ago
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/search/SearchBar.java | ||
---|---|---|
10 | 10 |
|
11 | 11 |
package eu.etaxonomy.taxeditor.navigation.search; |
12 | 12 |
|
13 |
import org.eclipse.core.runtime.IProgressMonitor; |
|
13 | 14 |
import org.eclipse.swt.SWT; |
14 | 15 |
import org.eclipse.swt.events.FocusEvent; |
15 | 16 |
import org.eclipse.swt.events.FocusListener; |
... | ... | |
27 | 28 |
import org.eclipse.swt.widgets.Text; |
28 | 29 |
import org.eclipse.swt.widgets.ToolBar; |
29 | 30 |
import org.eclipse.swt.widgets.ToolItem; |
31 |
import org.eclipse.ui.IMemento; |
|
30 | 32 |
import org.eclipse.ui.IViewPart; |
31 | 33 |
import org.eclipse.ui.IWorkbenchPage; |
32 | 34 |
import org.eclipse.ui.PartInitException; |
... | ... | |
35 | 37 |
import org.eclipse.ui.swt.IFocusService; |
36 | 38 |
|
37 | 39 |
import eu.etaxonomy.cdm.api.service.config.IFindTaxaAndNamesConfigurator; |
40 |
import eu.etaxonomy.taxeditor.model.AbstractUtility; |
|
41 |
import eu.etaxonomy.taxeditor.model.IContextListener; |
|
38 | 42 |
import eu.etaxonomy.taxeditor.model.MessagingUtils; |
39 |
import eu.etaxonomy.taxeditor.navigation.NavigationUtil; |
|
40 | 43 |
import eu.etaxonomy.taxeditor.navigation.internal.TaxeditorNavigationPlugin; |
41 | 44 |
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys; |
42 | 45 |
import eu.etaxonomy.taxeditor.preference.PreferencesUtil; |
43 | 46 |
import eu.etaxonomy.taxeditor.preference.Resources; |
47 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
|
44 | 48 |
|
45 | 49 |
/** |
46 |
* <p>SearchBar class.</p> |
|
47 |
* |
|
48 | 50 |
* @author n.hoffmann |
49 | 51 |
* @author e.-m.lee |
50 | 52 |
* @created 15.04.2009 |
51 | 53 |
* @version 1.0 |
52 | 54 |
*/ |
53 |
public class SearchBar extends WorkbenchWindowControlContribution{ |
|
55 |
public class SearchBar extends WorkbenchWindowControlContribution implements IContextListener{
|
|
54 | 56 |
private Text text_search; |
55 | 57 |
private String secondaryId; |
58 |
private ToolBar toolBar; |
|
56 | 59 |
|
57 | 60 |
private final String defaultText = Messages.SearchBar_0; |
58 | 61 |
|
... | ... | |
67 | 70 |
createSearchTextField(composite); |
68 | 71 |
createToolBar(composite); |
69 | 72 |
registerAtFocusService(); |
73 |
//register for context refreshes |
|
74 |
CdmStore.getContextManager().addContextListener(this); |
|
70 | 75 |
|
71 | 76 |
return composite; |
72 | 77 |
} |
... | ... | |
87 | 92 |
* @param composite |
88 | 93 |
*/ |
89 | 94 |
private void createToolBar(Composite composite) { |
90 |
final ToolBar toolBar = new ToolBar(composite, SWT.NULL);
|
|
95 |
toolBar = new ToolBar(composite, SWT.NULL); |
|
91 | 96 |
|
92 | 97 |
ToolItem toolItem = new ToolItem(toolBar, SWT.DROP_DOWN | SWT.BORDER); |
93 | 98 |
toolItem.setText(Messages.SearchBar_1); |
99 |
toolBar.setEnabled(false); |
|
94 | 100 |
|
95 | 101 |
DropdownSelectionListener dropdownListener = new DropdownSelectionListener( |
96 | 102 |
toolItem); |
... | ... | |
112 | 118 |
// is applied. I am not sure how to get rid of this. |
113 | 119 |
text_search = new Text(composite, SWT.BORDER | SWT.SINGLE |
114 | 120 |
| SWT.FULL_SELECTION); |
115 |
text_search.setForeground(NavigationUtil.getColor(Resources.SEARCH_VIEW_FOREGROUND));
|
|
121 |
text_search.setForeground(AbstractUtility.getColor(Resources.SEARCH_VIEW_FOREGROUND));
|
|
116 | 122 |
text_search.setText(defaultText); |
123 |
text_search.setEnabled(false); |
|
117 | 124 |
|
118 | 125 |
addTextListeners(); |
119 | 126 |
} |
... | ... | |
126 | 133 |
|
127 | 134 |
@Override |
128 | 135 |
public void focusGained(FocusEvent e) { |
129 |
text_search.setForeground(NavigationUtil.getColor(Resources.SEARCH_VIEW_FOCUS));
|
|
136 |
text_search.setForeground(AbstractUtility.getColor(Resources.SEARCH_VIEW_FOCUS));
|
|
130 | 137 |
if (defaultText.equals(text_search.getText())) { |
131 | 138 |
text_search.setText(""); |
132 | 139 |
} |
... | ... | |
135 | 142 |
@Override |
136 | 143 |
public void focusLost(FocusEvent e) { |
137 | 144 |
if (text_search.getText() == "") { |
138 |
text_search.setForeground(NavigationUtil.getColor(Resources.SEARCH_VIEW_FOREGROUND));
|
|
145 |
text_search.setForeground(AbstractUtility.getColor(Resources.SEARCH_VIEW_FOREGROUND));
|
|
139 | 146 |
text_search.setText(defaultText); |
140 | 147 |
} |
141 | 148 |
} |
142 | 149 |
}); |
143 | 150 |
|
144 | 151 |
text_search.addKeyListener(new KeyAdapter() { |
145 |
/* |
|
146 |
* (non-Javadoc) |
|
147 |
* @see org.eclipse.swt.events.KeyAdapter#keyPressed(org.eclipse.swt.events.KeyEvent) |
|
148 |
*/ |
|
149 | 152 |
@Override |
150 | 153 |
public void keyPressed(KeyEvent e) { |
151 | 154 |
if (e.keyCode == SWT.CR) { |
... | ... | |
270 | 273 |
|
271 | 274 |
private IFindTaxaAndNamesConfigurator configurator = PreferencesUtil.getSearchConfigurator(); |
272 | 275 |
|
273 |
/* |
|
274 |
* (non-Javadoc) |
|
275 |
* |
|
276 |
* @see |
|
277 |
* org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse |
|
278 |
* .swt.events.SelectionEvent) |
|
279 |
*/ |
|
280 | 276 |
@Override |
281 | 277 |
public void widgetSelected(SelectionEvent e) { |
282 | 278 |
SearchOption option = (SearchOption) e.widget.getData(); |
... | ... | |
334 | 330 |
|
335 | 331 |
public boolean getPreference() { |
336 | 332 |
if (!PreferencesUtil.getPreferenceStore().contains( |
337 |
PreferencesUtil.TAXON_SERVICE_CONFIGURATOR_TAXA)) {
|
|
333 |
IPreferenceKeys.TAXON_SERVICE_CONFIGURATOR_TAXA)) {
|
|
338 | 334 |
// initializes the search configurator |
339 | 335 |
PreferencesUtil.initializeSearchConfigurator(); |
340 | 336 |
} |
... | ... | |
342 | 338 |
switch (this) { |
343 | 339 |
case TAXON: |
344 | 340 |
boolean result = PreferencesUtil.getPreferenceStore().getBoolean( |
345 |
PreferencesUtil.TAXON_SERVICE_CONFIGURATOR_TAXA);
|
|
341 |
IPreferenceKeys.TAXON_SERVICE_CONFIGURATOR_TAXA);
|
|
346 | 342 |
return result; |
347 | 343 |
case SYNONYM: |
348 | 344 |
return PreferencesUtil.getPreferenceStore().getBoolean( |
349 |
PreferencesUtil.TAXON_SERVICE_CONFIGURATOR_SYNONYMS);
|
|
345 |
IPreferenceKeys.TAXON_SERVICE_CONFIGURATOR_SYNONYMS);
|
|
350 | 346 |
case NAME: |
351 | 347 |
return PreferencesUtil.getPreferenceStore().getBoolean( |
352 |
PreferencesUtil.TAXON_SERVICE_CONFIGURATOR_NAMES);
|
|
348 |
IPreferenceKeys.TAXON_SERVICE_CONFIGURATOR_NAMES);
|
|
353 | 349 |
case COMMON_NAME: |
354 | 350 |
return PreferencesUtil.getPreferenceStore().getBoolean( |
355 |
PreferencesUtil.TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES);
|
|
351 |
IPreferenceKeys.TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES);
|
|
356 | 352 |
} |
357 | 353 |
|
358 | 354 |
return true; |
359 | 355 |
} |
360 | 356 |
|
361 | 357 |
} |
358 |
|
|
359 |
@Override |
|
360 |
public void contextAboutToStop(IMemento memento, IProgressMonitor monitor) { |
|
361 |
} |
|
362 |
|
|
363 |
@Override |
|
364 |
public void contextStop(IMemento memento, IProgressMonitor monitor) { |
|
365 |
if(!text_search.isDisposed()){ |
|
366 |
text_search.setEnabled(false); |
|
367 |
} |
|
368 |
if(!toolBar.isDisposed()){ |
|
369 |
toolBar.setEnabled(false); |
|
370 |
} |
|
371 |
} |
|
372 |
|
|
373 |
@Override |
|
374 |
public void contextStart(IMemento memento, IProgressMonitor monitor) { |
|
375 |
text_search.setEnabled(true); |
|
376 |
toolBar.setEnabled(true); |
|
377 |
} |
|
378 |
|
|
379 |
@Override |
|
380 |
public void contextRefresh(IProgressMonitor monitor) { |
|
381 |
} |
|
382 |
|
|
383 |
@Override |
|
384 |
public void workbenchShutdown(IMemento memento, IProgressMonitor monitor) { |
|
385 |
} |
|
362 | 386 |
} |
Also available in: Unified diff
Disable search bar when not connected to CDM store (#3341)