import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID;
+import java.util.stream.Collectors;
import org.eclipse.core.runtime.ICoreRunnable;
import org.eclipse.core.runtime.jobs.Job;
model.clear();
if(getEntityUuid() != null){
-
T entity = loadEntity(getEntityUuid());
model.add(entity);
}
monitor.beginTask(jobLabel, totalWork);
int pageNumber = 0;
List<T> entities;
+
+ //load previously selected element
+ UUID selectedUuid = null;
+ if(selection!=null && selection.getFirstElement() instanceof CdmBase){
+ selectedUuid = ((CdmBase) selection.getFirstElement()).getUuid();
+ T entity = loadEntity(selectedUuid);
+ model.add(entity);
+ }
+
do {
if (monitor.isCanceled()) {
break;
}
configurator.setPageNumber(pageNumber);
entities = listEntities(configurator);
- /*
- * IMPORTANT!
- * Entities have to be loaded into the main session because they are
- * loaded in a parallel asynchronous thread
- */
- getCdmEntitySession().load(entities, true);
-
- model.addAll(entities);
-
- //select entity when it is loaded
- if(selection!=null && model.containsAll(selection.toList())){
- EventUtility.postAsyncEvent(WorkbenchEventConstants.BULK_EDITOR_SEARCH_FINISHED, selection);
- }
+
+ addToModel(entities, selectedUuid);
+
pageNumber++;
monitor.worked(pageSize);
long workedLong = pageSize*pageNumber;
int loadedCount = workedLong>Integer.MAX_VALUE?Integer.MAX_VALUE:(int)workedLong;
monitor.setTaskName(String.format(Messages.AbstractBulkEditorInput_LOADED, loadedCount, totalWork, getName()));
+
+ //Update selection
+ EventUtility.postAsyncEvent(WorkbenchEventConstants.BULK_EDITOR_SEARCH_FINISHED, selection);
} while (!entities.isEmpty());
monitor.done();
EventUtility.postAsyncEvent(WorkbenchEventConstants.BULK_EDITOR_SEARCH_FINISHED, selection);
}
}
+ private void addToModel(List<T> entities, UUID selectedUuid){
+ //filter pre-loaded previously selected element
+ if(selectedUuid!=null){
+ entities = entities.stream().filter(entity->!entity.getUuid().equals(selectedUuid)).collect(Collectors.toList());
+ }
+ /*
+ * IMPORTANT!
+ * Entities have to be loaded into the main session because they are
+ * loaded in a parallel asynchronous thread
+ */
+ if(getCdmEntitySession()!=null){//is null when closing the bulk editor during loading
+ getCdmEntitySession().load(entities, true);
+ }
+ model.addAll(entities);
+ }
+
public boolean isMergingEnabled() {
return false;
}