summaryrefslogtreecommitdiffstats
path: root/src/com/vaadin/tests/containers
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/vaadin/tests/containers')
-rw-r--r--src/com/vaadin/tests/containers/BeanItemContainerFilteringTest.java172
-rw-r--r--src/com/vaadin/tests/containers/BeanItemContainerTest.java75
-rw-r--r--src/com/vaadin/tests/containers/IndexedContainerFilteringTest.java139
3 files changed, 386 insertions, 0 deletions
diff --git a/src/com/vaadin/tests/containers/BeanItemContainerFilteringTest.java b/src/com/vaadin/tests/containers/BeanItemContainerFilteringTest.java
new file mode 100644
index 0000000000..e4b65d5676
--- /dev/null
+++ b/src/com/vaadin/tests/containers/BeanItemContainerFilteringTest.java
@@ -0,0 +1,172 @@
+package com.vaadin.tests.containers;
+
+import com.vaadin.data.Item;
+import com.vaadin.data.util.BeanItemContainer;
+import com.vaadin.terminal.Sizeable;
+import com.vaadin.tests.components.TestBase;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.CheckBox;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.Table;
+import com.vaadin.ui.TextField;
+import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.Button.ClickEvent;
+
+public class BeanItemContainerFilteringTest extends TestBase {
+
+ private Table table;
+ private BeanItemContainer<TestBean> container;
+ private TextField filterString;
+ private TextField position;
+ private int nextToAdd = 1;
+ private Label nextLabel;
+
+ protected static class TestBean {
+ private String id;
+ private String value;
+
+ public TestBean() {
+ }
+
+ public TestBean(String id, String value) {
+ setId(id);
+ setValue(value);
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ public String getValue() {
+ return value;
+ }
+ }
+
+ @Override
+ protected String getDescription() {
+ return "Test adding items in a filtered BeanItemContainer.";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return new Integer(1061);
+ }
+
+ @Override
+ protected void setup() {
+ table = new Table();
+ try {
+ container = new BeanItemContainer<TestBean>(TestBean.class);
+ table.setContainerDataSource(container);
+
+ table.setWidth(300, Sizeable.UNITS_PIXELS);
+ table.setSelectable(true);
+ table.setMultiSelect(false);
+ table.setEditable(true);
+ table.setImmediate(true);
+ // table.addContainerProperty("column1", String.class, "test");
+
+ for (int i = 0; i < 25; ++i) {
+ container.addItem(new TestBean("Item " + i, "Value for " + i));
+ }
+
+ VerticalLayout vl = new VerticalLayout();
+
+ // activate & deactivate filtering
+ filterString = new TextField("Filter string:", "1");
+ vl.addComponent(filterString);
+
+ final CheckBox cb = new CheckBox("Filter on value",
+ new Button.ClickListener() {
+ public void buttonClick(ClickEvent event) {
+ container.removeAllContainerFilters();
+ if (((CheckBox) event.getSource()).booleanValue()) {
+ container.addContainerFilter("value",
+ filterString.getValue().toString(),
+ false, false);
+ }
+ }
+ });
+ cb.setImmediate(true);
+ vl.addComponent(cb);
+
+ nextLabel = new Label();
+ nextLabel.setCaption("Next id: " + nextToAdd);
+ vl.addComponent(nextLabel);
+
+ // addItemAt(idx), addItemAfter(selection), addItem()
+
+ final Button addItemButton = new Button("addItem()",
+ new Button.ClickListener() {
+ public void buttonClick(ClickEvent event) {
+ container.addItem(new TestBean("addItem() "
+ + nextToAdd, "value " + nextToAdd));
+ nextToAdd++;
+ nextLabel.setCaption("Next id: " + nextToAdd);
+ }
+ });
+ addItemButton.setImmediate(true);
+ vl.addComponent(addItemButton);
+
+ final Button addItemAfterButton = new Button("addItemAfter()",
+ new Button.ClickListener() {
+ public void buttonClick(ClickEvent event) {
+ Object selection = table.getValue();
+ if (selection == null) {
+ return;
+ }
+ TestBean bean = new TestBean("addItemAfter() "
+ + nextToAdd, "value " + nextToAdd);
+ Item item = container.addItemAfter(selection, bean);
+ if (item == null) {
+ getMainWindow().showNotification(
+ "Adding item after " + selection
+ + " failed");
+ }
+ nextToAdd++;
+ nextLabel.setCaption("Next id: " + nextToAdd);
+ }
+ });
+ addItemAfterButton.setImmediate(true);
+ vl.addComponent(addItemAfterButton);
+
+ position = new TextField("Position:", "0");
+ vl.addComponent(position);
+
+ final Button addItemAtButton = new Button("addItemAt()",
+ new Button.ClickListener() {
+ public void buttonClick(ClickEvent event) {
+ int index = Integer.parseInt(position.getValue()
+ .toString());
+ TestBean bean = new TestBean("addItemAt() "
+ + nextToAdd, "value " + nextToAdd);
+ Item item = container.addItemAt(index, bean);
+ if (item == null) {
+ getMainWindow().showNotification(
+ "Adding item at index "
+ + position.getValue()
+ + " failed");
+ }
+ nextToAdd++;
+ nextLabel.setCaption("Next id: " + nextToAdd);
+ }
+ });
+ addItemAtButton.setImmediate(true);
+ vl.addComponent(addItemAtButton);
+
+ getLayout().addComponent(table);
+ getLayout().addComponent(vl);
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+
+}
diff --git a/src/com/vaadin/tests/containers/BeanItemContainerTest.java b/src/com/vaadin/tests/containers/BeanItemContainerTest.java
new file mode 100644
index 0000000000..905ec2f9ff
--- /dev/null
+++ b/src/com/vaadin/tests/containers/BeanItemContainerTest.java
@@ -0,0 +1,75 @@
+package com.vaadin.tests.containers;
+
+import java.util.Collection;
+import java.util.LinkedList;
+
+import com.vaadin.data.util.BeanItemContainer;
+
+public class BeanItemContainerTest {
+
+ /**
+ * Test class for BeanItemContainer
+ *
+ * @throws IllegalAccessException
+ * @throws InstantiationException
+ */
+ public static void main(String[] args) throws InstantiationException,
+ IllegalAccessException {
+ BeanItemContainer<Hello> c = new BeanItemContainer<Hello>(Hello.class);
+ c.addItem(new Hello());
+
+ Collection<Hello> col = new LinkedList<Hello>();
+ for (int i = 0; i < 100; i++) {
+ col.add(new Hello());
+ }
+ col.add(new Hello2());
+
+ c = new BeanItemContainer<Hello>(col);
+
+ System.out.println(c + " contains " + c.size() + " objects");
+
+ // test that subclass properties are handled correctly
+ System.out.println(c + " item 0 second = "
+ + c.getContainerProperty(c.getIdByIndex(0), "second"));
+ System.out.println(c + " item 100 second = "
+ + c.getContainerProperty(c.getIdByIndex(100), "second"));
+
+ }
+
+ public static class Hello {
+
+ public String first;
+ public String second;
+
+ public Hello() {
+ first = "f";
+ second = "l";
+ }
+
+ public String getFirst() {
+ return first;
+ }
+
+ public void setFirst(String first) {
+ this.first = first;
+ }
+
+ public String getSecond() {
+ return second;
+ }
+
+ public void setSecond(String second) {
+ this.second = second;
+ }
+
+ }
+
+ public static class Hello2 extends Hello {
+
+ @Override
+ public String getSecond() {
+ return "second";
+ }
+
+ }
+}
diff --git a/src/com/vaadin/tests/containers/IndexedContainerFilteringTest.java b/src/com/vaadin/tests/containers/IndexedContainerFilteringTest.java
new file mode 100644
index 0000000000..d66435bdaa
--- /dev/null
+++ b/src/com/vaadin/tests/containers/IndexedContainerFilteringTest.java
@@ -0,0 +1,139 @@
+package com.vaadin.tests.containers;
+
+import com.vaadin.data.Item;
+import com.vaadin.data.util.IndexedContainer;
+import com.vaadin.terminal.Sizeable;
+import com.vaadin.tests.components.TestBase;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.CheckBox;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.Table;
+import com.vaadin.ui.TextField;
+import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.Button.ClickEvent;
+
+public class IndexedContainerFilteringTest extends TestBase {
+
+ private Table table;
+ private IndexedContainer container;
+ private TextField filterString;
+ private TextField position;
+ private int nextToAdd = 1;
+ private Label nextLabel;
+
+ @Override
+ protected String getDescription() {
+ return "Adding items to a filtered IndexedContainer inserts the items at the wrong location.";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return new Integer(2809);
+ }
+
+ @Override
+ protected void setup() {
+ table = new Table();
+ container = (IndexedContainer) table.getContainerDataSource();
+
+ table.setWidth(300, Sizeable.UNITS_PIXELS);
+ table.setSelectable(true);
+ table.setMultiSelect(false);
+ table.addContainerProperty("column1", String.class, "test");
+
+ for (int i = 0; i < 25; ++i) {
+ table.addItem(new Object[] { "Item " + i }, "Item " + i);
+ }
+
+ VerticalLayout vl = new VerticalLayout();
+
+ // activate & deactivate filtering
+ filterString = new TextField("Filter string:", "1");
+ vl.addComponent(filterString);
+
+ final CheckBox cb = new CheckBox("Filter", new Button.ClickListener() {
+ public void buttonClick(ClickEvent event) {
+ container.removeAllContainerFilters();
+ if (((CheckBox) event.getSource()).booleanValue()) {
+ container.addContainerFilter("column1", filterString
+ .getValue().toString(), false, false);
+ }
+ }
+ });
+ cb.setImmediate(true);
+ vl.addComponent(cb);
+
+ nextLabel = new Label();
+ nextLabel.setCaption("Next id: " + nextToAdd);
+ vl.addComponent(nextLabel);
+
+ // addItemAt(idx), addItemAfter(selection), addItem()
+
+ final Button addItemButton = new Button("addItem()",
+ new Button.ClickListener() {
+ public void buttonClick(ClickEvent event) {
+ Item item = container.addItem("addItem() " + nextToAdd);
+ if (item != null) {
+ item.getItemProperty("column1").setValue(
+ "addItem() " + nextToAdd);
+ }
+ nextToAdd++;
+ nextLabel.setCaption("Next id: " + nextToAdd);
+ }
+ });
+ addItemButton.setImmediate(true);
+ vl.addComponent(addItemButton);
+
+ final Button addItemAfterButton = new Button("addItemAfter()",
+ new Button.ClickListener() {
+ public void buttonClick(ClickEvent event) {
+ Object selection = table.getValue();
+ if (selection == null) {
+ return;
+ }
+ String id = "addItemAfter() " + nextToAdd;
+ Item item = container.addItemAfter(selection, id);
+ if (item != null) {
+ item.getItemProperty("column1").setValue(id);
+ table.setValue(id);
+ } else {
+ getMainWindow().showNotification(
+ "Adding item after " + selection
+ + " failed");
+ }
+ nextToAdd++;
+ nextLabel.setCaption("Next id: " + nextToAdd);
+ }
+ });
+ addItemAfterButton.setImmediate(true);
+ vl.addComponent(addItemAfterButton);
+
+ position = new TextField("Position:", "0");
+ vl.addComponent(position);
+
+ final Button addItemAtButton = new Button("addItemAt()",
+ new Button.ClickListener() {
+ public void buttonClick(ClickEvent event) {
+ int index = Integer.parseInt(position.getValue()
+ .toString());
+ String id = "addItemAt() " + nextToAdd;
+ Item item = container.addItemAt(index, id);
+ if (item != null) {
+ item.getItemProperty("column1").setValue(id);
+ table.setValue(id);
+ } else {
+ getMainWindow().showNotification(
+ "Adding item at index "
+ + position.getValue() + " failed");
+ }
+ nextToAdd++;
+ nextLabel.setCaption("Next id: " + nextToAdd);
+ }
+ });
+ addItemAtButton.setImmediate(true);
+ vl.addComponent(addItemAtButton);
+
+ getLayout().addComponent(table);
+ getLayout().addComponent(vl);
+ }
+}