diff options
author | Patrik Lindström <patrik@vaadin.com> | 2014-06-17 18:30:04 +0300 |
---|---|---|
committer | Patrik Lindström <patrik@vaadin.com> | 2014-06-26 16:15:05 +0300 |
commit | 6294a26ab8ae5df83d25318c4a8b14db34f5b8a4 (patch) | |
tree | 6513a1c58d8b0e9b1699981269c630335ddd858b /uitest | |
parent | f4a538019bc6c5abeeb453d9f116088d03d7c32f (diff) | |
download | vaadin-framework-6294a26ab8ae5df83d25318c4a8b14db34f5b8a4.tar.gz vaadin-framework-6294a26ab8ae5df83d25318c4a8b14db34f5b8a4.zip |
Implement Grid client-side Sorting API (#13334)
Change-Id: I9ab18c93bdc1aaf66aa2701c3939311671a60f04
Diffstat (limited to 'uitest')
4 files changed, 89 insertions, 16 deletions
diff --git a/uitest/src/com/vaadin/tests/components/grid/GridClientRenderers.java b/uitest/src/com/vaadin/tests/components/grid/GridClientRenderers.java index 15bd323e08..91a4e19886 100644 --- a/uitest/src/com/vaadin/tests/components/grid/GridClientRenderers.java +++ b/uitest/src/com/vaadin/tests/components/grid/GridClientRenderers.java @@ -1,12 +1,12 @@ /* * 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 @@ -24,6 +24,7 @@ import org.openqa.selenium.WebElement; import com.vaadin.testbench.By; import com.vaadin.testbench.TestBenchElement; +import com.vaadin.testbench.elements.LabelElement; import com.vaadin.testbench.elements.NativeButtonElement; import com.vaadin.testbench.elements.NativeSelectElement; import com.vaadin.testbench.elements.ServerClass; @@ -33,7 +34,7 @@ import com.vaadin.tests.widgetset.server.grid.GridClientColumnRenderers; /** * Tests Grid client side renderers - * + * * @since 7.4 * @author Vaadin Ltd */ @@ -161,6 +162,21 @@ public class GridClientRenderers extends MultiBrowserTest { backgroundColor); } + @Test + public void testSortingEvent() throws Exception { + openTestURL(); + + $(NativeButtonElement.class).caption("Trigger sorting").first().click(); + sleep(1000); + + String consoleText = $(LabelElement.class).id("testDebugConsole") + .getText(); + + assertTrue("Console text as expected", + consoleText.contains("Columns: 1, order: Column 1: ASCENDING")); + + } + private GridElement getGrid() { return $(MyClientGridElement.class).first(); } diff --git a/uitest/src/com/vaadin/tests/widgetset/client/grid/GridClientColumnRendererConnector.java b/uitest/src/com/vaadin/tests/widgetset/client/grid/GridClientColumnRendererConnector.java index 24e79d775f..c07f6192b2 100644 --- a/uitest/src/com/vaadin/tests/widgetset/client/grid/GridClientColumnRendererConnector.java +++ b/uitest/src/com/vaadin/tests/widgetset/client/grid/GridClientColumnRendererConnector.java @@ -1,12 +1,12 @@ /* * 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 @@ -19,6 +19,8 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; +import com.google.gwt.dom.client.Document; +import com.google.gwt.dom.client.Element; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.user.client.Timer; @@ -39,6 +41,10 @@ import com.vaadin.client.ui.grid.renderers.HtmlRenderer; import com.vaadin.client.ui.grid.renderers.NumberRenderer; import com.vaadin.client.ui.grid.renderers.TextRenderer; import com.vaadin.client.ui.grid.renderers.WidgetRenderer; +import com.vaadin.client.ui.grid.sort.Sort; +import com.vaadin.client.ui.grid.sort.SortEvent; +import com.vaadin.client.ui.grid.sort.SortEventHandler; +import com.vaadin.client.ui.grid.sort.SortOrder; import com.vaadin.shared.ui.Connect; import com.vaadin.tests.widgetset.server.grid.GridClientColumnRenderers; @@ -109,7 +115,7 @@ public class GridClientColumnRendererConnector extends @Override protected void init() { Grid<String> grid = getWidget(); - grid.setColumnHeadersVisible(false); + // grid.setColumnHeadersVisible(false); // Generated some column data List<String> columnData = new ArrayList<String>(); @@ -127,7 +133,25 @@ public class GridClientColumnRendererConnector extends } // Add a column to display the data in - grid.addColumn(createColumnWithRenderer(Renderers.TEXT_RENDERER)); + GridColumn<String, String> c = createColumnWithRenderer(Renderers.TEXT_RENDERER); + c.setHeaderCaption("Column 1"); + grid.addColumn(c); + + // Add method for testing sort event firing + grid.addSortHandler(new SortEventHandler<String>() { + @Override + public void sort(SortEvent<String> event) { + Element console = Document.get().getElementById( + "testDebugConsole"); + String text = "Client-side sort event received<br>" + + "Columns: " + event.getOrder().size() + ", order: "; + for (SortOrder order : event.getOrder()) { + text += order.getColumn().getHeaderCaption() + ": " + + order.getDirection().toString(); + } + console.setInnerHTML(text); + } + }); // Handle RPC calls registerRpc(GridClientColumnRendererRpc.class, @@ -160,6 +184,11 @@ public class GridClientColumnRendererConnector extends // Re-attach parent.add(getWidget()); } + + @Override + public void triggerClientSorting() { + getWidget().sort(Sort.by(getWidget().getColumn(0))); + } }); } diff --git a/uitest/src/com/vaadin/tests/widgetset/client/grid/GridClientColumnRendererRpc.java b/uitest/src/com/vaadin/tests/widgetset/client/grid/GridClientColumnRendererRpc.java index d156bf9b88..ade239466e 100644 --- a/uitest/src/com/vaadin/tests/widgetset/client/grid/GridClientColumnRendererRpc.java +++ b/uitest/src/com/vaadin/tests/widgetset/client/grid/GridClientColumnRendererRpc.java @@ -1,12 +1,12 @@ /* * 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 @@ -22,7 +22,7 @@ public interface GridClientColumnRendererRpc extends ClientRpc { /** * Adds a new column with a specific renderer to the grid - * + * */ void addColumn(Renderers renderer); @@ -30,4 +30,9 @@ public interface GridClientColumnRendererRpc extends ClientRpc { * Detaches and attaches the client side Grid */ void detachAttach(); + + /** + * Used for client-side sorting API test + */ + void triggerClientSorting(); } diff --git a/uitest/src/com/vaadin/tests/widgetset/server/grid/GridClientColumnRenderers.java b/uitest/src/com/vaadin/tests/widgetset/server/grid/GridClientColumnRenderers.java index e968f13ff5..d41370cc02 100644 --- a/uitest/src/com/vaadin/tests/widgetset/server/grid/GridClientColumnRenderers.java +++ b/uitest/src/com/vaadin/tests/widgetset/server/grid/GridClientColumnRenderers.java @@ -1,12 +1,12 @@ /* * 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 @@ -19,6 +19,7 @@ import java.util.Arrays; import com.vaadin.annotations.Widgetset; import com.vaadin.server.VaadinRequest; +import com.vaadin.shared.ui.label.ContentMode; import com.vaadin.tests.widgetset.TestingWidgetSet; import com.vaadin.tests.widgetset.client.grid.GridClientColumnRendererConnector.Renderers; import com.vaadin.tests.widgetset.client.grid.GridClientColumnRendererRpc; @@ -26,6 +27,7 @@ import com.vaadin.ui.AbstractComponent; import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.Button.ClickListener; import com.vaadin.ui.CssLayout; +import com.vaadin.ui.Label; import com.vaadin.ui.NativeButton; import com.vaadin.ui.NativeSelect; import com.vaadin.ui.UI; @@ -56,6 +58,13 @@ public class GridClientColumnRenderers extends UI { public void detachAttach() { rpc().detachAttach(); } + + /** + * @since + */ + public void triggerClientSorting() { + rpc().triggerClientSorting(); + } } @Override @@ -94,5 +103,19 @@ public class GridClientColumnRenderers extends UI { } }); controls.addComponent(detachAttachBtn); + + NativeButton sortButton = new NativeButton("Trigger sorting"); + sortButton.addClickListener(new ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + controller.triggerClientSorting(); + } + }); + controls.addComponent(sortButton); + + Label console = new Label(); + console.setContentMode(ContentMode.HTML); + console.setId("testDebugConsole"); + content.addComponent(console); } } |