]> source.dussan.org Git - vaadin-framework.git/commitdiff
Restructure mini tutorial packages
authorLeif Åstrand <leif@vaadin.com>
Wed, 20 Jun 2012 13:33:37 +0000 (16:33 +0300)
committerLeif Åstrand <leif@vaadin.com>
Wed, 20 Jun 2012 13:33:37 +0000 (16:33 +0300)
18 files changed:
tests/testbench/com/vaadin/tests/minitutorials/CustomConverterFactoryRoot.java [deleted file]
tests/testbench/com/vaadin/tests/minitutorials/DynamicImageRoot.java [deleted file]
tests/testbench/com/vaadin/tests/minitutorials/FormUsingExistingLayout.java [deleted file]
tests/testbench/com/vaadin/tests/minitutorials/FormatTableValue.java [deleted file]
tests/testbench/com/vaadin/tests/minitutorials/IntegerTextFieldDataSource.java [deleted file]
tests/testbench/com/vaadin/tests/minitutorials/IntegerTextFieldStandalone.java [deleted file]
tests/testbench/com/vaadin/tests/minitutorials/MyConverterFactory.java [deleted file]
tests/testbench/com/vaadin/tests/minitutorials/MyStringToDoubleConverter.java [deleted file]
tests/testbench/com/vaadin/tests/minitutorials/StringMyTypeConverter.java [deleted file]
tests/testbench/com/vaadin/tests/minitutorials/v7a1/CustomConverterFactoryRoot.java [new file with mode: 0644]
tests/testbench/com/vaadin/tests/minitutorials/v7a1/DynamicImageRoot.java [new file with mode: 0644]
tests/testbench/com/vaadin/tests/minitutorials/v7a1/FormUsingExistingLayout.java [new file with mode: 0644]
tests/testbench/com/vaadin/tests/minitutorials/v7a1/FormatTableValue.java [new file with mode: 0644]
tests/testbench/com/vaadin/tests/minitutorials/v7a1/IntegerTextFieldDataSource.java [new file with mode: 0644]
tests/testbench/com/vaadin/tests/minitutorials/v7a1/IntegerTextFieldStandalone.java [new file with mode: 0644]
tests/testbench/com/vaadin/tests/minitutorials/v7a1/MyConverterFactory.java [new file with mode: 0644]
tests/testbench/com/vaadin/tests/minitutorials/v7a1/MyStringToDoubleConverter.java [new file with mode: 0644]
tests/testbench/com/vaadin/tests/minitutorials/v7a1/StringMyTypeConverter.java [new file with mode: 0644]

diff --git a/tests/testbench/com/vaadin/tests/minitutorials/CustomConverterFactoryRoot.java b/tests/testbench/com/vaadin/tests/minitutorials/CustomConverterFactoryRoot.java
deleted file mode 100644 (file)
index de32a81..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-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;
-    }
-}
diff --git a/tests/testbench/com/vaadin/tests/minitutorials/DynamicImageRoot.java b/tests/testbench/com/vaadin/tests/minitutorials/DynamicImageRoot.java
deleted file mode 100644 (file)
index a0e6a54..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-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;
-    }
-}
diff --git a/tests/testbench/com/vaadin/tests/minitutorials/FormUsingExistingLayout.java b/tests/testbench/com/vaadin/tests/minitutorials/FormUsingExistingLayout.java
deleted file mode 100644 (file)
index 9d20867..0000000
+++ /dev/null
@@ -1,98 +0,0 @@
-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;
-    }
-
-}
diff --git a/tests/testbench/com/vaadin/tests/minitutorials/FormatTableValue.java b/tests/testbench/com/vaadin/tests/minitutorials/FormatTableValue.java
deleted file mode 100644 (file)
index aba1447..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-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;
-    }
-
-}
diff --git a/tests/testbench/com/vaadin/tests/minitutorials/IntegerTextFieldDataSource.java b/tests/testbench/com/vaadin/tests/minitutorials/IntegerTextFieldDataSource.java
deleted file mode 100644 (file)
index 96b10d0..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-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;
-    }
-
-}
diff --git a/tests/testbench/com/vaadin/tests/minitutorials/IntegerTextFieldStandalone.java b/tests/testbench/com/vaadin/tests/minitutorials/IntegerTextFieldStandalone.java
deleted file mode 100644 (file)
index 5a47bd7..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-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;
-    }
-
-}
diff --git a/tests/testbench/com/vaadin/tests/minitutorials/MyConverterFactory.java b/tests/testbench/com/vaadin/tests/minitutorials/MyConverterFactory.java
deleted file mode 100644 (file)
index 456654e..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-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);
-    }
-}
diff --git a/tests/testbench/com/vaadin/tests/minitutorials/MyStringToDoubleConverter.java b/tests/testbench/com/vaadin/tests/minitutorials/MyStringToDoubleConverter.java
deleted file mode 100644 (file)
index 38268bd..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-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;
-    }
-}
diff --git a/tests/testbench/com/vaadin/tests/minitutorials/StringMyTypeConverter.java b/tests/testbench/com/vaadin/tests/minitutorials/StringMyTypeConverter.java
deleted file mode 100644 (file)
index 33602ce..0000000
+++ /dev/null
@@ -1,108 +0,0 @@
-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;
-    }
-}
diff --git a/tests/testbench/com/vaadin/tests/minitutorials/v7a1/CustomConverterFactoryRoot.java b/tests/testbench/com/vaadin/tests/minitutorials/v7a1/CustomConverterFactoryRoot.java
new file mode 100644 (file)
index 0000000..89b4a0f
--- /dev/null
@@ -0,0 +1,33 @@
+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;
+    }
+}
diff --git a/tests/testbench/com/vaadin/tests/minitutorials/v7a1/DynamicImageRoot.java b/tests/testbench/com/vaadin/tests/minitutorials/v7a1/DynamicImageRoot.java
new file mode 100644 (file)
index 0000000..9ed2bd2
--- /dev/null
@@ -0,0 +1,79 @@
+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;
+    }
+}
diff --git a/tests/testbench/com/vaadin/tests/minitutorials/v7a1/FormUsingExistingLayout.java b/tests/testbench/com/vaadin/tests/minitutorials/v7a1/FormUsingExistingLayout.java
new file mode 100644 (file)
index 0000000..1e460b2
--- /dev/null
@@ -0,0 +1,98 @@
+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;
+    }
+
+}
diff --git a/tests/testbench/com/vaadin/tests/minitutorials/v7a1/FormatTableValue.java b/tests/testbench/com/vaadin/tests/minitutorials/v7a1/FormatTableValue.java
new file mode 100644 (file)
index 0000000..e487c6d
--- /dev/null
@@ -0,0 +1,60 @@
+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;
+    }
+
+}
diff --git a/tests/testbench/com/vaadin/tests/minitutorials/v7a1/IntegerTextFieldDataSource.java b/tests/testbench/com/vaadin/tests/minitutorials/v7a1/IntegerTextFieldDataSource.java
new file mode 100644 (file)
index 0000000..dd32242
--- /dev/null
@@ -0,0 +1,66 @@
+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;
+    }
+
+}
diff --git a/tests/testbench/com/vaadin/tests/minitutorials/v7a1/IntegerTextFieldStandalone.java b/tests/testbench/com/vaadin/tests/minitutorials/v7a1/IntegerTextFieldStandalone.java
new file mode 100644 (file)
index 0000000..9c720e4
--- /dev/null
@@ -0,0 +1,55 @@
+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;
+    }
+
+}
diff --git a/tests/testbench/com/vaadin/tests/minitutorials/v7a1/MyConverterFactory.java b/tests/testbench/com/vaadin/tests/minitutorials/v7a1/MyConverterFactory.java
new file mode 100644 (file)
index 0000000..17c37f2
--- /dev/null
@@ -0,0 +1,17 @@
+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);
+    }
+}
diff --git a/tests/testbench/com/vaadin/tests/minitutorials/v7a1/MyStringToDoubleConverter.java b/tests/testbench/com/vaadin/tests/minitutorials/v7a1/MyStringToDoubleConverter.java
new file mode 100644 (file)
index 0000000..483f841
--- /dev/null
@@ -0,0 +1,18 @@
+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;
+    }
+}
diff --git a/tests/testbench/com/vaadin/tests/minitutorials/v7a1/StringMyTypeConverter.java b/tests/testbench/com/vaadin/tests/minitutorials/v7a1/StringMyTypeConverter.java
new file mode 100644 (file)
index 0000000..4ccd73b
--- /dev/null
@@ -0,0 +1,108 @@
+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;
+    }
+}