summaryrefslogtreecommitdiffstats
path: root/uitest
diff options
context:
space:
mode:
authorHenrik Paul <henrik@vaadin.com>2014-07-01 16:56:03 +0300
committerHenrik Paul <henrik@vaadin.com>2014-07-04 17:16:27 +0300
commit87e64d5af9cc1dc2a8d79be6227661b64b2077b5 (patch)
treed3ba25e33476de6de0406963b7001ea204d9d08a /uitest
parent6653224d8defe79ecb8749eab96adccd626c76bf (diff)
downloadvaadin-framework-87e64d5af9cc1dc2a8d79be6227661b64b2077b5.tar.gz
vaadin-framework-87e64d5af9cc1dc2a8d79be6227661b64b2077b5.zip
Adds key-related helper methods to Renderers. (#13334)
Change-Id: Ic7b1ece8b88126323acc2e216acdebe636091b98
Diffstat (limited to 'uitest')
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/CustomRenderer.java22
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/CustomRendererTest.java20
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/IntArrayRenderer.java2
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/RowAwareRenderer.java41
-rw-r--r--uitest/src/com/vaadin/tests/widgetset/client/grid/RowAwareRendererConnector.java78
5 files changed, 158 insertions, 5 deletions
diff --git a/uitest/src/com/vaadin/tests/components/grid/CustomRenderer.java b/uitest/src/com/vaadin/tests/components/grid/CustomRenderer.java
index 7e079e69b7..9ac1a03df3 100644
--- a/uitest/src/com/vaadin/tests/components/grid/CustomRenderer.java
+++ b/uitest/src/com/vaadin/tests/components/grid/CustomRenderer.java
@@ -22,28 +22,42 @@ import com.vaadin.data.util.IndexedContainer;
import com.vaadin.server.VaadinRequest;
import com.vaadin.tests.components.AbstractTestUI;
import com.vaadin.tests.widgetset.TestingWidgetSet;
+import com.vaadin.ui.Label;
import com.vaadin.ui.components.grid.Grid;
@Widgetset(TestingWidgetSet.NAME)
public class CustomRenderer extends AbstractTestUI {
private static final Object INT_ARRAY_PROPERTY = "int array";
+ private static final Object VOID_PROPERTY = "void";
+
+ static final Object ITEM_ID = "itemId1";
+ static final String DEBUG_LABEL_ID = "debuglabel";
+ static final String INIT_DEBUG_LABEL_CAPTION = "Debug label placeholder";
@Override
protected void setup(VaadinRequest request) {
IndexedContainer container = new IndexedContainer();
container.addContainerProperty(INT_ARRAY_PROPERTY, int[].class,
new int[] {});
+ container.addContainerProperty(VOID_PROPERTY, Void.class, null);
+
+ Item item = container.addItem(ITEM_ID);
- Object itemId = new Object();
- Item item = container.addItem(itemId);
@SuppressWarnings("unchecked")
- Property<int[]> property = item.getItemProperty(INT_ARRAY_PROPERTY);
- property.setValue(new int[] { 1, 1, 2, 3, 5, 8, 13 });
+ Property<int[]> propertyIntArray = item
+ .getItemProperty(INT_ARRAY_PROPERTY);
+ propertyIntArray.setValue(new int[] { 1, 1, 2, 3, 5, 8, 13 });
+
+ Label debugLabel = new Label(INIT_DEBUG_LABEL_CAPTION);
+ debugLabel.setId(DEBUG_LABEL_ID);
Grid grid = new Grid(container);
grid.getColumn(INT_ARRAY_PROPERTY).setRenderer(new IntArrayRenderer());
+ grid.getColumn(VOID_PROPERTY).setRenderer(
+ new RowAwareRenderer(debugLabel));
addComponent(grid);
+ addComponent(debugLabel);
}
@Override
diff --git a/uitest/src/com/vaadin/tests/components/grid/CustomRendererTest.java b/uitest/src/com/vaadin/tests/components/grid/CustomRendererTest.java
index 1827f66777..571a929c7e 100644
--- a/uitest/src/com/vaadin/tests/components/grid/CustomRendererTest.java
+++ b/uitest/src/com/vaadin/tests/components/grid/CustomRendererTest.java
@@ -21,6 +21,7 @@ import java.util.List;
import org.junit.Test;
+import com.vaadin.testbench.elements.LabelElement;
import com.vaadin.tests.annotations.TestCategory;
import com.vaadin.tests.tb3.MultiBrowserTest;
@@ -35,8 +36,27 @@ public class CustomRendererTest extends MultiBrowserTest {
.getText());
}
+ @Test
+ public void testRowAwareRenderer() throws Exception {
+ openTestURL();
+
+ GridElement grid = findGrid();
+ assertEquals("Click me!", grid.getCell(0, 1).getText());
+ assertEquals(CustomRenderer.INIT_DEBUG_LABEL_CAPTION, findDebugLabel()
+ .getText());
+
+ grid.getCell(0, 1).click();
+ assertEquals("row: 0, key: 0", grid.getCell(0, 1).getText());
+ assertEquals("key: 0, itemId: " + CustomRenderer.ITEM_ID,
+ findDebugLabel().getText());
+ }
+
private GridElement findGrid() {
List<GridElement> elements = $(GridElement.class).all();
return elements.get(0);
}
+
+ private LabelElement findDebugLabel() {
+ return $(LabelElement.class).id(CustomRenderer.DEBUG_LABEL_ID);
+ }
}
diff --git a/uitest/src/com/vaadin/tests/components/grid/IntArrayRenderer.java b/uitest/src/com/vaadin/tests/components/grid/IntArrayRenderer.java
index 9ebae4587d..142c370e13 100644
--- a/uitest/src/com/vaadin/tests/components/grid/IntArrayRenderer.java
+++ b/uitest/src/com/vaadin/tests/components/grid/IntArrayRenderer.java
@@ -18,7 +18,7 @@ package com.vaadin.tests.components.grid;
import org.json.JSONArray;
import org.json.JSONException;
-import com.vaadin.ui.components.grid.renderers.AbstractRenderer;
+import com.vaadin.ui.components.grid.AbstractRenderer;
public class IntArrayRenderer extends AbstractRenderer<int[]> {
public IntArrayRenderer() {
diff --git a/uitest/src/com/vaadin/tests/components/grid/RowAwareRenderer.java b/uitest/src/com/vaadin/tests/components/grid/RowAwareRenderer.java
new file mode 100644
index 0000000000..f55f5f064c
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/grid/RowAwareRenderer.java
@@ -0,0 +1,41 @@
+/*
+ * 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 org.json.JSONObject;
+
+import com.vaadin.tests.widgetset.client.grid.RowAwareRendererConnector.RowAwareRendererRpc;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.components.grid.AbstractRenderer;
+
+public class RowAwareRenderer extends AbstractRenderer<Void> {
+ public RowAwareRenderer(final Label debugLabel) {
+ super(Void.class);
+ registerRpc(new RowAwareRendererRpc() {
+ @Override
+ public void clicky(String key) {
+ Object itemId = getItemId(key);
+ debugLabel.setValue("key: " + key + ", itemId: " + itemId);
+ }
+ });
+ }
+
+ @Override
+ public Object encode(Void value) {
+ return JSONObject.NULL;
+ }
+
+}
diff --git a/uitest/src/com/vaadin/tests/widgetset/client/grid/RowAwareRendererConnector.java b/uitest/src/com/vaadin/tests/widgetset/client/grid/RowAwareRendererConnector.java
new file mode 100644
index 0000000000..c82c6c9a18
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/widgetset/client/grid/RowAwareRendererConnector.java
@@ -0,0 +1,78 @@
+/*
+ * 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.widgetset.client.grid;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import com.google.gwt.dom.client.BrowserEvents;
+import com.google.gwt.dom.client.DivElement;
+import com.google.gwt.dom.client.NativeEvent;
+import com.google.gwt.user.client.DOM;
+import com.vaadin.client.ui.grid.Cell;
+import com.vaadin.client.ui.grid.FlyweightCell;
+import com.vaadin.client.ui.grid.Renderer;
+import com.vaadin.client.ui.grid.renderers.AbstractRendererConnector;
+import com.vaadin.client.ui.grid.renderers.ComplexRenderer;
+import com.vaadin.shared.communication.ServerRpc;
+import com.vaadin.shared.ui.Connect;
+
+@Connect(com.vaadin.tests.components.grid.RowAwareRenderer.class)
+public class RowAwareRendererConnector extends AbstractRendererConnector<Void> {
+ public interface RowAwareRendererRpc extends ServerRpc {
+ void clicky(String key);
+ }
+
+ public class RowAwareRenderer extends ComplexRenderer<Void> {
+
+ @Override
+ public Collection<String> getConsumedEvents() {
+ return Arrays.asList(BrowserEvents.CLICK);
+ }
+
+ @Override
+ public void init(FlyweightCell cell) {
+ DivElement div = DivElement.as(DOM.createDiv());
+ div.setAttribute("style",
+ "border: 1px solid red; background: pink;");
+ div.setInnerText("Click me!");
+ cell.getElement().appendChild(div);
+ }
+
+ @Override
+ public void render(FlyweightCell cell, Void data) {
+ // NOOP
+ }
+
+ @Override
+ public void onBrowserEvent(Cell cell, NativeEvent event) {
+ int row = cell.getRow();
+ String key = getRowKey(row);
+ getRpcProxy(RowAwareRendererRpc.class).clicky(key);
+ cell.getElement().setInnerText("row: " + row + ", key: " + key);
+ }
+ }
+
+ @Override
+ protected Class<Void> getType() {
+ return Void.class;
+ }
+
+ @Override
+ protected Renderer<Void> createRenderer() {
+ return new RowAwareRenderer();
+ }
+}