Java tutorial
/******************************************************************************* * Copyright 2013 Sprachliche Informationsverarbeitung, University of Cologne * * 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 de.uni_koeln.spinfo.maalr.webapp.ui.common.client; import com.google.gwt.core.shared.GWT; import com.google.gwt.safehtml.shared.SafeHtmlUtils; import com.google.gwt.user.client.rpc.AsyncCallback; import de.uni_koeln.spinfo.maalr.common.shared.description.Escaper; import de.uni_koeln.spinfo.maalr.common.shared.description.LemmaDescription; public class AsyncLemmaDescriptionLoader { private static CommonServiceAsync service = GWT.create(CommonService.class); private static LemmaDescription description; public static LemmaDescription getDescription() { return description; } public static void afterLemmaDescriptionLoaded(final AsyncCallback<LemmaDescription> callback) { if (description == null) { service.getLemmaDescription(new AsyncCallback<LemmaDescription>() { @Override public void onSuccess(LemmaDescription loaded) { loaded.setDefaultEscaper(new Escaper() { @Override public String escape(String text) { return SafeHtmlUtils.htmlEscape(text); } }); description = loaded; callback.onSuccess(description); } @Override public void onFailure(Throwable arg0) { Dialog.showError("Service unavailable", arg0); } }); } else { // command.execute(); callback.onSuccess(description); } } }