浏览 4979 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2007-03-21
大部分代码也是参考文中的。 package com.javaeye.dengyin2000.truck.client.server; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.rpc.AsyncCallback; public abstract class AsyncCallbackWithStatus implements AsyncCallback { private static LoadingIndicator loadingIndicator; public static final void setLoadingIndicator(LoadingIndicator indicator) { loadingIndicator = indicator; } public AsyncCallbackWithStatus() { setLoading(true); } public final void onSuccess(Object object) { setLoading(false); onSuccessInternal(object); } public final void onFailure(Throwable throwable) { setLoading(false); onFailureInternal(throwable); } protected abstract void onSuccessInternal(Object object); protected void onFailureInternal(Throwable throwable){ Window.alert("服务器没有响应,请稍后再试!"); } private void setLoading(boolean isLoading) { if (null != loadingIndicator) { if (isLoading) { loadingIndicator.show(); } else { loadingIndicator.hide(); } } } interface LoadingIndicator { void show(); void hide(); } } package com.javaeye.dengyin2000.truck.client.server; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.WindowResizeListener; import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.PopupPanel; import com.javaeye.dengyin2000.truck.client.server.AsyncCallbackWithStatus.LoadingIndicator; public class LoadingStatus implements LoadingIndicator, WindowResizeListener { private PopupPanel popup; public LoadingStatus() { popup = new PopupPanel(); popup.add(new HTML("<div style='background-color: red;'> Loading, please wait...</div>")); placeIndicator(); Window.addWindowResizeListener(this); // set the style name for greater control over the } public void show() { popup.show(); } public void hide() { popup.hide(); } private void placeIndicator(){ popup.setPopupPosition(Window.getClientWidth() - 120, 10); } public void onWindowResized(int width, int height) { placeIndicator(); } } 在你的EntryPoint中装配好你的indicator private void prepareLoadingIndicator(){ LoadingStatus status = new LoadingStatus(); AsyncCallbackWithStatus.setLoadingIndicator(status); } 这样调用。 private void populateAndReadEnterprisesInfo(){ GWTRPCServiceLocator.getUserService().getEnterprisesInfo(new AsyncCallbackWithStatus(){ protected void onSuccessInternal(Object object) { EnterprisesInfoGTO gto = (EnterprisesInfoGTO) object; enterpriseName.setText(gto.getEnterprisesName()); contactName.setText(gto.getContactName()); contactTel.setText(gto.getContactTel()); contactFax.setText(gto.getContactFax()); contactAddress.setText(gto.getContactAddress()); zipCode.setText(gto.getZipCode()); email.setText(gto.getEmail()); siteAddress.setText(gto.getSiteAddress()); } }); } 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |