Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/main/java/org/fxmisc/flowless/CellListManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,27 @@ public C getCell(int itemIndex) {
return cells.get(itemIndex);
}

/**
* This is a noop on non visible items. For reusable Cells this will cause
* updateItem to be invoked on the next available pooled Cell. If a Cell is
* not available or reusable, a new Cell is created via the cell factory.
*/
public void refreshCells(int fromItem, int toItem) {
int start = Math.min( fromItem, toItem );
int end = Math.max( fromItem, toItem );

IndexRange memorizedRange = cells.getMemoizedItemsRange();
int min = memorizedRange.getStart();
int max = memorizedRange.getEnd();

start = Math.max( start, min );
end = Math.min( end, max );

if ( start < max && end > min ) {
Comment thread
Jugen marked this conversation as resolved.
Outdated
cells.forget(start, end);
}
}

/**
* Updates the list of cells to display
*
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/org/fxmisc/flowless/VirtualFlow.java
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,15 @@ public Optional<C> getCellIfVisible(int itemIndex) {
return cellPositioner.getCellIfVisible(itemIndex);
}

/**
* This is a noop on non visible items. For reusable Cells this will cause
* updateItem to be invoked on the next available pooled Cell. If a Cell is
* not available or reusable, a new Cell is created via the cell factory.
*/
public void refreshCells(int fromIndex, int toIndex) {
cellListManager.refreshCells(fromIndex, toIndex);
}

/**
* This method calls {@link #layout()} as a side-effect to insure
* that the VirtualFlow is up-to-date in light of any changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ public void updating_an_item_outside_viewport_does_not_create_or_lay_out_cell()
assertEquals(0, cellLayouts.getAndReset());
}

@Test
public void refreshing_cells_in_viewport_creates_and_lays_them_out_once() {
// refresh cells in the viewport
interact(() -> flow.refreshCells(10,12));
assertEquals(2, cellCreations.getAndReset());
assertEquals(2, cellLayouts.getAndReset());
}

@Test
public void deleting_an_item_in_viewport_only_creates_and_lays_out_cell_once() {
// delete an item in the middle of the viewport
Expand Down