com.appspot.socialinquirer.client.activity.NetworkActivity.java Source code

Java tutorial

Introduction

Here is the source code for com.appspot.socialinquirer.client.activity.NetworkActivity.java

Source

/*
 * Copyright 2012 Nabeel Mukhtar 
 * 
 * Licensed 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 com.appspot.socialinquirer.client.activity;

import java.util.ArrayList;

import com.appspot.socialinquirer.client.ClientFactory;
import com.appspot.socialinquirer.client.HistoryToken;
import com.appspot.socialinquirer.client.place.NetworkPlace;
import com.appspot.socialinquirer.client.util.UiUtils;
import com.appspot.socialinquirer.client.view.NetworkView;
import com.appspot.socialinquirer.shared.dto.User;
import com.google.gwt.activity.shared.AbstractActivity;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.RunAsyncCallback;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.place.shared.Place;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.AcceptsOneWidget;

/**
 * The Class NetworkActivity.
 */
public class NetworkActivity extends AbstractActivity implements NetworkView.Presenter {
    // Used to obtain views, eventBus, placeController
    // Alternatively, could be injected via GIN
    /** The client factory. */
    private ClientFactory clientFactory;
    // Name that will be appended to "Hello,"
    /** The name. */
    private String name;

    /** The dashboard view. */
    private NetworkView dashboardView;

    /**
     * Instantiates a new network activity.
     *
     * @param place the place
     * @param clientFactory the client factory
     */
    public NetworkActivity(NetworkPlace place, ClientFactory clientFactory) {
        this.name = place.getName();
        this.clientFactory = clientFactory;
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.google.gwt.activity.shared.Activity#start(com.google.gwt.user.client.ui.AcceptsOneWidget,
     *      com.google.gwt.event.shared.EventBus)
     */
    @Override
    public void start(final AcceptsOneWidget containerWidget, final EventBus eventBus) {
        GWT.runAsync(new RunAsyncCallback() {
            public void onFailure(Throwable caught) {
                UiUtils.showErrorDialog(clientFactory.getConstants(),
                        clientFactory.getConstants().errorCodeDownloadFailed());
            }

            public void onSuccess() {
                dashboardView = clientFactory.getNetworkView();
                dashboardView.setName(name);
                dashboardView.setPresenter(NetworkActivity.this);
                // dashboardView.setClassifiersList(user.getClassifiers());
                containerWidget.setWidget(dashboardView.asWidget());
                if (name.equals(HistoryToken.Network_Followers.token())) {
                    clientFactory.getUserService().getFollowers(new AsyncCallback<ArrayList<User>>() {

                        @Override
                        public void onFailure(Throwable caught) {
                            UiUtils.showErrorDialog(clientFactory.getConstants(), caught.getLocalizedMessage());
                        }

                        @Override
                        public void onSuccess(ArrayList<User> result) {
                            dashboardView.setConnections(result);
                        }
                    });
                } else if (name.equals(HistoryToken.Network_Following.token())) {
                    clientFactory.getUserService().getFollowing(new AsyncCallback<ArrayList<User>>() {

                        @Override
                        public void onFailure(Throwable caught) {
                            UiUtils.showErrorDialog(clientFactory.getConstants(), caught.getLocalizedMessage());
                        }

                        @Override
                        public void onSuccess(ArrayList<User> result) {
                            dashboardView.setConnections(result);
                        }
                    });
                } else if (name.equals(HistoryToken.Network_Recommended.token())) {
                    clientFactory.getUserService().getRecommendedUsers(new AsyncCallback<ArrayList<User>>() {

                        @Override
                        public void onFailure(Throwable caught) {
                            UiUtils.showErrorDialog(clientFactory.getConstants(), caught.getLocalizedMessage());
                        }

                        @Override
                        public void onSuccess(ArrayList<User> result) {
                            dashboardView.setConnections(result);
                        }
                    });
                }
            }
        });
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.appspot.linkedhub.client.view.ClassifiersView.Presenter#goTo(com.google.gwt.place.shared.Place)
     */
    public void goTo(Place place) {
        clientFactory.getPlaceController().goTo(place);
    }

    /* (non-Javadoc)
     * @see com.appspot.socialinquirer.client.view.NetworkView.Presenter#onViewConnectionClicked(com.appspot.socialinquirer.shared.dto.User)
     */
    @Override
    public void onViewConnectionClicked(User connection) {
        // TODO Auto-generated method stub
    }
}