]> source.dussan.org Git - vaadin-framework.git/commitdiff
RendererClickEvent now tells about propertyIds (#13334)
authorHenrik Paul <henrik@vaadin.com>
Fri, 19 Dec 2014 11:57:23 +0000 (13:57 +0200)
committerHenrik Paul <henrik@vaadin.com>
Thu, 8 Jan 2015 11:50:19 +0000 (13:50 +0200)
Change-Id: I5d67516516c46984c965577653b4fb44ddbaff11

server/src/com/vaadin/ui/renderer/ClickableRenderer.java
uitest/src/com/vaadin/tests/components/grid/WidgetRenderers.java
uitest/src/com/vaadin/tests/components/grid/WidgetRenderersTest.java

index 851bbf8510a06cd8d2b1268e408ffa96921b69d1..d640ce8b71c46836b5f4a9bdcaec38f1d69528fe 100644 (file)
@@ -91,6 +91,15 @@ public class ClickableRenderer<T> extends AbstractRenderer<T> {
         public Column getColumn() {
             return column;
         }
+
+        /**
+         * Returns the property ID where the click event originated.
+         * 
+         * @return the property ID of the clicked cell
+         */
+        public Object getPropertyId() {
+            return column.getPropertyId();
+        }
     }
 
     protected ClickableRenderer(Class<T> presentationType) {
index de6fb30e1c9610c2a2bc31430004891a7208fb75..310cd357faeed2512da2161daadd1ef7a6e4be17 100644 (file)
@@ -31,8 +31,11 @@ import com.vaadin.ui.renderer.ClickableRenderer.RendererClickListener;
 import com.vaadin.ui.renderer.ImageRenderer;
 import com.vaadin.ui.renderer.ProgressBarRenderer;
 
+@SuppressWarnings("all")
 public class WidgetRenderers extends AbstractTestUI {
 
+    static final String PROPERTY_ID = "property id";
+
     @Override
     protected void setup(VaadinRequest request) {
         IndexedContainer container = new IndexedContainer();
@@ -43,6 +46,7 @@ public class WidgetRenderers extends AbstractTestUI {
                 .addContainerProperty(ButtonRenderer.class, String.class, null);
         container.addContainerProperty(ImageRenderer.class, Resource.class,
                 null);
+        container.addContainerProperty(PROPERTY_ID, String.class, null);
 
         final Item item = container.getItem(container.addItem());
 
@@ -50,6 +54,7 @@ public class WidgetRenderers extends AbstractTestUI {
         item.getItemProperty(ButtonRenderer.class).setValue("Click");
         item.getItemProperty(ImageRenderer.class).setValue(
                 new ThemeResource("window/img/close.png"));
+        item.getItemProperty(PROPERTY_ID).setValue("Click");
 
         final Grid grid = new Grid(container);
 
@@ -78,6 +83,15 @@ public class WidgetRenderers extends AbstractTestUI {
                     }
                 }));
 
+        grid.getColumn(PROPERTY_ID).setRenderer(
+                new ButtonRenderer(new RendererClickListener() {
+                    @Override
+                    public void click(RendererClickEvent event) {
+                        item.getItemProperty(PROPERTY_ID).setValue(
+                                event.getPropertyId());
+                    }
+                }));
+
         addComponent(grid);
 
         addComponent(new Button("Change column order",
index 864a559fc6175b4423a22dc318a73a84922469fa..ba8e5135ab62b3093e0d443c1f69277b61a7c876 100644 (file)
@@ -92,6 +92,15 @@ public class WidgetRenderersTest extends MultiBrowserTest {
                 By.className("gwt-Button")));
     }
 
+    @Test
+    public void testPropertyIdInEvent() {
+        openTestURL();
+        WebElement button = getGridCell(0, 3).findElement(
+                By.className("gwt-Button"));
+        button.click();
+        assertEquals(WidgetRenderers.PROPERTY_ID, button.getText());
+    }
+
     GridCellElement getGridCell(int row, int col) {
         return $(GridElement.class).first().getCell(row, col);
     }