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.SettingsPlace; import com.appspot.socialinquirer.client.util.UiUtils; import com.appspot.socialinquirer.client.view.XmppSettingsView; import com.appspot.socialinquirer.shared.dto.User; import com.appspot.socialinquirer.shared.dto.XmppSettings; 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 SettingsActivity. */ public class SettingsActivity extends AbstractActivity implements XmppSettingsView.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 XmppSettingsView dashboardView; /** * Instantiates a new settings activity. * * @param place the place * @param clientFactory the client factory */ public SettingsActivity(SettingsPlace 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.getXmppSettingsView(); dashboardView.setName(name); dashboardView.setPaperSettings(user.getXmppSettings()); dashboardView.setPresenter(SettingsActivity.this); containerWidget.setWidget(dashboardView.asWidget()); // $(".help-link").click(new Function(){ // public void f(Element element) { // AnchorElement a = (AnchorElement) element; // UiUtils.showHelpDialog(clientFactory, a.getName()); // } // }); } }); } /* * (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.XmppSettingsView.Presenter#onSavePaperSettingsClicked(com.appspot.everscribe.shared.dto.PaperSettings) */ @Override public void onSaveXmppSettingsClicked(final XmppSettings settings) { final EverScribeConstants constants = clientFactory.getConstants(); clientFactory.getUserService().updateXmppSettings(settings, new AsyncCallback<Void>() { @Override public void onFailure(Throwable caught) { UiUtils.showErrorDialog(constants, caught.getLocalizedMessage()); } @Override public void onSuccess(Void result) { clientFactory.getUser().setXmppSettings(settings); UiUtils.showSettingsSavedDialog(constants); } }); } }