- added a flag to force also searching for FieldUnits when searching occurrences
authorPatric Plitzner <p.plitzner@bgbm.org>
Mon, 16 Dec 2013 14:07:52 +0000 (14:07 +0000)
committerPatric Plitzner <p.plitzner@bgbm.org>
Mon, 16 Dec 2013 14:07:52 +0000 (14:07 +0000)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/SearchManager.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/campanula/derivatesearch/DerivateSearchCompositeController.java

index 28c6cc18e0a37a772941f6e4b92e34536fffdc58..4da136f4e01ac4c9982f05822cc5cc8dd09334e9 100644 (file)
@@ -1,9 +1,9 @@
 // $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.
 */
@@ -47,16 +47,16 @@ import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
  * @version 1.0
  */
 public class SearchManager {
-       
+
        public static final List NO_RESULTS = Arrays.asList(new Object[]{});
-       
+
        public static final String WILDCARD = "*";
-       
+
        public static int NO_COUNT = -1;
-       
+
        // TODO make this configurable via preferences
-       private static final int MAX_RESULTS_BEFORE_WARNING = 500; 
-       
+       private static final int MAX_RESULTS_BEFORE_WARNING = 500;
+
        /**
         * <p>findNames</p>
         *
@@ -69,25 +69,25 @@ public class SearchManager {
                }
                return NO_RESULTS;
        }
-       
+
        public List<NameRelationship> findNameRelationships(
                        IIdentifiableEntityServiceConfigurator configurator) {
                if(true){
                        return NO_RESULTS;
                }
-               
-               List<NameRelationship> relationships = new ArrayList<NameRelationship>(); 
+
+               List<NameRelationship> relationships = new ArrayList<NameRelationship>();
                List<RelationshipBase> all = CdmStore.getService(INameService.class).getAllRelationships(0, 0);
-               
+
                for (RelationshipBase relationship : all){
                        if(relationship instanceof NameRelationship){
                                relationships.add((NameRelationship) relationship);
                        }
                }
-               
-               
+
+
                return relationships;
-               
+
        }
 
        /**
@@ -99,8 +99,8 @@ public class SearchManager {
        public List<UuidAndTitleCache<TaxonBase>> findTaxaAndNames(IFindTaxaAndNamesConfigurator<TaxonBase> configurator){
                return CdmStore.getService(ITaxonService.class).findTaxaAndNamesForEditor(configurator);
        }
-       
-       
+
+
        /**
         * <p>findReferences</p>
         *
@@ -113,8 +113,8 @@ public class SearchManager {
                }
                return NO_RESULTS;
        }
-       
-       
+
+
        /**
         * <p>findAgents</p>
         *
@@ -138,17 +138,32 @@ public class SearchManager {
                configurator.setClazz(TeamOrPersonBase.class);
                return findAgents(configurator);
        }
-       
-       
+
        /**
-        * <p>findOccurrences</p>
+        * Searches for {@link SpecimenOrObservationBase} with the parameters specified in the
+        * {@link IIdentifiableEntityServiceConfigurator}<br>
+        * <br>
+        * Note: FieldUnits are omitted by default. See {@link #findOccurrences(IIdentifiableEntityServiceConfigurator, boolean)}
         *
-        * @param configurator a {@link eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator} object.
-        * @return a {@link java.util.List} object.
+        * @param configurator the configurator to use for the search
+        * @return a list of the SpecimenOrObservationBases found
         */
        public List<SpecimenOrObservationBase> findOccurrences(IIdentifiableEntityServiceConfigurator configurator){
-               // by default we do not show field units. This may be configured via preferences
-               boolean showFieldUnits = PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.BULK_EDITOR_OCCURRENCE_SHOW_FIELD_UNITS);
+           // by default we do not show field units. This may be configured via preferences
+           return findOccurrences(configurator, PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.BULK_EDITOR_OCCURRENCE_SHOW_FIELD_UNITS));
+       }
+
+
+       /**
+        * Searches for {@link SpecimenOrObservationBase} with the parameters specified in the
+        * {@link IIdentifiableEntityServiceConfigurator}
+        *
+        * @param configurator the configurator to use for the search
+        * @return a list of the SpecimenOrObservationBases found
+        * @param showFieldUnits if <code>true</code> then also FieldUnits are searched
+        * @return
+        */
+       public List<SpecimenOrObservationBase> findOccurrences(IIdentifiableEntityServiceConfigurator configurator, boolean showFieldUnits){
                if(! showFieldUnits){
                        configurator.setClazz(DerivedUnit.class);
                }
@@ -157,38 +172,38 @@ public class SearchManager {
                }
                return NO_RESULTS;
        }
-       
-       
+
+
        public List<User> findUsers(IIdentifiableEntityServiceConfigurator configurator){
                String userNameSearchString = sqlizeTitleSearchString(configurator);
                // TODO why are users not identifiable entities?
                return CdmStore.getService(IUserService.class).listByUsername(userNameSearchString, null, null, null, null, null, null);
        }
-       
-       
+
+
        public List<Group> findGroups(IIdentifiableEntityServiceConfigurator configurator){
                String groupNameSearchString = sqlizeTitleSearchString(configurator);
                // TODO why are groups not identifiable entities?
                return CdmStore.getService(IGroupService.class).listByName(groupNameSearchString, null, null, null, null, null, null);
        }
-       
-       
+
+
        /**
         * @param count
         * @return
         */
        private boolean checkLargeResult(int count) {
                if(count > MAX_RESULTS_BEFORE_WARNING){
-                       return MessageDialog.openConfirm(Display.getDefault().getActiveShell(), "Large result expected", 
+                       return MessageDialog.openConfirm(Display.getDefault().getActiveShell(), "Large result expected",
                                        String.format("The current search will return %s objects. This will " +
                                                        "take a long time and/or might render the editor unusable. Please consider refining your search.", count));
                }else{
                        return true;
-               }               
+               }
        }
-       
+
        /**
-        * 
+        *
         * @param configurator
         * @return
         */
index 464389dd990024bfcec03e3bf042284f10aba328..03c09b4f463ae6a1b5c5030a5968d8cd8b07f3b3 100644 (file)
@@ -108,7 +108,7 @@ public class DerivateSearchCompositeController {
 
     private void searchDerivates(String searchString){
         configurator.setTitleSearchString(searchString);
-        List<SpecimenOrObservationBase> results = CdmStore.getSearchManager().findOccurrences(configurator);
+        List<SpecimenOrObservationBase> results = CdmStore.getSearchManager().findOccurrences(configurator, true);
         derivateSearchComposite.getResultViewer().setInput(results);
     }