summaryrefslogtreecommitdiffstats
path: root/uitest
diff options
context:
space:
mode:
authorLeif Åstrand <leif@vaadin.com>2012-11-27 11:06:34 +0000
committerVaadin Code Review <review@vaadin.com>2012-11-27 11:06:34 +0000
commitf94d3340ff17be88e4bf79f27c8e85753e9e50e5 (patch)
treeb17c56042674109c226412527e0de6225b168a01 /uitest
parentbcad61f83313b7ed73f56db39371491abe38e267 (diff)
parent94ae66a251af6c0962f89c37bb2220c5ed6aa719 (diff)
downloadvaadin-framework-f94d3340ff17be88e4bf79f27c8e85753e9e50e5.tar.gz
vaadin-framework-f94d3340ff17be88e4bf79f27c8e85753e9e50e5.zip
Merge "Updated some tutorials"
Diffstat (limited to 'uitest')
-rw-r--r--uitest/src/com/vaadin/tests/minitutorials/v7a1/AutoGeneratingForm.java2
-rw-r--r--uitest/src/com/vaadin/tests/minitutorials/v7a1/DifferentFeaturesForDifferentClients.java10
-rw-r--r--uitest/src/com/vaadin/tests/minitutorials/v7a1/FindCurrentUI.java4
-rw-r--r--uitest/src/com/vaadin/tests/minitutorials/v7a1/UsingXyzWhenInitializing.java25
-rw-r--r--uitest/src/com/vaadin/tests/minitutorials/v7b9/CountView.java21
-rw-r--r--uitest/src/com/vaadin/tests/minitutorials/v7b9/LoginView.java52
-rw-r--r--uitest/src/com/vaadin/tests/minitutorials/v7b9/MainView.java61
-rw-r--r--uitest/src/com/vaadin/tests/minitutorials/v7b9/MainViewEarlierExample.java60
-rw-r--r--uitest/src/com/vaadin/tests/minitutorials/v7b9/MainView__LastNavigatorExample.java29
-rw-r--r--uitest/src/com/vaadin/tests/minitutorials/v7b9/MessageView.java29
-rw-r--r--uitest/src/com/vaadin/tests/minitutorials/v7b9/NavigationtestUI.java77
-rw-r--r--uitest/src/com/vaadin/tests/minitutorials/v7b9/SassyUI.java28
-rw-r--r--uitest/src/com/vaadin/tests/minitutorials/v7b9/SecretView.java16
-rw-r--r--uitest/src/com/vaadin/tests/minitutorials/v7b9/SettingsView.java129
14 files changed, 523 insertions, 20 deletions
diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7a1/AutoGeneratingForm.java b/uitest/src/com/vaadin/tests/minitutorials/v7a1/AutoGeneratingForm.java
index 53d76a251f..e904525ef0 100644
--- a/uitest/src/com/vaadin/tests/minitutorials/v7a1/AutoGeneratingForm.java
+++ b/uitest/src/com/vaadin/tests/minitutorials/v7a1/AutoGeneratingForm.java
@@ -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));
diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7a1/DifferentFeaturesForDifferentClients.java b/uitest/src/com/vaadin/tests/minitutorials/v7a1/DifferentFeaturesForDifferentClients.java
index 6a713c4f64..7833419e59 100644
--- a/uitest/src/com/vaadin/tests/minitutorials/v7a1/DifferentFeaturesForDifferentClients.java
+++ b/uitest/src/com/vaadin/tests/minitutorials/v7a1/DifferentFeaturesForDifferentClients.java
@@ -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"
diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7a1/FindCurrentUI.java b/uitest/src/com/vaadin/tests/minitutorials/v7a1/FindCurrentUI.java
index 858f202e6d..d277c4f095 100644
--- a/uitest/src/com/vaadin/tests/minitutorials/v7a1/FindCurrentUI.java
+++ b/uitest/src/com/vaadin/tests/minitutorials/v7a1/FindCurrentUI.java
@@ -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 "
diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7a1/UsingXyzWhenInitializing.java b/uitest/src/com/vaadin/tests/minitutorials/v7a1/UsingXyzWhenInitializing.java
index 6cf0514df4..dfc39d3ea9 100644
--- a/uitest/src/com/vaadin/tests/minitutorials/v7a1/UsingXyzWhenInitializing.java
+++ b/uitest/src/com/vaadin/tests/minitutorials/v7a1/UsingXyzWhenInitializing.java
@@ -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
index 0000000000..6e4b2d790d
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/minitutorials/v7b9/CountView.java
@@ -0,0 +1,21 @@
+package com.vaadin.tests.minitutorials.v7b9;
+
+import com.vaadin.navigator.View;
+import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.Panel;
+
+public class CountView extends Panel implements View {
+ public static final String NAME = "count";
+
+ private static int count = 1;
+
+ public CountView() {
+ setContent(new Label("Created: " + count++));
+ }
+
+ public void enter(ViewChangeEvent event) {
+
+ }
+
+} \ 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
index 0000000000..a0cb6bacba
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/minitutorials/v7b9/LoginView.java
@@ -0,0 +1,52 @@
+package com.vaadin.tests.minitutorials.v7b9;
+
+import com.vaadin.navigator.Navigator;
+import com.vaadin.navigator.View;
+import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Layout;
+import com.vaadin.ui.Notification;
+import com.vaadin.ui.Panel;
+import com.vaadin.ui.PasswordField;
+import com.vaadin.ui.TextField;
+import com.vaadin.ui.UI;
+import com.vaadin.ui.VerticalLayout;
+
+public class LoginView extends Panel implements View {
+
+ public static final String NAME = "login";
+
+ public LoginView(final Navigator navigator,
+ final String fragmentAndParameters) {
+ Layout layout = new VerticalLayout();
+
+ final TextField email = new TextField("Email");
+ layout.addComponent(email);
+
+ final PasswordField password = new PasswordField("Password");
+ layout.addComponent(password);
+
+ final Button login = new Button("Login", new Button.ClickListener() {
+ public void buttonClick(ClickEvent event) {
+ Notification.show("Ok, let's pretend you're " + email);
+
+ // indicate the user is logged in
+ ((NavigationtestUI) UI.getCurrent()).setLoggedInUser(email
+ .getValue());
+
+ // navigate back to the intended place
+ navigator.navigateTo(fragmentAndParameters);
+ }
+ });
+ layout.addComponent(login);
+ setContent(layout);
+
+ }
+
+ @Override
+ public void enter(ViewChangeEvent event) {
+ // TODO Auto-generated method stub
+
+ }
+}
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
index 0000000000..c08803e549
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/minitutorials/v7b9/MainView.java
@@ -0,0 +1,61 @@
+package com.vaadin.tests.minitutorials.v7b9;
+
+import com.vaadin.navigator.Navigator;
+import com.vaadin.navigator.View;
+import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
+import com.vaadin.server.ExternalResource;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Link;
+import com.vaadin.ui.Panel;
+import com.vaadin.ui.UI;
+import com.vaadin.ui.VerticalLayout;
+
+public class MainView extends Panel implements View {
+
+ public static final String NAME = "";
+
+ private Button logOut;
+
+ public MainView(final Navigator navigator) {
+
+ VerticalLayout layout = new VerticalLayout();
+
+ Link lnk = new Link("Count",
+ new ExternalResource("#!" + CountView.NAME));
+ layout.addComponent(lnk);
+
+ lnk = new Link("Message: Hello", new ExternalResource("#!"
+ + MessageView.NAME + "/Hello"));
+ layout.addComponent(lnk);
+
+ lnk = new Link("Message: Bye", new ExternalResource("#!"
+ + MessageView.NAME + "/Bye/Goodbye"));
+ layout.addComponent(lnk);
+
+ lnk = new Link("Private message: Secret", new ExternalResource("#!"
+ + SecretView.NAME + "/Secret"));
+ layout.addComponent(lnk);
+
+ lnk = new Link("Private message: Topsecret", new ExternalResource("#!"
+ + SecretView.NAME + "/Topsecret"));
+ layout.addComponent(lnk);
+
+ logOut = new Button("Logout", new Button.ClickListener() {
+ public void buttonClick(ClickEvent event) {
+
+ ((NavigationtestUI) UI.getCurrent()).setLoggedInUser(null);
+ logOut.setCaption("Login");
+ navigator.navigateTo(LoginView.NAME);
+
+ }
+ });
+ layout.addComponent(logOut);
+ setContent(layout);
+ }
+
+ @Override
+ public void enter(ViewChangeEvent event) {
+
+ }
+} \ 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
index 0000000000..55b936f144
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/minitutorials/v7b9/MainViewEarlierExample.java
@@ -0,0 +1,60 @@
+package com.vaadin.tests.minitutorials.v7b9;
+
+import com.vaadin.navigator.View;
+import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
+import com.vaadin.server.ExternalResource;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Link;
+import com.vaadin.ui.Panel;
+import com.vaadin.ui.UI;
+import com.vaadin.ui.VerticalLayout;
+
+public class MainViewEarlierExample extends Panel implements View {
+
+ public static final String NAME = "";
+
+ public MainViewEarlierExample() {
+
+ VerticalLayout layout = new VerticalLayout();
+
+ Link lnk = new Link("Count",
+ new ExternalResource("#!" + CountView.NAME));
+ layout.addComponent(lnk);
+
+ lnk = new Link("Message: Hello", new ExternalResource("#!"
+ + MessageView.NAME + "/Hello"));
+ layout.addComponent(lnk);
+
+ lnk = new Link("Message: Bye", new ExternalResource("#!"
+ + MessageView.NAME + "/Bye/Goodbye"));
+ layout.addComponent(lnk);
+
+ lnk = new Link("Private message: Secret", new ExternalResource("#!"
+ + SecretView.NAME + "/Secret"));
+ layout.addComponent(lnk);
+
+ lnk = new Link("Private message: Topsecret", new ExternalResource("#!"
+ + SecretView.NAME + "/Topsecret"));
+ layout.addComponent(lnk);
+
+ // login/logout toggle so we can test this
+ Button logInOut = new Button("Toggle login",
+ new Button.ClickListener() {
+ public void buttonClick(ClickEvent event) {
+ Object user = ((NavigationtestUI) UI.getCurrent())
+ .getLoggedInUser();
+ ((NavigationtestUI) UI.getCurrent())
+ .setLoggedInUser(user == null ? "Smee" : null);
+ }
+ });
+ layout.addComponent(logInOut);
+ setContent(layout);
+ }
+
+ @Override
+ public void enter(ViewChangeEvent event) {
+
+ }
+
+} \ 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
index 0000000000..91d495cb24
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/minitutorials/v7b9/MainView__LastNavigatorExample.java
@@ -0,0 +1,29 @@
+package com.vaadin.tests.minitutorials.v7b9;
+
+import com.vaadin.navigator.Navigator;
+import com.vaadin.navigator.View;
+import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
+import com.vaadin.server.ExternalResource;
+import com.vaadin.ui.Link;
+import com.vaadin.ui.Panel;
+import com.vaadin.ui.VerticalLayout;
+
+public class MainView__LastNavigatorExample extends Panel implements View {
+
+ public static final String NAME = "";
+
+ public MainView__LastNavigatorExample(final Navigator navigator) {
+
+ Link lnk = new Link("Settings", new ExternalResource("#!"
+ + SettingsView.NAME));
+ VerticalLayout vl = new VerticalLayout();
+ vl.addComponent(lnk);
+ setContent(vl);
+
+ }
+
+ @Override
+ public void enter(ViewChangeEvent event) {
+
+ }
+}
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
index 0000000000..fbb28b6f4a
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/minitutorials/v7b9/MessageView.java
@@ -0,0 +1,29 @@
+package com.vaadin.tests.minitutorials.v7b9;
+
+import com.vaadin.navigator.View;
+import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.Layout;
+import com.vaadin.ui.Panel;
+import com.vaadin.ui.VerticalLayout;
+
+public class MessageView extends Panel implements View {
+ public static final String NAME = "message";
+ private Layout layout;
+
+ public MessageView() {
+ super(new VerticalLayout());
+ setCaption("Messages");
+ }
+
+ @Override
+ public void enter(ViewChangeEvent event) {
+ if (event.getParameters() != null) {
+ // split at "/", add each part as a label
+ String[] msgs = event.getParameters().split("/");
+ for (String msg : msgs) {
+ ((Layout) getContent()).addComponent(new Label(msg));
+ }
+ }
+ }
+} \ 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
index 0000000000..c31bbef748
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/minitutorials/v7b9/NavigationtestUI.java
@@ -0,0 +1,77 @@
+package com.vaadin.tests.minitutorials.v7b9;
+
+import com.vaadin.annotations.PreserveOnRefresh;
+import com.vaadin.navigator.Navigator;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.ui.UI;
+
+@PreserveOnRefresh
+public class NavigationtestUI extends UI {
+
+ Navigator navigator;
+
+ String loggedInUser;
+
+ @Override
+ public void init(VaadinRequest request) {
+ // Create Navigator, make it control the ViewDisplay
+ navigator = new Navigator(this, this);
+
+ // Add some Views
+ // no fragment for main view
+ navigator.addView(MainView__LastNavigatorExample.NAME,
+ new MainView__LastNavigatorExample(navigator));
+
+ // #settings
+ navigator.addView(SettingsView.NAME, new SettingsView(navigator));
+
+ // #count will be a new instance each time we navigate to it, counts:
+ /*
+ * Commented away from other example // no fragment for main view
+ * navigator.addView(MainView.NAME, new MainView(navigator));
+ *
+ * navigator.addView(CountView.NAME, CountView.class);
+ *
+ * // #message adds a label with whatever it receives as a parameter
+ * navigator.addView(MessageView.NAME, new MessageView());
+ *
+ * // #secret works as #message, but you need to be logged in
+ * navigator.addView(SecretView.NAME, new SecretView());
+ *
+ * // #login will navigate to the main view if invoked via this
+ * mechanism navigator.addView(LoginView.NAME, new LoginView(navigator,
+ * MainView.NAME));
+ *
+ * // we'll handle permissions with a listener here, you could also do
+ * // that in the View itself. navigator.addViewChangeListener(new
+ * ViewChangeListener() {
+ *
+ * @Override public boolean beforeViewChange(ViewChangeEvent event) { if
+ * (((NavigationtestUI)UI.getCurrent()).getLoggedInUser() == null) { //
+ * Show to LoginView instead, pass intended view String
+ * fragmentAndParameters = event.getViewName(); if
+ * (event.getParameters() != null) { fragmentAndParameters += "/";
+ * fragmentAndParameters += event.getParameters(); }
+ * navigator.getDisplay().showView(new LoginView(navigator,
+ * fragmentAndParameters)); return false;
+ *
+ * } else { return true; } }
+ *
+ * @Override public void afterViewChange(ViewChangeEvent event) {
+ *
+ * } });
+ */
+ // react to initial fragment, received before we created the Navigator
+
+ // This was removed in beta10
+ // navigator.navigate();
+ }
+
+ public String getLoggedInUser() {
+ return loggedInUser;
+ }
+
+ public void setLoggedInUser(String user) {
+ loggedInUser = user;
+ }
+}
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
index 0000000000..a167522eeb
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/minitutorials/v7b9/SassyUI.java
@@ -0,0 +1,28 @@
+package com.vaadin.tests.minitutorials.v7b9;
+
+import com.vaadin.annotations.Theme;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Layout;
+import com.vaadin.ui.UI;
+import com.vaadin.ui.VerticalLayout;
+
+@Theme("sassy")
+public class SassyUI extends UI {
+ @Override
+ public void init(VaadinRequest request) {
+ Button b = new Button("Reindeer");
+ Layout layout = new VerticalLayout();
+ layout.addComponent(b);
+
+ b = new Button("important");
+ b.addStyleName("important");
+ layout.addComponent(b);
+
+ b = new Button("More important");
+ b.setPrimaryStyleName("my-button");
+ layout.addComponent(b);
+
+ setContent(layout);
+ }
+} \ 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
index 0000000000..93dbe0b9e3
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/minitutorials/v7b9/SecretView.java
@@ -0,0 +1,16 @@
+package com.vaadin.tests.minitutorials.v7b9;
+
+import com.vaadin.navigator.View;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.Layout;
+
+public class SecretView extends MessageView implements View {
+ public static final String NAME = "secret";
+
+ public SecretView() {
+ setCaption("Private messages");
+
+ ((Layout) getContent()).addComponent(new Label("Some private stuff."));
+ }
+
+} \ 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
index 0000000000..1e026fe641
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/minitutorials/v7b9/SettingsView.java
@@ -0,0 +1,129 @@
+package com.vaadin.tests.minitutorials.v7b9;
+
+import java.util.Date;
+
+import com.vaadin.data.Property.ValueChangeEvent;
+import com.vaadin.data.Property.ValueChangeListener;
+import com.vaadin.data.util.ObjectProperty;
+import com.vaadin.navigator.Navigator;
+import com.vaadin.navigator.View;
+import com.vaadin.navigator.ViewChangeListener;
+import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.DateField;
+import com.vaadin.ui.InlineDateField;
+import com.vaadin.ui.Layout;
+import com.vaadin.ui.Notification;
+import com.vaadin.ui.Notification.Type;
+import com.vaadin.ui.Panel;
+import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.themes.Reindeer;
+
+public class SettingsView extends Panel implements View {
+
+ public static String NAME = "settings";
+
+ Navigator navigator;
+ DateField date;
+ Button apply;
+ Button cancel;
+
+ String pendingViewAndParameters = null;
+
+ public SettingsView(final Navigator navigator) {
+ this.navigator = navigator;
+ Layout layout = new VerticalLayout();
+
+ date = new InlineDateField("Birth date");
+ date.setImmediate(true);
+ layout.addComponent(date);
+ // pretend we have a datasource:
+ date.setPropertyDataSource(new ObjectProperty<Date>(new Date()));
+ date.setBuffered(true);
+ // show buttons when date is changed
+ date.addValueChangeListener(new ValueChangeListener() {
+ public void valueChange(ValueChangeEvent event) {
+ hideOrShowButtons();
+ pendingViewAndParameters = null;
+ }
+ });
+
+ // commit the TextField changes when "Save" is clicked
+ apply = new Button("Apply", new Button.ClickListener() {
+ public void buttonClick(ClickEvent event) {
+ date.commit();
+ hideOrShowButtons();
+ processPendingView();
+ }
+ });
+ layout.addComponent(apply);
+
+ // Discard the TextField changes when "Cancel" is clicked
+ cancel = new Button("Cancel", new Button.ClickListener() {
+ public void buttonClick(ClickEvent event) {
+ date.discard();
+ hideOrShowButtons();
+ processPendingView();
+ }
+ });
+ cancel.setStyleName(Reindeer.BUTTON_LINK);
+ layout.addComponent(cancel);
+
+ // attach a listener so that we'll get asked isViewChangeAllowed?
+ navigator.addViewChangeListener(new ViewChangeListener() {
+ public boolean beforeViewChange(ViewChangeEvent event) {
+ if (event.getOldView() == SettingsView.this
+ && date.isModified()) {
+
+ // save the View where the user intended to go
+ pendingViewAndParameters = event.getViewName();
+ if (event.getParameters() != null) {
+ pendingViewAndParameters += "/";
+ pendingViewAndParameters += event.getParameters();
+ }
+
+ // Prompt the user to save or cancel if the name is changed
+ Notification.show("Please apply or cancel your changes",
+ Type.WARNING_MESSAGE);
+
+ return false;
+ } else {
+ return true;
+ }
+ }
+
+ public void afterViewChange(ViewChangeEvent event) {
+ pendingViewAndParameters = null;
+ }
+ });
+
+ setContent(layout);
+
+ }
+
+ // Hide or show buttons depending on whether date is modified or not
+ private void hideOrShowButtons() {
+ apply.setVisible(date.isModified());
+ cancel.setVisible(date.isModified());
+ }
+
+ // if there is a pending view change, do it now
+ private void processPendingView() {
+ if (pendingViewAndParameters != null) {
+ navigator.navigateTo(pendingViewAndParameters);
+ pendingViewAndParameters = null;
+ }
+ }
+
+ public void navigateTo(String fragmentParameters) {
+ hideOrShowButtons();
+ }
+
+ @Override
+ public void enter(ViewChangeEvent event) {
+ // TODO Auto-generated method stub
+
+ }
+
+} \ No newline at end of file