diff --git a/src/main/java/org/gcube/portlets/widgets/sessionchecker/client/CheckSession.java b/src/main/java/org/gcube/portlets/widgets/sessionchecker/client/CheckSession.java index 13fa7a4..a61c3bb 100644 --- a/src/main/java/org/gcube/portlets/widgets/sessionchecker/client/CheckSession.java +++ b/src/main/java/org/gcube/portlets/widgets/sessionchecker/client/CheckSession.java @@ -18,10 +18,10 @@ import com.google.gwt.user.client.ui.VerticalPanel; public class CheckSession { private final int MILLI_SECONDS = 45 * 1000; //45 seconds - + //for css and images private CheckSessionBundle images = GWT.create(CheckSessionBundle.class); - + static { CheckSessionBundle.INSTANCE.css().ensureInjected(); } @@ -37,10 +37,13 @@ public class CheckSession { private String username; private String scope; private Timer t; - + + //we give the user the possibility to show the dialog or not + private boolean showSessionExpiredDialog = true; + //needed to mask the page when session id up! private Div maskDiv = new Div(); - + private static CheckSession singleton; /** * use this method if you want to get an event when session expires @@ -71,10 +74,10 @@ public class CheckSession { * constructor with no events launching when session expires */ private CheckSession() { - + addMaskDiv2DOM(); maskDiv.setStyleName("div-mask"); - + //polling timer t = new Timer() { @Override @@ -83,7 +86,7 @@ public class CheckSession { @Override public void onSuccess(SessionInfoBean result) { if (result != null) { - + username = result.getUsername(); scope = result.getScope(); boolean userValid = ( username != null) ? true : false; @@ -92,7 +95,13 @@ public class CheckSession { if (! (userValid && scopeValid) ) { mask(true); stopPolling(); - showLogoutDialog(); + if (showSessionExpiredDialog) { + showLogoutDialog(); + } else { + if (eventBus == null) + throw new NullPointerException("Hey, it seems you chose to handle yourself session expiration " + + "but also not to get informed about it (eventbus is null) what's the point then?"); + } if (eventBus != null) { eventBus.fireEvent(new SessionTimeoutEvent(result)); } @@ -124,22 +133,22 @@ public class CheckSession { else maskDiv.getElement().getStyle().setDisplay(Display.NONE); } - + private void showLogoutDialog() { GCubeDialog dlg = new GCubeDialog(); dlg.setText("Your Session Expired!"); - + VerticalPanel topPanel = new VerticalPanel(); topPanel.setPixelSize(420, 290); - + topPanel.setHorizontalAlignment(HasAlignment.ALIGN_CENTER); - + HTML toShow = new HTML("
" + "" + "
" + "Please reload this page.
"); - + topPanel.add(toShow); dlg.add(topPanel); dlg.center(); @@ -166,4 +175,11 @@ public class CheckSession { public void stopPolling() { t.cancel(); } + + public boolean isShowSessionExpiredDialog() { + return showSessionExpiredDialog; + } + public void setShowSessionExpiredDialog(boolean showSessionExpiredDialog) { + this.showSessionExpiredDialog = showSessionExpiredDialog; + } }