]> source.dussan.org Git - vaadin-framework.git/commitdiff
merged #3597 related changes from 6.1 branch
authorMatti Tahvonen <matti.tahvonen@itmill.com>
Mon, 26 Oct 2009 15:27:04 +0000 (15:27 +0000)
committerMatti Tahvonen <matti.tahvonen@itmill.com>
Mon, 26 Oct 2009 15:27:04 +0000 (15:27 +0000)
svn changeset:9379/svn branch:6.2

src/com/vaadin/tests/components/loginform/LoginFormTest.java [new file with mode: 0644]
src/com/vaadin/ui/LoginForm.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 (file)
index 0000000..f8e8b96
--- /dev/null
@@ -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;
+    }
+
+}
index 243ac99169c11cb5e018c2d9344cc8af21c6a353..928d39c6e03d895eaa5e136604d8abefa5a59e41 100644 (file)
@@ -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<String, String> params = new HashMap<String, String>();
                 // 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 = "<html><body>Login form handeled."
                 + "<script type='text/javascript'>top.vaadin.forceSync();"
                 + "</script></body></html>";
@@ -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 ("<!DOCTYPE html PUBLIC \"-//W3C//DTD "
@@ -147,14 +150,19 @@ public class LoginForm extends CustomComponent {
                 + "loginHandler"
                 + "'; var f = document.getElementById('loginf');"
                 + "document.forms[0].action = uri;document.forms[0].username.focus();};"
+                + ""
+                + "var styles = window.parent.document.styleSheets;"
+                + "for(var j = 0; j < styles.length; j++) {\n"
+                + "if(styles[j].href) {"
+                + "var stylesheet = document.createElement('link');\n"
+                + "stylesheet.setAttribute('rel', 'stylesheet');\n"
+                + "stylesheet.setAttribute('type', 'text/css');\n"
+                + "stylesheet.setAttribute('href', styles[j].href);\n"
+                + "document.getElementsByTagName('head')[0].appendChild(stylesheet);\n"
+                + "}"
+                + "}\n"
                 + "</script>"
-                + "<link rel='stylesheet' href='"
-                + guessedThemeUri
-                + "'/>"
-                + "<link rel='stylesheet' href='"
-                + guessedThemeUri2
-                + "'/>"
-                + "</head><body onload='setTarget();' style='margin:0;padding:0;'>"
+                + "</head><body onload='setTarget();' style='margin:0;padding:0;' class=\"v-generated-body\">"
                 + "<div class='v-app v-app-loginpage'>"
                 + "<iframe name='logintarget' style='width:0;height:0;"
                 + "border:0;margin:0;padding:0;'></iframe>"
@@ -163,7 +171,7 @@ public class LoginForm extends CustomComponent {
                 + "<input class='v-textfield' style='display:block;' type='text' name='username'></div>"
                 + "<div>Password</div>"
                 + "<div><input class='v-textfield' style='display:block;' type='password' name='password'></div>"
-                + "<div><input class='v-button' type='submit' value='Login'></div></form></div>" + "</body></html>")
+                + "<div><div onclick=\"document.forms[0].submit();\" tabindex=\"0\" class=\"v-button\" role=\"button\" ><span class=\"v-button-wrap\"><span class=\"v-button-caption\">Login</span></span></div></div></form></div>" + "</body></html>")
                 .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<String, String> params;
 
-        private LoginEvent(Map params) {
+        private LoginEvent(Map<String, String> 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;
             }