Project

General

Profile

Revision b49b7f6b

IDb49b7f6bb0e8c2cff1b058f83a5aeb722476fde5
Parent b3b21160
Child b1d7bf10

Added by Katja Luther about 1 year ago

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

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/IPreferenceKeys.java
220 220
    public static final String SORT_NAMED_AREA_BY_VOCABULARY_ORDER = "eu.etaxonomy.taxeditor.distribution.namedArea.sortByVocabularyOrder";
221 221

  
222 222

  
223

  
223
    public static final String LAST_SELECTED_REFERENCES = "eu.etaxonomy.taxeditor.references.selection.lastSelected";
224 224

  
225 225

  
226 226

  
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/PreferencesUtil.java
15 15
import java.io.IOException;
16 16
import java.util.ArrayList;
17 17
import java.util.Arrays;
18
import java.util.Collections;
18 19
import java.util.HashMap;
19 20
import java.util.List;
20 21
import java.util.Map;
......
1298 1299

  
1299 1300
/**
1300 1301
 * <p>
1301
 * setPreferredNomenclaturalCode
1302
 * setPreferredNamedAreasForDistributionEditor
1302 1303
 * </p>
1303 1304
 *
1304
 * @param preferredCode
1305
 *            a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode}
1306
 *            object.
1305
 * @param saveCheckedElements
1306
 * @param saveGrayedElements
1307
 */
1308
public static void setLastSelectedReference(
1309
        List<String> lastSelectedReferences) {
1310

  
1311
        IPreferenceStore preferenceStore = PreferencesUtil.getPreferenceStore();
1312
        preferenceStore.setValue(PreferencesUtil.LAST_SELECTED_REFERENCES, lastSelectedReferences.toString());
1313
    }
1314

  
1315
/**
1316
 * <p>
1317
 * setPreferredNamedAreasForDistributionEditor
1318
 * </p>
1319
 *
1320
 * @param saveCheckedElements
1321
 * @param saveGrayedElements
1322
 */
1323
public static List<String> getLastSelectedReferences() {
1324

  
1325
        IPreferenceStore preferenceStore = PreferencesUtil.getPreferenceStore();
1326
        String lastSelected = preferenceStore.getString(PreferencesUtil.LAST_SELECTED_REFERENCES);
1327
        List<String> result = new ArrayList<>();
1328
        Collections.addAll(result, lastSelected.substring(1,lastSelected.length()-1).split(", "));
1329
        return result;
1330
    }
1331

  
1332

  
1333
/**
1334
 * <p>
1335
 * setPreferredNamedAreasForDistributionEditor
1336
 * </p>
1337
 *
1338
 * @param saveCheckedElements
1339
 * @param saveGrayedElements
1307 1340
 */
1308 1341
public static CdmPreference setPreferredNamedAreasForDistributionEditor(
1309 1342
        String saveCheckedElements, String saveGrayedElements, boolean local) {
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/ReferenceSelectionDialog.java
9 9

  
10 10
package eu.etaxonomy.taxeditor.ui.dialog.selection;
11 11

  
12
import java.util.ArrayList;
13
import java.util.HashSet;
12 14
import java.util.List;
15
import java.util.Set;
13 16
import java.util.UUID;
14 17

  
18
import org.apache.commons.lang.StringUtils;
15 19
import org.eclipse.swt.SWT;
16 20
import org.eclipse.swt.events.SelectionAdapter;
17 21
import org.eclipse.swt.events.SelectionEvent;
18 22
import org.eclipse.swt.widgets.Button;
19 23
import org.eclipse.swt.widgets.Composite;
24
import org.eclipse.swt.widgets.Control;
20 25
import org.eclipse.swt.widgets.Shell;
26
import org.eclipse.swt.widgets.Text;
21 27

  
22 28
import eu.etaxonomy.cdm.api.service.IReferenceService;
23 29
import eu.etaxonomy.cdm.api.service.dto.IdentifiedEntityDTO;
......
25 31
import eu.etaxonomy.cdm.persistence.query.MatchMode;
26 32
import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard;
27 33
import eu.etaxonomy.taxeditor.newWizard.NewReferenceWizard;
34
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
28 35
import eu.etaxonomy.taxeditor.store.CdmStore;
29 36

  
30 37
/**
......
38 45

  
39 46
    protected static boolean isInReference = false;
40 47
    private Reference currentReference;
48
    List<String> lastSelectedReferences = null;
41 49

  
42 50
	/**
43 51
	 * <p>select</p>
......
117 125
	/** {@inheritDoc} */
118 126
	@Override
119 127
	protected Reference getPersistentObject(UUID cdmUuid) {
128
	    if (lastSelectedReferences == null){
129
	        lastSelectedReferences = new ArrayList<>();
130
	    }
131
	    if (lastSelectedReferences.size()<6){
132
	        lastSelectedReferences.add(cdmUuid.toString());
133
	    }else{
134
	        lastSelectedReferences.remove(0);
135
	        lastSelectedReferences.add(cdmUuid.toString());
136
	    }
137

  
138
	    PreferencesUtil.setLastSelectedReference(lastSelectedReferences);
120 139
		return CdmStore.getService(IReferenceService.class).load(cdmUuid);
121 140
	}
122 141

  
......
127 146
	@Override
128 147
	protected void callService(String pattern) {
129 148

  
130
        if (isInReference && currentReference != null){
149
	    if (StringUtils.isBlank(pattern) && lastSelectedReferences == null){
150
	        lastSelectedReferences = PreferencesUtil.getLastSelectedReferences();
151
	        Set<UUID> uuids = new HashSet<>();
152
	        for (String uuidString: lastSelectedReferences){
153
	            uuids.add(UUID.fromString(uuidString));
154
	        }
155
	        model = CdmStore.getService(IReferenceService.class).getUuidAndTitleCacheForUUIDS(uuids);
156

  
157
	    } else if (isInReference && currentReference != null){
131 158

  
132 159
            if (isUseIdentifier()){
133 160
                List<IdentifiedEntityDTO<Reference>> list = CdmStore.getService(IReferenceService.class).listByIdentifierAbbrev(pattern, null, MatchMode.BEGINNING, limitOfInitialElements);
......
196 223
		return new String[]{"New Reference"};
197 224
	}
198 225

  
226
	/** {@inheritDoc} */
227
    @Override
228
    protected void search() {
229
        Control control =getSearchField();
230
        String pattern = null;
231
        if (control != null){
232
            pattern = ((Text)control).getText();
233
            callService(pattern);
234

  
235
            fillContentProvider(null);
236
        }
237
    }
238

  
199 239
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)