package com.virtuallypreinstalled.marc.examples; import com.itmill.toolkit.Application; import com.itmill.toolkit.data.Property.ValueChangeEvent; import com.itmill.toolkit.terminal.ThemeResource; import com.itmill.toolkit.ui.Button; import com.itmill.toolkit.ui.ComboBox; import com.itmill.toolkit.ui.Label; import com.itmill.toolkit.ui.OrderedLayout; import com.itmill.toolkit.ui.Panel; import com.itmill.toolkit.ui.Window; import com.itmill.toolkit.ui.Button.ClickEvent; public class SuggestionsExample extends Application { private static final String[] names = { "Alvin", "Bob", "Craig", "Dan", "Eric", "Frank", "Greg", "Hank", "Ian", "John", "Ken", "Les", "Mick", "Ned", "Oliver", "Paul", "Quentin", "Rick", "Steve", "Uriel", "Vincent", "Will", "Xander", "Yosef", "Zack" }; private static final String[] tokens = { "answer", "booring", "cool", "data", "expert", "fun", "good", "hot", "idea", "journal", "knowledge", "long", "method", "new", "old", "product", "question", "resource", "short", "tag", "unbelievable", "view", "wtf", "xxx", "yummy", "zoom" }; private static final String[] choises = { "Minimum", "Medium", "Maximum" }; private static final String[] icons = { "rss", "flickr", "digg", "technorati" }; public void init() { setTheme("com.virtuallypreinstalled.marc.examples"); Window main = new MainWindow(); setMainWindow(main); } private class MainWindow extends Window { Label lastSearch = new Label(" "); OrderedLayout tokenLayout = new OrderedLayout( OrderedLayout.ORIENTATION_HORIZONTAL); int tokenCount = 0; OrderedLayout addressLayout = new OrderedLayout(); int addressCount = 0; MainWindow() { getLayout().setWidth("100%"); // Suggestbox Panel p = new Panel("Suggest / search"); p.setStyleName(Panel.STYLE_LIGHT); addComponent(p); ComboBox cb = new ComboBox(); cb.setDescription("Initially empty; will suggest your previous searches."); cb.setWidth("250px"); cb.setImmediate(true); cb.setNewItemsAllowed(true); cb.setNullSelectionAllowed(false); cb.addStyleName("search"); cb.addListener(new ComboBox.ValueChangeListener() { public void valueChange(ValueChangeEvent event) { Object val = event.getProperty().getValue(); if (val != null) { lastSearch.setValue("Your search for \"" + val + "\" returned no results."); event.getProperty().setValue(null); } } }); p.addComponent(cb); p.addComponent(lastSearch); // Token p = new Panel("Tag / token"); p.setStyleName(Panel.STYLE_LIGHT); addComponent(p); tokenLayout.setSpacing(true); p.addComponent(tokenLayout); cb = new ComboBox(); cb.setDescription("Has some pre-configured tags, accepts new ones."); cb.setWidth("70px"); cb.setImmediate(true); cb.setNewItemsAllowed(true); cb.setNullSelectionAllowed(false); cb.addStyleName("search"); cb.addListener(new ComboBox.ValueChangeListener() { public void valueChange(ValueChangeEvent event) { Object val = event.getProperty().getValue(); if (val != null) { Button b = new Button(val + " ⊠", new Button.ClickListener() { public void buttonClick(ClickEvent event) { tokenLayout.removeComponent(event .getButton()); tokenCount--; } }); b.setStyleName(Button.STYLE_LINK); tokenLayout.addComponent(b, tokenCount++); event.getProperty().setValue(null); } } }); for (int i = 0; i