Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix selecting a row that was deselected on the server (#19360)
Client-side connector of the SingleSelectionModel attempts to keep track of currently selected row. This tracking gets lost when the row get deselected on the server-side. Special case is now correctly handled. Change-Id: I1c45548bd11536bc85cddbc2ba8b6225965c1194
- Loading branch information
Teemu Suo-Anttila
committed
Dec 14, 2015
1 parent
4e0bfcd
commit 38a4ae4
Showing
3 changed files
with
210 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
uitest/src/com/vaadin/tests/components/grid/GridDefaultSelectionMode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* Copyright 2000-2014 Vaadin Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package com.vaadin.tests.components.grid; | ||
|
||
import java.util.ArrayList; | ||
|
||
import com.vaadin.data.util.BeanItemContainer; | ||
import com.vaadin.server.VaadinRequest; | ||
import com.vaadin.tests.components.AbstractTestUI; | ||
import com.vaadin.ui.Button; | ||
import com.vaadin.ui.Button.ClickEvent; | ||
import com.vaadin.ui.Button.ClickListener; | ||
import com.vaadin.ui.Grid; | ||
import com.vaadin.ui.VerticalLayout; | ||
|
||
public class GridDefaultSelectionMode extends AbstractTestUI { | ||
|
||
@Override | ||
protected void setup(VaadinRequest request) { | ||
final Person person1 = new Person(); | ||
person1.setFirstName("person"); | ||
person1.setLastName("one"); | ||
|
||
Person person2 = new Person(); | ||
person2.setFirstName("person"); | ||
person2.setLastName("two"); | ||
|
||
ArrayList<Person> items = new ArrayList<Person>(); | ||
items.add(person1); | ||
items.add(person2); | ||
|
||
final BeanItemContainer<Person> container = new BeanItemContainer<Person>( | ||
Person.class, items); | ||
|
||
final Grid grid = new Grid(); | ||
grid.setContainerDataSource(container); | ||
|
||
VerticalLayout v = new VerticalLayout(); | ||
|
||
v.addComponent(new Button("Deselect on server", new ClickListener() { | ||
|
||
@Override | ||
public void buttonClick(ClickEvent event) { | ||
grid.select(null); | ||
} | ||
})); | ||
|
||
v.addComponent(new Button("Select on server", new ClickListener() { | ||
|
||
@Override | ||
public void buttonClick(ClickEvent event) { | ||
grid.select(person1); | ||
} | ||
})); | ||
v.addComponent(grid); | ||
|
||
addComponent(v); | ||
} | ||
|
||
public static class Person { | ||
private String firstName; | ||
private String lastName; | ||
|
||
public String getFirstName() { | ||
return firstName; | ||
} | ||
|
||
public void setFirstName(String firstName) { | ||
this.firstName = firstName; | ||
} | ||
|
||
public String getLastName() { | ||
return lastName; | ||
} | ||
|
||
public void setLastName(String lastName) { | ||
this.lastName = lastName; | ||
} | ||
} | ||
|
||
} |
84 changes: 84 additions & 0 deletions
84
uitest/src/com/vaadin/tests/components/grid/GridDefaultSelectionModeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Copyright 2000-2014 Vaadin Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package com.vaadin.tests.components.grid; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import org.junit.Test; | ||
|
||
import com.vaadin.testbench.elements.ButtonElement; | ||
import com.vaadin.testbench.elements.GridElement; | ||
import com.vaadin.testbench.elements.GridElement.GridCellElement; | ||
import com.vaadin.tests.tb3.MultiBrowserTest; | ||
|
||
public class GridDefaultSelectionModeTest extends MultiBrowserTest { | ||
|
||
@Test | ||
public void testSelectionFromServer() { | ||
setDebug(true); | ||
openTestURL(); | ||
|
||
$(ButtonElement.class).caption("Select on server").first().click(); | ||
|
||
assertTrue("Row should be selected.", $(GridElement.class).first() | ||
.getRow(0).isSelected()); | ||
|
||
$(ButtonElement.class).caption("Deselect on server").first().click(); | ||
|
||
assertFalse("Row should not be selected.", $(GridElement.class).first() | ||
.getRow(0).isSelected()); | ||
|
||
assertNoErrorNotifications(); | ||
} | ||
|
||
@Test | ||
public void testSelectionWithSort() { | ||
setDebug(true); | ||
openTestURL(); | ||
|
||
GridElement grid = $(GridElement.class).first(); | ||
grid.getCell(0, 0).click(); | ||
|
||
GridCellElement header = grid.getHeaderCell(0, 1); | ||
header.click(); | ||
header.click(); | ||
|
||
assertTrue("Row should be selected.", grid.getRow(1).isSelected()); | ||
|
||
assertNoErrorNotifications(); | ||
} | ||
|
||
@Test | ||
public void testReselectDeselectedRow() { | ||
setDebug(true); | ||
openTestURL(); | ||
|
||
$(ButtonElement.class).caption("Select on server").first().click(); | ||
|
||
GridElement grid = $(GridElement.class).first(); | ||
assertTrue("Row should be selected.", grid.getRow(0).isSelected()); | ||
|
||
$(ButtonElement.class).caption("Deselect on server").first().click(); | ||
|
||
assertFalse("Row should not be selected.", grid.getRow(0).isSelected()); | ||
|
||
grid.getCell(0, 0).click(); | ||
assertTrue("Row should be selected.", grid.getRow(0).isSelected()); | ||
|
||
assertNoErrorNotifications(); | ||
} | ||
} |