fix #5837: fix the filter of the selection dialog of nomenclatural reference and...
authorKatja Luther <k.luther@bgbm.org>
Mon, 12 Sep 2016 12:57:11 +0000 (14:57 +0200)
committerKatja Luther <k.luther@bgbm.org>
Mon, 12 Sep 2016 13:01:30 +0000 (15:01 +0200)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/NomenclaturalAuthorSelectionDialog.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/NomenclaturalReferenceSelectionDialog.java

index e47346ab12311235f834656b9b559316e5ed0303..cc4c1f049a4e9f8b1ba4d481fc558fe04238b5ad 100644 (file)
@@ -11,6 +11,9 @@ package eu.etaxonomy.taxeditor.ui.dialog.selection;
 
 
 
 
 
 
+import java.text.Collator;
+import java.util.Comparator;
+
 import org.eclipse.core.runtime.Assert;
 import org.eclipse.core.runtime.ListenerList;
 import org.eclipse.jface.viewers.IColorProvider;
 import org.eclipse.core.runtime.Assert;
 import org.eclipse.core.runtime.ListenerList;
 import org.eclipse.jface.viewers.IColorProvider;
@@ -49,6 +52,7 @@ import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 import eu.etaxonomy.taxeditor.ui.dialog.selection.AbstractFilteredCdmResourceSelectionDialog.FilteredCdmResourceLabelProvider;
 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 import eu.etaxonomy.taxeditor.ui.dialog.selection.AbstractFilteredCdmResourceSelectionDialog.FilteredCdmResourceLabelProvider;
+import eu.etaxonomy.taxeditor.ui.dialog.selection.CdmFilteredItemsSelectionDialog.ItemsFilter;
 import eu.etaxonomy.taxeditor.ui.dialog.selection.CdmFilteredItemsSelectionDialog.ItemsListSeparator;
 
 /**
 import eu.etaxonomy.taxeditor.ui.dialog.selection.CdmFilteredItemsSelectionDialog.ItemsListSeparator;
 
 /**
@@ -161,5 +165,50 @@ public class NomenclaturalAuthorSelectionDialog extends AgentSelectionDialog {
             return abbrevTitleCache;
                }
        };
             return abbrevTitleCache;
                }
        };
+       
+       /** {@inheritDoc} */
+       @Override
+       protected ItemsFilter createFilter() {
+               return new ItemsFilter() {
+
+                       /**
+                        * Always returns false to enforce refiltering even if the pattern is equal
+                        */
+                       @Override
+                       public boolean equalsFilter(ItemsFilter filter) {
+                               return false;
+                       }
+
+                       @Override
+                       public boolean isConsistentItem(Object item) {
+                               return false;
+                       }
+
+                       @Override
+                       public boolean matchItem(Object item) {
+                               String text = null;
+                               if(item instanceof UuidAndTitleCache){
+                                       text = ((UuidAndTitleCache) item).getAbbrevTitleCache();
+                               }else if(item instanceof String){
+                                       text = (String) item;
+                               }
+                               return text != null ? matches(text) : false;
+                       }
+
+               };
+       }
+       
+       @Override
+       protected Comparator getItemsComparator() {
+               return new Comparator<UuidAndTitleCache>() {
+                       @Override
+                       public int compare(UuidAndTitleCache entity1,
+                                       UuidAndTitleCache entity2) {
+                               Collator collator = Collator.getInstance();
+                               return collator.compare(entity1.getAbbrevTitleCache(), entity2.getAbbrevTitleCache());
+                       }
+               };
+       }
+
 
 }
 
 }
index 797b3c2dde89bfd45a01ed22c1c4efc088a25cee..68cf6fe8b2a596562902c13702956e06c775f371 100755 (executable)
@@ -1,5 +1,8 @@
 package eu.etaxonomy.taxeditor.ui.dialog.selection;
 
 package eu.etaxonomy.taxeditor.ui.dialog.selection;
 
+import java.text.Collator;
+import java.util.Comparator;
+
 import org.eclipse.core.runtime.Assert;
 import org.eclipse.core.runtime.ListenerList;
 import org.eclipse.jface.viewers.IColorProvider;
 import org.eclipse.core.runtime.Assert;
 import org.eclipse.core.runtime.ListenerList;
 import org.eclipse.jface.viewers.IColorProvider;
@@ -111,7 +114,11 @@ public class NomenclaturalReferenceSelectionDialog extends
                        public boolean matchItem(Object item) {
                                String text = null;
                                if(item instanceof UuidAndTitleCache){
                        public boolean matchItem(Object item) {
                                String text = null;
                                if(item instanceof UuidAndTitleCache){
-                                       text = ((UuidAndTitleCache) item).getAbbrevTitleCache();
+                                       if (((UuidAndTitleCache) item).getAbbrevTitleCache() != null){
+                                               text = ((UuidAndTitleCache) item).getAbbrevTitleCache();
+                                       } else{
+                                               text = ((UuidAndTitleCache) item).getTitleCache();
+                                       }
                                }else if(item instanceof String){
                                        text = (String) item;
                                }
                                }else if(item instanceof String){
                                        text = (String) item;
                                }
@@ -132,6 +139,9 @@ public class NomenclaturalReferenceSelectionDialog extends
                        UuidAndTitleCache uuidAndTitleCache = (UuidAndTitleCache) element;
                        String titleCache = uuidAndTitleCache.getTitleCache();
                        String abbrevTitleCache = uuidAndTitleCache.getAbbrevTitleCache();
                        UuidAndTitleCache uuidAndTitleCache = (UuidAndTitleCache) element;
                        String titleCache = uuidAndTitleCache.getTitleCache();
                        String abbrevTitleCache = uuidAndTitleCache.getAbbrevTitleCache();
+                       if (abbrevTitleCache == null){
+                               abbrevTitleCache = "no abbrev title available";
+                       }
                        abbrevTitleCache += " - " + titleCache;
                        if(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_ID_IN_ENTITY_SELECTION_DIAOLOG)){
                                abbrevTitleCache += " ["+uuidAndTitleCache.getId()+"]";
                        abbrevTitleCache += " - " + titleCache;
                        if(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_ID_IN_ENTITY_SELECTION_DIAOLOG)){
                                abbrevTitleCache += " ["+uuidAndTitleCache.getId()+"]";
@@ -139,6 +149,30 @@ public class NomenclaturalReferenceSelectionDialog extends
             return abbrevTitleCache;
                }
        };
             return abbrevTitleCache;
                }
        };
+       
+       @Override
+       protected Comparator getItemsComparator() {
+               return new Comparator<UuidAndTitleCache>() {
+                       @Override
+                       public int compare(UuidAndTitleCache entity1,
+                                       UuidAndTitleCache entity2) {
+                               Collator collator = Collator.getInstance();
+                               String compareString1 = null;
+                               if (entity1.getAbbrevTitleCache() == null){
+                                       compareString1 = entity1.getTitleCache();
+                               }else{
+                                       compareString1 = entity1.getAbbrevTitleCache();
+                               }
+                               String compareString2 = null;
+                               if (entity2.getAbbrevTitleCache() == null){
+                                       compareString2 = entity2.getTitleCache();
+                               }else{
+                                       compareString2 = entity2.getAbbrevTitleCache();
+                               }
+                               return collator.compare(compareString1, compareString2);
+                       }
+               };
+       }