From b4906f7c204040f80cb8270a3d770cb28c982d99 Mon Sep 17 00:00:00 2001 From: Matti Tahvonen Date: Mon, 26 Oct 2009 15:27:04 +0000 Subject: [PATCH] merged #3597 related changes from 6.1 branch svn changeset:9379/svn branch:6.2 --- .../components/loginform/LoginFormTest.java | 63 +++++++++++++++++++ src/com/vaadin/ui/LoginForm.java | 58 ++++++++++------- 2 files changed, 98 insertions(+), 23 deletions(-) create mode 100644 src/com/vaadin/tests/components/loginform/LoginFormTest.java diff --git a/src/com/vaadin/tests/components/loginform/LoginFormTest.java b/src/com/vaadin/tests/components/loginform/LoginFormTest.java new file mode 100644 index 0000000000..f8e8b96f62 --- /dev/null +++ b/src/com/vaadin/tests/components/loginform/LoginFormTest.java @@ -0,0 +1,63 @@ +package com.vaadin.tests.components.loginform; + +import com.vaadin.tests.components.TestBase; +import com.vaadin.ui.Button; +import com.vaadin.ui.Label; +import com.vaadin.ui.LoginForm; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Button.ClickListener; +import com.vaadin.ui.LoginForm.LoginEvent; +import com.vaadin.ui.LoginForm.LoginListener; + +public class LoginFormTest extends TestBase { + + private LoginForm loginForm; + + @Override + protected void setup() { + loginForm = new LoginForm(); + getLayout().setSizeFull(); + loginForm.addListener(new LoginListener() { + + /** + * + */ + private static final long serialVersionUID = 1L; + + public void onLogin(LoginEvent event) { + login(event.getLoginParameter("user"), event + .getLoginParameter("password")); + + } + }); + addComponent(loginForm); + + } + + protected void login(String user, String password) { + Label info = new Label("User '" + user + "', password='" + password + + "' logged in"); + getLayout().removeAllComponents(); + getLayout().addComponent(info); + getLayout().addComponent(new Button("Log out", new ClickListener() { + + public void buttonClick(ClickEvent event) { + getLayout().removeAllComponents(); + getLayout().addComponent(loginForm); + } + + })); + + } + + @Override + protected String getDescription() { + return "Basic test for the LoginForm component. The login form should be visible. Entering a username+password and clicking 'login' should replace the login form with a label telling the user name as password. Also a logout button should then be shown and pressing that takes the user back to the original screen with the LoginForm"; + } + + @Override + protected Integer getTicketNumber() { + return 3597; + } + +} diff --git a/src/com/vaadin/ui/LoginForm.java b/src/com/vaadin/ui/LoginForm.java index 243ac99169..928d39c6e0 100644 --- a/src/com/vaadin/ui/LoginForm.java +++ b/src/com/vaadin/ui/LoginForm.java @@ -13,7 +13,6 @@ import com.vaadin.terminal.ApplicationResource; import com.vaadin.terminal.DownloadStream; import com.vaadin.terminal.ParameterHandler; import com.vaadin.terminal.URIHandler; -import com.vaadin.terminal.gwt.server.AbstractApplicationServlet; /** * LoginForm is a Vaadin component to handle common problem among Ajax @@ -35,13 +34,17 @@ import com.vaadin.terminal.gwt.server.AbstractApplicationServlet; * * @since 5.3 */ -@SuppressWarnings("serial") public class LoginForm extends CustomComponent { private Embedded iframe = new Embedded(); private ApplicationResource loginPage = new ApplicationResource() { + /** + * + */ + private static final long serialVersionUID = 1L; + public Application getApplication() { return LoginForm.this.getApplication(); } @@ -70,11 +73,16 @@ public class LoginForm extends CustomComponent { private ParameterHandler paramHandler = new ParameterHandler() { + /** + * + */ + private static final long serialVersionUID = 1L; + public void handleParameters(Map parameters) { if (parameters.containsKey("username")) { getWindow().addURIHandler(uriHandler); - HashMap params = new HashMap(); + HashMap params = new HashMap(); // expecting single params for (Iterator it = parameters.keySet().iterator(); it.hasNext();) { String key = (String) it.next(); @@ -88,6 +96,10 @@ public class LoginForm extends CustomComponent { }; private URIHandler uriHandler = new URIHandler() { + /** + * + */ + private static final long serialVersionUID = 1L; private final String responce = "Login form handeled." + ""; @@ -126,15 +138,6 @@ public class LoginForm extends CustomComponent { */ protected byte[] getLoginHTML() { - String defaultThemeName = AbstractApplicationServlet.getDefaultTheme(); - - String theme = getApplication().getMainWindow().getTheme(); - String guessedThemeUri = getApplication().getURL() + "VAADIN/themes/" - + (theme == null ? defaultThemeName : theme) + "/styles.css"; - String guessedThemeUri2 = getApplication().getURL() - + "../VAADIN/themes/" - + (theme == null ? defaultThemeName : theme) + "/styles.css"; - String appUri = getApplication().getURL().toString(); return ("" - + "" - + "" - + "" + + "" + "
" + "" @@ -163,7 +171,7 @@ public class LoginForm extends CustomComponent { + "
" + "
Password
" + "
" - + "
" + "") + + "
Login
" + "") .getBytes(); } @@ -194,9 +202,13 @@ public class LoginForm extends CustomComponent { */ public class LoginEvent extends Event { - private Map params; + /** + * + */ + private static final long serialVersionUID = 1L; + private Map params; - private LoginEvent(Map params) { + private LoginEvent(Map params) { super(LoginForm.this); this.params = params; } @@ -209,7 +221,7 @@ public class LoginForm extends CustomComponent { */ public String getLoginParameter(String name) { if (params.containsKey(name)) { - return (String) params.get(name); + return params.get(name); } else { return null; } -- 2.39.5