1 16 package com.google.gwt.user.client; 17 18 import com.google.gwt.core.client.GWT; 19 import com.google.gwt.core.client.GWT.UncaughtExceptionHandler; 20 import com.google.gwt.user.client.impl.HistoryImpl; 21 22 import java.util.ArrayList ; 23 import java.util.Iterator ; 24 25 44 public class History { 45 46 private static ArrayList historyListeners = new ArrayList (); 47 private static HistoryImpl impl; 48 49 static { 50 impl = (HistoryImpl) GWT.create(HistoryImpl.class); 51 if (!impl.init()) { 52 impl = null; 54 55 GWT.log( 57 "Unable to initialize the history subsystem; did you " 58 + "include the history frame in your host page? Try " 59 + "<iframe SRC=\"javascript:''\" id='__gwt_historyFrame' style='width:0;height:0;border:0'>" 60 + "</iframe>", null); 61 } 62 } 63 64 69 public static void addHistoryListener(HistoryListener listener) { 70 historyListeners.add(listener); 71 } 72 73 76 public static native void back() ; 79 80 84 public static native void forward() ; 87 88 97 public static String getToken() { 98 return impl != null ? impl.getToken() : ""; 99 } 100 101 109 public static void newItem(String historyToken) { 110 if (impl != null) { 111 impl.newItem(historyToken); 112 } 113 } 114 115 public static void onHistoryChanged(String historyToken) { 116 UncaughtExceptionHandler handler = GWT.getUncaughtExceptionHandler(); 117 if (handler != null) { 118 fireHistoryChangedAndCatch(historyToken, handler); 119 } else { 120 fireHistoryChangedImpl(historyToken); 121 } 122 } 123 124 129 public static void removeHistoryListener(HistoryListener listener) { 130 historyListeners.remove(listener); 131 } 132 133 private static void fireHistoryChangedAndCatch(String historyToken, 134 UncaughtExceptionHandler handler) { 135 try { 136 fireHistoryChangedImpl(historyToken); 137 } catch (Throwable e) { 138 handler.onUncaughtException(e); 139 } 140 } 141 142 private static void fireHistoryChangedImpl(String historyToken) { 143 for (Iterator it = historyListeners.iterator(); it.hasNext();) { 144 HistoryListener listener = (HistoryListener) it.next(); 145 listener.onHistoryChanged(historyToken); 146 } 147 } 148 } 149 | Popular Tags |