From 79a6f890e794df686fc28d2dea831515b23953d8 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Wed, 19 Sep 2012 13:45:09 +0000 Subject: [PATCH] Merged AbstractSelect now listens to changes in icon property (#9663) svn changeset:24490/svn branch:6.8 Change-Id: Id5fdf46295fba758fc4be7d1b3b47e29651e0535 --- server/src/com/vaadin/ui/AbstractSelect.java | 9 +++ .../tests/components/tree/TreeIconUpdate.html | 42 +++++++++++ .../tests/components/tree/TreeIconUpdate.java | 71 +++++++++++++++++++ 3 files changed, 122 insertions(+) create mode 100644 uitest/src/com/vaadin/tests/components/tree/TreeIconUpdate.html create mode 100644 uitest/src/com/vaadin/tests/components/tree/TreeIconUpdate.java diff --git a/server/src/com/vaadin/ui/AbstractSelect.java b/server/src/com/vaadin/ui/AbstractSelect.java index 45df42a9be..78fab068dd 100644 --- a/server/src/com/vaadin/ui/AbstractSelect.java +++ b/server/src/com/vaadin/ui/AbstractSelect.java @@ -1858,6 +1858,15 @@ public abstract class AbstractSelect extends AbstractField implements break; } + if (getItemIconPropertyId() != null) { + final Property p = getContainerProperty(itemId, + getItemIconPropertyId()); + if (p != null && p instanceof Property.ValueChangeNotifier) { + ((Property.ValueChangeNotifier) p) + .addListener(getCaptionChangeListener()); + captionChangeNotifiers.add(p); + } + } } public void clear() { diff --git a/uitest/src/com/vaadin/tests/components/tree/TreeIconUpdate.html b/uitest/src/com/vaadin/tests/components/tree/TreeIconUpdate.html new file mode 100644 index 0000000000..d16d8fd79d --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/tree/TreeIconUpdate.html @@ -0,0 +1,42 @@ + + + + + + +New Test + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
New Test
open/run/com.vaadin.tests.components.tree.TreeIconUpdate?restartApplication
clickvaadin=runcomvaadintestscomponentstreeTreeIconUpdate::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VButton[0]/domChild[0]/domChild[0]
screenCapturefoo-with-different-icon
clickvaadin=runcomvaadintestscomponentstreeTreeIconUpdate::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VButton[0]/domChild[0]/domChild[0]
assertTextvaadin=runcomvaadintestscomponentstreeTreeIconUpdate::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTree[0]#n[0]foo
+ + diff --git a/uitest/src/com/vaadin/tests/components/tree/TreeIconUpdate.java b/uitest/src/com/vaadin/tests/components/tree/TreeIconUpdate.java new file mode 100644 index 0000000000..8e0eac801d --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/tree/TreeIconUpdate.java @@ -0,0 +1,71 @@ +package com.vaadin.tests.components.tree; + +import com.vaadin.data.Item; +import com.vaadin.data.util.HierarchicalContainer; +import com.vaadin.server.Resource; +import com.vaadin.server.ThemeResource; +import com.vaadin.tests.components.TestBase; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Button.ClickListener; +import com.vaadin.ui.Tree; + +public class TreeIconUpdate extends TestBase { + + private static final Resource ICON1 = new ThemeResource( + "../runo/icons/16/folder.png"); + private static final Resource ICON2 = new ThemeResource( + "../runo/icons/16/ok.png"); + + @Override + protected void setup() { + HierarchicalContainer container = new HierarchicalContainer(); + container.addContainerProperty("name", String.class, null); + container.addContainerProperty("icon", Resource.class, null); + final Tree tree = new Tree(); + tree.setContainerDataSource(container); + tree.setItemIconPropertyId("icon"); + tree.setItemCaptionPropertyId("name"); + + for (int i = 0; i < 20; i++) { + Item bar = container.addItem("bar" + i); + bar.getItemProperty("name").setValue("Bar" + i); + bar.getItemProperty("icon").setValue(ICON1); + + if (i > 3) { + container.setParent("bar" + i, "bar" + (i - 1)); + } + } + + addComponent(tree); + + Button button = new Button("Change icon", new ClickListener() { + + public void buttonClick(ClickEvent event) { + tree.getItem("bar0").getItemProperty("icon").setValue(ICON2); + } + }); + + addComponent(button); + button = new Button("Change caption", new ClickListener() { + + public void buttonClick(ClickEvent event) { + tree.getItem("bar0").getItemProperty("name").setValue("foo"); + } + }); + + addComponent(button); + + } + + @Override + protected String getDescription() { + return "Click the button to change the icon. The tree should be updated"; + } + + @Override + protected Integer getTicketNumber() { + return 9663; + } + +} -- 2.39.5