Package com.ursu.client.presenter

Source Code of com.ursu.client.presenter.SecondPagePresenter$MyProxy

package com.ursu.client.presenter;

import com.gwtplatform.dispatch.shared.DispatchAsync;
import com.gwtplatform.mvp.client.Presenter;
import com.gwtplatform.mvp.client.View;
import com.gwtplatform.mvp.client.annotations.ProxyCodeSplit;
import com.gwtplatform.mvp.client.annotations.NameToken;
import com.gwtplatform.mvp.client.annotations.ProxyEvent;
import com.ursu.client.event.LoginAuthenticatedEvent;
import com.ursu.client.event.LoginAuthenticatedEvent.LoginAuthenticatedHandler;
import com.ursu.client.place.NameTokens;
import com.gwtplatform.mvp.client.annotations.UseGatekeeper;
import com.ursu.client.LoggedInGatekeeper;
import com.ursu.shared.actions.Logout;
import com.ursu.shared.actions.LogoutResult;
import com.gwtplatform.mvp.client.proxy.PlaceManager;
import com.gwtplatform.mvp.client.proxy.PlaceRequest;
import com.gwtplatform.mvp.client.proxy.ProxyPlace;
import com.google.inject.Inject;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.gwtplatform.mvp.client.proxy.RevealRootContentEvent;

public class SecondPagePresenter extends
    Presenter<SecondPagePresenter.MyView, SecondPagePresenter.MyProxy> implements LoginAuthenticatedHandler {

  private String username;
  private final EventBus eventBus;
 
  public interface MyView extends View {
    public Button getLogoutBtn();
  }

  @ProxyCodeSplit
  @NameToken(NameTokens.secondpage)
  @UseGatekeeper(LoggedInGatekeeper.class)
  public interface MyProxy extends ProxyPlace<SecondPagePresenter> {
  }

  @Inject DispatchAsync dispatchAsync;
  @Inject
  PlaceManager placeManager;
  @Inject
  public SecondPagePresenter(final EventBus eventBus, final MyView view,
      final MyProxy proxy) {
    super(eventBus, view, proxy);
    this.eventBus = eventBus;
  }

  @Override
  protected void revealInParent() {
    RevealRootContentEvent.fire(this, this);
  }

  @Override
  protected void onBind() {
    super.onBind();
   
registerHandler(getView().getLogoutBtn().addClickHandler(new ClickHandler() {
     
      @Override
      public void onClick(ClickEvent event) {
        Logout action = new Logout();
        dispatchAsync.execute(action, logoutCallback);
       
       
      }
    }));
  }

  @Override
  protected void onReset() {
    super.onReset();
    getView().getLogoutBtn().setText("Logout "+username);
  }

  @ProxyEvent
  @Override
  public void onLoginAuthenticated(LoginAuthenticatedEvent event) {
    if(event.getCurrentUser() !=  null)
    username = event.getCurrentUser().getUsername();
   
  }
 

private AsyncCallback<LogoutResult> logoutCallback = new AsyncCallback<LogoutResult>() {
   
    @Override
    public void onSuccess(LogoutResult result) {
 
      eventBus.fireEvent(new com.ursu.client.event.LoginAuthenticatedEvent(null));
     
      PlaceRequest request = new PlaceRequest(NameTokens.getLoginpage());
      placeManager.revealPlace(request);
 
    }
   
    @Override
    public void onFailure(Throwable caught) {
     
     
    }
  };
}
TOP

Related Classes of com.ursu.client.presenter.SecondPagePresenter$MyProxy

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.