summaryrefslogtreecommitdiffstats
path: root/tests/testbench/com/vaadin/tests/tickets/Ticket1230.java
diff options
context:
space:
mode:
Diffstat (limited to 'tests/testbench/com/vaadin/tests/tickets/Ticket1230.java')
-rw-r--r--tests/testbench/com/vaadin/tests/tickets/Ticket1230.java152
1 files changed, 152 insertions, 0 deletions
diff --git a/tests/testbench/com/vaadin/tests/tickets/Ticket1230.java b/tests/testbench/com/vaadin/tests/tickets/Ticket1230.java
new file mode 100644
index 0000000000..fd859459c0
--- /dev/null
+++ b/tests/testbench/com/vaadin/tests/tickets/Ticket1230.java
@@ -0,0 +1,152 @@
+package com.vaadin.tests.tickets;
+
+import com.vaadin.Application;
+import com.vaadin.data.Item;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Button.ClickListener;
+import com.vaadin.ui.GridLayout;
+import com.vaadin.ui.Select;
+import com.vaadin.ui.Window;
+
+public class Ticket1230 extends Application {
+
+ private static final Object PROPERTY_ID = new Object();
+ private static final Object NULL_ITEM_ID = new Object();
+ private Select selectWithoutNullItem;
+ private Select selectWithNullItem;
+
+ @Override
+ public void init() {
+ Window w = new Window(getClass().getName());
+ setMainWindow(w);
+
+ GridLayout layout = new GridLayout(5, 5);
+ w.setContent(layout);
+
+ layout.setSpacing(true);
+
+ {
+ selectWithoutNullItem = createSelect();
+
+ layout.addComponent(selectWithoutNullItem);
+ Button b = new Button("Select NULL_PROPERTY", new ClickListener() {
+
+ public void buttonClick(ClickEvent event) {
+ selectWithoutNullItem.select(NULL_ITEM_ID);
+ printState();
+
+ }
+ });
+ layout.addComponent(b);
+ b = new Button("Select 1", new ClickListener() {
+
+ public void buttonClick(ClickEvent event) {
+ selectWithoutNullItem.select("1");
+ printState();
+
+ }
+ });
+ layout.addComponent(b);
+ b = new Button("Select 2", new ClickListener() {
+
+ public void buttonClick(ClickEvent event) {
+ selectWithoutNullItem.select("2");
+ printState();
+
+ }
+ });
+ layout.addComponent(b);
+
+ b = new Button("Select null", new ClickListener() {
+
+ public void buttonClick(ClickEvent event) {
+ selectWithoutNullItem.select(null);
+ printState();
+
+ }
+ });
+ layout.addComponent(b);
+ }
+
+ {
+ selectWithNullItem = createSelect();
+ Item nullItem = selectWithNullItem.addItem(NULL_ITEM_ID);
+ nullItem.getItemProperty(PROPERTY_ID).setValue("NULL");
+ selectWithNullItem.setNullSelectionItemId(NULL_ITEM_ID);
+
+ layout.addComponent(selectWithNullItem);
+ selectWithNullItem.setCaption("Select with null item id");
+ Button b = new Button("Select NULL_PROPERTY", new ClickListener() {
+
+ public void buttonClick(ClickEvent event) {
+ selectWithNullItem.select(NULL_ITEM_ID);
+ printState();
+
+ }
+ });
+ layout.addComponent(b);
+
+ b = new Button("Select 1", new ClickListener() {
+
+ public void buttonClick(ClickEvent event) {
+ selectWithNullItem.select("1");
+ printState();
+
+ }
+ });
+ layout.addComponent(b);
+ b = new Button("Select 2", new ClickListener() {
+
+ public void buttonClick(ClickEvent event) {
+ selectWithNullItem.select("2");
+ printState();
+ }
+ });
+ layout.addComponent(b);
+
+ b = new Button("Select null", new ClickListener() {
+
+ public void buttonClick(ClickEvent event) {
+ selectWithNullItem.select(null);
+ printState();
+ }
+ });
+ layout.addComponent(b);
+
+ }
+
+ w.addComponent(new Button("print select values",
+ new Button.ClickListener() {
+ public void buttonClick(ClickEvent event) {
+ printState();
+ }
+ }));
+ }
+
+ @SuppressWarnings("deprecation")
+ private Select createSelect() {
+ Select select = new Select();
+ select.setMultiSelect(false);
+ select.addContainerProperty(PROPERTY_ID, String.class, "");
+ select.setItemCaptionPropertyId(PROPERTY_ID);
+
+ Item item1 = select.addItem("1");
+ item1.getItemProperty(PROPERTY_ID).setValue("1");
+ Item item2 = select.addItem("2");
+ item2.getItemProperty(PROPERTY_ID).setValue("2");
+
+ select.setNullSelectionAllowed(true);
+
+ return select;
+ }
+
+ void printState() {
+ System.out.println(" Select without null item "
+ + selectWithoutNullItem.getValue());
+ System.out.println(" Select with null item "
+ + selectWithNullItem.getValue());
+
+ }
+
+}