-// $Id$
/**
* Copyright (C) 2007 EDIT
- * European Distributed Institute of Taxonomy
+ * European Distributed Institute of Taxonomy
* http://www.e-taxonomy.eu
- *
+ *
* The contents of this file are subject to the Mozilla Public License Version 1.1
* See LICENSE.TXT at the top of this package for the full license terms.
*/
package eu.etaxonomy.taxeditor.navigation.search;
+import javax.annotation.PostConstruct;
+
+import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.FocusListener;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
+import org.eclipse.ui.IMemento;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.menus.WorkbenchWindowControlContribution;
import org.eclipse.ui.swt.IFocusService;
import eu.etaxonomy.cdm.api.service.config.IFindTaxaAndNamesConfigurator;
-import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
+import eu.etaxonomy.taxeditor.model.AbstractUtility;
+import eu.etaxonomy.taxeditor.model.IContextListener;
+import eu.etaxonomy.taxeditor.model.MessagingUtils;
import eu.etaxonomy.taxeditor.navigation.internal.TaxeditorNavigationPlugin;
+import eu.etaxonomy.taxeditor.navigation.l10n.Messages;
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
import eu.etaxonomy.taxeditor.preference.Resources;
+import eu.etaxonomy.taxeditor.store.CdmStore;
/**
- * <p>SearchBar class.</p>
- *
* @author n.hoffmann
* @author e.-m.lee
* @created 15.04.2009
* @version 1.0
*/
-public class SearchBar extends WorkbenchWindowControlContribution{
+public class SearchBar implements IContextListener{
private Text text_search;
private String secondaryId;
+ private ToolBar toolBar;
private final String defaultText = Messages.SearchBar_0;
final private ConfigurationSelectionListener configurationListener = new ConfigurationSelectionListener();
/** {@inheritDoc} */
- @Override
+ @PostConstruct
protected Control createControl(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
createSearchTextField(composite);
createToolBar(composite);
registerAtFocusService();
+ //register for context refreshes
+ CdmStore.getContextManager().addContextListener(this);
return composite;
}
* Handles focus changes for the search textfield.
*/
private void registerAtFocusService() {
- IFocusService focusService =
- (IFocusService) PlatformUI.getWorkbench().getService(IFocusService.class);
+ IFocusService focusService =
+ PlatformUI.getWorkbench().getService(IFocusService.class);
if (focusService != null) {
focusService.addFocusTracker(text_search, "navigation.textControlId");
}
* @param composite
*/
private void createToolBar(Composite composite) {
- final ToolBar toolBar = new ToolBar(composite, SWT.NULL);
+ toolBar = new ToolBar(composite, SWT.NULL);
ToolItem toolItem = new ToolItem(toolBar, SWT.DROP_DOWN | SWT.BORDER);
toolItem.setText(Messages.SearchBar_1);
+ toolBar.setEnabled(false);
DropdownSelectionListener dropdownListener = new DropdownSelectionListener(
toolItem);
// is applied. I am not sure how to get rid of this.
text_search = new Text(composite, SWT.BORDER | SWT.SINGLE
| SWT.FULL_SELECTION);
- text_search.setForeground(NavigationUtil.getColor(Resources.SEARCH_VIEW_FOREGROUND));
+ text_search.setForeground(AbstractUtility.getColor(Resources.SEARCH_VIEW_FOREGROUND));
text_search.setText(defaultText);
+ text_search.setEnabled(false);
addTextListeners();
}
private void addTextListeners() {
text_search.addFocusListener(new FocusListener() {
- public void focusGained(FocusEvent e) {
- text_search.setForeground(NavigationUtil.getColor(Resources.SEARCH_VIEW_FOCUS));
+ @Override
+ public void focusGained(FocusEvent e) {
+ text_search.setForeground(AbstractUtility.getColor(Resources.SEARCH_VIEW_FOCUS));
if (defaultText.equals(text_search.getText())) {
text_search.setText("");
}
}
- public void focusLost(FocusEvent e) {
+ @Override
+ public void focusLost(FocusEvent e) {
if (text_search.getText() == "") {
- text_search.setForeground(NavigationUtil.getColor(Resources.SEARCH_VIEW_FOREGROUND));
+ text_search.setForeground(AbstractUtility.getColor(Resources.SEARCH_VIEW_FOREGROUND));
text_search.setText(defaultText);
}
}
});
text_search.addKeyListener(new KeyAdapter() {
- /*
- * (non-Javadoc)
- * @see org.eclipse.swt.events.KeyAdapter#keyPressed(org.eclipse.swt.events.KeyEvent)
- */
@Override
public void keyPressed(KeyEvent e) {
if (e.keyCode == SWT.CR) {
if(searchString == null){
return;
}
-
- if("*".equals(searchString.trim())){
- NavigationUtil.warningDialog(Messages.SearchBar_2, this, Messages.SearchBar_3);
+
+ if(!searchString.trim().matches(".*\\p{L}+.*")){
+ MessagingUtils.warningDialog(Messages.SearchBar_2, this, Messages.SearchBar_3);
return;
}
-
-
+
+
IFindTaxaAndNamesConfigurator configurator = configurationListener.getConfigurator();
configurator.setTitleSearchString(searchString);
openSearchResultsView(configurator);
-
+
}
-
+
private String getSearchString(){
String searchString = text_search.getText().trim();
- if (searchString.equals(defaultText) || searchString.length() == 0)
- return null;
+ if (searchString.equals(defaultText) || searchString.length() == 0) {
+ return null;
+ }
return searchString;
}
-
+
/**
* Opens a new instance of the search result view to display the result to the user.
- *
+ *
* @param searchResult
*/
private void openSearchResultsView(IFindTaxaAndNamesConfigurator configurator) {
boolean openResultInSeparateWindows = PreferencesUtil.getPreferenceStore().getBoolean((IPreferenceKeys.SEARCH_OPEN_RESULTS_IN_SEPARATE_WINDOWS));
if(openResultInSeparateWindows){
- //increment change secondary id so it is unique
+ //increment change secondary id so it is unique
secondaryId += "1";
}
IWorkbenchPage.VIEW_ACTIVATE);
((SearchResultView) resultsView).performSearch(configurator);
} catch (PartInitException e) {
- NavigationUtil.error(this.getClass(), Messages.SearchBar_4, e);
+ MessagingUtils.error(this.getClass(), Messages.SearchBar_4, e);
}
}
/**
* Handles drop down menu selection. Available items are defined in the enumeration SearchOption.
- *
+ *
* @author n.hoffmann
* @created Feb 2, 2010
* @version 1.0
/**
* Handles search configuration selection.
- *
+ *
* @author n.hoffmann
* @created Feb 2, 2010
* @version 1.0
class ConfigurationSelectionListener extends SelectionAdapter {
private IFindTaxaAndNamesConfigurator configurator = PreferencesUtil.getSearchConfigurator();
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse
- * .swt.events.SelectionEvent)
- */
+
@Override
public void widgetSelected(SelectionEvent e) {
- NavigationUtil.info(Messages.SearchBar_5);
SearchOption option = (SearchOption) e.widget.getData();
switch (option){
break;
case COMMON_NAME:
configurator.setDoTaxaByCommonNames(getConfigurator().isDoTaxaByCommonNames() ? false : true);
- break;
+ break;
}
-
+
saveConfigurator();
}
/**
* Available search options.
- *
+ *
* @author n.hoffmann
* @created Feb 2, 2010
* @version 1.0
*/
enum SearchOption {
- TAXON(Messages.SearchBar_6),
- SYNONYM(Messages.SearchBar_7),
- NAME(Messages.SearchBar_8),
+ TAXON(Messages.SearchBar_6),
+ SYNONYM(Messages.SearchBar_7),
+ NAME(Messages.SearchBar_8),
COMMON_NAME(Messages.SearchBar_9);
private final String label;
public boolean getPreference() {
if (!PreferencesUtil.getPreferenceStore().contains(
- PreferencesUtil.TAXON_SERVICE_CONFIGURATOR_TAXA)) {
+ IPreferenceKeys.TAXON_SERVICE_CONFIGURATOR_TAXA)) {
// initializes the search configurator
PreferencesUtil.initializeSearchConfigurator();
}
switch (this) {
case TAXON:
boolean result = PreferencesUtil.getPreferenceStore().getBoolean(
- PreferencesUtil.TAXON_SERVICE_CONFIGURATOR_TAXA);
+ IPreferenceKeys.TAXON_SERVICE_CONFIGURATOR_TAXA);
return result;
case SYNONYM:
return PreferencesUtil.getPreferenceStore().getBoolean(
- PreferencesUtil.TAXON_SERVICE_CONFIGURATOR_SYNONYMS);
+ IPreferenceKeys.TAXON_SERVICE_CONFIGURATOR_SYNONYMS);
case NAME:
return PreferencesUtil.getPreferenceStore().getBoolean(
- PreferencesUtil.TAXON_SERVICE_CONFIGURATOR_NAMES);
+ IPreferenceKeys.TAXON_SERVICE_CONFIGURATOR_NAMES);
case COMMON_NAME:
return PreferencesUtil.getPreferenceStore().getBoolean(
- PreferencesUtil.TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES);
+ IPreferenceKeys.TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES);
}
return true;
}
}
+
+ @Override
+ public void contextAboutToStop(IMemento memento, IProgressMonitor monitor) {
+ }
+
+ @Override
+ public void contextStop(IMemento memento, IProgressMonitor monitor) {
+ if(!text_search.isDisposed()){
+ text_search.setEnabled(false);
+ }
+ if(!toolBar.isDisposed()){
+ toolBar.setEnabled(false);
+ }
+ }
+
+ @Override
+ public void contextStart(IMemento memento, IProgressMonitor monitor) {
+ text_search.setEnabled(true);
+ toolBar.setEnabled(true);
+ }
+
+ @Override
+ public void contextRefresh(IProgressMonitor monitor) {
+ }
+
+ @Override
+ public void workbenchShutdown(IMemento memento, IProgressMonitor monitor) {
+ }
}