+++ /dev/null
-package com.vaadin.tests.minitutorials;
-
-import com.vaadin.terminal.WrappedRequest;
-import com.vaadin.tests.components.AbstractTestRoot;
-import com.vaadin.ui.TextField;
-
-public class CustomConverterFactoryRoot extends AbstractTestRoot {
- @Override
- public void setup(WrappedRequest request) {
- getApplication().setConverterFactory(new MyConverterFactory());
-
- TextField tf = new TextField("This is my double field");
- tf.setImmediate(true);
- tf.setConverter(Double.class);
- addComponent(tf);
-
- // As we do not set the locale explicitly for the field we set the value
- // after the field has been attached so it uses the application locale
- // for conversion
- tf.setConvertedValue(50.1);
-
- }
-
- @Override
- protected String getTestDescription() {
- return "Mini tutorial for https://vaadin.com/wiki/-/wiki/Main/Changing%20the%20default%20converters%20for%20an%20application";
- }
-
- @Override
- protected Integer getTicketNumber() {
- return null;
- }
-}
+++ /dev/null
-package com.vaadin.tests.minitutorials;
-
-import java.awt.image.BufferedImage;
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URL;
-
-import javax.imageio.ImageIO;
-
-import com.vaadin.Application;
-import com.vaadin.terminal.ExternalResource;
-import com.vaadin.terminal.RequestHandler;
-import com.vaadin.terminal.WrappedRequest;
-import com.vaadin.terminal.WrappedResponse;
-import com.vaadin.tests.components.AbstractTestRoot;
-import com.vaadin.ui.Embedded;
-
-public class DynamicImageRoot extends AbstractTestRoot {
-
- @Override
- public void setup(WrappedRequest request) {
- // Add the request handler that handles our dynamic image
- getApplication().addRequestHandler(new DynamicImageRequestHandler());
-
- // Create a URL that we can handle in DynamicImageRequestHandler
- URL imageUrl;
- try {
- imageUrl = new URL(getApplication().getURL(),
- DynamicImageRequestHandler.IMAGE_URL + "?text=Hello!");
- } catch (MalformedURLException e) {
- // This should never happen
- throw new RuntimeException(e);
- }
-
- // Add an embedded using the created URL
- Embedded embedded = new Embedded("A dynamically generated image",
- new ExternalResource(imageUrl));
- embedded.setType(Embedded.TYPE_IMAGE);
- getContent().addComponent(embedded);
-
- }
-
- @Override
- protected String getTestDescription() {
- return "Mini tutorial for https://vaadin.com/wiki/-/wiki/Main/Generating%20dynamic%20resources%20based%20on%20URI%20or%20parameters";
- }
-
- @Override
- protected Integer getTicketNumber() {
- return null;
- }
-}
-
-class DynamicImageRequestHandler implements RequestHandler {
-
- public static final String IMAGE_URL = "myimage.png";
-
- public boolean handleRequest(Application application,
- WrappedRequest request, WrappedResponse response)
- throws IOException {
- String pathInfo = request.getRequestPathInfo();
- if (("/" + IMAGE_URL).equals(pathInfo)) {
- // Create an image, draw the "text" parameter to it and output it to
- // the browser.
- String text = request.getParameter("text");
- BufferedImage bi = new BufferedImage(100, 30,
- BufferedImage.TYPE_3BYTE_BGR);
- bi.getGraphics().drawChars(text.toCharArray(), 0, text.length(),
- 10, 20);
- response.setContentType("image/png");
- ImageIO.write(bi, "png", response.getOutputStream());
-
- return true;
- }
- // If the URL did not match our image URL, let the other request
- // handlers handle it
- return false;
- }
-}
+++ /dev/null
-package com.vaadin.tests.minitutorials;
-
-import com.vaadin.data.fieldgroup.FieldGroup;
-import com.vaadin.data.fieldgroup.PropertyId;
-import com.vaadin.data.util.BeanItem;
-import com.vaadin.terminal.WrappedRequest;
-import com.vaadin.tests.components.AbstractTestRoot;
-import com.vaadin.ui.GridLayout;
-import com.vaadin.ui.TextArea;
-import com.vaadin.ui.TextField;
-
-public class FormUsingExistingLayout extends AbstractTestRoot {
-
- public static class Notice {
- String firstName;
- String lastName;
- String message;
-
- public Notice(String firstName, String lastName, String message) {
- this.firstName = firstName;
- this.lastName = lastName;
- this.message = message;
- }
-
- public String getFirstName() {
- return firstName;
- }
-
- public void setFirstName(String firstName) {
- this.firstName = firstName;
- }
-
- public String getLastName() {
- return lastName;
- }
-
- public void setLastName(String lastName) {
- this.lastName = lastName;
- }
-
- public String getMessage() {
- return message;
- }
-
- public void setMessage(String message) {
- this.message = message;
- }
-
- }
-
- public static class MyFormLayout extends GridLayout {
- private TextField firstName = new TextField("First name");
- private TextField lastName = new TextField("Last name");
-
- // The name of the property is by default the name of the member field,
- // but it can be redefined with the @PropertyId annotation
- @PropertyId("message")
- private TextArea messageField = new TextArea("Your message");
-
- public MyFormLayout() {
- // Set up the GridLayout
- super(2, 3);
- setSpacing(true);
-
- // Add the (currently unbound) fields
- addComponent(firstName);
- addComponent(lastName);
-
- addComponent(messageField, 0, 1, 1, 1);
- messageField.setWidth("100%");
- }
-
- }
-
- @Override
- protected void setup(WrappedRequest request) {
- // Create the layout
- MyFormLayout myFormLayout = new MyFormLayout();
-
- // Create a field group and use it to bind the fields in the layout
- FieldGroup fieldGroup = new FieldGroup(new BeanItem<Notice>(new Notice(
- "John", "Doe", "")));
- fieldGroup.bindMemberFields(myFormLayout);
-
- addComponent(myFormLayout);
- }
-
- @Override
- protected String getTestDescription() {
- return "Mini tutorial for https://vaadin.com/wiki/-/wiki/Main/Creating%20a%20form%20using%20an%20existing%20layout";
- }
-
- @Override
- protected Integer getTicketNumber() {
- return null;
- }
-
-}
+++ /dev/null
-package com.vaadin.tests.minitutorials;
-
-import java.text.NumberFormat;
-import java.util.Locale;
-
-import com.vaadin.data.util.converter.StringToNumberConverter;
-import com.vaadin.terminal.WrappedRequest;
-import com.vaadin.tests.components.AbstractTestRoot;
-import com.vaadin.ui.Table;
-
-public class FormatTableValue extends AbstractTestRoot {
-
- private static final String PERCENT_PROPERTY = "percent";
- private static final String CURRENCY_PROPERTY = "currency";
- private static final String DEFAULT_PROPERTY = "default";
-
- @Override
- protected void setup(WrappedRequest request) {
- Table table = new Table();
- table.setLocale(Locale.FRANCE);
- table.addContainerProperty(PERCENT_PROPERTY, Double.class, 0);
- table.addContainerProperty(CURRENCY_PROPERTY, Double.class, 0);
- table.addContainerProperty(DEFAULT_PROPERTY, Double.class, 0);
-
- Object itemId = table.addItem();
- table.getItem(itemId).getItemProperty(PERCENT_PROPERTY)
- .setValue(3.1415);
- table.getItem(itemId).getItemProperty(CURRENCY_PROPERTY)
- .setValue(3.1415);
- table.getItem(itemId).getItemProperty(DEFAULT_PROPERTY)
- .setValue(3.1415);
-
- table.setConverter(PERCENT_PROPERTY, new StringToNumberConverter() {
- @Override
- protected NumberFormat getFormat(Locale locale) {
- return NumberFormat.getPercentInstance(locale);
- }
- });
-
- table.setConverter(CURRENCY_PROPERTY, new StringToNumberConverter() {
- @Override
- protected NumberFormat getFormat(Locale locale) {
- return NumberFormat.getCurrencyInstance(locale);
- }
- });
-
- addComponent(table);
- }
-
- @Override
- protected String getTestDescription() {
- return "Mini tutorial for https://vaadin.com/wiki/-/wiki/Main/Formatting%20data%20in%20Table";
- }
-
- @Override
- protected Integer getTicketNumber() {
- return null;
- }
-
-}
+++ /dev/null
-package com.vaadin.tests.minitutorials;
-
-import com.vaadin.data.Property;
-import com.vaadin.data.util.BeanItem;
-import com.vaadin.terminal.WrappedRequest;
-import com.vaadin.tests.components.AbstractTestRoot;
-import com.vaadin.ui.Button;
-import com.vaadin.ui.Button.ClickEvent;
-import com.vaadin.ui.Button.ClickListener;
-import com.vaadin.ui.Label;
-import com.vaadin.ui.Notification;
-import com.vaadin.ui.TextField;
-
-public class IntegerTextFieldDataSource extends AbstractTestRoot {
-
- public class MyBean {
- private int value;
-
- public int getValue() {
- return value;
- }
-
- public void setValue(int integer) {
- value = integer;
- }
- }
-
- @Override
- protected void setup(WrappedRequest request) {
- final MyBean myBean = new MyBean();
- BeanItem<MyBean> beanItem = new BeanItem<MyBean>(myBean);
-
- final Property<Integer> integerProperty = (Property<Integer>) beanItem
- .getItemProperty("value");
- final TextField textField = new TextField("Text field", integerProperty);
-
- Button submitButton = new Button("Submit value", new ClickListener() {
- public void buttonClick(ClickEvent event) {
- String uiValue = textField.getValue();
- Integer propertyValue = integerProperty.getValue();
- int dataModelValue = myBean.getValue();
-
- Notification.show("UI value (String): " + uiValue
- + "<br />Property value (Integer): " + propertyValue
- + "<br />Data model value (int): " + dataModelValue);
- }
- });
-
- addComponent(new Label("Text field type: " + textField.getType()));
- addComponent(new Label("Text field type: " + integerProperty.getType()));
- addComponent(textField);
- addComponent(submitButton);
- }
-
- @Override
- protected String getTestDescription() {
- return "Mini tutorial for https://vaadin.com/wiki/-/wiki/Main/Creating%20a%20TextField%20for%20Integer%20only%20input%20using%20a%20data%20source";
- }
-
- @Override
- protected Integer getTicketNumber() {
- // TODO Auto-generated method stub
- return null;
- }
-
-}
+++ /dev/null
-package com.vaadin.tests.minitutorials;
-
-import com.vaadin.data.util.converter.Converter.ConversionException;
-import com.vaadin.data.util.converter.StringToIntegerConverter;
-import com.vaadin.terminal.WrappedRequest;
-import com.vaadin.tests.components.AbstractTestRoot;
-import com.vaadin.ui.Button;
-import com.vaadin.ui.Button.ClickEvent;
-import com.vaadin.ui.Button.ClickListener;
-import com.vaadin.ui.Label;
-import com.vaadin.ui.Notification;
-import com.vaadin.ui.TextField;
-
-public class IntegerTextFieldStandalone extends AbstractTestRoot {
-
- @Override
- protected void setup(WrappedRequest request) {
- final TextField textField = new TextField("Text field");
- textField.setConverter(new StringToIntegerConverter());
-
- Button submitButton = new Button("Submit value", new ClickListener() {
- public void buttonClick(ClickEvent event) {
- String uiValue = textField.getValue();
- try {
- Integer convertedValue = (Integer) textField
- .getConvertedValue();
- Notification.show("UI value (String): " + uiValue
- + "<br />Converted value (Integer): "
- + convertedValue);
- } catch (ConversionException e) {
- e.printStackTrace();
- Notification.show("Could not convert value: " + uiValue);
- }
- }
- });
-
- addComponent(new Label("Text field type: " + textField.getType()));
- addComponent(new Label("Converterd text field type: "
- + textField.getConverter().getModelType()));
- addComponent(textField);
- addComponent(submitButton);
- }
-
- @Override
- protected String getTestDescription() {
- return "Mini tutorial for https://vaadin.com/wiki/-/wiki/Main/Creating%20a%20TextField%20for%20Integer%20only%20input%20when%20not%20using%20a%20data%20source";
- }
-
- @Override
- protected Integer getTicketNumber() {
- // TODO Auto-generated method stub
- return null;
- }
-
-}
+++ /dev/null
-package com.vaadin.tests.minitutorials;
-
-import com.vaadin.data.util.converter.Converter;
-import com.vaadin.data.util.converter.DefaultConverterFactory;
-
-public class MyConverterFactory extends DefaultConverterFactory {
- @Override
- protected <PRESENTATION, MODEL> Converter<PRESENTATION, MODEL> findConverter(
- Class<PRESENTATION> presentationType, Class<MODEL> modelType) {
- // Handle String <-> Double
- if (presentationType == String.class && modelType == Double.class) {
- return (Converter<PRESENTATION, MODEL>) new MyStringToDoubleConverter();
- }
- // Let default factory handle the rest
- return super.findConverter(presentationType, modelType);
- }
-}
+++ /dev/null
-package com.vaadin.tests.minitutorials;
-
-import java.text.NumberFormat;
-import java.util.Locale;
-
-import com.vaadin.data.util.converter.StringToDoubleConverter;
-
-public class MyStringToDoubleConverter extends StringToDoubleConverter {
-
- @Override
- protected NumberFormat getFormat(Locale locale) {
- NumberFormat format = super.getFormat(locale);
- format.setGroupingUsed(false);
- format.setMaximumFractionDigits(3);
- format.setMinimumFractionDigits(3);
- return format;
- }
-}
+++ /dev/null
-package com.vaadin.tests.minitutorials;
-
-import java.util.Locale;
-
-import com.vaadin.data.util.converter.Converter;
-import com.vaadin.data.util.converter.Converter.ConversionException;
-import com.vaadin.terminal.WrappedRequest;
-import com.vaadin.tests.components.AbstractTestRoot;
-import com.vaadin.ui.Button;
-import com.vaadin.ui.Button.ClickEvent;
-import com.vaadin.ui.Button.ClickListener;
-import com.vaadin.ui.Notification;
-import com.vaadin.ui.TextField;
-
-public class StringMyTypeConverter extends AbstractTestRoot {
-
- @Override
- protected void setup(WrappedRequest request) {
- Name name = new Name("Rudolph", "Reindeer");
-
- final TextField textField = new TextField("Name");
- textField.setConverter(new StringToNameConverter());
- textField.setConvertedValue(name);
-
- addComponent(textField);
- addComponent(new Button("Submit value", new ClickListener() {
- public void buttonClick(ClickEvent event) {
- try {
- Name name = (Name) textField.getConvertedValue();
- Notification.show("First name: " + name.getFirstName()
- + "<br />Last name: " + name.getLastName());
- } catch (ConversionException e) {
- e.printStackTrace();
- Notification.show(e.getCause().getMessage());
- }
- }
- }));
- }
-
- @Override
- protected String getTestDescription() {
- return "Mini tutorial for https://vaadin.com/wiki/-/wiki/Main/Creating%20your%20own%20converter%20for%20String%20-%20MyType%20conversion";
- }
-
- @Override
- protected Integer getTicketNumber() {
- return null;
- }
-
-}
-
-class StringToNameConverter implements Converter<String, Name> {
- public Name convertToModel(String text, Locale locale)
- throws ConversionException {
- if (text == null) {
- return null;
- }
- String[] parts = text.split(" ");
- if (parts.length != 2) {
- throw new ConversionException("Can not convert text to a name: "
- + text);
- }
- return new Name(parts[0], parts[1]);
- }
-
- public String convertToPresentation(Name name, Locale locale)
- throws ConversionException {
- if (name == null) {
- return null;
- } else {
- return name.getFirstName() + " " + name.getLastName();
- }
- }
-
- public Class<Name> getModelType() {
- return Name.class;
- }
-
- public Class<String> getPresentationType() {
- return String.class;
- }
-}
-
-class Name {
- private String firstName;
- private String lastName;
-
- public Name(String firstName, String lastName) {
- this.firstName = firstName;
- this.lastName = lastName;
- }
-
- public String getFirstName() {
- return firstName;
- }
-
- public void setFirstName(String firstName) {
- this.firstName = firstName;
- }
-
- public String getLastName() {
- return lastName;
- }
-
- public void setLastName(String lastName) {
- this.lastName = lastName;
- }
-}
--- /dev/null
+package com.vaadin.tests.minitutorials.v7a1;
+
+import com.vaadin.terminal.WrappedRequest;
+import com.vaadin.tests.components.AbstractTestRoot;
+import com.vaadin.ui.TextField;
+
+public class CustomConverterFactoryRoot extends AbstractTestRoot {
+ @Override
+ public void setup(WrappedRequest request) {
+ getApplication().setConverterFactory(new MyConverterFactory());
+
+ TextField tf = new TextField("This is my double field");
+ tf.setImmediate(true);
+ tf.setConverter(Double.class);
+ addComponent(tf);
+
+ // As we do not set the locale explicitly for the field we set the value
+ // after the field has been attached so it uses the application locale
+ // for conversion
+ tf.setConvertedValue(50.1);
+
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "Mini tutorial for https://vaadin.com/wiki/-/wiki/Main/Changing%20the%20default%20converters%20for%20an%20application";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return null;
+ }
+}
--- /dev/null
+package com.vaadin.tests.minitutorials.v7a1;
+
+import java.awt.image.BufferedImage;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import javax.imageio.ImageIO;
+
+import com.vaadin.Application;
+import com.vaadin.terminal.ExternalResource;
+import com.vaadin.terminal.RequestHandler;
+import com.vaadin.terminal.WrappedRequest;
+import com.vaadin.terminal.WrappedResponse;
+import com.vaadin.tests.components.AbstractTestRoot;
+import com.vaadin.ui.Embedded;
+
+public class DynamicImageRoot extends AbstractTestRoot {
+
+ @Override
+ public void setup(WrappedRequest request) {
+ // Add the request handler that handles our dynamic image
+ getApplication().addRequestHandler(new DynamicImageRequestHandler());
+
+ // Create a URL that we can handle in DynamicImageRequestHandler
+ URL imageUrl;
+ try {
+ imageUrl = new URL(getApplication().getURL(),
+ DynamicImageRequestHandler.IMAGE_URL + "?text=Hello!");
+ } catch (MalformedURLException e) {
+ // This should never happen
+ throw new RuntimeException(e);
+ }
+
+ // Add an embedded using the created URL
+ Embedded embedded = new Embedded("A dynamically generated image",
+ new ExternalResource(imageUrl));
+ embedded.setType(Embedded.TYPE_IMAGE);
+ getContent().addComponent(embedded);
+
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "Mini tutorial for https://vaadin.com/wiki/-/wiki/Main/Generating%20dynamic%20resources%20based%20on%20URI%20or%20parameters";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return null;
+ }
+}
+
+class DynamicImageRequestHandler implements RequestHandler {
+
+ public static final String IMAGE_URL = "myimage.png";
+
+ public boolean handleRequest(Application application,
+ WrappedRequest request, WrappedResponse response)
+ throws IOException {
+ String pathInfo = request.getRequestPathInfo();
+ if (("/" + IMAGE_URL).equals(pathInfo)) {
+ // Create an image, draw the "text" parameter to it and output it to
+ // the browser.
+ String text = request.getParameter("text");
+ BufferedImage bi = new BufferedImage(100, 30,
+ BufferedImage.TYPE_3BYTE_BGR);
+ bi.getGraphics().drawChars(text.toCharArray(), 0, text.length(),
+ 10, 20);
+ response.setContentType("image/png");
+ ImageIO.write(bi, "png", response.getOutputStream());
+
+ return true;
+ }
+ // If the URL did not match our image URL, let the other request
+ // handlers handle it
+ return false;
+ }
+}
--- /dev/null
+package com.vaadin.tests.minitutorials.v7a1;
+
+import com.vaadin.data.fieldgroup.FieldGroup;
+import com.vaadin.data.fieldgroup.PropertyId;
+import com.vaadin.data.util.BeanItem;
+import com.vaadin.terminal.WrappedRequest;
+import com.vaadin.tests.components.AbstractTestRoot;
+import com.vaadin.ui.GridLayout;
+import com.vaadin.ui.TextArea;
+import com.vaadin.ui.TextField;
+
+public class FormUsingExistingLayout extends AbstractTestRoot {
+
+ public static class Notice {
+ String firstName;
+ String lastName;
+ String message;
+
+ public Notice(String firstName, String lastName, String message) {
+ this.firstName = firstName;
+ this.lastName = lastName;
+ this.message = message;
+ }
+
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ public String getLastName() {
+ return lastName;
+ }
+
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public void setMessage(String message) {
+ this.message = message;
+ }
+
+ }
+
+ public static class MyFormLayout extends GridLayout {
+ private TextField firstName = new TextField("First name");
+ private TextField lastName = new TextField("Last name");
+
+ // The name of the property is by default the name of the member field,
+ // but it can be redefined with the @PropertyId annotation
+ @PropertyId("message")
+ private TextArea messageField = new TextArea("Your message");
+
+ public MyFormLayout() {
+ // Set up the GridLayout
+ super(2, 3);
+ setSpacing(true);
+
+ // Add the (currently unbound) fields
+ addComponent(firstName);
+ addComponent(lastName);
+
+ addComponent(messageField, 0, 1, 1, 1);
+ messageField.setWidth("100%");
+ }
+
+ }
+
+ @Override
+ protected void setup(WrappedRequest request) {
+ // Create the layout
+ MyFormLayout myFormLayout = new MyFormLayout();
+
+ // Create a field group and use it to bind the fields in the layout
+ FieldGroup fieldGroup = new FieldGroup(new BeanItem<Notice>(new Notice(
+ "John", "Doe", "")));
+ fieldGroup.bindMemberFields(myFormLayout);
+
+ addComponent(myFormLayout);
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "Mini tutorial for https://vaadin.com/wiki/-/wiki/Main/Creating%20a%20form%20using%20an%20existing%20layout";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return null;
+ }
+
+}
--- /dev/null
+package com.vaadin.tests.minitutorials.v7a1;
+
+import java.text.NumberFormat;
+import java.util.Locale;
+
+import com.vaadin.data.util.converter.StringToNumberConverter;
+import com.vaadin.terminal.WrappedRequest;
+import com.vaadin.tests.components.AbstractTestRoot;
+import com.vaadin.ui.Table;
+
+public class FormatTableValue extends AbstractTestRoot {
+
+ private static final String PERCENT_PROPERTY = "percent";
+ private static final String CURRENCY_PROPERTY = "currency";
+ private static final String DEFAULT_PROPERTY = "default";
+
+ @Override
+ protected void setup(WrappedRequest request) {
+ Table table = new Table();
+ table.setLocale(Locale.FRANCE);
+ table.addContainerProperty(PERCENT_PROPERTY, Double.class, 0);
+ table.addContainerProperty(CURRENCY_PROPERTY, Double.class, 0);
+ table.addContainerProperty(DEFAULT_PROPERTY, Double.class, 0);
+
+ Object itemId = table.addItem();
+ table.getItem(itemId).getItemProperty(PERCENT_PROPERTY)
+ .setValue(3.1415);
+ table.getItem(itemId).getItemProperty(CURRENCY_PROPERTY)
+ .setValue(3.1415);
+ table.getItem(itemId).getItemProperty(DEFAULT_PROPERTY)
+ .setValue(3.1415);
+
+ table.setConverter(PERCENT_PROPERTY, new StringToNumberConverter() {
+ @Override
+ protected NumberFormat getFormat(Locale locale) {
+ return NumberFormat.getPercentInstance(locale);
+ }
+ });
+
+ table.setConverter(CURRENCY_PROPERTY, new StringToNumberConverter() {
+ @Override
+ protected NumberFormat getFormat(Locale locale) {
+ return NumberFormat.getCurrencyInstance(locale);
+ }
+ });
+
+ addComponent(table);
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "Mini tutorial for https://vaadin.com/wiki/-/wiki/Main/Formatting%20data%20in%20Table";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return null;
+ }
+
+}
--- /dev/null
+package com.vaadin.tests.minitutorials.v7a1;
+
+import com.vaadin.data.Property;
+import com.vaadin.data.util.BeanItem;
+import com.vaadin.terminal.WrappedRequest;
+import com.vaadin.tests.components.AbstractTestRoot;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Button.ClickListener;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.Notification;
+import com.vaadin.ui.TextField;
+
+public class IntegerTextFieldDataSource extends AbstractTestRoot {
+
+ public class MyBean {
+ private int value;
+
+ public int getValue() {
+ return value;
+ }
+
+ public void setValue(int integer) {
+ value = integer;
+ }
+ }
+
+ @Override
+ protected void setup(WrappedRequest request) {
+ final MyBean myBean = new MyBean();
+ BeanItem<MyBean> beanItem = new BeanItem<MyBean>(myBean);
+
+ final Property<Integer> integerProperty = (Property<Integer>) beanItem
+ .getItemProperty("value");
+ final TextField textField = new TextField("Text field", integerProperty);
+
+ Button submitButton = new Button("Submit value", new ClickListener() {
+ public void buttonClick(ClickEvent event) {
+ String uiValue = textField.getValue();
+ Integer propertyValue = integerProperty.getValue();
+ int dataModelValue = myBean.getValue();
+
+ Notification.show("UI value (String): " + uiValue
+ + "<br />Property value (Integer): " + propertyValue
+ + "<br />Data model value (int): " + dataModelValue);
+ }
+ });
+
+ addComponent(new Label("Text field type: " + textField.getType()));
+ addComponent(new Label("Text field type: " + integerProperty.getType()));
+ addComponent(textField);
+ addComponent(submitButton);
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "Mini tutorial for https://vaadin.com/wiki/-/wiki/Main/Creating%20a%20TextField%20for%20Integer%20only%20input%20using%20a%20data%20source";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
--- /dev/null
+package com.vaadin.tests.minitutorials.v7a1;
+
+import com.vaadin.data.util.converter.Converter.ConversionException;
+import com.vaadin.data.util.converter.StringToIntegerConverter;
+import com.vaadin.terminal.WrappedRequest;
+import com.vaadin.tests.components.AbstractTestRoot;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Button.ClickListener;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.Notification;
+import com.vaadin.ui.TextField;
+
+public class IntegerTextFieldStandalone extends AbstractTestRoot {
+
+ @Override
+ protected void setup(WrappedRequest request) {
+ final TextField textField = new TextField("Text field");
+ textField.setConverter(new StringToIntegerConverter());
+
+ Button submitButton = new Button("Submit value", new ClickListener() {
+ public void buttonClick(ClickEvent event) {
+ String uiValue = textField.getValue();
+ try {
+ Integer convertedValue = (Integer) textField
+ .getConvertedValue();
+ Notification.show("UI value (String): " + uiValue
+ + "<br />Converted value (Integer): "
+ + convertedValue);
+ } catch (ConversionException e) {
+ e.printStackTrace();
+ Notification.show("Could not convert value: " + uiValue);
+ }
+ }
+ });
+
+ addComponent(new Label("Text field type: " + textField.getType()));
+ addComponent(new Label("Converterd text field type: "
+ + textField.getConverter().getModelType()));
+ addComponent(textField);
+ addComponent(submitButton);
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "Mini tutorial for https://vaadin.com/wiki/-/wiki/Main/Creating%20a%20TextField%20for%20Integer%20only%20input%20when%20not%20using%20a%20data%20source";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
--- /dev/null
+package com.vaadin.tests.minitutorials.v7a1;
+
+import com.vaadin.data.util.converter.Converter;
+import com.vaadin.data.util.converter.DefaultConverterFactory;
+
+public class MyConverterFactory extends DefaultConverterFactory {
+ @Override
+ protected <PRESENTATION, MODEL> Converter<PRESENTATION, MODEL> findConverter(
+ Class<PRESENTATION> presentationType, Class<MODEL> modelType) {
+ // Handle String <-> Double
+ if (presentationType == String.class && modelType == Double.class) {
+ return (Converter<PRESENTATION, MODEL>) new MyStringToDoubleConverter();
+ }
+ // Let default factory handle the rest
+ return super.findConverter(presentationType, modelType);
+ }
+}
--- /dev/null
+package com.vaadin.tests.minitutorials.v7a1;
+
+import java.text.NumberFormat;
+import java.util.Locale;
+
+import com.vaadin.data.util.converter.StringToDoubleConverter;
+
+public class MyStringToDoubleConverter extends StringToDoubleConverter {
+
+ @Override
+ protected NumberFormat getFormat(Locale locale) {
+ NumberFormat format = super.getFormat(locale);
+ format.setGroupingUsed(false);
+ format.setMaximumFractionDigits(3);
+ format.setMinimumFractionDigits(3);
+ return format;
+ }
+}
--- /dev/null
+package com.vaadin.tests.minitutorials.v7a1;
+
+import java.util.Locale;
+
+import com.vaadin.data.util.converter.Converter;
+import com.vaadin.data.util.converter.Converter.ConversionException;
+import com.vaadin.terminal.WrappedRequest;
+import com.vaadin.tests.components.AbstractTestRoot;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Button.ClickListener;
+import com.vaadin.ui.Notification;
+import com.vaadin.ui.TextField;
+
+public class StringMyTypeConverter extends AbstractTestRoot {
+
+ @Override
+ protected void setup(WrappedRequest request) {
+ Name name = new Name("Rudolph", "Reindeer");
+
+ final TextField textField = new TextField("Name");
+ textField.setConverter(new StringToNameConverter());
+ textField.setConvertedValue(name);
+
+ addComponent(textField);
+ addComponent(new Button("Submit value", new ClickListener() {
+ public void buttonClick(ClickEvent event) {
+ try {
+ Name name = (Name) textField.getConvertedValue();
+ Notification.show("First name: " + name.getFirstName()
+ + "<br />Last name: " + name.getLastName());
+ } catch (ConversionException e) {
+ e.printStackTrace();
+ Notification.show(e.getCause().getMessage());
+ }
+ }
+ }));
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "Mini tutorial for https://vaadin.com/wiki/-/wiki/Main/Creating%20your%20own%20converter%20for%20String%20-%20MyType%20conversion";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return null;
+ }
+
+}
+
+class StringToNameConverter implements Converter<String, Name> {
+ public Name convertToModel(String text, Locale locale)
+ throws ConversionException {
+ if (text == null) {
+ return null;
+ }
+ String[] parts = text.split(" ");
+ if (parts.length != 2) {
+ throw new ConversionException("Can not convert text to a name: "
+ + text);
+ }
+ return new Name(parts[0], parts[1]);
+ }
+
+ public String convertToPresentation(Name name, Locale locale)
+ throws ConversionException {
+ if (name == null) {
+ return null;
+ } else {
+ return name.getFirstName() + " " + name.getLastName();
+ }
+ }
+
+ public Class<Name> getModelType() {
+ return Name.class;
+ }
+
+ public Class<String> getPresentationType() {
+ return String.class;
+ }
+}
+
+class Name {
+ private String firstName;
+ private String lastName;
+
+ public Name(String firstName, String lastName) {
+ this.firstName = firstName;
+ this.lastName = lastName;
+ }
+
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ public String getLastName() {
+ return lastName;
+ }
+
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+}