Project

General

Profile

Revision a186543e

IDa186543e24da3e3bd7e4b57b0c993d88b93aa007
Parent 6959d272
Child b3fb4578

Added by Patrick Plitzner 11 months ago

ref #7518 Pre-load and select previously selected element

View differences:

eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/AbstractBulkEditorInput.java
17 17
import java.util.Map.Entry;
18 18
import java.util.Set;
19 19
import java.util.UUID;
20
import java.util.stream.Collectors;
20 21

  
21 22
import org.eclipse.core.runtime.ICoreRunnable;
22 23
import org.eclipse.core.runtime.jobs.Job;
......
173 174
	    model.clear();
174 175

  
175 176
		if(getEntityUuid() != null){
176

  
177 177
			T entity = loadEntity(getEntityUuid());
178 178
			model.add(entity);
179 179
		}
......
202 202
	            monitor.beginTask(jobLabel, totalWork);
203 203
	            int pageNumber = 0;
204 204
	            List<T> entities;
205

  
206
	            //load previously selected element
207
	            UUID selectedUuid = null;
208
	            if(selection!=null && selection.getFirstElement() instanceof CdmBase){
209
	                selectedUuid = ((CdmBase) selection.getFirstElement()).getUuid();
210
	                T entity = loadEntity(selectedUuid);
211
	                model.add(entity);
212
	            }
213

  
205 214
                do {
206 215
                    if (monitor.isCanceled()) {
207 216
                        break;
208 217
                    }
209 218
                    configurator.setPageNumber(pageNumber);
210 219
                    entities = listEntities(configurator);
211
                    /*
212
                     * IMPORTANT!
213
                     * Entities have to be loaded into the main session because they are
214
                     * loaded in a parallel asynchronous thread
215
                     */
216
                    getCdmEntitySession().load(entities, true);
217

  
218
                    model.addAll(entities);
219

  
220
                    //select entity when it is loaded
221
                    if(selection!=null && model.containsAll(selection.toList())){
222
                        EventUtility.postAsyncEvent(WorkbenchEventConstants.BULK_EDITOR_SEARCH_FINISHED, selection);
223
                    }
220

  
221
                    addToModel(entities, selectedUuid);
222

  
224 223
                    pageNumber++;
225 224
                    monitor.worked(pageSize);
226 225
                    long workedLong = pageSize*pageNumber;
227 226
                    int loadedCount =  workedLong>Integer.MAX_VALUE?Integer.MAX_VALUE:(int)workedLong;
228 227
                    monitor.setTaskName(String.format(Messages.AbstractBulkEditorInput_LOADED, loadedCount, totalWork, getName()));
228

  
229
                    //Update selection
230
                    EventUtility.postAsyncEvent(WorkbenchEventConstants.BULK_EDITOR_SEARCH_FINISHED, selection);
229 231
                } while (!entities.isEmpty());
230 232
	            monitor.done();
231 233
	            EventUtility.postAsyncEvent(WorkbenchEventConstants.BULK_EDITOR_SEARCH_FINISHED, selection);
......
234 236
		}
235 237
	}
236 238

  
239
	private void addToModel(List<T> entities, UUID selectedUuid){
240
	    //filter pre-loaded previously selected element
241
	    if(selectedUuid!=null){
242
	        entities = entities.stream().filter(entity->!entity.getUuid().equals(selectedUuid)).collect(Collectors.toList());
243
	    }
244
	    /*
245
         * IMPORTANT!
246
         * Entities have to be loaded into the main session because they are
247
         * loaded in a parallel asynchronous thread
248
         */
249
        if(getCdmEntitySession()!=null){//is null when closing the bulk editor during loading
250
            getCdmEntitySession().load(entities, true);
251
        }
252
        model.addAll(entities);
253
	}
254

  
237 255
	public boolean isMergingEnabled() {
238 256
		return false;
239 257
	}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)