commit b49b7f6bb0e8c2cff1b058f83a5aeb722476fde5
Author: Katja Luther <k.luther@bgbm.org>
Date:   Wed May 30 16:07:04 2018 +0200

    ref #3984: first implementation for remembering the last selected references in selection dialog

diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/IPreferenceKeys.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/IPreferenceKeys.java
index d83ad54ff..b6fc6f3e3 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/IPreferenceKeys.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/IPreferenceKeys.java
@@ -220,7 +220,7 @@ public interface IPreferenceKeys {
     public static final String SORT_NAMED_AREA_BY_VOCABULARY_ORDER = "eu.etaxonomy.taxeditor.distribution.namedArea.sortByVocabularyOrder";
 
 
-
+    public static final String LAST_SELECTED_REFERENCES = "eu.etaxonomy.taxeditor.references.selection.lastSelected";
 
 
 
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/PreferencesUtil.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/PreferencesUtil.java
index 6c2476a21..096570479 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/PreferencesUtil.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/PreferencesUtil.java
@@ -15,6 +15,7 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -1298,12 +1299,44 @@ public static void setSortNamedAreasByOrderInVocabulary(boolean isSortByVocabula
 
 /**
  * <p>
- * setPreferredNomenclaturalCode
+ * setPreferredNamedAreasForDistributionEditor
  * </p>
  *
- * @param preferredCode
- *            a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode}
- *            object.
+ * @param saveCheckedElements
+ * @param saveGrayedElements
+ */
+public static void setLastSelectedReference(
+        List<String> lastSelectedReferences) {
+
+        IPreferenceStore preferenceStore = PreferencesUtil.getPreferenceStore();
+        preferenceStore.setValue(PreferencesUtil.LAST_SELECTED_REFERENCES, lastSelectedReferences.toString());
+    }
+
+/**
+ * <p>
+ * setPreferredNamedAreasForDistributionEditor
+ * </p>
+ *
+ * @param saveCheckedElements
+ * @param saveGrayedElements
+ */
+public static List<String> getLastSelectedReferences() {
+
+        IPreferenceStore preferenceStore = PreferencesUtil.getPreferenceStore();
+        String lastSelected = preferenceStore.getString(PreferencesUtil.LAST_SELECTED_REFERENCES);
+        List<String> result = new ArrayList<>();
+        Collections.addAll(result, lastSelected.substring(1,lastSelected.length()-1).split(", "));
+        return result;
+    }
+
+
+/**
+ * <p>
+ * setPreferredNamedAreasForDistributionEditor
+ * </p>
+ *
+ * @param saveCheckedElements
+ * @param saveGrayedElements
  */
 public static CdmPreference setPreferredNamedAreasForDistributionEditor(
         String saveCheckedElements, String saveGrayedElements, boolean local) {
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/ReferenceSelectionDialog.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/ReferenceSelectionDialog.java
index 6a9506fed..24605f43d 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/ReferenceSelectionDialog.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/ReferenceSelectionDialog.java
@@ -9,15 +9,21 @@
 
 package eu.etaxonomy.taxeditor.ui.dialog.selection;
 
+import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 import java.util.UUID;
 
+import org.apache.commons.lang.StringUtils;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.SelectionAdapter;
 import org.eclipse.swt.events.SelectionEvent;
 import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
 
 import eu.etaxonomy.cdm.api.service.IReferenceService;
 import eu.etaxonomy.cdm.api.service.dto.IdentifiedEntityDTO;
@@ -25,6 +31,7 @@ import eu.etaxonomy.cdm.model.reference.Reference;
 import eu.etaxonomy.cdm.persistence.query.MatchMode;
 import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard;
 import eu.etaxonomy.taxeditor.newWizard.NewReferenceWizard;
+import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 
 /**
@@ -38,6 +45,7 @@ public class ReferenceSelectionDialog extends AbstractFilteredCdmResourceSelecti
 
     protected static boolean isInReference = false;
     private Reference currentReference;
+    List<String> lastSelectedReferences = null;
 
 	/**
 	 * <p>select</p>
@@ -117,6 +125,17 @@ public class ReferenceSelectionDialog extends AbstractFilteredCdmResourceSelecti
 	/** {@inheritDoc} */
 	@Override
 	protected Reference getPersistentObject(UUID cdmUuid) {
+	    if (lastSelectedReferences == null){
+	        lastSelectedReferences = new ArrayList<>();
+	    }
+	    if (lastSelectedReferences.size()<6){
+	        lastSelectedReferences.add(cdmUuid.toString());
+	    }else{
+	        lastSelectedReferences.remove(0);
+	        lastSelectedReferences.add(cdmUuid.toString());
+	    }
+
+	    PreferencesUtil.setLastSelectedReference(lastSelectedReferences);
 		return CdmStore.getService(IReferenceService.class).load(cdmUuid);
 	}
 
@@ -127,7 +146,15 @@ public class ReferenceSelectionDialog extends AbstractFilteredCdmResourceSelecti
 	@Override
 	protected void callService(String pattern) {
 
-        if (isInReference && currentReference != null){
+	    if (StringUtils.isBlank(pattern) && lastSelectedReferences == null){
+	        lastSelectedReferences = PreferencesUtil.getLastSelectedReferences();
+	        Set<UUID> uuids = new HashSet<>();
+	        for (String uuidString: lastSelectedReferences){
+	            uuids.add(UUID.fromString(uuidString));
+	        }
+	        model = CdmStore.getService(IReferenceService.class).getUuidAndTitleCacheForUUIDS(uuids);
+
+	    } else if (isInReference && currentReference != null){
 
             if (isUseIdentifier()){
                 List<IdentifiedEntityDTO<Reference>> list = CdmStore.getService(IReferenceService.class).listByIdentifierAbbrev(pattern, null, MatchMode.BEGINNING, limitOfInitialElements);
@@ -196,4 +223,17 @@ public class ReferenceSelectionDialog extends AbstractFilteredCdmResourceSelecti
 		return new String[]{"New Reference"};
 	}
 
+	/** {@inheritDoc} */
+    @Override
+    protected void search() {
+        Control control =getSearchField();
+        String pattern = null;
+        if (control != null){
+            pattern = ((Text)control).getText();
+            callService(pattern);
+
+            fillContentProvider(null);
+        }
+    }
+
 }
