added sending of event on eventBus when session expires
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/widgets/session-checker@93509 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
70fd68e106
commit
ae93c863fe
|
@ -3,10 +3,12 @@ package org.gcube.portlets.widgets.sessionchecker.client;
|
|||
import org.gcube.portlets.user.gcubewidgets.client.popup.GCubeDialog;
|
||||
import org.gcube.portlets.widgets.sessionchecker.client.bundle.CheckSessionBundle;
|
||||
import org.gcube.portlets.widgets.sessionchecker.client.elements.Div;
|
||||
import org.gcube.portlets.widgets.sessionchecker.client.event.SessionTimeoutEvent;
|
||||
import org.gcube.portlets.widgets.sessionchecker.shared.SessionInfoBean;
|
||||
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.dom.client.Style.Display;
|
||||
import com.google.gwt.event.shared.HandlerManager;
|
||||
import com.google.gwt.user.client.Timer;
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
import com.google.gwt.user.client.ui.HTML;
|
||||
|
@ -23,6 +25,10 @@ public class CheckSession {
|
|||
static {
|
||||
CheckSessionBundle.INSTANCE.css().ensureInjected();
|
||||
}
|
||||
/**
|
||||
* the eventbus where to launch the events
|
||||
*/
|
||||
private HandlerManager eventBus = null;
|
||||
/**
|
||||
* Create a remote service proxy to talk to the server-side Greeting service.
|
||||
*/
|
||||
|
@ -36,13 +42,34 @@ public class CheckSession {
|
|||
private Div maskDiv = new Div();
|
||||
|
||||
private static CheckSession singleton;
|
||||
|
||||
/**
|
||||
* use this method if you want to get an event when session expires
|
||||
* @param eventBus your GWT webapp instance of {@link HandlerManager}
|
||||
*/
|
||||
public static CheckSession getInstance(HandlerManager eventBus) {
|
||||
if (singleton == null)
|
||||
singleton = new CheckSession(eventBus);
|
||||
return singleton;
|
||||
}
|
||||
/**
|
||||
* method with no events launching when session expires
|
||||
*/
|
||||
public static CheckSession getInstance() {
|
||||
if (singleton == null)
|
||||
singleton = new CheckSession();
|
||||
return singleton;
|
||||
}
|
||||
|
||||
/**
|
||||
* use this constructor if you want to get an event when session expires
|
||||
* @param eventBus GWT webapp instance of {@link HandlerManager}
|
||||
*/
|
||||
private CheckSession(HandlerManager eventBus) {
|
||||
this();
|
||||
this.eventBus = eventBus;
|
||||
}
|
||||
/**
|
||||
* constructor with no events launching when session expires
|
||||
*/
|
||||
private CheckSession() {
|
||||
|
||||
addMaskDiv2DOM();
|
||||
|
@ -66,6 +93,9 @@ public class CheckSession {
|
|||
mask(true);
|
||||
stopPolling();
|
||||
showLogoutDialog();
|
||||
if (eventBus != null) {
|
||||
eventBus.fireEvent(new SessionTimeoutEvent(result));
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
package org.gcube.portlets.widgets.sessionchecker.client.event;
|
||||
|
||||
import org.gcube.portlets.widgets.sessionchecker.shared.SessionInfoBean;
|
||||
|
||||
import com.google.gwt.event.shared.GwtEvent;
|
||||
|
||||
|
||||
|
||||
public class SessionTimeoutEvent extends GwtEvent<SessionTimoutEventHandler> {
|
||||
public static Type<SessionTimoutEventHandler> TYPE = new Type<SessionTimoutEventHandler>();
|
||||
|
||||
private SessionInfoBean sessionInfo;
|
||||
|
||||
public SessionTimeoutEvent(SessionInfoBean sessionInfo) {
|
||||
this.sessionInfo = sessionInfo;
|
||||
}
|
||||
|
||||
public SessionInfoBean getSessionInfo() {
|
||||
return sessionInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type<SessionTimoutEventHandler> getAssociatedType() {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void dispatch(SessionTimoutEventHandler handler) {
|
||||
handler.onSessionExpiration(this);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package org.gcube.portlets.widgets.sessionchecker.client.event;
|
||||
|
||||
import com.google.gwt.event.shared.EventHandler;
|
||||
|
||||
public interface SessionTimoutEventHandler extends EventHandler {
|
||||
void onSessionExpiration(SessionTimeoutEvent event);
|
||||
}
|
Loading…
Reference in New Issue