| /** |
| * |
| * Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany) |
| * |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Florian Pirchner <florian.pirchner@gmail.com> - Initial implementation |
| */ |
| package org.eclipse.osbp.vaadin.addons.suggesttext.sample; |
| |
| import javax.servlet.annotation.WebServlet; |
| |
| import org.eclipse.osbp.vaadin.addons.suggesttext.SuggestTextField; |
| |
| import com.vaadin.annotations.Theme; |
| import com.vaadin.annotations.VaadinServletConfiguration; |
| import com.vaadin.data.Property; |
| import com.vaadin.data.Property.ValueChangeEvent; |
| import com.vaadin.data.util.BeanItemContainer; |
| import com.vaadin.server.VaadinRequest; |
| import com.vaadin.server.VaadinServlet; |
| import com.vaadin.ui.Button; |
| import com.vaadin.ui.CheckBox; |
| import com.vaadin.ui.GridLayout; |
| import com.vaadin.ui.HorizontalLayout; |
| import com.vaadin.ui.Slider; |
| import com.vaadin.ui.UI; |
| import com.vaadin.ui.VerticalLayout; |
| |
| @SuppressWarnings("serial") |
| @Theme("valo") |
| public class SuggestTextUI extends UI { |
| |
| @WebServlet(value = "/*", asyncSupported = true) |
| @VaadinServletConfiguration(productionMode = false, ui = SuggestTextUI.class, widgetset = "org.eclipse.osbp.vaadin.addons.suggesttext.SuggestTextWidgetset") |
| public static class Servlet extends VaadinServlet { |
| } |
| |
| private GridLayout touchLayout; |
| |
| @Override |
| protected void init(VaadinRequest request) { |
| |
| final HorizontalLayout mainLayout = new HorizontalLayout(); |
| setContent(mainLayout); |
| |
| addForPerson(mainLayout); |
| addForPersonForUUIDMapping(mainLayout); |
| } |
| |
| private void addForPerson(final HorizontalLayout mainLayout) { |
| final VerticalLayout layout = new VerticalLayout(); |
| layout.setMargin(true); |
| mainLayout.addComponent(layout); |
| |
| // create SuggestTextField |
| final SuggestTextField suggestionBox = new SuggestTextField(); |
| suggestionBox.setId("suggestField1"); |
| suggestionBox.getTextField().setId("suggestField1_textField"); |
| |
| // setup text field |
| final Slider popupdelay = new Slider("Popup delay"); |
| popupdelay.setId("delay1"); |
| popupdelay.setMin(10); |
| popupdelay.setMax(1000); |
| popupdelay.setValue(500d); |
| popupdelay.setResolution(0); |
| layout.addComponent(popupdelay); |
| |
| popupdelay.addValueChangeListener(new Property.ValueChangeListener() { |
| @Override |
| public void valueChange(Property.ValueChangeEvent event) { |
| suggestionBox.setPopupDelay(popupdelay.getValue().intValue()); |
| } |
| }); |
| |
| // setup text field |
| final Slider limit = new Slider("Suggestion Limit"); |
| limit.setId("limit1"); |
| limit.setMin(2); |
| limit.setMax(30); |
| limit.setValue(10d); |
| limit.setResolution(0); |
| layout.addComponent(limit); |
| |
| limit.addValueChangeListener(new Property.ValueChangeListener() { |
| @Override |
| public void valueChange(Property.ValueChangeEvent event) { |
| suggestionBox.setLimit(limit.getValue().intValue()); |
| } |
| }); |
| |
| final CheckBox suggestionEnabled = new CheckBox("suggestion enabled"); |
| suggestionEnabled.setId("suggestionEnabled1"); |
| suggestionEnabled.setValue(true); |
| layout.addComponent(suggestionEnabled); |
| suggestionEnabled.addValueChangeListener(new Property.ValueChangeListener() { |
| @Override |
| public void valueChange(Property.ValueChangeEvent event) { |
| suggestionBox.setSuggestionEnabled(suggestionEnabled.getValue()); |
| } |
| }); |
| |
| final CheckBox autoHide = new CheckBox("auto hide popup"); |
| autoHide.setId("autoHide1"); |
| autoHide.setValue(true); |
| layout.addComponent(autoHide); |
| autoHide.addValueChangeListener(new Property.ValueChangeListener() { |
| @Override |
| public void valueChange(Property.ValueChangeEvent event) { |
| suggestionBox.setAutoHide(autoHide.getValue()); |
| |
| touchLayout.setEnabled(!autoHide.getValue()); |
| } |
| }); |
| |
| touchLayout = new GridLayout(2, 2); |
| touchLayout.setEnabled(false); |
| touchLayout.setDescription("Set auto hide popup to false"); |
| layout.addComponent(touchLayout); |
| |
| Button openSuggestList = new Button("open list", e -> { |
| suggestionBox.openPopup(); |
| }); |
| openSuggestList.setWidth("100%"); |
| touchLayout.addComponent(openSuggestList); |
| |
| Button closeSuggestList = new Button("close list", e -> { |
| suggestionBox.closePopup(); |
| }); |
| closeSuggestList.setWidth("100%"); |
| touchLayout.addComponent(closeSuggestList); |
| |
| Button navUpSuggestList = new Button("nav up", e -> { |
| suggestionBox.navigateToPrevious(); |
| }); |
| navUpSuggestList.setWidth("100%"); |
| touchLayout.addComponent(navUpSuggestList); |
| |
| Button navDownSuggestList = new Button("nav down", e -> { |
| suggestionBox.navigateToNext(); |
| }); |
| navDownSuggestList.setWidth("100%"); |
| touchLayout.addComponent(navDownSuggestList); |
| |
| Button selectCurrent = new Button("select", e -> { |
| suggestionBox.selectCurrent(); |
| }); |
| selectCurrent.setWidth("100%"); |
| touchLayout.addComponent(selectCurrent); |
| |
| Button sendKeys = new Button("send 'Pirchner1234' as Keys", e -> { |
| int length = suggestionBox.getKeys().length(); |
| if (length < "Pirchner12345".length()) { |
| String keys = suggestionBox.getKeys() + "Pirchner12345".substring(length, length + 1); |
| suggestionBox.setKeys(keys); |
| } |
| }); |
| sendKeys.setWidth("100%"); |
| layout.addComponent(sendKeys); |
| |
| Button sendKeysAsValue = new Button("send 'Pirchner1234' as Value", e -> { |
| int length = suggestionBox.getValue().length(); |
| if (length < "Pirchner12345".length()) { |
| String keys = suggestionBox.getValue() + "Pirchner12345".substring(length, length + 1); |
| suggestionBox.setValue(keys); |
| } |
| }); |
| sendKeysAsValue.setWidth("100%"); |
| layout.addComponent(sendKeysAsValue); |
| |
| Button simFastInputs = new Button("Simulate fast inputs", e -> { |
| access(() -> suggestionBox.setValue("")); |
| access(() -> suggestionBox.setValue("Pirchner12345")); |
| access(() -> suggestionBox.setValue("")); |
| }); |
| simFastInputs.setWidth("100%"); |
| layout.addComponent(simFastInputs); |
| |
| // configure and add suggestion box |
| suggestionBox.setCaption("Select"); |
| suggestionBox.getTextField().addValueChangeListener(new Property.ValueChangeListener() { |
| @Override |
| public void valueChange(ValueChangeEvent event) { |
| System.out.println("Value changed to " + event.getProperty().getValue()); |
| } |
| }); |
| suggestionBox.setSuggestionEnabled(true); |
| suggestionBox.setLimit(10); |
| suggestionBox.setPopupDelay(500); |
| suggestionBox.addStyleName("os-cash"); |
| suggestionBox.setDisableSuggestionTooltip("enable / disable suggestions"); |
| layout.addComponent(suggestionBox); |
| BeanItemContainer<Person> container = new BeanItemContainer<>(Person.class); |
| |
| suggestionBox.addSelectionChangedListener(e -> System.out.println("Selection changed " + e.getItemId())); |
| |
| for (int i = 0; i < 100; i++) { |
| container.addBean(new Person("Florian" + i, "Pirchner" + i)); |
| container.addBean(new Person("Klemens" + i, "Edler" + i)); |
| container.addBean(new Person("Berni" + i, "Edler" + i)); |
| } |
| container.addBean(new Person("Florian", "Pirchner1")); |
| container.addBean(new Person("Florian", "Pirchner12")); |
| container.addBean(new Person("Florian", "Pirchner123")); |
| container.addBean(new Person("Florian", "Pirchner1234")); |
| container.addBean(new Person("Florian", "Pirchner12345")); |
| container.addBean(new Person("Jörg", "Riegel")); |
| container.addBean(new Person("EAN", "00012348")); |
| |
| suggestionBox.setContainerDataSource(container); |
| suggestionBox.setCaptionPropertyId("lastname"); |
| suggestionBox.setFilterPropertyId("lastname"); |
| suggestionBox.setUniqueIdPropertyId("uuid"); |
| |
| } |
| |
| private void addForPersonForUUIDMapping(final HorizontalLayout mainLayout) { |
| final VerticalLayout layout = new VerticalLayout(); |
| layout.setMargin(true); |
| mainLayout.addComponent(layout); |
| |
| // create SuggestTextField |
| final SuggestTextField suggestionBox = new SuggestTextField(); |
| |
| // setup text field |
| final Slider popupdelay = new Slider("Popup delay"); |
| popupdelay.setMin(10); |
| popupdelay.setMax(1000); |
| popupdelay.setValue(500d); |
| popupdelay.setResolution(0); |
| layout.addComponent(popupdelay); |
| |
| popupdelay.addValueChangeListener(new Property.ValueChangeListener() { |
| @Override |
| public void valueChange(Property.ValueChangeEvent event) { |
| suggestionBox.setPopupDelay(popupdelay.getValue().intValue()); |
| } |
| }); |
| |
| // setup text field |
| final Slider limit = new Slider("Suggestion Limit"); |
| limit.setMin(2); |
| limit.setMax(30); |
| limit.setValue(10d); |
| limit.setResolution(0); |
| layout.addComponent(limit); |
| |
| limit.addValueChangeListener(new Property.ValueChangeListener() { |
| @Override |
| public void valueChange(Property.ValueChangeEvent event) { |
| suggestionBox.setLimit(limit.getValue().intValue()); |
| } |
| }); |
| |
| final CheckBox suggestionEnabled = new CheckBox("suggestion enabled"); |
| suggestionEnabled.setValue(true); |
| layout.addComponent(suggestionEnabled); |
| suggestionEnabled.addValueChangeListener(new Property.ValueChangeListener() { |
| @Override |
| public void valueChange(Property.ValueChangeEvent event) { |
| suggestionBox.setSuggestionEnabled(suggestionEnabled.getValue()); |
| } |
| }); |
| |
| // configure and add SuggestTextField |
| suggestionBox.setCaption("Select with uuid mapping"); |
| suggestionBox.getTextField().addValueChangeListener(new Property.ValueChangeListener() { |
| @Override |
| public void valueChange(ValueChangeEvent event) { |
| System.out.println("Foo"); |
| } |
| }); |
| suggestionBox.setSuggestionEnabled(true); |
| suggestionBox.setLimit(10); |
| suggestionBox.setPopupDelay(500); |
| suggestionBox.setDisableSuggestionTooltip("enable / disable suggestions"); |
| layout.addComponent(suggestionBox); |
| BeanItemContainer<PersonForUUIDMapping> container = new BeanItemContainer<>(PersonForUUIDMapping.class); |
| |
| for (int i = 0; i < 100; i++) { |
| container.addBean(new PersonForUUIDMapping("Florian" + i, "Pirchner" + i)); |
| container.addBean(new PersonForUUIDMapping("Klemens" + i, "Edler" + i)); |
| container.addBean(new PersonForUUIDMapping("Berni" + i, "Edler" + i)); |
| } |
| container.addBean(new PersonForUUIDMapping("Jörg", "Riegel")); |
| |
| suggestionBox.setContainerDataSource(container); |
| suggestionBox.setCaptionPropertyId("lastname"); |
| suggestionBox.setFilterPropertyId("lastname"); |
| suggestionBox.setUniqueIdPropertyId("uuid"); |
| } |
| } |