]> source.dussan.org Git - vaadin-framework.git/commitdiff
Updated some tutorials 79/379/4
authorjohan <johan@vaadin.com>
Tue, 27 Nov 2012 09:34:38 +0000 (11:34 +0200)
committerjohan <johan@vaadin.com>
Tue, 27 Nov 2012 11:03:08 +0000 (13:03 +0200)
Change-Id: I5c59b2d08b2b811020c1fca7420eefd740dbe01a

14 files changed:
uitest/src/com/vaadin/tests/minitutorials/v7a1/AutoGeneratingForm.java
uitest/src/com/vaadin/tests/minitutorials/v7a1/DifferentFeaturesForDifferentClients.java
uitest/src/com/vaadin/tests/minitutorials/v7a1/FindCurrentUI.java
uitest/src/com/vaadin/tests/minitutorials/v7a1/UsingXyzWhenInitializing.java
uitest/src/com/vaadin/tests/minitutorials/v7b9/CountView.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/minitutorials/v7b9/LoginView.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/minitutorials/v7b9/MainView.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/minitutorials/v7b9/MainViewEarlierExample.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/minitutorials/v7b9/MainView__LastNavigatorExample.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/minitutorials/v7b9/MessageView.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/minitutorials/v7b9/NavigationtestUI.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/minitutorials/v7b9/SassyUI.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/minitutorials/v7b9/SecretView.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/minitutorials/v7b9/SettingsView.java [new file with mode: 0644]

index 53d76a251f4213a16fd21460c41a806ac7e0d7c8..e904525ef0fc3b0ff37e4a80513f8f64c71a8a2b 100644 (file)
@@ -46,7 +46,7 @@ public class AutoGeneratingForm extends UI {
         fieldGroup.setItemDataSource(new BeanItem<Person>(new Person("John",
                 "Doe", 34)));
 
-        // Loop through the properties, build fields for them and add the fields
+        // Loop through the properties, build fields for them and add the fields 
         // to this root
         for (Object propertyId : fieldGroup.getUnboundPropertyIds()) {
             layout.addComponent(fieldGroup.buildAndBind(propertyId));
index 6a713c4f64745a1bd2b880fdcdc1025b46752d10..7833419e5973399eb079ba39a03e8ae6cf2a6a45 100644 (file)
@@ -38,9 +38,9 @@ public class DifferentFeaturesForDifferentClients extends UIProvider {
     public Class<? extends UI> getUIClass(UIClassSelectionEvent event) {
         // could also use browser version etc.
         if (event.getRequest().getHeader("user-agent").contains("mobile")) {
-            return TouchRoot.class;
+            return TouchUI.class;
         } else {
-            return DefaultRoot.class;
+            return DefaultUI.class;
         }
     }
 
@@ -56,17 +56,17 @@ public class DifferentFeaturesForDifferentClients extends UIProvider {
     }
 }
 
-class DefaultRoot extends UI {
+class DefaultUI extends UI {
     @Override
     protected void init(VaadinRequest request) {
         setContent(new Label("This browser does not support touch events"));
     }
 }
 
-class TouchRoot extends UI {
+class TouchUI extends UI {
     @Override
     protected void init(VaadinRequest request) {
-        WebBrowser webBrowser = getSession().getBrowser();
+        WebBrowser webBrowser = getPage().getWebBrowser();
         String screenSize = "" + webBrowser.getScreenWidth() + "x"
                 + webBrowser.getScreenHeight();
         setContent(new Label("Using a touch enabled device with screen size"
index 858f202e6d2c1b96e23bb124e6436d675f1a534b..d277c4f09519e5ab13c5a96128407799b6c05d0a 100644 (file)
@@ -37,7 +37,7 @@ public class FindCurrentUI extends UI {
     @Override
     protected void init(VaadinRequest request) {
         Button helloButton = new Button("Say Hello");
-        helloButton.addListener(new ClickListener() {
+        helloButton.addClickListener(new ClickListener() {
             @Override
             public void buttonClick(ClickEvent event) {
                 String msg = "Running in ";
@@ -47,7 +47,7 @@ public class FindCurrentUI extends UI {
             }
         });
 
-        helloButton.addListener(new ClickListener() {
+        helloButton.addClickListener(new ClickListener() {
             @Override
             public void buttonClick(ClickEvent event) {
                 Notification.show("This UI is "
index 6cf0514df4472e1800e0b339a0b9df7debcb98a2..dfc39d3ea9c694f96cb424f8d10d4222acf35cb9 100644 (file)
@@ -17,6 +17,7 @@
 package com.vaadin.tests.minitutorials.v7a1;
 
 import com.vaadin.server.VaadinRequest;
+import com.vaadin.server.WebBrowser;
 import com.vaadin.ui.Label;
 import com.vaadin.ui.UI;
 import com.vaadin.ui.VerticalLayout;
@@ -51,18 +52,18 @@ public class UsingXyzWhenInitializing extends UI {
             layout.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));
-        // }
+        WebBrowser browser = getPage().getWebBrowser();
+        String resolution = "Your browser window on startup was "
+                + browser.getScreenWidth() + "x" + browser.getScreenHeight();
+        if (browser.getScreenWidth() > 1024) {
+            layout.addComponent(new Label(
+                    "The is the large version of the application. "
+                            + resolution));
+        } else {
+            layout.addComponent(new Label(
+                    "This is the small version of the application. "
+                            + resolution));
+        }
     }
 
 }
diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7b9/CountView.java b/uitest/src/com/vaadin/tests/minitutorials/v7b9/CountView.java
new file mode 100644 (file)
index 0000000..6e4b2d7
--- /dev/null
@@ -0,0 +1,21 @@
+package com.vaadin.tests.minitutorials.v7b9;\r
+\r
+import com.vaadin.navigator.View;\r
+import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;\r
+import com.vaadin.ui.Label;\r
+import com.vaadin.ui.Panel;\r
+\r
+public class CountView extends Panel implements View {\r
+    public static final String NAME = "count";\r
+\r
+    private static int count = 1;\r
+\r
+    public CountView() {\r
+        setContent(new Label("Created: " + count++));\r
+    }\r
+\r
+    public void enter(ViewChangeEvent event) {\r
+\r
+    }\r
+\r
+}
\ No newline at end of file
diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7b9/LoginView.java b/uitest/src/com/vaadin/tests/minitutorials/v7b9/LoginView.java
new file mode 100644 (file)
index 0000000..a0cb6ba
--- /dev/null
@@ -0,0 +1,52 @@
+package com.vaadin.tests.minitutorials.v7b9;\r
+\r
+import com.vaadin.navigator.Navigator;\r
+import com.vaadin.navigator.View;\r
+import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;\r
+import com.vaadin.ui.Button;\r
+import com.vaadin.ui.Button.ClickEvent;\r
+import com.vaadin.ui.Layout;\r
+import com.vaadin.ui.Notification;\r
+import com.vaadin.ui.Panel;\r
+import com.vaadin.ui.PasswordField;\r
+import com.vaadin.ui.TextField;\r
+import com.vaadin.ui.UI;\r
+import com.vaadin.ui.VerticalLayout;\r
+\r
+public class LoginView extends Panel implements View {\r
+\r
+    public static final String NAME = "login";\r
+\r
+    public LoginView(final Navigator navigator,\r
+            final String fragmentAndParameters) {\r
+        Layout layout = new VerticalLayout();\r
+\r
+        final TextField email = new TextField("Email");\r
+        layout.addComponent(email);\r
+\r
+        final PasswordField password = new PasswordField("Password");\r
+        layout.addComponent(password);\r
+\r
+        final Button login = new Button("Login", new Button.ClickListener() {\r
+            public void buttonClick(ClickEvent event) {\r
+                Notification.show("Ok, let's pretend you're " + email);\r
+\r
+                // indicate the user is logged in\r
+                ((NavigationtestUI) UI.getCurrent()).setLoggedInUser(email\r
+                        .getValue());\r
+\r
+                // navigate back to the intended place\r
+                navigator.navigateTo(fragmentAndParameters);\r
+            }\r
+        });\r
+        layout.addComponent(login);\r
+        setContent(layout);\r
+\r
+    }\r
+\r
+    @Override\r
+    public void enter(ViewChangeEvent event) {\r
+        // TODO Auto-generated method stub\r
+\r
+    }\r
+}\r
diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7b9/MainView.java b/uitest/src/com/vaadin/tests/minitutorials/v7b9/MainView.java
new file mode 100644 (file)
index 0000000..c08803e
--- /dev/null
@@ -0,0 +1,61 @@
+package com.vaadin.tests.minitutorials.v7b9;\r
+\r
+import com.vaadin.navigator.Navigator;\r
+import com.vaadin.navigator.View;\r
+import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;\r
+import com.vaadin.server.ExternalResource;\r
+import com.vaadin.ui.Button;\r
+import com.vaadin.ui.Button.ClickEvent;\r
+import com.vaadin.ui.Link;\r
+import com.vaadin.ui.Panel;\r
+import com.vaadin.ui.UI;\r
+import com.vaadin.ui.VerticalLayout;\r
+\r
+public class MainView extends Panel implements View {\r
+\r
+    public static final String NAME = "";\r
+\r
+    private Button logOut;\r
+\r
+    public MainView(final Navigator navigator) {\r
+\r
+        VerticalLayout layout = new VerticalLayout();\r
+\r
+        Link lnk = new Link("Count",\r
+                new ExternalResource("#!" + CountView.NAME));\r
+        layout.addComponent(lnk);\r
+\r
+        lnk = new Link("Message: Hello", new ExternalResource("#!"\r
+                + MessageView.NAME + "/Hello"));\r
+        layout.addComponent(lnk);\r
+\r
+        lnk = new Link("Message: Bye", new ExternalResource("#!"\r
+                + MessageView.NAME + "/Bye/Goodbye"));\r
+        layout.addComponent(lnk);\r
+\r
+        lnk = new Link("Private message: Secret", new ExternalResource("#!"\r
+                + SecretView.NAME + "/Secret"));\r
+        layout.addComponent(lnk);\r
+\r
+        lnk = new Link("Private message: Topsecret", new ExternalResource("#!"\r
+                + SecretView.NAME + "/Topsecret"));\r
+        layout.addComponent(lnk);\r
+\r
+        logOut = new Button("Logout", new Button.ClickListener() {\r
+            public void buttonClick(ClickEvent event) {\r
+\r
+                ((NavigationtestUI) UI.getCurrent()).setLoggedInUser(null);\r
+                logOut.setCaption("Login");\r
+                navigator.navigateTo(LoginView.NAME);\r
+\r
+            }\r
+        });\r
+        layout.addComponent(logOut);\r
+        setContent(layout);\r
+    }\r
+\r
+    @Override\r
+    public void enter(ViewChangeEvent event) {\r
+\r
+    }\r
+}
\ No newline at end of file
diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7b9/MainViewEarlierExample.java b/uitest/src/com/vaadin/tests/minitutorials/v7b9/MainViewEarlierExample.java
new file mode 100644 (file)
index 0000000..55b936f
--- /dev/null
@@ -0,0 +1,60 @@
+package com.vaadin.tests.minitutorials.v7b9;\r
+\r
+import com.vaadin.navigator.View;\r
+import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;\r
+import com.vaadin.server.ExternalResource;\r
+import com.vaadin.ui.Button;\r
+import com.vaadin.ui.Button.ClickEvent;\r
+import com.vaadin.ui.Link;\r
+import com.vaadin.ui.Panel;\r
+import com.vaadin.ui.UI;\r
+import com.vaadin.ui.VerticalLayout;\r
+\r
+public class MainViewEarlierExample extends Panel implements View {\r
+\r
+    public static final String NAME = "";\r
+\r
+    public MainViewEarlierExample() {\r
+\r
+        VerticalLayout layout = new VerticalLayout();\r
+\r
+        Link lnk = new Link("Count",\r
+                new ExternalResource("#!" + CountView.NAME));\r
+        layout.addComponent(lnk);\r
+\r
+        lnk = new Link("Message: Hello", new ExternalResource("#!"\r
+                + MessageView.NAME + "/Hello"));\r
+        layout.addComponent(lnk);\r
+\r
+        lnk = new Link("Message: Bye", new ExternalResource("#!"\r
+                + MessageView.NAME + "/Bye/Goodbye"));\r
+        layout.addComponent(lnk);\r
+\r
+        lnk = new Link("Private message: Secret", new ExternalResource("#!"\r
+                + SecretView.NAME + "/Secret"));\r
+        layout.addComponent(lnk);\r
+\r
+        lnk = new Link("Private message: Topsecret", new ExternalResource("#!"\r
+                + SecretView.NAME + "/Topsecret"));\r
+        layout.addComponent(lnk);\r
+\r
+        // login/logout toggle so we can test this\r
+        Button logInOut = new Button("Toggle login",\r
+                new Button.ClickListener() {\r
+                    public void buttonClick(ClickEvent event) {\r
+                        Object user = ((NavigationtestUI) UI.getCurrent())\r
+                                .getLoggedInUser();\r
+                        ((NavigationtestUI) UI.getCurrent())\r
+                                .setLoggedInUser(user == null ? "Smee" : null);\r
+                    }\r
+                });\r
+        layout.addComponent(logInOut);\r
+        setContent(layout);\r
+    }\r
+\r
+    @Override\r
+    public void enter(ViewChangeEvent event) {\r
+\r
+    }\r
+\r
+}
\ No newline at end of file
diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7b9/MainView__LastNavigatorExample.java b/uitest/src/com/vaadin/tests/minitutorials/v7b9/MainView__LastNavigatorExample.java
new file mode 100644 (file)
index 0000000..91d495c
--- /dev/null
@@ -0,0 +1,29 @@
+package com.vaadin.tests.minitutorials.v7b9;\r
+\r
+import com.vaadin.navigator.Navigator;\r
+import com.vaadin.navigator.View;\r
+import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;\r
+import com.vaadin.server.ExternalResource;\r
+import com.vaadin.ui.Link;\r
+import com.vaadin.ui.Panel;\r
+import com.vaadin.ui.VerticalLayout;\r
+\r
+public class MainView__LastNavigatorExample extends Panel implements View {\r
+\r
+    public static final String NAME = "";\r
+\r
+    public MainView__LastNavigatorExample(final Navigator navigator) {\r
+\r
+        Link lnk = new Link("Settings", new ExternalResource("#!"\r
+                + SettingsView.NAME));\r
+        VerticalLayout vl = new VerticalLayout();\r
+        vl.addComponent(lnk);\r
+        setContent(vl);\r
+\r
+    }\r
+\r
+    @Override\r
+    public void enter(ViewChangeEvent event) {\r
+\r
+    }\r
+}\r
diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7b9/MessageView.java b/uitest/src/com/vaadin/tests/minitutorials/v7b9/MessageView.java
new file mode 100644 (file)
index 0000000..fbb28b6
--- /dev/null
@@ -0,0 +1,29 @@
+package com.vaadin.tests.minitutorials.v7b9;\r
+\r
+import com.vaadin.navigator.View;\r
+import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;\r
+import com.vaadin.ui.Label;\r
+import com.vaadin.ui.Layout;\r
+import com.vaadin.ui.Panel;\r
+import com.vaadin.ui.VerticalLayout;\r
+\r
+public class MessageView extends Panel implements View {\r
+    public static final String NAME = "message";\r
+    private Layout layout;\r
+\r
+    public MessageView() {\r
+        super(new VerticalLayout());\r
+        setCaption("Messages");\r
+    }\r
+\r
+    @Override\r
+    public void enter(ViewChangeEvent event) {\r
+        if (event.getParameters() != null) {\r
+            // split at "/", add each part as a label\r
+            String[] msgs = event.getParameters().split("/");\r
+            for (String msg : msgs) {\r
+                ((Layout) getContent()).addComponent(new Label(msg));\r
+            }\r
+        }\r
+    }\r
+}
\ No newline at end of file
diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7b9/NavigationtestUI.java b/uitest/src/com/vaadin/tests/minitutorials/v7b9/NavigationtestUI.java
new file mode 100644 (file)
index 0000000..c31bbef
--- /dev/null
@@ -0,0 +1,77 @@
+package com.vaadin.tests.minitutorials.v7b9;\r
+\r
+import com.vaadin.annotations.PreserveOnRefresh;\r
+import com.vaadin.navigator.Navigator;\r
+import com.vaadin.server.VaadinRequest;\r
+import com.vaadin.ui.UI;\r
+\r
+@PreserveOnRefresh\r
+public class NavigationtestUI extends UI {\r
+\r
+    Navigator navigator;\r
+\r
+    String loggedInUser;\r
+\r
+    @Override\r
+    public void init(VaadinRequest request) {\r
+        // Create Navigator, make it control the ViewDisplay\r
+        navigator = new Navigator(this, this);\r
+\r
+        // Add some Views\r
+        // no fragment for main view\r
+        navigator.addView(MainView__LastNavigatorExample.NAME,\r
+                new MainView__LastNavigatorExample(navigator));\r
+\r
+        // #settings\r
+        navigator.addView(SettingsView.NAME, new SettingsView(navigator));\r
+\r
+        // #count will be a new instance each time we navigate to it, counts:\r
+        /*\r
+         * Commented away from other example // no fragment for main view\r
+         * navigator.addView(MainView.NAME, new MainView(navigator));\r
+         * \r
+         * navigator.addView(CountView.NAME, CountView.class);\r
+         * \r
+         * // #message adds a label with whatever it receives as a parameter\r
+         * navigator.addView(MessageView.NAME, new MessageView());\r
+         * \r
+         * // #secret works as #message, but you need to be logged in\r
+         * navigator.addView(SecretView.NAME, new SecretView());\r
+         * \r
+         * // #login will navigate to the main view if invoked via this\r
+         * mechanism navigator.addView(LoginView.NAME, new LoginView(navigator,\r
+         * MainView.NAME));\r
+         * \r
+         * // we'll handle permissions with a listener here, you could also do\r
+         * // that in the View itself. navigator.addViewChangeListener(new\r
+         * ViewChangeListener() {\r
+         * \r
+         * @Override public boolean beforeViewChange(ViewChangeEvent event) { if\r
+         * (((NavigationtestUI)UI.getCurrent()).getLoggedInUser() == null) { //\r
+         * Show to LoginView instead, pass intended view String\r
+         * fragmentAndParameters = event.getViewName(); if\r
+         * (event.getParameters() != null) { fragmentAndParameters += "/";\r
+         * fragmentAndParameters += event.getParameters(); }\r
+         * navigator.getDisplay().showView(new LoginView(navigator,\r
+         * fragmentAndParameters)); return false;\r
+         * \r
+         * } else { return true; } }\r
+         * \r
+         * @Override public void afterViewChange(ViewChangeEvent event) {\r
+         * \r
+         * } });\r
+         */\r
+        // react to initial fragment, received before we created the Navigator\r
+\r
+        // This was removed in beta10\r
+        // navigator.navigate();\r
+    }\r
+\r
+    public String getLoggedInUser() {\r
+        return loggedInUser;\r
+    }\r
+\r
+    public void setLoggedInUser(String user) {\r
+        loggedInUser = user;\r
+    }\r
+}\r
diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7b9/SassyUI.java b/uitest/src/com/vaadin/tests/minitutorials/v7b9/SassyUI.java
new file mode 100644 (file)
index 0000000..a167522
--- /dev/null
@@ -0,0 +1,28 @@
+package com.vaadin.tests.minitutorials.v7b9;\r
+\r
+import com.vaadin.annotations.Theme;\r
+import com.vaadin.server.VaadinRequest;\r
+import com.vaadin.ui.Button;\r
+import com.vaadin.ui.Layout;\r
+import com.vaadin.ui.UI;\r
+import com.vaadin.ui.VerticalLayout;\r
+\r
+@Theme("sassy")\r
+public class SassyUI extends UI {\r
+    @Override\r
+    public void init(VaadinRequest request) {\r
+        Button b = new Button("Reindeer");\r
+        Layout layout = new VerticalLayout();\r
+        layout.addComponent(b);\r
+\r
+        b = new Button("important");\r
+        b.addStyleName("important");\r
+        layout.addComponent(b);\r
+\r
+        b = new Button("More important");\r
+        b.setPrimaryStyleName("my-button");\r
+        layout.addComponent(b);\r
+\r
+        setContent(layout);\r
+    }\r
+}
\ No newline at end of file
diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7b9/SecretView.java b/uitest/src/com/vaadin/tests/minitutorials/v7b9/SecretView.java
new file mode 100644 (file)
index 0000000..93dbe0b
--- /dev/null
@@ -0,0 +1,16 @@
+package com.vaadin.tests.minitutorials.v7b9;\r
+\r
+import com.vaadin.navigator.View;\r
+import com.vaadin.ui.Label;\r
+import com.vaadin.ui.Layout;\r
+\r
+public class SecretView extends MessageView implements View {\r
+    public static final String NAME = "secret";\r
+\r
+    public SecretView() {\r
+        setCaption("Private messages");\r
+\r
+        ((Layout) getContent()).addComponent(new Label("Some private stuff."));\r
+    }\r
+\r
+}
\ No newline at end of file
diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7b9/SettingsView.java b/uitest/src/com/vaadin/tests/minitutorials/v7b9/SettingsView.java
new file mode 100644 (file)
index 0000000..1e026fe
--- /dev/null
@@ -0,0 +1,129 @@
+package com.vaadin.tests.minitutorials.v7b9;\r
+\r
+import java.util.Date;\r
+\r
+import com.vaadin.data.Property.ValueChangeEvent;\r
+import com.vaadin.data.Property.ValueChangeListener;\r
+import com.vaadin.data.util.ObjectProperty;\r
+import com.vaadin.navigator.Navigator;\r
+import com.vaadin.navigator.View;\r
+import com.vaadin.navigator.ViewChangeListener;\r
+import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;\r
+import com.vaadin.ui.Button;\r
+import com.vaadin.ui.Button.ClickEvent;\r
+import com.vaadin.ui.DateField;\r
+import com.vaadin.ui.InlineDateField;\r
+import com.vaadin.ui.Layout;\r
+import com.vaadin.ui.Notification;\r
+import com.vaadin.ui.Notification.Type;\r
+import com.vaadin.ui.Panel;\r
+import com.vaadin.ui.VerticalLayout;\r
+import com.vaadin.ui.themes.Reindeer;\r
+\r
+public class SettingsView extends Panel implements View {\r
+\r
+    public static String NAME = "settings";\r
+\r
+    Navigator navigator;\r
+    DateField date;\r
+    Button apply;\r
+    Button cancel;\r
+\r
+    String pendingViewAndParameters = null;\r
+\r
+    public SettingsView(final Navigator navigator) {\r
+        this.navigator = navigator;\r
+        Layout layout = new VerticalLayout();\r
+\r
+        date = new InlineDateField("Birth date");\r
+        date.setImmediate(true);\r
+        layout.addComponent(date);\r
+        // pretend we have a datasource:\r
+        date.setPropertyDataSource(new ObjectProperty<Date>(new Date()));\r
+        date.setBuffered(true);\r
+        // show buttons when date is changed\r
+        date.addValueChangeListener(new ValueChangeListener() {\r
+            public void valueChange(ValueChangeEvent event) {\r
+                hideOrShowButtons();\r
+                pendingViewAndParameters = null;\r
+            }\r
+        });\r
+\r
+        // commit the TextField changes when "Save" is clicked\r
+        apply = new Button("Apply", new Button.ClickListener() {\r
+            public void buttonClick(ClickEvent event) {\r
+                date.commit();\r
+                hideOrShowButtons();\r
+                processPendingView();\r
+            }\r
+        });\r
+        layout.addComponent(apply);\r
+\r
+        // Discard the TextField changes when "Cancel" is clicked\r
+        cancel = new Button("Cancel", new Button.ClickListener() {\r
+            public void buttonClick(ClickEvent event) {\r
+                date.discard();\r
+                hideOrShowButtons();\r
+                processPendingView();\r
+            }\r
+        });\r
+        cancel.setStyleName(Reindeer.BUTTON_LINK);\r
+        layout.addComponent(cancel);\r
+\r
+        // attach a listener so that we'll get asked isViewChangeAllowed?\r
+        navigator.addViewChangeListener(new ViewChangeListener() {\r
+            public boolean beforeViewChange(ViewChangeEvent event) {\r
+                if (event.getOldView() == SettingsView.this\r
+                        && date.isModified()) {\r
+\r
+                    // save the View where the user intended to go\r
+                    pendingViewAndParameters = event.getViewName();\r
+                    if (event.getParameters() != null) {\r
+                        pendingViewAndParameters += "/";\r
+                        pendingViewAndParameters += event.getParameters();\r
+                    }\r
+\r
+                    // Prompt the user to save or cancel if the name is changed\r
+                    Notification.show("Please apply or cancel your changes",\r
+                            Type.WARNING_MESSAGE);\r
+\r
+                    return false;\r
+                } else {\r
+                    return true;\r
+                }\r
+            }\r
+\r
+            public void afterViewChange(ViewChangeEvent event) {\r
+                pendingViewAndParameters = null;\r
+            }\r
+        });\r
+\r
+        setContent(layout);\r
+\r
+    }\r
+\r
+    // Hide or show buttons depending on whether date is modified or not\r
+    private void hideOrShowButtons() {\r
+        apply.setVisible(date.isModified());\r
+        cancel.setVisible(date.isModified());\r
+    }\r
+\r
+    // if there is a pending view change, do it now\r
+    private void processPendingView() {\r
+        if (pendingViewAndParameters != null) {\r
+            navigator.navigateTo(pendingViewAndParameters);\r
+            pendingViewAndParameters = null;\r
+        }\r
+    }\r
+\r
+    public void navigateTo(String fragmentParameters) {\r
+        hideOrShowButtons();\r
+    }\r
+\r
+    @Override\r
+    public void enter(ViewChangeEvent event) {\r
+        // TODO Auto-generated method stub\r
+\r
+    }\r
+\r
+}
\ No newline at end of file