Java tutorial
/* * 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 com.appspot.socialinquirer.client.ClientFactory; import com.appspot.socialinquirer.client.constant.EverScribeConstants; import com.appspot.socialinquirer.client.place.NewspaperPlace; import com.appspot.socialinquirer.client.util.UiUtils; import com.appspot.socialinquirer.client.view.NewsPaperView; import com.appspot.socialinquirer.shared.dto.Page; 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 PageActivity. */ public class PageActivity extends AbstractActivity implements NewsPaperView.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 NewsPaperView dashboardView; /** * Instantiates a new page activity. * * @param place the place * @param clientFactory the client factory */ public PageActivity(NewspaperPlace 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) { final EverScribeConstants constants = clientFactory.getConstants(); GWT.runAsync(new RunAsyncCallback() { public void onFailure(Throwable caught) { UiUtils.showErrorDialog(constants, constants.errorCodeDownloadFailed()); } public void onSuccess() { String pageId = getPageId(name); dashboardView = clientFactory.getNewsPaperView(); dashboardView.setName(name); dashboardView.setPresenter(PageActivity.this); // dashboardView.setTemplatesList(user.getTemplates()); containerWidget.setWidget(dashboardView.asWidget()); clientFactory.getContentService().getPage(pageId, new AsyncCallback<Page>() { @Override public void onFailure(Throwable caught) { UiUtils.showErrorDialog(constants, caught.getLocalizedMessage()); } @Override public void onSuccess(Page result) { dashboardView.setPage(result); } }); } private String getPageId(String name) { int index = name.indexOf(':'); return (index > 0) ? name.substring(index + 1) : null; } }); } /* * (non-Javadoc) * * @see com.appspot.linkedhub.client.view.TemplatesView.Presenter#goTo(com.google.gwt.place.shared.Place) */ public void goTo(Place place) { clientFactory.getPlaceController().goTo(place); } }