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

Java tutorial

Introduction

Here is the source code for com.appspot.socialinquirer.client.activity.PagesActivity.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.PagesPlace;
import com.appspot.socialinquirer.client.util.UiUtils;
import com.appspot.socialinquirer.client.view.PagesView;
import com.appspot.socialinquirer.shared.dto.Page;
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 PagesActivity.
 */
public class PagesActivity extends AbstractActivity implements PagesView.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 user. */
    private User user;

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

    /**
     * Instantiates a new pages activity.
     *
     * @param place the place
     * @param clientFactory the client factory
     */
    public PagesActivity(PagesPlace place, ClientFactory clientFactory) {
        this.name = place.getName();
        this.user = clientFactory.getUser();
        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.getPagesView();
                dashboardView.setName(name);
                dashboardView.setPresenter(PagesActivity.this);
                containerWidget.setWidget(dashboardView.asWidget());
                clientFactory.getContentService().getPages(new AsyncCallback<ArrayList<Page>>() {

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

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

            }
        });

    }

    /*
     * (non-Javadoc)
     * 
     * @see com.appspot.linkedhub.client.view.PaperSettingsView.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.PagesView.Presenter#onAddPageClicked()
     */
    @Override
    public void onAddPageClicked() {
        // TODO Auto-generated method stub

    }

    /* (non-Javadoc)
     * @see com.appspot.socialinquirer.client.view.PagesView.Presenter#onViewPageClicked(com.appspot.socialinquirer.shared.dto.Page)
     */
    @Override
    public void onViewPageClicked(Page page) {
        HistoryToken.Newspaper.fire(page.getKey());
    }
}