@@ -187,6 +187,20 @@ public class GridMultiSelect<T> implements MultiSelect<T> { | |||
model.setUserSelectionAllowed(allowed); | |||
} | |||
/** | |||
* Returns whether all items are selected or not. | |||
* <p> | |||
* This is only {@code true} if user has selected all rows with the select | |||
* all checkbox on client side, or if {@link #selectAll()} has been used | |||
* from server side. | |||
* | |||
* @return {@code true} if all selected, {@code false} if not | |||
* @since 8.12.0 | |||
*/ | |||
public boolean isAllSelected() { | |||
return model.isAllSelected(); | |||
} | |||
/** | |||
* Checks if the user is allowed to change the selection. | |||
* <p> |
@@ -135,4 +135,16 @@ public interface MultiSelectionModel<T> | |||
* @see #setSelectAllCheckBoxVisibility(SelectAllCheckBoxVisibility) | |||
*/ | |||
public boolean isSelectAllCheckBoxVisible(); | |||
/** | |||
* Returns whether all items are selected or not. | |||
* <p> | |||
* This is only {@code true} if user has selected all rows with the select | |||
* all checkbox on client side, or if {@link #selectAll()} has been used | |||
* from server side. | |||
* | |||
* @return {@code true} if all selected, {@code false} if not | |||
* @since 8.12.0 | |||
*/ | |||
boolean isAllSelected(); | |||
} |
@@ -131,15 +131,7 @@ public class MultiSelectionModelImpl<T> extends AbstractSelectionModel<T> | |||
return getState(false).selectAllCheckBoxVisible; | |||
} | |||
/** | |||
* Returns whether all items are selected or not. | |||
* <p> | |||
* This is only {@code true} if user has selected all rows with the select | |||
* all checkbox on client side, or if {@link #selectAll()} has been used | |||
* from server side. | |||
* | |||
* @return {@code true} if all selected, {@code false} if not | |||
*/ | |||
@Override | |||
public boolean isAllSelected() { | |||
return getState(false).allSelected; | |||
} |
@@ -0,0 +1,42 @@ | |||
package com.vaadin.tests.components.grid; | |||
import com.vaadin.server.VaadinRequest; | |||
import com.vaadin.tests.components.AbstractTestUI; | |||
import com.vaadin.ui.Grid; | |||
import com.vaadin.ui.Grid.SelectionMode; | |||
import com.vaadin.ui.Label; | |||
public class GridSelectAllStatus extends AbstractTestUI { | |||
public Grid<String> grid; | |||
@Override | |||
protected void setup(VaadinRequest request) { | |||
grid = new Grid<>(); | |||
grid.setSelectionMode(SelectionMode.MULTI); | |||
grid.setItems("Item 1", "Item 2"); | |||
grid.addColumn(item -> item); | |||
Label label = new Label("Select-all checkbox is checked?"); | |||
Label selectAllStatus = new Label( | |||
String.valueOf(grid.asMultiSelect().isAllSelected())); | |||
selectAllStatus.setId("status"); | |||
grid.asMultiSelect() | |||
.addMultiSelectionListener(e -> selectAllStatus.setValue( | |||
String.valueOf(grid.asMultiSelect().isAllSelected()))); | |||
addComponents(grid, label, selectAllStatus); | |||
} | |||
@Override | |||
protected Integer getTicketNumber() { | |||
return 12081; | |||
} | |||
@Override | |||
protected String getTestDescription() { | |||
return "The status of the Grid's select-all checkbox should be " | |||
+ "accessible through the Java API."; | |||
} | |||
} |
@@ -0,0 +1,37 @@ | |||
package com.vaadin.tests.components.grid; | |||
import static org.junit.Assert.assertFalse; | |||
import static org.junit.Assert.assertTrue; | |||
import org.junit.Test; | |||
import org.openqa.selenium.WebElement; | |||
import com.vaadin.testbench.By; | |||
import com.vaadin.testbench.elements.GridElement; | |||
import com.vaadin.testbench.elements.LabelElement; | |||
import com.vaadin.tests.tb3.MultiBrowserTest; | |||
public class GridSelectAllStatusTest extends MultiBrowserTest { | |||
@Test | |||
public void checkSelectAllStatus() { | |||
openTestURL(); | |||
GridElement grid = $(GridElement.class).first(); | |||
LabelElement selectAllStatusLabel = $(LabelElement.class).id("status"); | |||
WebElement selectAllCheckbox = grid | |||
.findElement(By.className("v-grid-select-all-checkbox")); | |||
// select all | |||
selectAllCheckbox.click(); | |||
assertTrue( | |||
"The status of the select-all checkbox is expected to be True.", | |||
Boolean.parseBoolean(selectAllStatusLabel.getText())); | |||
// De-select all selections | |||
selectAllCheckbox.click(); | |||
assertFalse( | |||
"The status of the select-all checkbox is expected to be False.", | |||
Boolean.parseBoolean(selectAllStatusLabel.getText())); | |||
} | |||
} |