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 java.util.ArrayList; import com.appspot.socialinquirer.client.ClientFactory; import com.appspot.socialinquirer.client.HistoryToken; import com.appspot.socialinquirer.client.place.ActivityPlace; import com.appspot.socialinquirer.client.util.UiUtils; import com.appspot.socialinquirer.client.view.ActivityView; import com.appspot.socialinquirer.shared.dto.Message; import com.appspot.socialinquirer.shared.dto.Page; import com.appspot.socialinquirer.shared.dto.Poll; import com.appspot.socialinquirer.shared.dto.Quiz; import com.appspot.socialinquirer.shared.dto.Task; 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 ActivityActivity. */ public class ActivityActivity extends AbstractActivity implements ActivityView.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 final String name; /** The user. */ private User user; /** The dashboard view. */ private ActivityView dashboardView; /** * Instantiates a new activity activity. * * @param place the place * @param clientFactory the client factory */ public ActivityActivity(ActivityPlace 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) { if (name.equals(HistoryToken.Activity_Messages.token())) { GWT.runAsync(new RunAsyncCallback() { public void onFailure(Throwable caught) { UiUtils.showErrorDialog(clientFactory.getConstants(), clientFactory.getConstants().errorCodeDownloadFailed()); } public void onSuccess() { dashboardView = clientFactory.getActivityView(); dashboardView.setName(name); dashboardView.setPresenter(ActivityActivity.this); containerWidget.setWidget(dashboardView.asWidget()); clientFactory.getUserService().getUserMessages(new AsyncCallback<ArrayList<Message>>() { @Override public void onFailure(Throwable caught) { UiUtils.showErrorDialog(clientFactory.getConstants(), caught.getLocalizedMessage()); } @Override public void onSuccess(ArrayList<Message> result) { dashboardView.setMessages(result); } }); } }); } else if (name.equals(HistoryToken.Activity_Polls.token())) { GWT.runAsync(new RunAsyncCallback() { public void onFailure(Throwable caught) { UiUtils.showErrorDialog(clientFactory.getConstants(), clientFactory.getConstants().errorCodeDownloadFailed()); } public void onSuccess() { dashboardView = clientFactory.getActivityView(); dashboardView.setName(name); dashboardView.setPresenter(ActivityActivity.this); containerWidget.setWidget(dashboardView.asWidget()); clientFactory.getContentService().getPolls(new AsyncCallback<ArrayList<Poll>>() { @Override public void onFailure(Throwable caught) { UiUtils.showErrorDialog(clientFactory.getConstants(), caught.getLocalizedMessage()); } @Override public void onSuccess(ArrayList<Poll> result) { dashboardView.setPolls(result); } }); } }); } else if (name.equals(HistoryToken.Activity_Quizzes.token())) { GWT.runAsync(new RunAsyncCallback() { public void onFailure(Throwable caught) { UiUtils.showErrorDialog(clientFactory.getConstants(), clientFactory.getConstants().errorCodeDownloadFailed()); } public void onSuccess() { dashboardView = clientFactory.getActivityView(); dashboardView.setName(name); dashboardView.setPresenter(ActivityActivity.this); containerWidget.setWidget(dashboardView.asWidget()); clientFactory.getContentService().getQuizzes(new AsyncCallback<ArrayList<Quiz>>() { @Override public void onFailure(Throwable caught) { UiUtils.showErrorDialog(clientFactory.getConstants(), caught.getLocalizedMessage()); } @Override public void onSuccess(ArrayList<Quiz> result) { dashboardView.setQuizzes(result); } }); } }); } else if (name.equals(HistoryToken.Activity_Tasks.token())) { GWT.runAsync(new RunAsyncCallback() { public void onFailure(Throwable caught) { UiUtils.showErrorDialog(clientFactory.getConstants(), clientFactory.getConstants().errorCodeDownloadFailed()); } public void onSuccess() { dashboardView = clientFactory.getActivityView(); dashboardView.setName(name); dashboardView.setPresenter(ActivityActivity.this); containerWidget.setWidget(dashboardView.asWidget()); clientFactory.getUserService().getUserTasks(new AsyncCallback<ArrayList<Task>>() { @Override public void onFailure(Throwable caught) { UiUtils.showErrorDialog(clientFactory.getConstants(), caught.getLocalizedMessage()); } @Override public void onSuccess(ArrayList<Task> result) { dashboardView.setTasks(result); } }); } }); } else if (name.equals(HistoryToken.Activity_Pages.token())) { GWT.runAsync(new RunAsyncCallback() { public void onFailure(Throwable caught) { UiUtils.showErrorDialog(clientFactory.getConstants(), clientFactory.getConstants().errorCodeDownloadFailed()); } public void onSuccess() { dashboardView = clientFactory.getActivityView(); dashboardView.setName(name); dashboardView.setPresenter(ActivityActivity.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.IdeaSettingsView.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.ActivityView.Presenter#onViewTaskClicked(com.appspot.socialinquirer.shared.dto.Task) */ @Override public void onViewTaskClicked(Task task) { UiUtils.showTaskDialog(task, clientFactory); } /* (non-Javadoc) * @see com.appspot.socialinquirer.client.view.ActivityView.Presenter#onAddTaskClicked() */ @Override public void onAddTaskClicked() { UiUtils.showTaskDialog(new Task(), clientFactory); } /* (non-Javadoc) * @see com.appspot.socialinquirer.client.view.ActivityView.Presenter#onRemoveTaskClicked(com.appspot.socialinquirer.shared.dto.Task) */ @Override public void onRemoveTaskClicked(Task task) { // TODO Auto-generated method stub } /* (non-Javadoc) * @see com.appspot.socialinquirer.client.view.ActivityView.Presenter#onViewPollClicked(com.appspot.socialinquirer.shared.dto.Poll) */ @Override public void onViewPollClicked(Poll poll) { UiUtils.showPollDialog(poll, clientFactory); } /* (non-Javadoc) * @see com.appspot.socialinquirer.client.view.ActivityView.Presenter#onAddPollClicked() */ @Override public void onAddPollClicked() { UiUtils.showPollDialog(null, clientFactory); } /* (non-Javadoc) * @see com.appspot.socialinquirer.client.view.ActivityView.Presenter#onViewQuizzClicked(com.appspot.socialinquirer.shared.dto.Quiz) */ @Override public void onViewQuizzClicked(Quiz quiz) { UiUtils.showQuizDialog(quiz, clientFactory); } /* (non-Javadoc) * @see com.appspot.socialinquirer.client.view.ActivityView.Presenter#onAddQuizzClicked() */ @Override public void onAddQuizzClicked() { UiUtils.showQuizDialog(null, clientFactory); } /* (non-Javadoc) * @see com.appspot.socialinquirer.client.view.ActivityView.Presenter#onViewMessageClicked(com.appspot.socialinquirer.shared.dto.Message) */ @Override public void onViewMessageClicked(Message message) { UiUtils.showMessageDialog(message, clientFactory); } }