Project

General

Profile

« Previous | Next » 

Revision 27a07b9c

Added by Patrick Plitzner almost 4 years ago

fix #6321 Implement parallel loading + progress bar for bulk editor

View differences:

eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/BulkEditorQuery.java
37 37
		searchConfigurator.setTitleSearchString(searchString);
38 38
		searchConfigurator.setMatchMode(null);
39 39
		searchConfigurator.setPropertyPaths(propertyPath);
40

  
41
		if(searchString != null && searchString.trim().equals("*")){
42
			searchConfigurator.setPageSize(1000);
43
		}
44

  
40
		searchConfigurator.setPageSize(20);
45 41
	}
46 42

  
47 43
	public Comparator getComparator() {
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/AbstractBulkEditorInput.java
19 19
import java.util.Set;
20 20
import java.util.UUID;
21 21

  
22
import org.eclipse.core.runtime.ICoreRunnable;
23
import org.eclipse.core.runtime.IProgressMonitor;
24
import org.eclipse.core.runtime.jobs.Job;
25

  
22 26
import ca.odell.glazedlists.BasicEventList;
23 27
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
24 28
import eu.etaxonomy.cdm.api.service.config.DeleteConfiguratorBase;
......
137 141

  
138 142
	public void performSearch(final BulkEditorQuery bulkEditorQuery) {
139 143
	    model.clear();
140
	    BasicEventList<T> entityList = new BasicEventList<>();
141 144

  
142 145
		if(getEntityUuid() != null){
143 146

  
144 147
			T entity = loadEntity(getEntityUuid());
145
			entityList.add(entity);
146
			model.addAll(entityList);
148
			model.add(entity);
147 149
		}
148 150
		else if(bulkEditorQuery != null){
149 151

  
150 152
			IIdentifiableEntityServiceConfigurator configurator = bulkEditorQuery.getSearchConfigurator();
151 153
			Comparator queryComparator = (bulkEditorQuery.getComparator() != null) ? bulkEditorQuery.getComparator() : new TitleCacheComparator();
152 154

  
153
			entityList.addAll(listEntities(configurator));
154

  
155
			Collections.sort(entityList, queryComparator);
155
			String jobLabel = "Load data";
156
	        Job job = Job.create(jobLabel, (ICoreRunnable) monitor -> {
157
	            monitor.beginTask(jobLabel, IProgressMonitor.UNKNOWN);
158
	            int pageNumber = 0;
159
	            List<T> entities = listEntities(configurator);
160
	            while(!entities.isEmpty()){
161
	                if(monitor.isCanceled()){
162
	                    break;
163
	                }
164
	                configurator.setPageNumber(pageNumber);
165
	                entities = listEntities(configurator);
166
	                model.addAll(entities);
167
	                pageNumber++;
168
	                Collections.sort(model, queryComparator);
169
	            }
170
	            monitor.done();
171
	        });
172
	        job.schedule();
156 173
		}
157
		model.addAll(entityList);
158 174
	}
159 175

  
160 176
	public boolean isMergingEnabled() {
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/SearchManager.java
14 14
import java.util.List;
15 15
import java.util.UUID;
16 16

  
17
import org.eclipse.jface.dialogs.MessageDialog;
18
import org.eclipse.swt.widgets.Display;
19

  
20 17
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
21 18
import eu.etaxonomy.cdm.api.service.IAgentService;
22 19
import eu.etaxonomy.cdm.api.service.IGroupService;
......
43 40
import eu.etaxonomy.cdm.model.reference.Reference;
44 41
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
45 42
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
46
import eu.etaxonomy.taxeditor.l10n.Messages;
47 43
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
48 44
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
49 45

  
......
59 55

  
60 56
	public static int NO_COUNT = -1;
61 57

  
62

  
63
	// TODO make this configurable via preferences
64
	private static final int MAX_RESULTS_BEFORE_WARNING = 500;
65

  
66 58
	public List<TaxonName> findNames(IIdentifiableEntityServiceConfigurator configurator, ConversationHolder conversation){
67

  
68
		if(checkLargeResult(CdmStore.getService(INameService.class).countByTitle(configurator))){
69
			List<TaxonName> records = CdmStore.getService(INameService.class).findByTitle(configurator).getRecords();
70
			addUuidSearchResults(records, configurator, INameService.class);
71
            return records;
72
		}
73
		return NO_RESULTS;
59
	    List<TaxonName> records = CdmStore.getService(INameService.class).findByTitle(configurator).getRecords();
60
	    addUuidSearchResults(records, configurator, INameService.class);
61
	    return records;
74 62
	}
75 63

  
76 64
	public List<NameRelationship> findNameRelationships(
......
96 84
	}
97 85

  
98 86
	public List<Reference> findReferences(IIdentifiableEntityServiceConfigurator configurator){
99
		if(checkLargeResult(CdmStore.getService(IReferenceService.class).countByTitle(configurator))){
100
			List<Reference> records = CdmStore.getService(IReferenceService.class).findByTitle(configurator).getRecords();
101
			addUuidSearchResults(records, configurator, IReferenceService.class);
102
            return records;
103
		}
104
		return NO_RESULTS;
87
	    List<Reference> records = CdmStore.getService(IReferenceService.class).findByTitle(configurator).getRecords();
88
	    addUuidSearchResults(records, configurator, IReferenceService.class);
89
	    return records;
105 90
	}
106 91

  
107 92
	public List<AgentBase> findAgents(IIdentifiableEntityServiceConfigurator configurator){
108

  
109
		if(checkLargeResult(CdmStore.getService(IAgentService.class).countByTitle(configurator))){
110
			List<AgentBase> records = CdmStore.getService(IAgentService.class).findByTitle(configurator).getRecords();
111
			addUuidSearchResults(records, configurator, IAgentService.class);
112
            return records;
113
		}
114
		return NO_RESULTS;
93
	    List<AgentBase> records = CdmStore.getService(IAgentService.class).findByTitle(configurator).getRecords();
94
	    addUuidSearchResults(records, configurator, IAgentService.class);
95
	    return records;
115 96
	}
116 97

  
117 98
    /**
......
188 169
		}
189 170
		configurator.setPropertyPaths(occurrencePropertyPaths);
190 171

  
191
		if(checkLargeResult(CdmStore.getService(IOccurrenceService.class).countOccurrences(configurator))){
192
			records = CdmStore.getService(IOccurrenceService.class).findByTitle(configurator).getRecords();
193
		}
172
		records = CdmStore.getService(IOccurrenceService.class).findByTitle(configurator).getRecords();
194 173
		addUuidSearchResults(records, configurator, IOccurrenceService.class);
195 174
		return records;
196 175
	}
......
213 192
	}
214 193

  
215 194

  
216
	private boolean checkLargeResult(int count) {
217
	    return checkLargeResult(count, MAX_RESULTS_BEFORE_WARNING);
218
	}
219

  
220
	private boolean checkLargeResult(int count, int maxBeforWarning) {
221
		if(count > maxBeforWarning){
222
			return MessageDialog.openConfirm(Display.getDefault().getActiveShell(), Messages.SearchManager_LARGE_RESULT_EXPECTED,
223
					String.format(Messages.SearchManager_LONG_SEARCH_WARNING, count));
224
		}else{
225
			return true;
226
		}
227
	}
228

  
229 195
	private String sqlizeTitleSearchString(IIdentifiableEntityServiceConfigurator configurator){
230 196
		return configurator.getTitleSearchString().replace(WILDCARD, "%"); //$NON-NLS-1$
231 197
	}
232 198

  
233 199
	public List findTaxa(IIdentifiableEntityServiceConfigurator configurator) {
234
		if(checkLargeResult(CdmStore.getService(ITaxonService.class).countByTitle(configurator))){
235
			List<TaxonBase> records = CdmStore.getService(ITaxonService.class).findByTitle(configurator).getRecords();
236
			addUuidSearchResults(records, configurator, ITaxonService.class);
237
            return records;
238
		}
239
		return NO_RESULTS;
200
	    List<TaxonBase> records = CdmStore.getService(ITaxonService.class).findByTitle(configurator).getRecords();
201
	    addUuidSearchResults(records, configurator, ITaxonService.class);
202
	    return records;
240 203
	}
241 204

  
242 205
	public List findMedia(IIdentifiableEntityServiceConfigurator configurator) {
243
        if(checkLargeResult(CdmStore.getService(IMediaService.class).countByTitle(configurator))){
244
            List<Media> records = CdmStore.getService(IMediaService.class).findByTitle(configurator).getRecords();
245
            addUuidSearchResults(records, configurator, IMediaService.class);
246
            return records;
247
        }
248
        return NO_RESULTS;
206
	    List<Media> records = CdmStore.getService(IMediaService.class).findByTitle(configurator).getRecords();
207
	    addUuidSearchResults(records, configurator, IMediaService.class);
208
	    return records;
249 209
    }
250 210

  
251 211

  

Also available in: Unified diff