BanController.java :  » Image » jchannel » org » jchannel » client » controller » Java Open Source

Java Open Source » Image » jchannel 
jchannel » org » jchannel » client » controller » BanController.java
package org.jchannel.client.controller;

import java.util.List;

import com.google.gwt.user.client.rpc.AsyncCallback;

import org.jchannel.client.state.BanState;
import org.jchannel.client.ui.dialog.MessageDialog;
import org.jchannel.server.entity.Ban;
import org.jchannel.server.entity.Post;

public final class BanController extends Controller {

  public static final BanController INSTANCE = new BanController();

  public void countPages() {
    SERVICE.countBans(new AsyncCallback<Long>() {

      @Override
      public void onFailure(final Throwable t) {
        MessageDialog.INSTANCE.show("Error counting ban pages");
      }

      @Override
      public void onSuccess(final Long count) {
        BanState.INSTANCE.setPages(
                (int) Math.ceil(count / BanState.INSTANCE.getPageSize()));
      }
    });
  }

  public void deleteBan(final String ipAddress) {
    SERVICE.deleteBan(ipAddress,
            new AsyncCallback<Void>() {

              @Override
              public void onFailure(final Throwable t) {
                MessageDialog.INSTANCE.show("Error deleting ban");
              }

              @Override
              public void onSuccess(final Void result) {
                findBans(BanState.INSTANCE.getPage(), BanState.INSTANCE.getPageSize());
                MessageDialog.INSTANCE.show("Ban deleted");
              }
            });
  }

  public void findBan(final String ipAddress) {
    SERVICE.readBan(ipAddress,
            new AsyncCallback<Ban>() {

              @Override
              public void onFailure(final Throwable t) {
                MessageDialog.INSTANCE.show("Error finding ban");
              }

              @Override
              public void onSuccess(final Ban ban) {
                BanState.INSTANCE.setBan(ban);
              }
            });
  }

  public void findBans(final int page, final int pageSize) {
    SERVICE.readBans(page, pageSize, new AsyncCallback<List<Ban>>() {

      @Override
      public void onFailure(final Throwable t) {
        MessageDialog.INSTANCE.show("Error finding bans");
      }

      @Override
      public void onSuccess(final List<Ban> bans) {
        BanState.INSTANCE.setBans(bans);
      }
    });
  }

  public void saveBan(final Post post) {
    SERVICE.saveBan(post, new AsyncCallback<Void>() {

      @Override
      public void onFailure(final Throwable t) {
        MessageDialog.INSTANCE.show("Error creating ban");
      }

      @Override
      public void onSuccess(Void result) {
        findBans(BanState.INSTANCE.getPage(), BanState.INSTANCE.getPageSize());
        MessageDialog.INSTANCE.show("IP address banned");
      }
    });
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.