Package net.ajiaojr.spadger.client.activity

Source Code of net.ajiaojr.spadger.client.activity.SettingsActivity$Driver

/*
* Spadger - an open source discussion forum system.
*
* Copyright (C) 2011 The Spadger Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
*
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package net.ajiaojr.spadger.client.activity;

import javax.inject.Inject;
import javax.inject.Singleton;

import net.ajiaojr.spadger.client.view.SettingsView;
import net.ajiaojr.spadger.shared.entity.SpadgerUser;
import net.ajiaojr.spadger.shared.request.SpadgerRequestFactory;
import net.ajiaojr.spadger.shared.request.SpadgerUserProxy;
import net.ajiaojr.spadger.shared.request.SpadgerUserRequest;

import com.google.gwt.activity.shared.AbstractActivity;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.user.client.ui.AcceptsOneWidget;
import com.google.web.bindery.requestfactory.gwt.client.RequestFactoryEditorDriver;
import com.google.web.bindery.requestfactory.shared.Receiver;

/**
* @author The Spadger Team
*/
@Singleton
public class SettingsActivity extends AbstractActivity implements
    SettingsView.Presenter {

  interface Driver extends
      RequestFactoryEditorDriver<SpadgerUserProxy, SettingsView> {
  }

  private final Driver driver = GWT.create(Driver.class);

  private SettingsView view;

  private SpadgerRequestFactory requestFactory;

  private native final SpadgerUser getUser() /*-{
    return $wnd.Spadger.user;
  }-*/;

  @Inject
  public void setSpadgerRequestFactory(SpadgerRequestFactory requestFactory) {
    this.requestFactory = requestFactory;
  }

  /*
   * (non-Javadoc)
   *
   * @see
   * com.google.gwt.activity.shared.Activity#start(com.google.gwt.user.client
   * .ui.AcceptsOneWidget, com.google.gwt.event.shared.EventBus)
   */
  @Inject
  public void setView(SettingsView view) {
    this.view = view;
    view.setPresenter(this);
  }

  @Override
  public void start(AcceptsOneWidget panel, EventBus eventBus) {
    panel.setWidget(view);

    final SpadgerUserRequest request = requestFactory.spadgerUserRequest();

    driver.initialize(view);

    request.findSpadgerUser(getUser().getId()).fire(
        new Receiver<SpadgerUserProxy>() {

          @Override
          public void onSuccess(SpadgerUserProxy response) {
            driver.edit(response, request);
            driver.flush().fire();
          }
        });
  }
}
TOP

Related Classes of net.ajiaojr.spadger.client.activity.SettingsActivity$Driver

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.