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;
public abstract class AbstractBulkEditorInput<T extends CdmBase> extends CdmEntitySessionInput implements
IEntityPersistenceService<T> {
+
+ private static final String TYPE_PROPERTY = Messages.BulkEditorE4_TYPE;
+ private static final String ID_PROPERTY = "Id"; //$NON-NLS-1$
+ private static final String UUID_PROPERTY = "Uuid"; //$NON-NLS-1$
+
private UUID entityUuid;
private BasicEventList<T> model = new BasicEventList<>();
protected abstract T loadEntity(UUID entityUuid);
+ public List<String> getPropertyKeys(){
+ List<String> properties = new ArrayList<>();
+ properties.add(getName());
+ properties.add(TYPE_PROPERTY);
+ properties.addAll(getPropertyKeys_internal());
+ properties.add(ID_PROPERTY);
+ properties.add(UUID_PROPERTY);
+ return properties;
+ }
+
+ protected abstract List<String> getPropertyKeys_internal();
+
+
+ public Object getPropertyValue(T cdmBase, String property){
+ if(property.equals(getName())){
+ return getText(cdmBase);
+ }else if(property.equals(TYPE_PROPERTY)){
+ return getTypeText(cdmBase);
+ }else if(property.equals(UUID_PROPERTY)){
+ return cdmBase.getUuid();
+ }else if(property.equals(ID_PROPERTY)){
+ return cdmBase.getId();
+ }
+ return null;
+ }
+
public Comparator<T> getTitleComparator(){
return new TitleCacheComparator();
}
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);
- model.addAll(entities);
- //select if entity 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;
}
public void setMergedEntities(HashMap<T, Set<T>> mergedEntities) {
this.mergedEntities = mergedEntities;
}
+
}