+
+ class DropdownSelectionListener extends SelectionAdapter {
+
+ private Menu menu;
+
+ public DropdownSelectionListener(ToolItem dropdown) {
+ menu = new Menu(dropdown.getParent().getShell());
+ }
+
+ public void add(SearchOption option) {
+ MenuItem menuItem = new MenuItem(menu, SWT.CHECK);
+ menuItem.setData(option);
+ menuItem.setText(option.getLabel());
+ menuItem.setSelection(option.getPreference());
+ menuItem.addSelectionListener(configurationListener);
+ }
+
+ public void widgetSelected(SelectionEvent event) {
+ if (event.detail == SWT.ARROW) {
+ ToolItem item = (ToolItem) event.widget;
+ Rectangle rect = item.getBounds();
+ Point pt = item.getParent().toDisplay(new Point(rect.x, rect.y));
+ menu.setLocation(pt.x, pt.y + rect.height);
+ menu.setVisible(true);
+ } else {
+ openSearchResultsView();
+ }
+ }
+ }
+
+ class ConfigurationSelectionListener extends SelectionAdapter{
+
+ ITaxonServiceConfigurator configurator;
+
+ /* (non-Javadoc)
+ * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
+ */
+ public void widgetSelected(SelectionEvent e) {
+ logger.warn("configuration menu clicked");
+ SearchOption option = (SearchOption) e.widget.getData();
+
+ if(option == SearchOption.TAXON){
+ getConfigurator().setDoTaxa(configurator.isDoTaxa() ? false : true);
+ }
+
+ if(option == SearchOption.SYNONYM){
+ getConfigurator().setDoSynonyms(configurator.isDoSynonyms() ? false : true);
+ }
+
+ if(option == SearchOption.NAME){
+ getConfigurator().setDoNamesWithoutTaxa(configurator.isDoNamesWithoutTaxa() ? false : true);
+ }
+
+ if(option == SearchOption.COMMON_NAME){
+ getConfigurator().setDoTaxaByCommonNames(configurator.isDoTaxaByCommonNames() ? false : true);
+ }
+ saveConfigurator();
+ }
+
+ public ITaxonServiceConfigurator getConfigurator(){
+ if(configurator == null){
+ configurator = PreferencesUtil.getSearchConfigurator();
+ }
+ return configurator;
+ }
+
+ private void saveConfigurator(){
+ PreferencesUtil.setSearchConfigurator(configurator);
+ this.configurator = PreferencesUtil.getSearchConfigurator();
+ }
+ }
+
+ enum SearchOption {
+ TAXON("Taxa"),
+ SYNONYM("Synonyms"),
+ NAME("Names (without taxa)"),
+ COMMON_NAME("Common Names");
+
+ private String label;
+
+ private SearchOption(String label){
+ this.label = label;
+ }
+
+ public String getLabel(){
+ return label;
+ }
+
+ public boolean getPreference(){
+ switch(this){
+ case TAXON:
+ return PreferencesUtil.getPreferenceStore().getBoolean(PreferencesUtil.TAXON_SERVICE_CONFIGURATOR_TAXA);
+ case SYNONYM:
+ return PreferencesUtil.getPreferenceStore().getBoolean(PreferencesUtil.TAXON_SERVICE_CONFIGURATOR_SYNONYMS);
+ case NAME:
+ return PreferencesUtil.getPreferenceStore().getBoolean(PreferencesUtil.TAXON_SERVICE_CONFIGURATOR_NAMES);
+ case COMMON_NAME:
+ return PreferencesUtil.getPreferenceStore().getBoolean(PreferencesUtil.TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES);
+ }
+
+ return true;
+ }
+
+
+
+ }