--- /dev/null
+/*
+@VaadinApache2LicenseForJavaFiles@
+ */
+
+package com.vaadin.tests.minitutorials.v7a1;
+
+import com.vaadin.data.fieldgroup.BeanFieldGroup;
+import com.vaadin.data.fieldgroup.FieldGroup;
+import com.vaadin.data.util.BeanItem;
+import com.vaadin.terminal.WrappedRequest;
+import com.vaadin.ui.Root;
+
+/**
+ * Mini tutorial code for
+ * https://vaadin.com/wiki/-/wiki/Main/Auto%20generating%20
+ * a%20form%20based%20on%20a%20bean%20-%20Vaadin%206%20style%20Form
+ *
+ * @author Vaadin Ltd
+ * @version @VERSION@
+ * @since 7.0.0
+ */
+public class AutoGeneratingForm extends Root {
+
+ @Override
+ protected void init(WrappedRequest request) {
+ FieldGroup fieldGroup = new BeanFieldGroup<Person>(Person.class);
+
+ // We need an item data source before we create the fields to be able to
+ // find the properties, otherwise we have to specify them by hand
+ fieldGroup.setItemDataSource(new BeanItem<Person>(new Person("John",
+ "Doe", 34)));
+
+ // Loop through the properties, build fields for them and add the fields
+ // to this root
+ for (Object propertyId : fieldGroup.getUnboundPropertyIds()) {
+ addComponent(fieldGroup.buildAndBind(propertyId));
+ }
+ }
+
+}
+
+class Person {
+ private String firstName, lastName;
+ private int age;
+
+ // + setters and getters
+
+ public Person(String firstName, String lastName, int age) {
+ this.firstName = firstName;
+ this.lastName = lastName;
+ this.age = age;
+ }
+
+ 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 int getAge() {
+ return age;
+ }
+
+ public void setAge(int age) {
+ this.age = age;
+ }
+}
--- /dev/null
+/*
+@VaadinApache2LicenseForJavaFiles@
+ */
+
+package com.vaadin.tests.minitutorials.v7a1;
+
+import com.vaadin.terminal.WrappedRequest;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.Root;
+import com.vaadin.ui.VerticalLayout;
+
+/**
+ * Mini tutorial code for
+ * https://vaadin.com/wiki/-/wiki/Main/Creating%20a%20basic%20application
+ *
+ * @author Vaadin Ltd
+ * @version @VERSION@
+ * @since 7.0.0
+ */
+public class BasicApplication extends Root {
+
+ @Override
+ protected void init(WrappedRequest request) {
+ VerticalLayout view = new VerticalLayout();
+ view.addComponent(new Label("Hello Vaadin!"));
+ setContent(view);
+ }
+}
--- /dev/null
+/*
+@VaadinApache2LicenseForJavaFiles@
+ */
+
+package com.vaadin.tests.minitutorials.v7a1;
+
+import com.vaadin.terminal.WrappedRequest;
+import com.vaadin.ui.Root;
+import com.vaadin.ui.TextField;
+
+/**
+ * Mini tutorial code for
+ * https://vaadin.com/wiki/-/wiki/Main/Creating%20an%20application
+ * %20that%20preserves%20state%20on%20refresh
+ *
+ * @author Vaadin Ltd
+ * @version @VERSION@
+ * @since 7.0.0
+ */
+public class CreatingPreserveState extends Root {
+ private static int windowCounter = 0;
+
+ @Override
+ public void init(WrappedRequest request) {
+ TextField tf = new TextField("Window #" + (++windowCounter));
+ tf.setImmediate(true);
+ getContent().addComponent(tf);
+ getApplication().setRootPreserved(true);
+ }
+
+}
--- /dev/null
+/*
+@VaadinApache2LicenseForJavaFiles@
+ */
+
+package com.vaadin.tests.minitutorials.v7a1;
+
+import com.vaadin.annotations.Theme;
+import com.vaadin.terminal.WrappedRequest;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.Root;
+import com.vaadin.ui.VerticalLayout;
+
+/**
+ * Mini tutorial code for
+ * https://vaadin.com/wiki/-/wiki/Main/Defining%20the%20theme%20for%20a%20Root
+ *
+ * @author Vaadin Ltd
+ * @version @VERSION@
+ * @since 7.0.0
+ */
+@Theme("hello-theme")
+public class DefineRootTheme extends Root {
+
+ @Override
+ protected void init(WrappedRequest request) {
+ VerticalLayout view = new VerticalLayout();
+ view.addComponent(new Label("Hello Vaadin"));
+ setContent(view);
+ }
+
+}
--- /dev/null
+/*
+@VaadinApache2LicenseForJavaFiles@
+ */
+
+package com.vaadin.tests.minitutorials.v7a1;
+
+import com.vaadin.Application;
+import com.vaadin.RootRequiresMoreInformationException;
+import com.vaadin.terminal.WrappedRequest;
+import com.vaadin.terminal.WrappedRequest.BrowserDetails;
+import com.vaadin.terminal.gwt.server.WebBrowser;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.Root;
+
+/**
+ * Mini tutorial code for
+ * https://vaadin.com/wiki/-/wiki/Main/Creating%20an%20application
+ * %20with%20different%20features%20for%20different%20clients
+ *
+ * @author Vaadin Ltd
+ * @version @VERSION@
+ * @since 7.0.0
+ */
+public class DifferentFeaturesForDifferentClients extends Application {
+
+ @Override
+ protected Root getRoot(WrappedRequest request)
+ throws RootRequiresMoreInformationException {
+ BrowserDetails browserDetails = request.getBrowserDetails();
+ // This is a limitation of 7.0.0.alpha1 that there is no better way to
+ // check if WebBrowser has been fully initialized
+ if (browserDetails.getUriFragment() == null) {
+ throw new RootRequiresMoreInformationException();
+ }
+
+ // could also use screen size, browser version etc.
+ if (browserDetails.getWebBrowser().isTouchDevice()) {
+ return new TouchRoot();
+ } else {
+ return new DefaultRoot();
+ }
+ }
+}
+
+class DefaultRoot extends Root {
+ @Override
+ protected void init(WrappedRequest request) {
+ getContent().addComponent(
+ new Label("This browser does not support touch events"));
+ }
+}
+
+class TouchRoot extends Root {
+ @Override
+ protected void init(WrappedRequest request) {
+ WebBrowser webBrowser = request.getBrowserDetails().getWebBrowser();
+ String screenSize = "" + webBrowser.getScreenWidth() + "x"
+ + webBrowser.getScreenHeight();
+ getContent().addComponent(
+ new Label("Using a touch enabled device with screen size"
+ + screenSize));
+ }
+}
--- /dev/null
+/*
+@VaadinApache2LicenseForJavaFiles@
+ */
+
+package com.vaadin.tests.minitutorials.v7a1;
+
+import com.vaadin.Application;
+import com.vaadin.terminal.WrappedRequest;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Button.ClickListener;
+import com.vaadin.ui.Root;
+
+/**
+ * Mini tutorial code for
+ * https://vaadin.com/wiki/-/wiki/Main/Finding%20the%20current
+ * %20Root%20and%20Application
+ *
+ * @author Vaadin Ltd
+ * @version @VERSION@
+ * @since 7.0.0
+ */
+public class FindCurrentRootAndApplication extends Root {
+
+ @Override
+ protected void init(WrappedRequest request) {
+ Button helloButton = new Button("Say Hello");
+ helloButton.addListener(new ClickListener() {
+ public void buttonClick(ClickEvent event) {
+ String msg = "Running in ";
+ msg += Application.getCurrentApplication().isProductionMode() ? "production"
+ : "debug";
+ msg += " mode";
+ Root.getCurrentRoot().showNotification(msg);
+ Root.getCurrentRoot().showNotification("Hello Vaadin user!");
+ }
+ });
+
+ addComponent(helloButton);
+ }
+
+}
--- /dev/null
+/*
+@VaadinApache2LicenseForJavaFiles@
+ */
+
+package com.vaadin.tests.minitutorials.v7a1;
+
+import com.vaadin.terminal.ExternalResource;
+import com.vaadin.terminal.WrappedRequest;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.Link;
+import com.vaadin.ui.Root;
+import com.vaadin.ui.VerticalLayout;
+
+/**
+ * Mini tutorial code for
+ * https://vaadin.com/wiki/-/wiki/Main/Creating%20multi%20tab%20applications
+ *
+ * @author Vaadin Ltd
+ * @version @VERSION@
+ * @since 7.0.0
+ */
+public class MultiTabApplication extends Root {
+
+ private class MainView extends VerticalLayout {
+ public MainView() {
+ addComponent(new Link("Edit person 1", new ExternalResource(
+ "?editPerson=person1")));
+ addComponent(new Link("Edit person 2", new ExternalResource(
+ "?editPerson=person2")));
+ }
+ }
+
+ private class EditPersonView extends VerticalLayout {
+
+ public EditPersonView(String person) {
+ addComponent(new Label("Editor for " + person));
+ }
+
+ }
+
+ @Override
+ public void init(WrappedRequest request) {
+ String person = request.getParameter("editPerson");
+ if (person == null) {
+ setContent(new MainView());
+ } else {
+ setContent(new EditPersonView(person));
+ }
+ }
+
+}
--- /dev/null
+/*
+@VaadinApache2LicenseForJavaFiles@
+ */
+
+package com.vaadin.tests.minitutorials.v7a1;
+
+import javax.validation.constraints.Max;
+import javax.validation.constraints.Min;
+import javax.validation.constraints.Size;
+
+import com.vaadin.data.util.BeanItem;
+import com.vaadin.data.validator.BeanValidator;
+import com.vaadin.terminal.WrappedRequest;
+import com.vaadin.ui.Root;
+import com.vaadin.ui.TextField;
+
+/**
+ * Mini tutorial code for
+ * https://vaadin.com/wiki/-/wiki/Main/Using%20Bean%20Validation
+ * %20to%20validate%20input
+ *
+ * @author Vaadin Ltd
+ * @version @VERSION@
+ * @since 7.0.0
+ */
+public class UsingBeanValidation extends Root {
+ class Person {
+
+ @Size(min = 5, max = 50)
+ private String name;
+
+ @Min(0)
+ @Max(100)
+ private int age;
+
+ // + constructor + setters + getters
+
+ public Person(String name, int age) {
+ this.name = name;
+ this.age = age;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public int getAge() {
+ return age;
+ }
+
+ private void setN() {
+ // TODO Auto-generated method stub
+
+ }
+ }
+
+ @Override
+ protected void init(WrappedRequest request) {
+ Person person = new Person("John", 26);
+ BeanItem<Person> item = new BeanItem<Person>(person);
+
+ TextField firstName = new TextField("First name",
+ item.getItemProperty("name"));
+ firstName.setImmediate(true);
+ addComponent(firstName);
+
+ firstName.addValidator(new BeanValidator(Person.class, "name"));
+ }
+
+}
--- /dev/null
+/*
+@VaadinApache2LicenseForJavaFiles@
+ */
+
+package com.vaadin.tests.minitutorials.v7a1;
+
+import com.vaadin.terminal.Page.FragmentChangedEvent;
+import com.vaadin.terminal.Page.FragmentChangedListener;
+import com.vaadin.terminal.WrappedRequest;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.Root;
+
+/**
+ * Mini tutorial code for
+ * https://vaadin.com/wiki/-/wiki/Main/Using%20URI%20fragments
+ *
+ * @author Vaadin Ltd
+ * @version @VERSION@
+ * @since 7.0.0
+ */
+public class UsingUriFragments extends Root {
+
+ @Override
+ protected void init(WrappedRequest request) {
+ Label label = new Label("Hello, your fragment is "
+ + request.getBrowserDetails().getUriFragment());
+ getContent().addComponent(label);
+
+ // React to fragment changes
+ addListener(new FragmentChangedListener() {
+ public void fragmentChanged(FragmentChangedEvent source) {
+ handleFragment(source.getFragment());
+ }
+ });
+
+ // Handle the fragment received in the initial request
+ handleFragment(request.getBrowserDetails().getUriFragment());
+
+ addComponent(new Button("Show and set fragment",
+ new Button.ClickListener() {
+ public void buttonClick(ClickEvent event) {
+ handleFragment(getFragment());
+ setFragment("customFragment");
+ }
+ }));
+ }
+
+ private void handleFragment(String uriFragment) {
+ addComponent(new Label("Got new fragment: " + uriFragment));
+ }
+
+}
--- /dev/null
+/*
+@VaadinApache2LicenseForJavaFiles@
+ */
+
+package com.vaadin.tests.minitutorials.v7a1;
+
+import com.vaadin.terminal.WrappedRequest;
+import com.vaadin.terminal.gwt.server.WebBrowser;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.Root;
+
+/**
+ * Mini tutorial code for
+ * https://vaadin.com/wiki/-/wiki/Main/Using%20URI%20or%20
+ * parameters%20or%20screen%20size%20when%20initializing%20an%20application
+ *
+ * @author Vaadin Ltd
+ * @version @VERSION@
+ * @since 7.0.0
+ */
+public class UsingXyzWhenInitializing extends Root {
+
+ @Override
+ protected void init(WrappedRequest request) {
+ String name = request.getParameter("name");
+ if (name == null) {
+ name = "Unknown";
+ }
+
+ getContent().addComponent(new Label("Hello " + name));
+
+ String pathInfo = request.getRequestPathInfo();
+ if ("/viewSource".equals(pathInfo)) {
+ getContent().addComponent(new Label("This is the source"));
+ } else {
+ getContent().addComponent(new Label("Welcome to my application"));
+ }
+
+ WebBrowser browser = request.getBrowserDetails().getWebBrowser();
+ String resolution = "Your browser window on startup was "
+ + browser.getClientWidth() + "x" + browser.getClientHeight();
+ if (browser.getClientWidth() > 1024) {
+ getContent().addComponent(
+ new Label("The is the large version of the application. "
+ + resolution));
+ } else {
+ getContent().addComponent(
+ new Label("This is the small version of the application. "
+ + resolution));
+ }
+ }
+
+}