// private implementation
}
- void preActiveRowsChange(Range newActiveRange, int firstNewIndex,
- List<?> itemIds) {
+ void setActiveRange(Range newActiveRange) {
final Range[] removed = activeRange.partitionWith(newActiveRange);
final Range[] added = newActiveRange.partitionWith(activeRange);
removeActiveRows(removed[0]);
removeActiveRows(removed[2]);
- addActiveRows(added[0], firstNewIndex, itemIds);
- addActiveRows(added[2], firstNewIndex, itemIds);
+ addActiveRows(added[0]);
+ addActiveRows(added[2]);
activeRange = newActiveRange;
}
}
}
- private void addActiveRows(final Range added, int firstNewIndex,
- List<?> newItemIds) {
+ private void addActiveRows(Range added) {
+ if (added.isEmpty()) {
+ // Some container.getItemIds() implementations just might be
+ // expensive even for an empty range, so bail out early
+ return;
+ }
- for (int i = added.getStart(); i < added.getEnd(); i++) {
+ List<?> newItemIds = container.getItemIds(added.getStart(),
+ added.length());
+
+ for (int i = 0; i < newItemIds.size(); i++) {
/*
* We might be in a situation we have an index <-> itemId entry
* if-state. But it sounds too stupid (and most often too
* insignificant) to try out.
*/
- final Integer ii = Integer.valueOf(i);
- if (indexToItemId.containsKey(ii)) {
+ final Integer index = Integer.valueOf(i + added.getStart());
+ if (indexToItemId.containsKey(index)) {
continue;
}
* In that case, we only want to add an index for that entry,
* and not overwrite the key.
*/
- final Object itemId = newItemIds.get(i - firstNewIndex);
+ final Object itemId = newItemIds.get(i);
if (!itemIdToKey.containsKey(itemId)) {
itemIdToKey.put(itemId, nextKey());
}
- indexToItemId.forcePut(ii, itemId);
+ indexToItemId.forcePut(index, itemId);
}
}
active = active.combineWith(cached);
}
- List<?> itemIds = RpcDataProviderExtension.this.container.getItemIds(
- firstRowToPush, numberOfRows);
- keyMapper.preActiveRowsChange(active, firstRowToPush, itemIds);
+ keyMapper.setActiveRange(active);
+ List<?> itemIds = container.getItemIds(firstRowToPush, numberOfRows);
JsonArray rows = Json.createArray();
for (int i = 0; i < itemIds.size(); ++i) {
rows.set(i, getRowData(getGrid().getColumns(), itemIds.get(i)));
selectMenuPath("Component", "Editor", "Enabled");
selectMenuPath("Component", "Editor", "Edit item 5");
assertEditorClosed();
- boolean thrown = getLogRow(0).startsWith(
- "5. Exception occured, java.lang.IllegalStateException");
+ boolean thrown = logContainsText("Exception occured, java.lang.IllegalStateException");
assertTrue("IllegalStateException thrown", thrown);
}
selectMenuPath("Component", "Editor", "Edit item 5");
selectMenuPath("Component", "Editor", "Enabled");
assertEditorOpen();
- boolean thrown = getLogRow(0).startsWith(
- "5. Exception occured, java.lang.IllegalStateException");
+ boolean thrown = logContainsText("Exception occured, java.lang.IllegalStateException");
assertTrue("IllegalStateException thrown", thrown);
}