Author: norman
Date: Tue Jul  7 12:23:56 2009
New Revision: 791812

URL: http://svn.apache.org/viewvc?rev=791812&view=rev
Log:
The Login now use MVP (only EventBus is missing so far)

Added:
    labs/hupa/src/main/java/org/apache/hupa/client/mvp/
    labs/hupa/src/main/java/org/apache/hupa/client/mvp/LoginPresenter.java
    labs/hupa/src/main/java/org/apache/hupa/client/mvp/LoginView.java
      - copied, changed from r791750, 
labs/hupa/src/main/java/org/apache/hupa/client/LoginWidget.java
Removed:
    labs/hupa/src/main/java/org/apache/hupa/client/LoginWidget.java
Modified:
    labs/hupa/src/main/java/org/apache/hupa/client/Hupa.java
    labs/hupa/src/main/java/org/apache/hupa/client/gin/MyClientModule.java
    labs/hupa/src/main/java/org/apache/hupa/client/gin/MyGinjector.java

Modified: labs/hupa/src/main/java/org/apache/hupa/client/Hupa.java
URL: 
http://svn.apache.org/viewvc/labs/hupa/src/main/java/org/apache/hupa/client/Hupa.java?rev=791812&r1=791811&r2=791812&view=diff
==============================================================================
--- labs/hupa/src/main/java/org/apache/hupa/client/Hupa.java (original)
+++ labs/hupa/src/main/java/org/apache/hupa/client/Hupa.java Tue Jul  7 
12:23:56 2009
@@ -1,6 +1,27 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
 package org.apache.hupa.client;
 
 import org.apache.hupa.client.gin.MyGinjector;
+import org.apache.hupa.client.mvp.LoginPresenter;
+import org.apache.hupa.client.mvp.LoginView;
 
 import com.google.gwt.core.client.EntryPoint;
 import com.google.gwt.core.client.GWT;
@@ -10,8 +31,10 @@
        private final MyGinjector injector = GWT.create(MyGinjector.class);
        
        public void onModuleLoad() {
-        LoginWidget lPanel = injector.getLoginWidget();
-        lPanel.go(RootPanel.get());
+        LoginView loginView = injector.getLoginView();
+        LoginPresenter loginPresenter = injector.getLoginPresenter();
+        loginPresenter.bind(loginView);
+        RootPanel.get().add(loginView);
     }
 
 }

Modified: labs/hupa/src/main/java/org/apache/hupa/client/gin/MyClientModule.java
URL: 
http://svn.apache.org/viewvc/labs/hupa/src/main/java/org/apache/hupa/client/gin/MyClientModule.java?rev=791812&r1=791811&r2=791812&view=diff
==============================================================================
--- labs/hupa/src/main/java/org/apache/hupa/client/gin/MyClientModule.java 
(original)
+++ labs/hupa/src/main/java/org/apache/hupa/client/gin/MyClientModule.java Tue 
Jul  7 12:23:56 2009
@@ -19,8 +19,8 @@
 
 package org.apache.hupa.client.gin;
 
-import org.apache.hupa.client.LoginWidget;
 import org.apache.hupa.client.events.EventBus;
+import org.apache.hupa.client.mvp.LoginView;
 
 import com.google.gwt.inject.client.AbstractGinModule;
 import com.google.inject.Singleton;
@@ -30,7 +30,7 @@
        @Override
        protected void configure() {
                bind(EventBus.class).in(Singleton.class);
-               bind(LoginWidget.class).in(Singleton.class);
+               bind(LoginView.class).in(Singleton.class);
        }
 
 }

Modified: labs/hupa/src/main/java/org/apache/hupa/client/gin/MyGinjector.java
URL: 
http://svn.apache.org/viewvc/labs/hupa/src/main/java/org/apache/hupa/client/gin/MyGinjector.java?rev=791812&r1=791811&r2=791812&view=diff
==============================================================================
--- labs/hupa/src/main/java/org/apache/hupa/client/gin/MyGinjector.java 
(original)
+++ labs/hupa/src/main/java/org/apache/hupa/client/gin/MyGinjector.java Tue Jul 
 7 12:23:56 2009
@@ -20,12 +20,14 @@
 
 import net.customware.gwt.dispatch.client.gin.ClientDispatchModule;
 
-import org.apache.hupa.client.LoginWidget;
+import org.apache.hupa.client.mvp.LoginPresenter;
+import org.apache.hupa.client.mvp.LoginView;
 
 import com.google.gwt.inject.client.GinModules;
 import com.google.gwt.inject.client.Ginjector;
 
 @GinModules({ClientDispatchModule.class,MyClientModule.class})
 public interface MyGinjector extends Ginjector {
-       public LoginWidget getLoginWidget();
+       public LoginView getLoginView();
+       public LoginPresenter getLoginPresenter();
 }

Added: labs/hupa/src/main/java/org/apache/hupa/client/mvp/LoginPresenter.java
URL: 
http://svn.apache.org/viewvc/labs/hupa/src/main/java/org/apache/hupa/client/mvp/LoginPresenter.java?rev=791812&view=auto
==============================================================================
--- labs/hupa/src/main/java/org/apache/hupa/client/mvp/LoginPresenter.java 
(added)
+++ labs/hupa/src/main/java/org/apache/hupa/client/mvp/LoginPresenter.java Tue 
Jul  7 12:23:56 2009
@@ -0,0 +1,90 @@
+package org.apache.hupa.client.mvp;
+
+import net.customware.gwt.dispatch.client.DispatchAsync;
+
+import org.apache.hupa.client.HupaConstants;
+import org.apache.hupa.client.rpc.LoginUser;
+import org.apache.hupa.client.rpc.LoginUserResult;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.event.dom.client.ClickEvent;
+import com.google.gwt.event.dom.client.ClickHandler;
+import com.google.gwt.event.dom.client.HasClickHandlers;
+import com.google.gwt.event.dom.client.HasKeyUpHandlers;
+import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.google.gwt.user.client.ui.HasText;
+import com.google.gwt.user.client.ui.HasValue;
+import com.google.inject.Inject;
+
+public class LoginPresenter {
+    private HupaConstants constants = GWT.create(HupaConstants.class);
+
+       public interface Display {
+               public HasClickHandlers getLoginClick();
+               public HasClickHandlers getResetClick();
+               public HasValue<String> getUserNameValue();
+               public HasKeyUpHandlers getUserNameKeyUp();
+               public HasKeyUpHandlers getPasswordKeyUp();
+               public HasValue<String> getPasswordValue();
+               public HasText getErrorText();
+       }
+       
+       private DispatchAsync dispatcher;
+       private Display display;
+       
+       @Inject
+       public LoginPresenter(DispatchAsync dispatcher) {
+               this.dispatcher = dispatcher;
+       }
+       
+       /**
+        * Bind Display to this Presenter
+        * 
+        * @param display
+        */
+       public void bind(Display display) {
+               this.display = display;
+               display.getLoginClick().addClickHandler(new ClickHandler() {
+
+                       public void onClick(ClickEvent event) {
+                               doLogin();
+                       }
+                       
+               });
+               display.getResetClick().addClickHandler(new ClickHandler() {
+
+                       public void onClick(ClickEvent event) {
+                               doReset();
+                       }
+                       
+               });
+       }
+       
+       /**
+        * Try to login the user
+        */
+       private void doLogin() {
+               dispatcher.execute(new 
LoginUser(display.getUserNameValue().getValue(),display.getPasswordValue().getValue()),
 new AsyncCallback<LoginUserResult>() {
+
+                       public void onFailure(Throwable caught) {
+                               doReset();
+                               
display.getErrorText().setText(constants.loginInvalid());
+                       }
+
+                       public void onSuccess(LoginUserResult result) {
+                               GWT.log("SUCCESS", null);
+                       }
+                       
+               });
+       }
+       
+       /**
+        * Reset display
+        */
+       private void doReset() {
+               display.getUserNameValue().setValue("");
+               display.getPasswordValue().setValue("");
+               display.getErrorText().setText("");
+       }
+
+}

Copied: labs/hupa/src/main/java/org/apache/hupa/client/mvp/LoginView.java (from 
r791750, labs/hupa/src/main/java/org/apache/hupa/client/LoginWidget.java)
URL: 
http://svn.apache.org/viewvc/labs/hupa/src/main/java/org/apache/hupa/client/mvp/LoginView.java?p2=labs/hupa/src/main/java/org/apache/hupa/client/mvp/LoginView.java&p1=labs/hupa/src/main/java/org/apache/hupa/client/LoginWidget.java&r1=791750&r2=791812&rev=791812&view=diff
==============================================================================
--- labs/hupa/src/main/java/org/apache/hupa/client/LoginWidget.java (original)
+++ labs/hupa/src/main/java/org/apache/hupa/client/mvp/LoginView.java Tue Jul  
7 12:23:56 2009
@@ -17,35 +17,30 @@
  * under the License.                                           *
  ****************************************************************/
 
-package org.apache.hupa.client;
+package org.apache.hupa.client.mvp;
 
-import net.customware.gwt.dispatch.client.DispatchAsync;
-
-import org.apache.hupa.client.events.EventBus;
-import org.apache.hupa.client.rpc.LoginUser;
-import org.apache.hupa.client.rpc.LoginUserResult;
+import org.apache.hupa.client.HupaConstants;
 import org.cobogw.gwt.user.client.ui.Button;
 import org.cobogw.gwt.user.client.ui.ButtonBar;
 
 import com.google.gwt.core.client.GWT;
-import com.google.gwt.event.dom.client.ClickEvent;
-import com.google.gwt.event.dom.client.ClickHandler;
+import com.google.gwt.event.dom.client.HasClickHandlers;
+import com.google.gwt.event.dom.client.HasKeyUpHandlers;
 import com.google.gwt.event.dom.client.KeyCodes;
 import com.google.gwt.event.dom.client.KeyUpEvent;
 import com.google.gwt.event.dom.client.KeyUpHandler;
-import com.google.gwt.user.client.Cookies;
-import com.google.gwt.user.client.rpc.AsyncCallback;
 import com.google.gwt.user.client.ui.CheckBox;
 import com.google.gwt.user.client.ui.Composite;
 import com.google.gwt.user.client.ui.Grid;
+import com.google.gwt.user.client.ui.HasText;
+import com.google.gwt.user.client.ui.HasValue;
 import com.google.gwt.user.client.ui.Label;
 import com.google.gwt.user.client.ui.Panel;
 import com.google.gwt.user.client.ui.PasswordTextBox;
 import com.google.gwt.user.client.ui.TextBox;
 import com.google.gwt.user.client.ui.VerticalPanel;
-import com.google.inject.Inject;
 
-public class LoginWidget extends Composite implements 
KeyUpHandler,ClickHandler{
+public class LoginView extends Composite implements 
KeyUpHandler,LoginPresenter.Display{
     
     private HupaConstants constants = GWT.create(HupaConstants.class);
     private Button loginButton = new Button(constants.loginButton());
@@ -53,16 +48,12 @@
     private TextBox usernameTextBox = new TextBox();
     private PasswordTextBox passwordTextBox = new PasswordTextBox();
     private CheckBox saveBox = new CheckBox(constants.saveLoginLabel());
-    private Label errorLabel = new Label(constants.loginInvalid());
+    private Label errorLabel = new Label();
 
     private int minUsernameLength = 1;
     private int minPasswordLength = 1;
-    private DispatchAsync dispatcher;
-    private EventBus bus;
-    
-    @Inject
-    public LoginWidget(DispatchAsync dispatcher,EventBus bus) {
-        this.dispatcher = dispatcher;
+
+    public LoginView() {
        VerticalPanel vPanel = new VerticalPanel();
         vPanel.setSpacing(5);
         vPanel.setWidth("100%");
@@ -85,11 +76,9 @@
         grid.setWidget(1, 1, passwordTextBox);
         grid.setWidget(2, 1, saveBox);
         usernameTextBox.addKeyUpHandler(this);
-        usernameTextBox.setText(Cookies.getCookie("username"));
         usernameTextBox.setFocus(true);
         
         passwordTextBox.addKeyUpHandler(this);
-        passwordTextBox.setText(Cookies.getCookie("password"));
         vPanel.add(grid);
         ButtonBar buttonBar = new ButtonBar();
 
@@ -97,72 +86,16 @@
         buttonBar.add(resetButton);
 
         loginButton.setEnabled(false);
-        loginButton.addClickHandler(this);
-        resetButton.addClickHandler(this);
+       
 
         vPanel.add(buttonBar);
         
         errorLabel.setStyleName("hupa-ErrorLabel");
-        errorLabel.setVisible(false);
         vPanel.add(errorLabel);
  
         initWidget(vPanel);
     }
 
-   
-
-    /*
-     * (non-Javadoc)
-     * 
-     * @see
-     * 
com.google.gwt.event.dom.client.ClickHandler#onClick(com.google.gwt.event
-     * .dom.client.ClickEvent)
-     */
-    public void onClick(ClickEvent event) {
-               if (resetButton.equals(event.getSource())) {
-                       reset();
-               } else if (loginButton.equals(event.getSource())) {
-                       dispatcher.execute(new LoginUser(getUsername(), 
getPassword()),
-                                       new AsyncCallback<LoginUserResult>() {
-
-                                               public void onFailure(Throwable 
caught) {
-                                                       error();
-                                                       GWT.log("ERROR", 
caught);
-                                               }
-
-                                               public void 
onSuccess(LoginUserResult result) {
-                                                       success();
-                                                       GWT.log("SUCCESS", 
null);
-
-                                               }
-                                       });
-               }
-       }
-
-    private void reset() {
-        errorLabel.setVisible(false);
-        loginButton.setEnabled(false);
-        usernameTextBox.setText("");
-        passwordTextBox.setText("");
-        usernameTextBox.setFocus(true);
-    }
-
-    private void error() {
-        reset();
-        errorLabel.setVisible(true);
-
-        if (saveBox.getValue()) {
-            Cookies.removeCookie("username");
-            Cookies.removeCookie("password");
-        }
-    }
-
-    private void success() {
-        if (saveBox.getValue()) {
-            Cookies.setCookie("username", getUsername());
-            Cookies.setCookie("password", getPassword());
-        }
-    }
 
     /*
      * (non-Javadoc)
@@ -191,18 +124,58 @@
         
     }
     
-    
-    private String getUsername() {
-        return usernameTextBox.getText();
-    }
 
-    private String getPassword() {
-        return passwordTextBox.getText();
-    }
-    
     
     public void go(Panel panel) {
         panel.clear();
         panel.add(this);
     }
+
+
+
+       public HasText getErrorText() {
+               return errorLabel;
+       }
+
+
+
+       public HasClickHandlers getLoginClick() {
+               return loginButton;
+       }
+
+
+
+       public HasValue<String> getPasswordValue() {
+               return passwordTextBox;
+       }
+
+
+
+       public HasClickHandlers getResetClick() {
+               return resetButton;
+       }
+
+
+
+       public HasValue<String> getUserNameValue() {
+               return usernameTextBox;
+       }
+
+
+       public HasValue<String> getErrorValue() {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+
+       public HasKeyUpHandlers getPasswordKeyUp() {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+
+       public HasKeyUpHandlers getUserNameKeyUp() {
+               // TODO Auto-generated method stub
+               return null;
+       }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to