aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/src/com/vaadin/data/RpcDataProviderExtension.java16
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/GridBasicFeatures.java36
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/GridBasicFeaturesTest.java56
3 files changed, 97 insertions, 11 deletions
diff --git a/server/src/com/vaadin/data/RpcDataProviderExtension.java b/server/src/com/vaadin/data/RpcDataProviderExtension.java
index 801b925e2a..f731e4575d 100644
--- a/server/src/com/vaadin/data/RpcDataProviderExtension.java
+++ b/server/src/com/vaadin/data/RpcDataProviderExtension.java
@@ -583,11 +583,17 @@ public class RpcDataProviderExtension extends AbstractExtension {
}
else {
- // TODO no diff info available, redraw everything
- throw new UnsupportedOperationException("bare "
- + "ItemSetChangeEvents are currently "
- + "not supported, use a container that "
- + "uses AddItemEvents and RemoveItemEvents.");
+ Range visibleRows = activeRowHandler.activeRange;
+ List<?> itemIds = container.getItemIds(visibleRows.getStart(),
+ visibleRows.length());
+
+ keyMapper.removeActiveRows(keyMapper.activeRange);
+ keyMapper.addActiveRows(visibleRows, visibleRows.getStart(),
+ itemIds);
+
+ pushRows(visibleRows.getStart(), itemIds);
+ activeRowHandler.setActiveRows(visibleRows.getStart(),
+ visibleRows.length());
}
}
};
diff --git a/uitest/src/com/vaadin/tests/components/grid/GridBasicFeatures.java b/uitest/src/com/vaadin/tests/components/grid/GridBasicFeatures.java
index 66eb9ec2d6..5800c83738 100644
--- a/uitest/src/com/vaadin/tests/components/grid/GridBasicFeatures.java
+++ b/uitest/src/com/vaadin/tests/components/grid/GridBasicFeatures.java
@@ -23,10 +23,12 @@ import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
+import java.util.Random;
import com.vaadin.data.Item;
import com.vaadin.data.util.IndexedContainer;
import com.vaadin.shared.ui.grid.HeightMode;
+import com.vaadin.shared.ui.grid.SortDirection;
import com.vaadin.tests.components.AbstractComponentTest;
import com.vaadin.ui.components.grid.ColumnGroup;
import com.vaadin.ui.components.grid.ColumnGroupRow;
@@ -36,6 +38,8 @@ import com.vaadin.ui.components.grid.GridColumn;
import com.vaadin.ui.components.grid.renderers.DateRenderer;
import com.vaadin.ui.components.grid.renderers.HtmlRenderer;
import com.vaadin.ui.components.grid.renderers.NumberRenderer;
+import com.vaadin.ui.components.grid.sort.Sort;
+import com.vaadin.ui.components.grid.sort.SortOrder;
/**
* Tests the basic features like columns, footers and headers
@@ -45,9 +49,9 @@ import com.vaadin.ui.components.grid.renderers.NumberRenderer;
*/
public class GridBasicFeatures extends AbstractComponentTest<Grid> {
- private static final int MANUALLY_FORMATTED_COLUMNS = 3;
- private static final int COLUMNS = 10;
- private static final int ROWS = 1000;
+ private static final int MANUALLY_FORMATTED_COLUMNS = 4;
+ public static final int COLUMNS = 11;
+ public static final int ROWS = 1000;
private int columnGroupRows = 0;
private IndexedContainer ds;
@@ -78,9 +82,14 @@ public class GridBasicFeatures extends AbstractComponentTest<Grid> {
ds.addContainerProperty(getColumnProperty(col++), Date.class,
new Date());
ds.addContainerProperty(getColumnProperty(col++), String.class, "");
+
+ ds.addContainerProperty(getColumnProperty(col++), Integer.class, 0);
+
}
{
+ Random rand = new Random();
+ rand.setSeed(13334);
long timestamp = 0;
for (int row = 0; row < ROWS; row++) {
Item item = ds.addItem(Integer.valueOf(row));
@@ -97,6 +106,9 @@ public class GridBasicFeatures extends AbstractComponentTest<Grid> {
// variation
item.getItemProperty(getColumnProperty(col++)).setValue(
"<b>" + row + "</b>");
+
+ item.getItemProperty(getColumnProperty(col++)).setValue(
+ rand.nextInt());
}
}
@@ -115,6 +127,8 @@ public class GridBasicFeatures extends AbstractComponentTest<Grid> {
new DateRenderer(new SimpleDateFormat("dd.MM.yy HH:mm")));
grid.getColumn(getColumnProperty(col++)).setRenderer(
new HtmlRenderer());
+ grid.getColumn(getColumnProperty(col++)).setRenderer(
+ new NumberRenderer());
}
// Add footer values (header values are automatically created)
@@ -175,6 +189,22 @@ public class GridBasicFeatures extends AbstractComponentTest<Grid> {
grid.setSelectionMode(selectionMode);
}
});
+
+ LinkedHashMap<String, List<SortOrder>> sortableProperties = new LinkedHashMap<String, List<SortOrder>>();
+ for (Object propertyId : ds.getSortableContainerPropertyIds()) {
+ sortableProperties.put(propertyId + ", ASC", Sort.by(propertyId)
+ .build());
+ sortableProperties.put(propertyId + ", DESC",
+ Sort.by(propertyId, SortDirection.DESCENDING).build());
+ }
+ createSelectAction("Sort by column", "State", sortableProperties,
+ "Column 9, ascending", new Command<Grid, List<SortOrder>>() {
+ @Override
+ public void execute(Grid grid, List<SortOrder> sortOrder,
+ Object data) {
+ grid.setSortOrder(sortOrder);
+ }
+ });
}
protected void createHeaderActions() {
diff --git a/uitest/src/com/vaadin/tests/components/grid/GridBasicFeaturesTest.java b/uitest/src/com/vaadin/tests/components/grid/GridBasicFeaturesTest.java
index 2546def990..d09f55537d 100644
--- a/uitest/src/com/vaadin/tests/components/grid/GridBasicFeaturesTest.java
+++ b/uitest/src/com/vaadin/tests/components/grid/GridBasicFeaturesTest.java
@@ -21,6 +21,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@@ -44,7 +45,7 @@ public class GridBasicFeaturesTest extends MultiBrowserTest {
// Column headers should be visible
List<TestBenchElement> cells = getGridHeaderRowCells();
- assertEquals(10, cells.size());
+ assertEquals(GridBasicFeatures.COLUMNS, cells.size());
assertEquals("Column0", cells.get(0).getText());
assertEquals("Column1", cells.get(1).getText());
assertEquals("Column2", cells.get(2).getText());
@@ -63,7 +64,7 @@ public class GridBasicFeaturesTest extends MultiBrowserTest {
// Footers should now be visible
cells = getGridFooterRowCells();
- assertEquals(10, cells.size());
+ assertEquals(GridBasicFeatures.COLUMNS, cells.size());
assertEquals("Footer 0", cells.get(0).getText());
assertEquals("Footer 1", cells.get(1).getText());
assertEquals("Footer 2", cells.get(2).getText());
@@ -86,7 +87,7 @@ public class GridBasicFeaturesTest extends MultiBrowserTest {
// Empty group row cells should be present
cells = getGridHeaderRowCells();
- assertEquals(10, cells.size());
+ assertEquals(GridBasicFeatures.COLUMNS, cells.size());
// Group columns 0 & 1
selectMenuPath("Component", "Column groups", "Column group row 1",
@@ -372,6 +373,55 @@ public class GridBasicFeaturesTest extends MultiBrowserTest {
+ "back into view", isSelected(getRow(0)));
}
+ @Test
+ public void testSorting() throws IOException {
+ openTestURL();
+
+ GridElement grid = getGridElement();
+
+ // Sorting by column 9 is sorting by row index that is represented as a
+ // String.
+ // First cells for first 3 rows are (9, 0), (99, 0) and (999, 0)
+ sortBy("Column9, DESC");
+ String row = "";
+ for (int i = 0; i < 3; ++i) {
+ row += "9";
+ assertEquals(
+ "Grid is not sorted by Column9 using descending direction.",
+ "(" + row + ", 0)", grid.getCell(i, 0).getText());
+ }
+
+ // Column 10 is random numbers from Random with seed 13334
+ sortBy("Column10, ASC");
+
+ // Not cleaning up correctly causes exceptions when scrolling.
+ grid.scrollToRow(50);
+ assertFalse("Scrolling caused and exception when shuffled.",
+ getLogRow(0).contains("Exception"));
+
+ for (int i = 0; i < 5; ++i) {
+ assertGreater(
+ "Grid is not sorted by Column10 using ascending direction",
+ Integer.parseInt(grid.getCell(i + 1, 10).getText()),
+ Integer.parseInt(grid.getCell(i, 10).getText()));
+
+ }
+
+ // Column 7 is row index as a number. Last three row are original rows
+ // 2, 1 and 0.
+ sortBy("Column7, DESC");
+ for (int i = 0; i < 3; ++i) {
+ assertEquals(
+ "Grid is not sorted by Column7 using descending direction",
+ "(" + i + ", 0)",
+ grid.getCell(GridBasicFeatures.ROWS - (i + 1), 0).getText());
+ }
+ }
+
+ private void sortBy(String column) {
+ selectMenuPath("Component", "State", "Sort by column", column);
+ }
+
private void toggleFirstRowSelection() {
selectMenuPath("Component", "Body rows", "Select first row");
}