From 57decccde83a8473ad3efb3c9a45c18e746982a1 Mon Sep 17 00:00:00 2001 From: Jouni Koivuviita Date: Tue, 1 Apr 2008 07:18:47 +0000 Subject: [PATCH] New ticket testcase for #1506 svn changeset:4101/svn branch:trunk --- .../toolkit/tests/tickets/Ticket1506.java | 15 +++ .../tests/tickets/Ticket1506_Panel.java | 44 +++++++ .../tickets/Ticket1506_TestContainer.java | 116 ++++++++++++++++++ .../tickets/Ticket1506_TestContainer2.java | 110 +++++++++++++++++ 4 files changed, 285 insertions(+) create mode 100644 src/com/itmill/toolkit/tests/tickets/Ticket1506.java create mode 100644 src/com/itmill/toolkit/tests/tickets/Ticket1506_Panel.java create mode 100644 src/com/itmill/toolkit/tests/tickets/Ticket1506_TestContainer.java create mode 100644 src/com/itmill/toolkit/tests/tickets/Ticket1506_TestContainer2.java diff --git a/src/com/itmill/toolkit/tests/tickets/Ticket1506.java b/src/com/itmill/toolkit/tests/tickets/Ticket1506.java new file mode 100644 index 0000000000..6f25a531e1 --- /dev/null +++ b/src/com/itmill/toolkit/tests/tickets/Ticket1506.java @@ -0,0 +1,15 @@ +package com.itmill.toolkit.tests.tickets; + +import com.itmill.toolkit.ui.CustomComponent; +import com.itmill.toolkit.ui.Panel; + +public class Ticket1506 extends CustomComponent { + + Panel p; + + public Ticket1506() { + p = new Ticket1506_Panel(); + setCompositionRoot(p); + } + +} diff --git a/src/com/itmill/toolkit/tests/tickets/Ticket1506_Panel.java b/src/com/itmill/toolkit/tests/tickets/Ticket1506_Panel.java new file mode 100644 index 0000000000..a8446fb97d --- /dev/null +++ b/src/com/itmill/toolkit/tests/tickets/Ticket1506_Panel.java @@ -0,0 +1,44 @@ +package com.itmill.toolkit.tests.tickets; + +import com.itmill.toolkit.data.util.ObjectProperty; +import com.itmill.toolkit.data.Container; +import com.itmill.toolkit.ui.Component; +import com.itmill.toolkit.ui.Panel; +import com.itmill.toolkit.ui.Select; +import com.itmill.toolkit.ui.Button; + +/** + * @author Efecte R&D + * @version $Revision$, $Date$ + */ +public class Ticket1506_Panel extends Panel { + + public Ticket1506_Panel() { + ObjectProperty property1 = new ObjectProperty(null, String.class); + addComponent(initSelect(new Ticket1506_TestContainer(), "Test select", property1)); + addComponent(initButton(property1)); + addComponent(initSelect(new Ticket1506_TestContainer2(), "Test select 2", new ObjectProperty(null, String.class))); + } + + private Component initButton(final ObjectProperty property) { + Button button = new Button("Clear select"); + button.addListener(new Button.ClickListener() { + public void buttonClick(Button.ClickEvent event) { + property.setValue(null); + } + }); + return button; + } + + private Component initSelect(Container containerDataSource, String caption, ObjectProperty property) { + Select select = new Select(caption); + select.setFilteringMode(Select.FILTERINGMODE_CONTAINS); + select.setImmediate(true); + select.setNullSelectionAllowed(false); + select.setItemCaptionPropertyId(Ticket1506_TestContainer.PROPERTY_2_ID); + + select.setContainerDataSource(containerDataSource); + select.setPropertyDataSource(property); + return select; + } +} diff --git a/src/com/itmill/toolkit/tests/tickets/Ticket1506_TestContainer.java b/src/com/itmill/toolkit/tests/tickets/Ticket1506_TestContainer.java new file mode 100644 index 0000000000..329f3014d8 --- /dev/null +++ b/src/com/itmill/toolkit/tests/tickets/Ticket1506_TestContainer.java @@ -0,0 +1,116 @@ +package com.itmill.toolkit.tests.tickets; + +import com.itmill.toolkit.data.Container; +import com.itmill.toolkit.data.Item; +import com.itmill.toolkit.data.Property; +import com.itmill.toolkit.data.util.PropertysetItem; +import com.itmill.toolkit.data.util.ObjectProperty; + +import java.util.*; + +/** + * @author Efecte R&D + * @version $Revision$, $Date$ + */ +public class Ticket1506_TestContainer implements Container { + private Map items = new HashMap(); + public static final String ITEM_1_ID = "1"; + public static final String ITEM_2_ID = "2"; + public static final String PROPERTY_1_ID = "property 1"; + public static final String PROPERTY_2_ID = "property 2"; + + private void loadItems() { + final PropertysetItem item1 = new PropertysetItem(); + item1.addItemProperty(PROPERTY_1_ID, new ObjectProperty("value 1", String.class)); + item1.addItemProperty(PROPERTY_2_ID, new ObjectProperty("name 1", String.class)); + this.items.put(ITEM_1_ID, item1); + + final PropertysetItem item2 = new PropertysetItem(); + item2.addItemProperty(PROPERTY_1_ID, new ObjectProperty("value 2", String.class)); + item2.addItemProperty(PROPERTY_2_ID, new ObjectProperty("name 2", String.class)); + this.items.put(ITEM_2_ID, item2); + } + + public Item getItem(Object itemId) { + if (items.isEmpty()) { + loadItems(); + } + return (Item) items.get(itemId); + } + + public Collection getContainerPropertyIds() { + if (items.isEmpty()) { + loadItems(); + } + ArrayList a = new ArrayList(); + a.add(PROPERTY_1_ID); + a.add(PROPERTY_2_ID); + return a; + } + + public Collection getItemIds() { + if (items.isEmpty()) { + loadItems(); + } + ArrayList a = new ArrayList(); + a.add(ITEM_1_ID); + a.add(ITEM_2_ID); + return a; + } + + public Property getContainerProperty(Object itemId, Object propertyId) { + if (items.isEmpty()) { + loadItems(); + } + Item item = (Item) items.get(itemId); + if (item != null) { + return item.getItemProperty(propertyId); + } + return null; + } + + public Class getType(Object propertyId) { + if (items.isEmpty()) { + loadItems(); + } + return String.class; + } + + public int size() { + if (items.isEmpty()) { + loadItems(); + } + return items.size(); + } + + public boolean containsId(Object itemId) { + if (items.isEmpty()) { + loadItems(); + } + return items.containsKey(itemId); + } + + public Item addItem(Object itemId) throws UnsupportedOperationException { + throw new UnsupportedOperationException("Not implemented"); + } + + public Object addItem() throws UnsupportedOperationException { + throw new UnsupportedOperationException("Not implemented"); + } + + public boolean removeItem(Object itemId) throws UnsupportedOperationException { + throw new UnsupportedOperationException("Not implemented"); + } + + public boolean addContainerProperty(Object propertyId, Class type, Object defaultValue) throws UnsupportedOperationException { + throw new UnsupportedOperationException("Not implemented"); + } + + public boolean removeContainerProperty(Object propertyId) throws UnsupportedOperationException { + throw new UnsupportedOperationException("Not implemented"); + } + + public boolean removeAllItems() throws UnsupportedOperationException { + throw new UnsupportedOperationException("Not implemented"); + } +} diff --git a/src/com/itmill/toolkit/tests/tickets/Ticket1506_TestContainer2.java b/src/com/itmill/toolkit/tests/tickets/Ticket1506_TestContainer2.java new file mode 100644 index 0000000000..dda5bb2fe3 --- /dev/null +++ b/src/com/itmill/toolkit/tests/tickets/Ticket1506_TestContainer2.java @@ -0,0 +1,110 @@ +package com.itmill.toolkit.tests.tickets; + +import com.itmill.toolkit.data.Container; +import com.itmill.toolkit.data.Item; +import com.itmill.toolkit.data.Property; +import com.itmill.toolkit.data.util.PropertysetItem; +import com.itmill.toolkit.data.util.ObjectProperty; + +import java.util.*; + +/** + * @author Efecte R&D + * @version $Revision$, $Date$ + */ +public class Ticket1506_TestContainer2 implements Container { + private Map items = new HashMap(); + public static final String ITEM_1_ID = "1"; + public static final String ITEM_2_ID = "2"; + public static final String PROPERTY_1_ID = "property 1"; + public static final String PROPERTY_2_ID = "property 2"; + + private void loadItems() { + for (int i = 1; i < 15; i++) { + final PropertysetItem item = new PropertysetItem(); + item.addItemProperty(PROPERTY_1_ID, new ObjectProperty("value " + i, String.class)); + item.addItemProperty(PROPERTY_2_ID, new ObjectProperty("name " + i, String.class)); + this.items.put(String.valueOf(i), item); + } + } + + public Item getItem(Object itemId) { + if (items.isEmpty()) { + loadItems(); + } + return (Item) items.get(itemId); + } + + public Collection getContainerPropertyIds() { + if (items.isEmpty()) { + loadItems(); + } + ArrayList a = new ArrayList(); + a.add(PROPERTY_1_ID); + a.add(PROPERTY_2_ID); + return a; + } + + public Collection getItemIds() { + if (items.isEmpty()) { + loadItems(); + } + return items.keySet(); + } + + public Property getContainerProperty(Object itemId, Object propertyId) { + if (items.isEmpty()) { + loadItems(); + } + Item item = (Item) items.get(itemId); + if (item != null) { + return item.getItemProperty(propertyId); + } + return null; + } + + public Class getType(Object propertyId) { + if (items.isEmpty()) { + loadItems(); + } + return String.class; + } + + public int size() { + if (items.isEmpty()) { + loadItems(); + } + return items.size(); + } + + public boolean containsId(Object itemId) { + if (items.isEmpty()) { + loadItems(); + } + return items.containsKey(itemId); + } + + public Item addItem(Object itemId) throws UnsupportedOperationException { + throw new UnsupportedOperationException("Not implemented"); + } + + public Object addItem() throws UnsupportedOperationException { + throw new UnsupportedOperationException("Not implemented"); + } + + public boolean removeItem(Object itemId) throws UnsupportedOperationException { + throw new UnsupportedOperationException("Not implemented"); + } + + public boolean addContainerProperty(Object propertyId, Class type, Object defaultValue) throws UnsupportedOperationException { + throw new UnsupportedOperationException("Not implemented"); + } + + public boolean removeContainerProperty(Object propertyId) throws UnsupportedOperationException { + throw new UnsupportedOperationException("Not implemented"); + } + + public boolean removeAllItems() throws UnsupportedOperationException { + throw new UnsupportedOperationException("Not implemented"); + } +} \ No newline at end of file -- 2.39.5