]> source.dussan.org Git - vaadin-framework.git/commitdiff
Table should only unregister property data sources that it has registered itself...
authorLeif Åstrand <leif@vaadin.com>
Wed, 7 Sep 2011 06:49:55 +0000 (06:49 +0000)
committerLeif Åstrand <leif@vaadin.com>
Wed, 7 Sep 2011 06:49:55 +0000 (06:49 +0000)
svn changeset:20896/svn branch:6.6

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

index 738f9c53c501699f6fd0b8cdbbf6df2425d7b6e3..8519f4ec2cb9d46efed3b670d242dd37b2ce39b0 100644 (file)
@@ -393,6 +393,8 @@ public class Table extends AbstractSelect implements Action.Container,
 
     private MultiSelectMode multiSelectMode = MultiSelectMode.DEFAULT;
 
+    private final Map<Field, Property> associatedProperties = new HashMap<Field, Property>();
+
     /* Table constructors */
 
     /**
@@ -1707,7 +1709,15 @@ public class Table extends AbstractSelect implements Action.Container,
          * fields in memory.
          */
         if (component instanceof Field) {
-            ((Field) component).setPropertyDataSource(null);
+            Field field = (Field) component;
+            Property associatedProperty = associatedProperties
+                    .remove(component);
+            if (associatedProperty != null
+                    && field.getPropertyDataSource() == associatedProperty) {
+                // Remove the property data source only if it's the one we
+                // added in getPropertyValue
+                field.setPropertyDataSource(null);
+            }
         }
     }
 
@@ -2784,6 +2794,9 @@ public class Table extends AbstractSelect implements Action.Container,
             final Field f = fieldFactory.createField(getContainerDataSource(),
                     rowId, colId, this);
             if (f != null) {
+                // Remember that we have made this association so we can remove
+                // it when the component is removed
+                associatedProperties.put(f, property);
                 f.setPropertyDataSource(property);
                 return f;
             }
diff --git a/tests/src/com/vaadin/tests/components/table/TableUnregisterComponent.html b/tests/src/com/vaadin/tests/components/table/TableUnregisterComponent.html
new file mode 100644 (file)
index 0000000..1e5617d
--- /dev/null
@@ -0,0 +1,52 @@
+<?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="" />
+<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.TableUnregisterComponent?restartApplication</td>
+       <td></td>
+</tr>
+<tr>
+       <td>click</td>
+       <td>vaadin=runcomvaadintestscomponentstableTableUnregisterComponent::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VButton[0]/domChild[0]/domChild[0]</td>
+       <td></td>
+</tr>
+<tr>
+       <td>assertText</td>
+       <td>vaadin=runcomvaadintestscomponentstableTableUnregisterComponent::PID_SLog_row_0</td>
+       <td>1. Embedded field property data source set</td>
+</tr>
+<tr>
+       <td>click</td>
+       <td>vaadin=runcomvaadintestscomponentstableTableUnregisterComponent::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[3]/VButton[0]/domChild[0]/domChild[0]</td>
+       <td></td>
+</tr>
+<tr>
+       <td>assertText</td>
+       <td>vaadin=runcomvaadintestscomponentstableTableUnregisterComponent::PID_SLog_row_0</td>
+       <td>2. Edit field property data source set</td>
+</tr>
+<tr>
+       <td>click</td>
+       <td>vaadin=runcomvaadintestscomponentstableTableUnregisterComponent::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[3]/VButton[0]/domChild[0]/domChild[0]</td>
+       <td></td>
+</tr>
+<tr>
+       <td>assertText</td>
+       <td>vaadin=runcomvaadintestscomponentstableTableUnregisterComponent::PID_SLog_row_0</td>
+       <td>3. Edit field property data source cleared</td>
+</tr>
+
+</tbody></table>
+</body>
+</html>
diff --git a/tests/src/com/vaadin/tests/components/table/TableUnregisterComponent.java b/tests/src/com/vaadin/tests/components/table/TableUnregisterComponent.java
new file mode 100644 (file)
index 0000000..91f5aec
--- /dev/null
@@ -0,0 +1,102 @@
+package com.vaadin.tests.components.table;
+
+import com.vaadin.data.Container;
+import com.vaadin.data.Item;
+import com.vaadin.data.Property;
+import com.vaadin.data.util.IndexedContainer;
+import com.vaadin.data.util.ObjectProperty;
+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.Button.ClickListener;
+import com.vaadin.ui.Component;
+import com.vaadin.ui.DefaultFieldFactory;
+import com.vaadin.ui.Field;
+import com.vaadin.ui.Table;
+import com.vaadin.ui.TextField;
+
+public class TableUnregisterComponent extends TestBase {
+
+    private static final String COL_A = "textFieldA";
+    private static final String COL_B = "textB";
+
+    @Override
+    protected void setup() {
+        final Log log = new Log(5);
+
+        IndexedContainer container = new IndexedContainer();
+        container.addContainerProperty(COL_A, TextField.class, null);
+        container.addContainerProperty(COL_B, String.class, "");
+
+        Item it = container.addItem("a");
+        final ObjectProperty<String> valA = new ObjectProperty<String>("orgVal");
+        final TextField fieldA = new TextField(valA) {
+            @Override
+            public void setPropertyDataSource(Property newDataSource) {
+                super.setPropertyDataSource(newDataSource);
+                if (newDataSource == null) {
+                    log.log("Embedded field property data source cleared");
+                } else {
+                    log.log("Embedded field property data source set");
+                }
+            }
+        };
+        it.getItemProperty(COL_A).setValue(fieldA);
+        it.getItemProperty(COL_B).setValue("Some text here");
+
+        final Table table = new Table("", container);
+        table.setColumnCollapsingAllowed(true);
+        table.setTableFieldFactory(new DefaultFieldFactory() {
+            @Override
+            public Field createField(Container container, Object itemId,
+                    Object propertyId, Component uiContext) {
+                if (COL_B.equals(propertyId)) {
+                    Field field = new TextField() {
+                        @Override
+                        public void setPropertyDataSource(Property newDataSource) {
+                            super.setPropertyDataSource(newDataSource);
+                            if (newDataSource == null) {
+                                log.log("Edit field property data source cleared");
+                            } else {
+                                log.log("Edit field property data source set");
+                            }
+                        }
+                    };
+                    field.setCaption(createCaptionByPropertyId(propertyId));
+                    return field;
+                } else {
+                    return super.createField(container, itemId, propertyId,
+                            uiContext);
+                }
+            }
+        });
+
+        addComponent(log);
+        addComponent(table);
+
+        addComponent(new Button("Switch column collapse", new ClickListener() {
+            public void buttonClick(ClickEvent event) {
+                table.setColumnCollapsed(COL_A, !table.isColumnCollapsed(COL_A));
+            }
+        }));
+
+        addComponent(new Button("Switch editable", new ClickListener() {
+            public void buttonClick(ClickEvent event) {
+                table.setEditable(!table.isEditable());
+            }
+        }));
+
+    }
+
+    @Override
+    protected String getDescription() {
+        return "Table.uncollapseColumn (triggered by collapsing column or disabling editable mode) should only unregister property data sources that have been added by the table.";
+    }
+
+    @Override
+    protected Integer getTicketNumber() {
+        return Integer.valueOf("7541");
+    }
+
+}