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));
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;
}
}
}
}
-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"
@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 ";
}
});
- helloButton.addListener(new ClickListener() {
+ helloButton.addClickListener(new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
Notification.show("This UI is "
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;
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));
+ }
}
}
--- /dev/null
+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
--- /dev/null
+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
--- /dev/null
+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
--- /dev/null
+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
--- /dev/null
+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
--- /dev/null
+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
--- /dev/null
+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
--- /dev/null
+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
--- /dev/null
+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
--- /dev/null
+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