summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJani Laakso <jani.laakso@itmill.com>2007-04-18 06:19:48 +0000
committerJani Laakso <jani.laakso@itmill.com>2007-04-18 06:19:48 +0000
commit78e180871a5f15d2bda91b6549b034fc8a2c7a53 (patch)
tree965ae176e9a1b0b842f658c096a7cd87024ee4ed
parent121ae54f709f887c95592b95bdc09977642b8c3b (diff)
downloadvaadin-framework-78e180871a5f15d2bda91b6549b034fc8a2c7a53.tar.gz
vaadin-framework-78e180871a5f15d2bda91b6549b034fc8a2c7a53.zip
Added new demo FilterSelect, changed it's layout and texts.
svn changeset:1264/svn branch:trunk
-rw-r--r--WebContent/WEB-INF/web.xml13
-rw-r--r--WebContent/index.html13
-rw-r--r--src/com/itmill/toolkit/demo/FilterSelect.java141
3 files changed, 167 insertions, 0 deletions
diff --git a/WebContent/WEB-INF/web.xml b/WebContent/WEB-INF/web.xml
index e649cafceb..5a11c3cd99 100644
--- a/WebContent/WEB-INF/web.xml
+++ b/WebContent/WEB-INF/web.xml
@@ -55,6 +55,19 @@
</servlet-mapping>
<servlet>
+ <servlet-name>FilterSelect</servlet-name>
+ <servlet-class>com.itmill.toolkit.terminal.web.ApplicationServlet</servlet-class>
+ <init-param>
+ <param-name>application</param-name>
+ <param-value>com.itmill.toolkit.demo.FilterSelect</param-value>
+ </init-param>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>FilterSelect</servlet-name>
+ <url-pattern>/FilterSelect/*</url-pattern>
+ </servlet-mapping>
+
+ <servlet>
<servlet-name>features</servlet-name>
<servlet-class>com.itmill.toolkit.terminal.web.ApplicationServlet</servlet-class>
<init-param>
diff --git a/WebContent/index.html b/WebContent/index.html
index 7c798c8058..b486a56fc8 100644
--- a/WebContent/index.html
+++ b/WebContent/index.html
@@ -207,6 +207,19 @@
</div>
<div id="feature-browser">
+ <h3><a href="FilterSelect?renderingMode=ajax">FilterSelect demo</a></h3>
+ <div class="option">
+ <p>
+ This example shows three select components with lazy loading functionality enabled.
+ First select works like Google Suggest, second uses "Contains" filter and third uses custom "Ends with" filter.
+ Click to select components and type few letters using your keyboard to see it in action.
+ </p>
+ </div>
+ Source code:
+ <span class="link"><a href="src/com/itmill/toolkit/demo/FilterSelect.java.html">FilterSelect.java</a></span>
+ </div>
+
+ <div id="feature-browser">
<h3><a href="ModalWindow?renderingMode=ajax">Modal window</a></h3>
<div class="option">
Example of how Modal Windows may be created using Window component.
diff --git a/src/com/itmill/toolkit/demo/FilterSelect.java b/src/com/itmill/toolkit/demo/FilterSelect.java
new file mode 100644
index 0000000000..97d7ee20da
--- /dev/null
+++ b/src/com/itmill/toolkit/demo/FilterSelect.java
@@ -0,0 +1,141 @@
+package com.itmill.toolkit.demo;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import com.itmill.toolkit.data.Item;
+import com.itmill.toolkit.ui.*;
+import com.itmill.toolkit.ui.select.ContainsFilter;
+import com.itmill.toolkit.ui.select.OptionFilter;
+
+/**
+ * The classic "hello, world!" example for IT Mill Toolkit. The class simply
+ * implements the abstract {@link com.itmill.toolkit.Application#init() init()}
+ * method in which it creates a Window and adds a Label to it.
+ *
+ * @author IT Mill Ltd.
+ * @see com.itmill.toolkit.Application
+ * @see com.itmill.toolkit.ui.Window
+ * @see com.itmill.toolkit.ui.Label
+ */
+public class FilterSelect extends com.itmill.toolkit.Application {
+
+ 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" };
+
+ /**
+ * The initialization method that is the only requirement for inheriting the
+ * com.itmill.toolkit.service.Application class. It will be automatically
+ * called by the framework when a user accesses the application.
+ */
+ public void init() {
+
+ /*
+ * - Create new window for the application - Give the window a visible
+ * title - Set the window to be the main window of the application
+ */
+ Window main = new Window("Filter select examples");
+ setMainWindow(main);
+
+ // default filter
+ Select s1 = new Select();
+ for (int i = 0; i < 500; i++)
+ s1
+ .addItem(firstnames[(int) (Math.random() * (firstnames.length - 1))]
+ + " "
+ + lastnames[(int) (Math.random() * (lastnames.length - 1))]);
+ s1.setLazyLoading(true);
+
+ // contains filter
+ Select s2 = new Select();
+ for (int i = 0; i < 500; i++)
+ s2
+ .addItem(firstnames[(int) (Math.random() * (firstnames.length - 1))]
+ + " "
+ + lastnames[(int) (Math.random() * (lastnames.length - 1))]);
+ s2.setLazyLoading(true);
+ s2.setOptionFilter(new ContainsFilter(s2));
+
+ // custom filter
+ Select s3 = new Select();
+ for (int i = 0; i < 500; i++)
+ s3
+ .addItem(firstnames[(int) (Math.random() * (firstnames.length - 1))]
+ + " "
+ + lastnames[(int) (Math.random() * (lastnames.length - 1))]);
+ s3.setLazyLoading(true);
+ s3.setOptionFilter(new FilterSelect.EndsWithFilter(s3));
+
+ // Add selects to UI using ordered layout and panels
+ OrderedLayout orderedLayout = new OrderedLayout(
+ OrderedLayout.ORIENTATION_HORIZONTAL);
+
+ Panel panel1 = new Panel("Select with default filter");
+ Panel panel2 = new Panel("Select with contains filter");
+ Panel panel3 = new Panel("Select with custom 'EndsWith' filter");
+
+ panel1.addComponent(s1);
+ panel2.addComponent(s2);
+ panel3.addComponent(s3);
+
+ orderedLayout.addComponent(panel1);
+ orderedLayout.addComponent(panel2);
+ orderedLayout.addComponent(panel3);
+ main.addComponent(orderedLayout);
+
+ }
+
+ /**
+ * Custom filter that implements "ends with" functionality.
+ *
+ * @author IT Mill Ltd.
+ *
+ */
+ public class EndsWithFilter implements OptionFilter {
+ private Select s;
+
+ private ArrayList filteredItemsBuffer;
+
+ public EndsWithFilter(Select s) {
+ this.s = s;
+ }
+
+ public ArrayList filter(String filterstring) {
+ // prefix MUST be in lowercase
+ if ("".equals(filterstring)) {
+ this.filteredItemsBuffer = new ArrayList(s.getItemIds());
+ return this.filteredItemsBuffer;
+
+ } else if (s.getContainerDataSource() != null) {
+ // all items will be iterated and tested.
+ // SLOW when there are lot of items.
+ this.filteredItemsBuffer = new ArrayList();
+ for (Iterator iter = s.getItemIds().iterator(); iter.hasNext();) {
+ Object id = iter.next();
+
+ Item item = s.getItem(id);
+ String test = "";
+ if (s.getItemCaptionMode() == Select.ITEM_CAPTION_MODE_PROPERTY)
+ test = item.getItemProperty(
+ s.getItemCaptionPropertyId()).getValue()
+ .toString().trim();
+ else
+ test = String.valueOf(id);
+
+ if (test.toLowerCase().endsWith(filterstring)) {
+ this.filteredItemsBuffer.add(id);
+ }
+ }
+ }
+ return this.filteredItemsBuffer;
+ }
+ }
+
+}