List of usage examples for com.google.gwt.user.client Window addWindowClosingHandler
public static HandlerRegistration addWindowClosingHandler(final ClosingHandler handler)
From source file:com.vaadin.client.communication.XhrConnection.java
License:Apache License
public XhrConnection() { Window.addWindowClosingHandler(new ClosingHandler() { @Override//from w w w.j a v a2s . c o m public void onWindowClosing(ClosingEvent event) { webkitMaybeIgnoringRequests = true; } }); }
From source file:com.vaadin.client.ui.ui.UIConnector.java
License:Apache License
@Override public void updateFromUIDL(final UIDL uidl, ApplicationConnection client) { getWidget().id = getConnectorId();//from w w w . j a v a 2 s. c o m boolean firstPaint = getWidget().connection == null; getWidget().connection = client; getWidget().immediate = getState().immediate; getWidget().resizeLazy = uidl.hasAttribute(UIConstants.RESIZE_LAZY); // this also implicitly removes old styles String styles = ""; styles += getWidget().getStylePrimaryName() + " "; if (ComponentStateUtil.hasStyles(getState())) { for (String style : getState().styles) { styles += style + " "; } } if (!client.getConfiguration().isStandalone()) { styles += getWidget().getStylePrimaryName() + "-embedded"; } getWidget().setStyleName(styles.trim()); getWidget().makeScrollable(); clickEventHandler.handleEventHandlerRegistration(); // Process children int childIndex = 0; // Open URL:s boolean isClosed = false; // was this window closed? while (childIndex < uidl.getChildCount() && "open".equals(uidl.getChildUIDL(childIndex).getTag())) { final UIDL open = uidl.getChildUIDL(childIndex); final String url = client.translateVaadinUri(open.getStringAttribute("src")); final String target = open.getStringAttribute("name"); if (target == null) { // source will be opened to this browser window, but we may have // to finish rendering this window in case this is a download // (and window stays open). Scheduler.get().scheduleDeferred(new Command() { @Override public void execute() { VUI.goTo(url); } }); } else if ("_self".equals(target)) { // This window is closing (for sure). Only other opens are // relevant in this change. See #3558, #2144 isClosed = true; VUI.goTo(url); } else { String options; boolean alwaysAsPopup = true; if (open.hasAttribute("popup")) { alwaysAsPopup = open.getBooleanAttribute("popup"); } if (alwaysAsPopup) { if (open.hasAttribute("border")) { if (open.getStringAttribute("border").equals("minimal")) { options = "menubar=yes,location=no,status=no"; } else { options = "menubar=no,location=no,status=no"; } } else { options = "resizable=yes,menubar=yes,toolbar=yes,directories=yes,location=yes,scrollbars=yes,status=yes"; } if (open.hasAttribute("width")) { int w = open.getIntAttribute("width"); options += ",width=" + w; } if (open.hasAttribute("height")) { int h = open.getIntAttribute("height"); options += ",height=" + h; } Window.open(url, target, options); } else { open(url, target); } } childIndex++; } if (isClosed) { // We're navigating away, so stop the application. client.setApplicationRunning(false); return; } // Handle other UIDL children UIDL childUidl; while ((childUidl = uidl.getChildUIDL(childIndex++)) != null) { String tag = childUidl.getTag().intern(); if (tag == "actions") { if (getWidget().actionHandler == null) { getWidget().actionHandler = new ShortcutActionHandler(getWidget().id, client); } getWidget().actionHandler.updateActionMap(childUidl); } else if (tag == "notifications") { for (final Iterator<?> it = childUidl.getChildIterator(); it.hasNext();) { final UIDL notification = (UIDL) it.next(); VNotification.showNotification(client, notification); } } else if (tag == "css-injections") { injectCSS(childUidl); } } if (uidl.hasAttribute("focused")) { // set focused component when render phase is finished Scheduler.get().scheduleDeferred(new Command() { @Override public void execute() { ComponentConnector connector = (ComponentConnector) uidl.getPaintableAttribute("focused", getConnection()); if (connector == null) { // Do not try to focus invisible components which not // present in UIDL return; } final Widget toBeFocused = connector.getWidget(); /* * Two types of Widgets can be focused, either implementing * GWT Focusable of a thinner Vaadin specific Focusable * interface. */ if (toBeFocused instanceof com.google.gwt.user.client.ui.Focusable) { final com.google.gwt.user.client.ui.Focusable toBeFocusedWidget = (com.google.gwt.user.client.ui.Focusable) toBeFocused; toBeFocusedWidget.setFocus(true); } else if (toBeFocused instanceof Focusable) { ((Focusable) toBeFocused).focus(); } else { getLogger().severe("Server is trying to set focus to the widget of connector " + Util.getConnectorString(connector) + " but it is not focusable. The widget should implement either " + com.google.gwt.user.client.ui.Focusable.class.getName() + " or " + Focusable.class.getName()); } } }); } // Add window listeners on first paint, to prevent premature // variablechanges if (firstPaint) { Window.addWindowClosingHandler(getWidget()); Window.addResizeHandler(getWidget()); } if (uidl.hasAttribute("scrollTo")) { final ComponentConnector connector = (ComponentConnector) uidl.getPaintableAttribute("scrollTo", getConnection()); scrollIntoView(connector); } if (uidl.hasAttribute(UIConstants.LOCATION_VARIABLE)) { String location = uidl.getStringAttribute(UIConstants.LOCATION_VARIABLE); String newFragment; int fragmentIndex = location.indexOf('#'); if (fragmentIndex >= 0) { // Decode fragment to avoid double encoding (#10769) newFragment = URL.decodePathSegment(location.substring(fragmentIndex + 1)); if (newFragment.isEmpty() && Location.getHref().indexOf('#') == -1) { // Ensure there is a trailing # even though History and // Location.getHash() treat null and "" the same way. Location.assign(Location.getHref() + "#"); } } else { // No fragment in server-side location, but can't completely // remove the browser fragment since that would reload the page newFragment = ""; } getWidget().currentFragment = newFragment; if (!newFragment.equals(History.getToken())) { History.newItem(newFragment, true); } } if (firstPaint) { // Queue the initial window size to be sent with the following // request. Scheduler.get().scheduleDeferred(new ScheduledCommand() { @Override public void execute() { getWidget().sendClientResized(); } }); } }
From source file:com.vaadin.terminal.gwt.client.ui.VView.java
License:Open Source License
public void updateFromUIDL(final UIDL uidl, ApplicationConnection client) { rendering = true;//from w w w .j a v a2 s .c o m id = uidl.getId(); boolean firstPaint = connection == null; connection = client; immediate = uidl.hasAttribute("immediate"); resizeLazy = uidl.hasAttribute(RESIZE_LAZY); String newTheme = uidl.getStringAttribute("theme"); if (theme != null && !newTheme.equals(theme)) { // Complete page refresh is needed due css can affect layout // calculations etc reloadHostPage(); } else { theme = newTheme; } if (uidl.hasAttribute("style")) { setStyleName(getStylePrimaryName() + " " + uidl.getStringAttribute("style")); } clickEventHandler.handleEventHandlerRegistration(client); if (!isEmbedded() && uidl.hasAttribute("caption")) { // only change window title if we're in charge of the whole page com.google.gwt.user.client.Window.setTitle(uidl.getStringAttribute("caption")); } // Process children int childIndex = 0; // Open URL:s boolean isClosed = false; // was this window closed? while (childIndex < uidl.getChildCount() && "open".equals(uidl.getChildUIDL(childIndex).getTag())) { final UIDL open = uidl.getChildUIDL(childIndex); final String url = client.translateVaadinUri(open.getStringAttribute("src")); final String target = open.getStringAttribute("name"); if (target == null) { // source will be opened to this browser window, but we may have // to finish rendering this window in case this is a download // (and window stays open). Scheduler.get().scheduleDeferred(new Command() { public void execute() { goTo(url); } }); } else if ("_self".equals(target)) { // This window is closing (for sure). Only other opens are // relevant in this change. See #3558, #2144 isClosed = true; goTo(url); } else { String options; if (open.hasAttribute("border")) { if (open.getStringAttribute("border").equals("minimal")) { options = "menubar=yes,location=no,status=no"; } else { options = "menubar=no,location=no,status=no"; } } else { options = "resizable=yes,menubar=yes,toolbar=yes,directories=yes,location=yes,scrollbars=yes,status=yes"; } if (open.hasAttribute("width")) { int w = open.getIntAttribute("width"); options += ",width=" + w; } if (open.hasAttribute("height")) { int h = open.getIntAttribute("height"); options += ",height=" + h; } Window.open(url, target, options); } childIndex++; } if (isClosed) { // don't render the content, something else will be opened to this // browser view rendering = false; return; } // Draw this application level window UIDL childUidl = uidl.getChildUIDL(childIndex); final Paintable lo = client.getPaintable(childUidl); if (layout != null) { if (layout != lo) { // remove old client.unregisterPaintable(layout); // add new setWidget((Widget) lo); layout = lo; } } else { setWidget((Widget) lo); layout = lo; } layout.updateFromUIDL(childUidl, client); if (!childUidl.getBooleanAttribute("cached")) { updateParentFrameSize(); } // Save currently open subwindows to track which will need to be closed final HashSet<VWindow> removedSubWindows = new HashSet<VWindow>(subWindows); // Handle other UIDL children while ((childUidl = uidl.getChildUIDL(++childIndex)) != null) { String tag = childUidl.getTag().intern(); if (tag == "actions") { if (actionHandler == null) { actionHandler = new ShortcutActionHandler(id, client); } actionHandler.updateActionMap(childUidl); } else if (tag == "execJS") { String script = childUidl.getStringAttribute("script"); eval(script); } else if (tag == "notifications") { for (final Iterator<?> it = childUidl.getChildIterator(); it.hasNext();) { final UIDL notification = (UIDL) it.next(); VNotification.showNotification(client, notification); } } else { // subwindows final Paintable w = client.getPaintable(childUidl); if (subWindows.contains(w)) { removedSubWindows.remove(w); } else { subWindows.add((VWindow) w); } w.updateFromUIDL(childUidl, client); } } // Close old windows which where not in UIDL anymore for (final Iterator<VWindow> rem = removedSubWindows.iterator(); rem.hasNext();) { final VWindow w = rem.next(); client.unregisterPaintable(w); subWindows.remove(w); w.hide(); } if (uidl.hasAttribute("focused")) { // set focused component when render phase is finished Scheduler.get().scheduleDeferred(new Command() { public void execute() { final Paintable toBeFocused = uidl.getPaintableAttribute("focused", connection); /* * Two types of Widgets can be focused, either implementing * GWT HasFocus of a thinner Vaadin specific Focusable * interface. */ if (toBeFocused instanceof com.google.gwt.user.client.ui.Focusable) { final com.google.gwt.user.client.ui.Focusable toBeFocusedWidget = (com.google.gwt.user.client.ui.Focusable) toBeFocused; toBeFocusedWidget.setFocus(true); } else if (toBeFocused instanceof Focusable) { ((Focusable) toBeFocused).focus(); } else { VConsole.log("Could not focus component"); } } }); } // Add window listeners on first paint, to prevent premature // variablechanges if (firstPaint) { Window.addWindowClosingHandler(this); Window.addResizeHandler(this); } onResize(); // finally set scroll position from UIDL if (uidl.hasVariable("scrollTop")) { scrollable = true; scrollTop = uidl.getIntVariable("scrollTop"); DOM.setElementPropertyInt(getElement(), "scrollTop", scrollTop); scrollLeft = uidl.getIntVariable("scrollLeft"); DOM.setElementPropertyInt(getElement(), "scrollLeft", scrollLeft); } else { scrollable = false; } // Safari workaround must be run after scrollTop is updated as it sets // scrollTop using a deferred command. if (BrowserInfo.get().isSafari()) { Util.runWebkitOverflowAutoFix(getElement()); } scrollIntoView(uidl); if (uidl.hasAttribute(FRAGMENT_VARIABLE)) { currentFragment = uidl.getStringAttribute(FRAGMENT_VARIABLE); if (!currentFragment.equals(History.getToken())) { History.newItem(currentFragment, true); } } else { // Initial request for which the server doesn't yet have a fragment // (and haven't shown any interest in getting one) currentFragment = History.getToken(); // Include current fragment in the next request client.updateVariable(id, FRAGMENT_VARIABLE, currentFragment, false); } rendering = false; }
From source file:es.deusto.weblab.client.lab.controller.LabController.java
License:Open Source License
public LabController(IConfigurationManager configurationManager, ILabCommunication communications, IPollingHandler pollingHandler, boolean isMobile, boolean isFacebook) { this.configurationManager = configurationManager; this.communications = communications; this.pollingHandler = pollingHandler; this.isMobile = isMobile; this.isFacebook = isFacebook; Window.addWindowClosingHandler(new ClosingHandler() { @Override/* w ww .j av a2 s .c om*/ public void onWindowClosing(ClosingEvent event) { onWindowClose(); } }); History.addValueChangeHandler(new ValueChangeHandler<String>() { @Override public void onValueChange(ValueChangeEvent<String> event) { if (getCurrentSession() != null && !getCurrentSession().isNull()) { HistoryProperties.reloadHistory(); loadUserHomeWindow(); } } }); }
From source file:fi.jyu.student.jatahama.onlineinquirytool.client.OnlineInquiryTool.java
License:Open Source License
/** * UI Creator. Called after we have checked servlet existence *///from ww w.j a v a 2s .c o m public void createUI() { // Won't need this anymore because will build it right here! needUI = false; // Set window title Window.setTitle(constants.tcLblToolTitle()); // Create anchor createAnchor.addClickHandler(this); createAnchor.setStyleName("nav"); // Open anchor // NOTE: Because we use input (type=file), we wrap anchor inside a div which has invisible input over our anchor. openAnchor.setStyleName("nav"); // Open button openButton.addChangeHandler(this); openButton.getElement().setId("file-input"); openButton.setName("file-input"); openButton.setStyleName("file-open"); openButton.addMouseOutHandler(this); openButton.addMouseOverHandler(this); openButton.setTitle(""); // Wrapper for open stuff final FlowPanel openWrap = new FlowPanel(); openWrap.setStyleName("file-wrap"); openWrap.add(openAnchor); loadForm.setAction(loadsaveServletUrl); loadForm.setEncoding(FormPanel.ENCODING_MULTIPART); loadForm.setMethod(FormPanel.METHOD_POST); loadForm.add(openButton); loadForm.addSubmitCompleteHandler(this); openWrap.add(loadForm); // Save anchor saveAnchor.addClickHandler(this); saveAnchor.setStyleName("nav"); // Save as popup saveAsPopup.setStylePrimaryName("save-popup"); final VerticalPanel sv = new VerticalPanel(); sv.setStylePrimaryName("save-wrap"); final Label slbl = new Label(constants.tcLblSaveAs()); slbl.setStyleName("save-label"); sv.add(slbl); final HorizontalPanel sh1 = new HorizontalPanel(); sh1.setStylePrimaryName("save-name-wrap"); saveName.setStylePrimaryName("save-name"); sh1.add(saveName); saveName.setText(constants.tcTxtDefaultChartFilename()); saveName.addKeyDownHandler(this); final Label ssuf = new Label(".xhtml"); ssuf.setStylePrimaryName("save-suffix"); sh1.add(ssuf); sv.add(sh1); final HorizontalPanel sh2 = new HorizontalPanel(); sh2.setStylePrimaryName("save-button-wrap"); // btnSaveOk.setStylePrimaryName("save-button"); // btnSaveCancel.setStylePrimaryName("save-button"); sh2.add(btnSaveCancel); sh2.add(btnSaveOk); sv.add(sh2); btnSaveCancel.addClickHandler(this); btnSaveOk.addClickHandler(this); saveAsPopup.setWidget(sv); saveAsPopup.setGlassEnabled(true); saveAsPopup.setGlassStyleName("save-glass"); // (hidden) Form panel for save saveForm.setAction(loadsaveServletUrl); saveForm.setEncoding(FormPanel.ENCODING_MULTIPART); saveForm.setMethod(FormPanel.METHOD_POST); saveForm.setStylePrimaryName("no-display"); chartData.setStylePrimaryName("no-display"); chartData.setName("chartDataXML"); chartName.setStylePrimaryName("no-display"); chartName.setName("chartFilename"); final FlowPanel sp = new FlowPanel(); // Ordering is important because server expects name first! // Otherwise default filename would be used on server side. sp.add(chartName); sp.add(chartData); saveForm.add(sp); // loadingPopup final Label loadingLabel = new Label(OnlineInquiryTool.constants.tcLblLoading()); loadingLabel.setStyleName("loading-text", true); loadingPopup.setStyleName("popup-z", true); loadingPopup.setGlassEnabled(true); loadingPopup.setWidget(loadingLabel); // loadingFailed final VerticalPanel loadingFailContent = new VerticalPanel(); loadingFailContent.setStyleName("black-border"); loadingFailLabel.setStyleName("fail-label"); loadingFailedPopup.setStyleName("popup-z", true); loadingFailedPopup.setGlassEnabled(true); final ClickHandler failCloseHandler = new ClickHandler() { @Override public void onClick(ClickEvent event) { loadingFailedPopup.hide(); } }; final Button failPopClose = new Button(constants.tcBtnOk(), failCloseHandler); final SimplePanel failCloseHolder = new SimplePanel(); failCloseHolder.setStyleName("popup-button-holder"); failCloseHolder.add(failPopClose); loadingFailContent.add(loadingFailLabel); loadingFailContent.add(failCloseHolder); loadingFailedPopup.add(loadingFailContent); // Dirty popup dirtyPopup.setStylePrimaryName("dirty-popup"); final VerticalPanel sv2 = new VerticalPanel(); sv2.setStylePrimaryName("dirty-wrap"); final Label dlbl = new Label(constants.tcLblNotSaved()); dlbl.setStyleName("dirty-header"); sv2.add(dlbl); final Label dlbl2 = new Label(constants.tcLblPromptSave()); dlbl2.setStylePrimaryName("dirty-label"); sv2.add(dlbl2); final HorizontalPanel sh3 = new HorizontalPanel(); sh3.setStylePrimaryName("dirty-button-wrap"); sh3.add(btnDirtyCancel); sh3.add(btnDirtyNo); sh3.add(btnDirtyYes); sv2.add(sh3); btnDirtyCancel.addClickHandler(this); btnDirtyNo.addClickHandler(this); btnDirtyYes.addClickHandler(this); dirtyPopup.setWidget(sv2); dirtyPopup.setGlassEnabled(true); dirtyPopup.setGlassStyleName("dirty-glass"); // Navigation Hyperlink instructionsLink = new Hyperlink(constants.tcBtnInstructions(), "instructions"); instructionsLink.setStyleName("nav"); final Label spacer1 = new Label(); // Spacer for second column spacer1.setStyleName("nav-spacer"); final Label spacer2 = new Label(); // Spacer for second column spacer2.setStyleName("nav-spacer"); final FlowPanel navWrap1 = new FlowPanel(); navWrap1.setStyleName("clear-wrap nav-wrap rmargin10"); navWrap1.add(createAnchor); navWrap1.add(openWrap); navWrap1.add(saveAnchor); final FlowPanel navWrap2 = new FlowPanel(); navWrap2.setStyleName("clear-wrap nav-wrap"); navWrap2.add(spacer1); navWrap2.add(spacer2); navWrap2.add(instructionsLink); final FlowPanel navPanel = new FlowPanel(); navPanel.setStyleName("blue-border page-nav"); navPanel.add(navWrap1); navPanel.add(navWrap2); RootPanel.get("content").add(navPanel); // Site title Label siteTitle = new Label(constants.tcLblToolTitle()); siteTitle.setStyleName("site-title"); RootPanel.get("content").add(siteTitle); // Check load save states checkLoadSaveState(); // Build main deck final FlowPanel contentWrap = new FlowPanel(); contentWrap.setStyleName("blue-border page-main-content"); mainDeck.setStyleName("clear-wrap"); contentWrap.add(mainDeck); RootPanel.get("content").add(contentWrap); mainDeck.add(claimAnalysisPanel); mainDeck.showWidget(0); // Help popup final HTML helpText = new HTML(constants.tcTxtInstructionsText()); final ScrollPanel textWrapper = new ScrollPanel(); textWrapper.setStyleName("help-text-wrap", true); textWrapper.add(helpText); final VerticalPanel popContent = new VerticalPanel(); final ClickHandler closeHandler = new ClickHandler() { @Override public void onClick(ClickEvent event) { helpPanel.hide(); } }; final Button popClose = new Button(constants.tcBtnClose(), closeHandler); final SimplePanel holder = new SimplePanel(); holder.setStyleName("popup-button-holder"); holder.add(popClose); popContent.setStyleName("help-popup-wrap"); popContent.add(textWrapper); popContent.add(holder); helpPanel.setGlassEnabled(true); helpPanel.setWidget(popContent); helpPanel.setStyleName("popup-z", true); // helpPanel.setWidth("500px"); // Add history listener and set initial state History.addValueChangeHandler(this); String initToken = History.getToken(); if (initToken.length() == 0) { History.newItem("welcome"); } else { // Fire initial history state. History.fireCurrentHistoryState(); } claimAnalysisPanel.setClaim(null); claimAnalysisPanel.updateLayout(); claimAnalysisPanel.updateClaimTitleAndConclusionWidgets(); // App info (hidden) RootPanel.get("appinfo").add( new HTML("Version: " + AppInfo.getBuildVersion() + (AppInfo.isBuildClean() ? "-clean" : "-dirty") + "<br />" + "Date: " + AppInfo.getBuildDate() + "<br />" + "Branch: " + AppInfo.getBuildBranch() + "<br />" + "Commit: " + AppInfo.getBuildCommit())); // Copyright stuff + version VerticalPanel copyWrap = new VerticalPanel(); copyWrap.setStyleName("copyright-wrap"); copyAnchor.setStyleName("copyright-text"); copyAnchor.setText(constants.tcLblCopyright()); copyAnchor.addClickHandler(this); copyWrap.add(copyAnchor); versionAnchor.setStyleName("copyright-text"); versionAnchor.setText(constants.tcLblVersion() + " " + AppInfo.getBuildVersion()); versionAnchor.addClickHandler(this); copyWrap.add(versionAnchor); contentWrap.add(copyWrap); // Copyright and appinfo final SimplePanel infoWrapper = new SimplePanel(); infoWrapper.setStyleName("help-text-wrap", true); infoWrapper.add(infoText); final VerticalPanel infoPopContent = new VerticalPanel(); final ClickHandler infoCloseHandler = new ClickHandler() { @Override public void onClick(ClickEvent event) { infoPopup.hide(); } }; final Button infoPopClose = new Button(constants.tcBtnClose(), infoCloseHandler); final SimplePanel infoBtnHolder = new SimplePanel(); infoBtnHolder.setStyleName("popup-button-holder"); infoBtnHolder.add(infoPopClose); infoPopContent.setStyleName("info-popup-wrap"); infoPopContent.add(infoWrapper); infoPopContent.add(infoBtnHolder); infoPopup.setGlassEnabled(true); infoPopup.setWidget(infoPopContent); infoPopup.setStyleName("popup-z", true); // Confirm page leave if not saved Window.addWindowClosingHandler(new Window.ClosingHandler() { public void onWindowClosing(Window.ClosingEvent closingEvent) { ClaimAnalysis claim = claimAnalysisPanel.getClaim(); if (claim != null) { if (claim.isDirty()) { closingEvent.setMessage(constants.tcLblNotSaved()); } } } }); // Save form must be on doc or it will not work RootPanel.get().add(saveForm); }
From source file:nl.mpi.tg.eg.experiment.client.AppController.java
License:Open Source License
final protected void preventWindowClose(final String messageString) { // on page close, back etc. provide a warning that their session will be invalide and they will not be paid etc. Window.addWindowClosingHandler(new Window.ClosingHandler() { @Override/*from w ww .j ava2s .c om*/ public void onWindowClosing(ClosingEvent event) { event.setMessage(messageString); } }); // on page close, back etc. send a screen event to the server Window.addCloseHandler(new CloseHandler<Window>() { @Override public void onClose(CloseEvent<Window> event) { submissionService.submitScreenChange(userResults.getUserData().getUserId(), "BrowserWindowClosed"); presenter.fireWindowClosing(); } }); }
From source file:nl.mpi.tg.eg.experiment.client.AppController.java
License:Open Source License
public void start() { setBackButtonAction();// w ww. jav a 2 s . co m History.addValueChangeHandler(new ValueChangeHandler<String>() { @Override public void onValueChange(ValueChangeEvent<String> event) { if (preserveLastState()) { // when the navigation is blocked a new item is added over the last back event // this prevents both back and forward history actions triggering the back action, however no forward navigation will available unless the back action is to hide/show the stimuli menu, in which case it is ok History.newItem(localStorage.getAppState(userResults.getUserData().getUserId()), false); backAction(); } else if (event != null) { presenter.savePresenterState(); try { // this allows the browser navigation buttons to control the screen shown ApplicationState lastAppState = ApplicationState.valueOf(event.getValue()); requestApplicationState(lastAppState); } catch (IllegalArgumentException argumentException) { } } } }); Window.addWindowClosingHandler(new Window.ClosingHandler() { @Override public void onWindowClosing(ClosingEvent event) { presenter.savePresenterState(); submissionService.submitAllData(userResults, new DataSubmissionListener() { @Override public void scoreSubmissionFailed(DataSubmissionException exception) { } @Override public void scoreSubmissionComplete(JsArray<DataSubmissionResult> highScoreData) { } }); } }); try { submissionService.submitScreenChange(userResults.getUserData().getUserId(), "ApplicationStarted"); // application specific information submissionService.submitTagValue(userResults.getUserData().getUserId(), "ApplicationStarted", "projectVersion", version.projectVersion(), 0); submissionService.submitTagValue(userResults.getUserData().getUserId(), "ApplicationStarted", "lastCommitDate", version.lastCommitDate().replace("\"", ""), 0); submissionService.submitTagValue(userResults.getUserData().getUserId(), "ApplicationStarted", "compileDate", version.compileDate(), 0); submissionService.submitTagValue(userResults.getUserData().getUserId(), "ApplicationStarted", "navigator.platform", Window.Navigator.getPlatform(), 0); submissionService.submitTagValue(userResults.getUserData().getUserId(), "ApplicationStarted", "navigator.userAgent", Window.Navigator.getUserAgent(), 0); submissionService.submitTagValue(userResults.getUserData().getUserId(), "ApplicationStarted", "navigator.cookieEnabled", Boolean.toString(Window.Navigator.isCookieEnabled()), 0); submissionService.submitTagValue(userResults.getUserData().getUserId(), "ApplicationStarted", "storageLength", Integer.toString(localStorage.getStorageLength()), 0); if (hasCordova()) { // cordova specific information submissionService.submitTagValue(userResults.getUserData().getUserId(), "ApplicationStarted", "cordovaVersion", getCordovaVersion(), 0); submissionService.submitTagValue(userResults.getUserData().getUserId(), "ApplicationStarted", "deviceModel", getDeviceModel(), 0); submissionService.submitTagValue(userResults.getUserData().getUserId(), "ApplicationStarted", "devicePlatform", getDevicePlatform(), 0); submissionService.submitTagValue(userResults.getUserData().getUserId(), "ApplicationStarted", "deviceUUID", getDeviceUUID(), 0); submissionService.submitTagValue(userResults.getUserData().getUserId(), "ApplicationStarted", "deviceVersion", getDeviceVersion(), 0); } ApplicationState lastAppState = ApplicationState.start; try { final String appState = localStorage.getAppState(userResults.getUserData().getUserId()); // if the app state is preserved, then only the last saved state is used lastAppState = (appState != null) ? ApplicationState.valueOf(appState) : lastAppState; } catch (IllegalArgumentException argumentException) { } if (!preserveLastState() || isDebugMode /* checking for debug mode here and allowing presenter navigation here if true */) { // if the history token is valid then that is used otherwise the last saved or the start states are used final String token = History.getToken(); if (token != null) { try { submissionService.submitScreenChange(userResults.getUserData().getUserId(), "usingHistoryToken"); // this allows the URL to control the screen shown lastAppState = ApplicationState.valueOf(token); } catch (IllegalArgumentException argumentException) { } } } if (!submissionService.isProductionVersion()) { this.presenter = new TestingVersionPresenter(widgetTag, lastAppState); presenter.setState(this, null, null); } else { requestApplicationState(lastAppState); } addKeyboardEvents(); } catch (Exception exception) { this.presenter = new StorageFullPresenter(widgetTag, exception.getMessage()); presenter.setState(this, ApplicationState.start, null); } }
From source file:org.activityinfo.ui.client.page.NavigationHandler.java
License:Open Source License
@Inject public NavigationHandler(final EventBus eventBus, final @Root Frame root) { this.eventBus = eventBus; this.root = root; eventBus.addListener(NAVIGATION_REQUESTED, new Listener<NavigationEvent>() { @Override/*from w ww . j ava2 s. c om*/ public void handleEvent(NavigationEvent be) { onNavigationRequested(be); } }); Log.debug("PageManager: connected to EventBus and listening."); Window.addWindowClosingHandler(new Window.ClosingHandler() { @Override public void onWindowClosing(Window.ClosingEvent event) { if (activeNavigation != null && activeNavigation.currentPage != null) { event.setMessage(activeNavigation.currentPage.beforeWindowCloses()); } } }); }
From source file:org.atmosphere.gwt.client.extra.LoadRegister.java
License:Apache License
private static void initWindowHandlers() { Window.addWindowClosingHandler(new Window.ClosingHandler() { @Override/*from w w w.jav a 2 s .co m*/ public void onWindowClosing(ClosingEvent event) { onBeforeUnload(); } }); Window.addCloseHandler(new CloseHandler<Window>() { @Override public void onClose(CloseEvent<Window> event) { onUnload(); } }); }
From source file:org.cruxframework.crux.core.client.screen.views.ViewHandlers.java
License:Apache License
/** * /* w w w .ja v a2s . com*/ * @param viewContainer */ protected static void ensureViewContainerClosingHandler(ViewContainer viewContainer) { if (!hasWindowClosingHandler && viewContainer.hasWindowClosingHandlers()) { hasWindowClosingHandler = true; closingHandler = Window.addWindowClosingHandler(new ClosingHandler() { @Override public void onWindowClosing(ClosingEvent event) { for (int i = 0; i < boundContainers.size(); i++) { boundContainers.get(i).notifyViewsAboutWindowClosing(event); } } }); } }