]> source.dussan.org Git - vaadin-framework.git/commitdiff
[merge from 6.7] Use equals instead of == to compare item ids (#8712). Using == will...
authorAutomerge <automerge@vaadin.com>
Fri, 27 Apr 2012 11:39:21 +0000 (11:39 +0000)
committerAutomerge <automerge@vaadin.com>
Fri, 27 Apr 2012 11:39:21 +0000 (11:39 +0000)
svn changeset:23655/svn branch:6.8

src/com/vaadin/ui/Table.java
tests/testbench/com/vaadin/tests/components/table/TableWithContainerRequiringEqualsForItemId.html [new file with mode: 0644]
tests/testbench/com/vaadin/tests/components/table/TableWithContainerRequiringEqualsForItemId.java [new file with mode: 0644]

index e605ec4f6b69002fb01fe12d9f9e22ab8d1956ef..7828fdb7340f04be7e89d2ce1a095647b0495d3f 100644 (file)
@@ -1819,7 +1819,7 @@ public class Table extends AbstractSelect implements Action.Container,
                         if (index < firstIndexNotInCache
                                 && index >= pageBufferFirstIndex
                                 && pageBuffer[CELL_GENERATED_ROW][indexInOldBuffer] == null
-                                && pageBuffer[CELL_ITEMID][indexInOldBuffer] == id) {
+                                && id.equals(pageBuffer[CELL_ITEMID][indexInOldBuffer])) {
                             // we already have data in our cache,
                             // recycle it instead of fetching it via
                             // getValue/getPropertyValue
diff --git a/tests/testbench/com/vaadin/tests/components/table/TableWithContainerRequiringEqualsForItemId.html b/tests/testbench/com/vaadin/tests/components/table/TableWithContainerRequiringEqualsForItemId.html
new file mode 100644 (file)
index 0000000..5364b1c
--- /dev/null
@@ -0,0 +1,97 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head profile="http://selenium-ide.openqa.org/profiles/test-case">
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<link rel="selenium.base" href="http://arturwin.office.itmill.com:9999/" />
+<title>New Test</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">New Test</td></tr>
+</thead><tbody>
+<tr>
+       <td>open</td>
+       <td>/run/com.vaadin.tests.components.table.TableWithContainerRequiringEqualsForItemId?debug&amp;restartApplication</td>
+       <td></td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentstableTableWithContainerRequiringEqualsForItemId::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/domChild[0]/domChild[0]</td>
+       <td>523,81</td>
+</tr>
+<tr>
+       <td>click</td>
+       <td>vaadin=runcomvaadintestscomponentstableTableWithContainerRequiringEqualsForItemId::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VScrollTable[0]/FocusableScrollPanel[0]/VScrollTable$VScrollTableBody[0]/VScrollTable$VScrollTableBody$VScrollTableRow[0]/VButton[0]/domChild[0]/domChild[0]</td>
+       <td></td>
+</tr>
+<tr>
+       <td>assertText</td>
+       <td>vaadin=runcomvaadintestscomponentstableTableWithContainerRequiringEqualsForItemId::PID_SLog_row_0</td>
+       <td>1. Button Button999 clicked</td>
+</tr>
+<tr>
+       <td>click</td>
+       <td>vaadin=runcomvaadintestscomponentstableTableWithContainerRequiringEqualsForItemId::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VScrollTable[0]/FocusableScrollPanel[0]/VScrollTable$VScrollTableBody[0]/VScrollTable$VScrollTableBody$VScrollTableRow[14]/VButton[0]/domChild[0]/domChild[0]</td>
+       <td></td>
+</tr>
+<tr>
+       <td>assertText</td>
+       <td>vaadin=runcomvaadintestscomponentstableTableWithContainerRequiringEqualsForItemId::PID_SLog_row_0</td>
+       <td>2. Button Button985 clicked</td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentstableTableWithContainerRequiringEqualsForItemId::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VScrollTable[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[2]</td>
+       <td>19,7</td>
+</tr>
+<tr>
+       <td>contextmenu</td>
+       <td>vaadin=runcomvaadintestscomponentstableTableWithContainerRequiringEqualsForItemId::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VScrollTable[0]/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[0]/domChild[0]/domChild[0]</td>
+       <td></td>
+</tr>
+<tr>
+       <td>assertText</td>
+       <td>vaadin=runcomvaadintestscomponentstableTableWithContainerRequiringEqualsForItemId::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VScrollTable[0]/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[0]/domChild[0]/domChild[0]</td>
+       <td>0</td>
+</tr>
+<tr>
+       <td>click</td>
+       <td>vaadin=runcomvaadintestscomponentstableTableWithContainerRequiringEqualsForItemId::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VScrollTable[0]/FocusableScrollPanel[0]/VScrollTable$VScrollTableBody[0]/VScrollTable$VScrollTableBody$VScrollTableRow[0]/VButton[0]/domChild[0]/domChild[0]</td>
+       <td></td>
+</tr>
+<tr>
+       <td>assertText</td>
+       <td>vaadin=runcomvaadintestscomponentstableTableWithContainerRequiringEqualsForItemId::PID_SLog_row_0</td>
+       <td>3. Button Button0 clicked</td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentstableTableWithContainerRequiringEqualsForItemId::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VScrollTable[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[2]</td>
+       <td>8,15</td>
+</tr>
+<tr>
+       <td>contextmenu</td>
+       <td>vaadin=runcomvaadintestscomponentstableTableWithContainerRequiringEqualsForItemId::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VScrollTable[0]/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[0]/domChild[0]/domChild[0]</td>
+       <td></td>
+</tr>
+<tr>
+       <td>assertText</td>
+       <td>vaadin=runcomvaadintestscomponentstableTableWithContainerRequiringEqualsForItemId::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VScrollTable[0]/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[0]/domChild[0]/domChild[0]</td>
+       <td>999</td>
+</tr>
+<tr>
+       <td>click</td>
+       <td>vaadin=runcomvaadintestscomponentstableTableWithContainerRequiringEqualsForItemId::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VScrollTable[0]/FocusableScrollPanel[0]/VScrollTable$VScrollTableBody[0]/VScrollTable$VScrollTableBody$VScrollTableRow[0]/VButton[0]/domChild[0]/domChild[0]</td>
+       <td></td>
+</tr>
+<tr>
+       <td>assertText</td>
+       <td>vaadin=runcomvaadintestscomponentstableTableWithContainerRequiringEqualsForItemId::PID_SLog_row_0</td>
+       <td>4. Button Button999 clicked</td>
+</tr>
+
+</tbody></table>
+</body>
+</html>
diff --git a/tests/testbench/com/vaadin/tests/components/table/TableWithContainerRequiringEqualsForItemId.java b/tests/testbench/com/vaadin/tests/components/table/TableWithContainerRequiringEqualsForItemId.java
new file mode 100644 (file)
index 0000000..1b0335b
--- /dev/null
@@ -0,0 +1,128 @@
+package com.vaadin.tests.components.table;
+
+import java.util.Date;
+
+import com.vaadin.data.util.BeanContainer;
+import com.vaadin.data.util.BeanItem;
+import com.vaadin.tests.components.TestBase;
+import com.vaadin.tests.util.Log;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Component;
+import com.vaadin.ui.Table;
+import com.vaadin.ui.themes.Reindeer;
+
+public class TableWithContainerRequiringEqualsForItemId extends TestBase {
+
+    private MyEntityContainer container = new MyEntityContainer();
+    private Log log = new Log(10);
+
+    public static class MyEntityContainer extends BeanContainer<Long, MyEntity> {
+
+        public MyEntityContainer() {
+            super(MyEntity.class);
+            setBeanIdResolver(new BeanIdResolver<Long, TableWithContainerRequiringEqualsForItemId.MyEntity>() {
+
+                public Long getIdForBean(MyEntity bean) {
+                    // Return a new instance every time to ensure Table can
+                    // handle it
+                    return new Long(bean.getId());
+                }
+            });
+
+        }
+
+        @Override
+        public Long getIdByIndex(int index) {
+            // Explicitly get the id using the resolver to make sure the
+            // instance does not stay the same
+            BeanItem<MyEntity> beanItem = getItem(super.getIdByIndex(index));
+            return getBeanIdResolver().getIdForBean(beanItem.getBean());
+        };
+
+    }
+
+    @Override
+    protected void setup() {
+        Table t = new Table("Table with 1000 item");
+        t.addGeneratedColumn("Actions", new Table.ColumnGenerator() {
+            public Component generateCell(final Table source,
+                    final Object itemId, final Object columnId) {
+                Button tripFolderLink = new Button("Button" + itemId);
+                tripFolderLink.addListener(new Button.ClickListener() {
+                    public void buttonClick(final ClickEvent event) {
+                        log.log("Button " + event.getButton().getCaption()
+                                + " clicked");
+                    }
+                });
+                tripFolderLink.setStyleName(Reindeer.BUTTON_SMALL);
+                return tripFolderLink;
+            }
+        });
+
+        for (int i = 0; i < 1000; i++) {
+            MyEntity myEntity = new MyEntity(i + "st");
+            myEntity.setCreated(new Date(new Date().getTime() - 24 * 60 * 60
+                    * 1000L));
+            myEntity.setId(i);
+            container.addBean(myEntity);
+            // entityProvider.addEntity(myEntity);
+        }
+
+        t.setContainerDataSource(container);
+        t.setVisibleColumns(new String[] { "id", "created", "name", "Actions" });
+
+        addComponent(t);
+        addComponent(log);
+
+        t.sort(new Object[] { "id" }, new boolean[] { false });
+
+    }
+
+    @Override
+    protected String getDescription() {
+        return "Test that verifies that Table works correctly with containers which do not return the same instance of the itemId object but instead requires an itemId.equals(otherItemId) check";
+    }
+
+    @Override
+    protected Integer getTicketNumber() {
+        return 8712;
+    }
+
+    public static class MyEntity {
+
+        private long id;
+
+        private String name;
+
+        private Date created;
+
+        public MyEntity() {
+        }
+
+        public MyEntity(String string) {
+            name = string;
+        }
+
+        public String getName() {
+            return name;
+        }
+
+        public Date getCreated() {
+            return created;
+        }
+
+        public void setCreated(Date created) {
+            this.created = created;
+        }
+
+        public long getId() {
+            return id;
+        }
+
+        public void setId(long id) {
+            this.id = id;
+        }
+    }
+
+}