private void updateAllSelectedState() {
int totalRowCount = getParentGrid().datasource.size();
int rows = Math.min(totalRowCount, selectionLimit);
- if (getState().allSelected != selection.size() >= rows) {
+ if (totalRowCount == 0) {
+ getState().allSelected = false;
+ } else {
getState().allSelected = selection.size() >= rows;
}
}
import com.vaadin.data.util.IndexedContainer;
import com.vaadin.event.SelectionEvent;
import com.vaadin.event.SelectionEvent.SelectionListener;
+import com.vaadin.shared.ui.grid.selection.MultiSelectionModelState;
import com.vaadin.ui.Grid;
-import com.vaadin.ui.Grid.MultiSelectionModel;
-import com.vaadin.ui.Grid.SelectionMode;
public class MultiSelectionModelTest {
+ private static class MultiSelectionModel
+ extends com.vaadin.ui.Grid.MultiSelectionModel {
+ @Override
+ protected MultiSelectionModelState getState() {
+ // Overridden to be accessible from test
+ return super.getState();
+ }
+ }
+
private Object itemId1Present = "itemId1Present";
private Object itemId2Present = "itemId2Present";
private Object itemId3Present = "itemId3Present";
public void setUp() {
dataSource = createDataSource();
grid = new Grid(dataSource);
- grid.setSelectionMode(SelectionMode.MULTI);
- model = (MultiSelectionModel) grid.getSelectionModel();
+ model = new MultiSelectionModel();
+ grid.setSelectionModel(model);
}
@After
verifyCurrentSelection(itemId1Present, itemId2Present);
}
+ @Test
+ public void testSelectAllWithoutItems() throws Throwable {
+ Assert.assertFalse(model.getState().allSelected);
+ dataSource.removeAllItems();
+ Assert.assertFalse(model.getState().allSelected);
+ model.select();
+ Assert.assertFalse(model.getState().allSelected);
+ model.deselect();
+ Assert.assertFalse(model.getState().allSelected);
+ }
+
@Test
public void testSettingSelection() throws Throwable {
try {