| 1 |  |   | 
  | 2 |  |   | 
  | 3 |  |   | 
  | 4 |  |   | 
  | 5 |  |   | 
  | 6 |  |   | 
  | 7 |  |   | 
  | 8 |  |   | 
  | 9 |  |   | 
  | 10 |  |   | 
  | 11 |  |   | 
  | 12 |  |   | 
  | 13 |  |   | 
  | 14 |  |   | 
  | 15 |  |   | 
  | 16 |  |  package org.kuali.student.common.ui.client.application; | 
  | 17 |  |   | 
  | 18 |  |  import org.kuali.student.common.ui.client.security.SessionTimeoutHandler; | 
  | 19 |  |  import org.kuali.student.common.ui.client.security.SpringSecurityLoginDialogHandler; | 
  | 20 |  |  import org.kuali.student.common.ui.client.service.exceptions.VersionMismatchClientException; | 
  | 21 |  |  import org.kuali.student.common.ui.client.widgets.KSErrorDialog; | 
  | 22 |  |   | 
  | 23 |  |  import com.google.gwt.core.client.GWT; | 
  | 24 |  |  import com.google.gwt.user.client.Window; | 
  | 25 |  |  import com.google.gwt.user.client.rpc.AsyncCallback; | 
  | 26 |  |   | 
  | 27 |  |   | 
  | 28 |  |   | 
  | 29 |  |   | 
  | 30 |  |   | 
  | 31 |  |   | 
  | 32 |  |   | 
  | 33 |  |   | 
  | 34 | 0 |  public abstract class KSAsyncCallback<T> implements AsyncCallback<T>{ | 
  | 35 |  |          | 
  | 36 | 0 |          private static final SessionTimeoutHandler sessionTimeoutHandler = GWT.create(SpringSecurityLoginDialogHandler.class); | 
  | 37 |  |           | 
  | 38 |  |           | 
  | 39 |  |   | 
  | 40 |  |   | 
  | 41 |  |   | 
  | 42 |  |   | 
  | 43 |  |          public void onFailure(Throwable caught) {   | 
  | 44 | 0 |              if (sessionTimeoutHandler.isSessionTimeout(caught)){ | 
  | 45 | 0 |                  handleTimeout(caught); | 
  | 46 | 0 |                  sessionTimeoutHandler.handleSessionTimeout(); | 
  | 47 | 0 |          } else if (caught instanceof VersionMismatchClientException){ | 
  | 48 | 0 |              handleVersionMismatch(caught); | 
  | 49 |  |          }else {         | 
  | 50 | 0 |                  handleFailure(caught); | 
  | 51 |  |          } | 
  | 52 | 0 |      } | 
  | 53 |  |   | 
  | 54 |  |       | 
  | 55 |  |   | 
  | 56 |  |   | 
  | 57 |  |   | 
  | 58 |  |   | 
  | 59 |  |   | 
  | 60 |  |      public void handleFailure(Throwable caught){ | 
  | 61 | 0 |              if (!sessionTimeoutHandler.isSessionTimeout(caught)){ | 
  | 62 | 0 |                      KSErrorDialog.show(caught); | 
  | 63 |  |              } | 
  | 64 | 0 |          GWT.log("Exception:", caught); | 
  | 65 | 0 |      } | 
  | 66 |  |       | 
  | 67 |  |       | 
  | 68 |  |   | 
  | 69 |  |   | 
  | 70 |  |   | 
  | 71 |  |   | 
  | 72 |  |   | 
  | 73 |  |      public void handleTimeout(Throwable caught){ | 
  | 74 | 0 |              handleFailure(caught); | 
  | 75 | 0 |      } | 
  | 76 |  |           | 
  | 77 |  |      public void handleVersionMismatch(Throwable caught){ | 
  | 78 | 0 |          String message = null; | 
  | 79 | 0 |          if (caught.getMessage() != null){ | 
  | 80 | 0 |              message = "Version Error: " + caught.getMessage() + "\n\n"; | 
  | 81 |  |          } | 
  | 82 | 0 |          message += "This page has been updated by another user since you loaded it. Please refresh and re-apply changes before saving."; | 
  | 83 | 0 |          Window.alert(message); | 
  | 84 | 0 |      } | 
  | 85 |  |  } |