summaryrefslogtreecommitdiffstats
path: root/src/com/vaadin/demo/featurebrowser/ComboBoxExample.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/vaadin/demo/featurebrowser/ComboBoxExample.java')
-rw-r--r--src/com/vaadin/demo/featurebrowser/ComboBoxExample.java70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/com/vaadin/demo/featurebrowser/ComboBoxExample.java b/src/com/vaadin/demo/featurebrowser/ComboBoxExample.java
new file mode 100644
index 0000000000..a28d16e597
--- /dev/null
+++ b/src/com/vaadin/demo/featurebrowser/ComboBoxExample.java
@@ -0,0 +1,70 @@
+/*
+@ITMillApache2LicenseForJavaFiles@
+ */
+
+package com.vaadin.demo.featurebrowser;
+
+import java.util.Random;
+
+import com.vaadin.ui.ComboBox;
+import com.vaadin.ui.CustomComponent;
+import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.AbstractSelect.Filtering;
+
+/**
+ *
+ */
+public class ComboBoxExample extends CustomComponent {
+
+ private static final String[] firstnames = new String[] { "John", "Mary",
+ "Joe", "Sarah", "Jeff", "Jane", "Peter", "Marc", "Robert", "Paula",
+ "Lenny", "Kenny", "Nathan", "Nicole", "Laura", "Jos", "Josie",
+ "Linus" };
+
+ private static final String[] lastnames = new String[] { "Torvalds",
+ "Smith", "Adams", "Black", "Wilson", "Richards", "Thompson",
+ "McGoff", "Halas", "Jones", "Beck", "Sheridan", "Picard", "Hill",
+ "Fielding", "Einstein" };
+
+ public ComboBoxExample() {
+ final VerticalLayout main = new VerticalLayout();
+ main.setMargin(true);
+ setCompositionRoot(main);
+
+ // starts-with filter
+ final ComboBox s1 = new ComboBox("Select with starts-with filter");
+ s1.setFilteringMode(Filtering.FILTERINGMODE_STARTSWITH);
+ s1.setWidth("20em");
+ Random r = new Random(5);
+ for (int i = 0; i < 105; i++) {
+ s1
+ .addItem(firstnames[(int) (r.nextDouble() * (firstnames.length - 1))]
+ + " "
+ + lastnames[(int) (r.nextDouble() * (lastnames.length - 1))]);
+ }
+ s1.setImmediate(true);
+ main.addComponent(s1);
+
+ // contains filter
+ final ComboBox s2 = new ComboBox("Select with contains filter");
+ s2.setFilteringMode(Filtering.FILTERINGMODE_CONTAINS);
+ s2.setWidth("20em");
+ for (int i = 0; i < 500; i++) {
+ s2
+ .addItem(firstnames[(int) (r.nextDouble() * (firstnames.length - 1))]
+ + " "
+ + lastnames[(int) (r.nextDouble() * (lastnames.length - 1))]);
+ }
+ s2.setImmediate(true);
+ main.addComponent(s2);
+
+ // initially empty
+ final ComboBox s3 = new ComboBox("Initially empty; enter your own");
+ s3.setWidth("20em");
+ s3.setImmediate(true);
+ s3.setNewItemsAllowed(true);
+ main.addComponent(s3);
+
+ }
+
+}