- Timestamp:
- 2024-04-12T22:15:35+12:00 (4 weeks ago)
- Location:
- main/trunk/greenstone3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/applet/GsdlCollageApplet/GsdlCollageApplet.java
r38922 r38925 2 2 3 3 import org.webswing.toolkit.api.WebswingUtil; 4 import org.webswing.toolkit.api.action.WebActionEvent; 5 import org.webswing.toolkit.api.action.WebActionListener; 4 6 5 7 //import java.applet.Applet; … … 161 163 //} 162 164 165 // Handle getting called by webswing JavaScript: 166 // when the user navigates away from the webswing app's web page, do cleanup 167 // https://www.webswing.org/docs/23.2/integrate/jslink.html#invoking-java-from-javascript 168 // https://vaadin.com/directory/component/webswing-vaadin1 169 org.webswing.toolkit.api.WebswingUtil.getWebswingApi().addBrowserActionListener(new org.webswing.toolkit.api.action.WebActionListener() { 170 @Override 171 public void actionPerformed(org.webswing.toolkit.api.action.WebActionEvent actionEvent) { 172 switch (actionEvent.getActionName()) { 173 case "navigatingAway": 174 // do cleanup 175 System.err.println("@@@@ In Java collage addBrowserActionListener on navigatingAway - called"); 176 GsdlCollageApplet.this.stopRunning(); 177 break; 178 case "testJavaCall": 179 org.webswing.toolkit.api.WebswingUtil.getWebswingApi().sendActionEvent("javaToWebswingJSConsoleLog", "GsdlCollageApplet got TEST call !!", null); 180 //WebswingUtil.getWebswingApi().sendActionEvent("@@@ javaToWebswingJSConsoleLog", "GsdlCollageApplet - testjavaCall handler got your message", null); 181 } 182 } 183 }); 184 163 185 this.addMouseListener(new CollageMouseAdapter()); 164 186 } … … 724 746 d.width = collageApp.getWidth(); 725 747 statusBar.setPreferredSize(d); 726 //statusBar.setPreferredSize(new Dimension(collageApp.getWidth(), EXTRA_HEIGHT)); 748 //statusBar.setPreferredSize(new Dimension(collageApp.getWidth(), EXTRA_HEIGHT)); 727 749 } 728 750 … … 737 759 frame.addWindowListener(new WindowAdapter() { 738 760 public void windowClosing(WindowEvent e) { 761 // WHY doesn't javascript console log unless I prefix webswing package name?? 762 //WebswingUtil.getWebswingApi().sendActionEvent("@@@ javaToWebswingJSConsoleLog", "GsdlCollageApplet - quitting now", null); 763 org.webswing.toolkit.api.WebswingUtil.getWebswingApi().sendActionEvent("javaToWebswingJSConsoleLog", "GsdlCollageApplet about to QUIT !!", null); 764 739 765 collageApp.showStatus("Stopping threads"); 740 766 System.err.println("\n\n*** Closing applet: stopping threads..."); 741 767 collageApp.stopRunning(); 768 742 769 //collageApp.stop(); 743 770 //collageApp.destroy(); -
main/trunk/greenstone3/web/interfaces/default/transform/pages/webswing-collage.xsl
r38890 r38925 82 82 <xsl:template name="webswing-embed-collage"> 83 83 <link rel="stylesheet" href="/webswing-server/css/style.css" /> 84 85 84 <div id="webswing-collage" class="webswing-element" data-webswing-instance="webswingInstance0" style="width: 800px; height: 400px;"> 86 85 <div id="loading" class="ws-modal-container"> … … 131 130 window.open(url, '_blank'); 132 131 } 132 } else if (actionName == "javaToWebswingJSConsoleLog") { 133 console.log("Got message from java:\n" + data); 133 134 } 134 135 … … 201 202 <script data-webswing-global-var="webswing"> 202 203 <xsl:text disable-output-escaping="yes"> 204 205 var doButtonClick = function() { 206 console.log("button clicked"); 207 webswingInstance0.performAction({actionName: "testJavaCall"}); 208 } 209 var unloaded = false; 203 210 (function (window, document) { 204 211 var loader = function () { 205 var baseUrl = '/webswing-server/collage'; 212 213 unloaded = false; // reset state, because we are reloading the webswing app 214 215 var baseUrl = '/webswing-server/collage'; 206 216 baseUrl = baseUrl.indexOf("/", baseUrl.length - 1) !== -1 ? baseUrl : (baseUrl + "/"); 207 217 var xmlhttp = new XMLHttpRequest(); … … 218 228 xmlhttp.send(); 219 229 }; 230 231 var navigatingAway = function () { 232 console.log("*** navigatingAway called"); 233 234 // Multiple eventlisteners are registered to call navigatingAway, as not all are 235 // triggered in all contexts (desktop vs mobile vs older browsers) 236 // https://developer.mozilla.org/en-US/docs/Web/API/Window/unload_event 237 // We work with multiple eventlisteners to ensure we cleanup webswing collage app when 238 // user navigates away from page. But we should only do the cleanup once, even if *all* 239 // event handlers got triggered. We use the unloaded var to ensure we cleanup only once 240 if(!unloaded) { 241 if(typeof webswingInstance0.performAction === 'function') { 242 //event.preventDefault(); // if listening for beforeunload event 243 console.log("@@@@ Calling Java to stop running the webswing collage app"); 244 webswingInstance0.performAction({actionName: "navigatingAway"}); 245 unloaded = true; 246 console.log("@@@@ unloaded"); 247 //alert("check log"); 248 } else { 249 console.log("performAction method DOESN'T exist on the webswing object!"); 250 } 251 } else { 252 console.log("@@@@ already unloaded."); 253 } 254 255 }; 256 220 257 window.addEventListener ? window.addEventListener("load", loader, false) : window.attachEvent("onload", loader); 258 259 // https://developer.mozilla.org/en-US/docs/Web/API/Window/unload_event 260 // unload has been deprecated, and so we try pagehide and visibilitychange events 261 window.addEventListener ? window.addEventListener("unload", navigatingAway, false) : window.attachEvent("onunload", navigatingAway); 262 window.addEventListener ? window.addEventListener("pagehide", navigatingAway, false) : window.attachEvent("onpagehide", navigatingAway); 263 window.addEventListener ? window.addEventListener("visibilitychange", navigatingAway, false) : window.attachEvent("onvisibilitychange", navigatingAway); 264 221 265 })(window, document); 222 266 </xsl:text> 223 267 </script> 224 225 226 268 269 <button type="button" onclick="doButtonClick()">Click Me!</button> 227 270 </xsl:template> 228 271
Note:
See TracChangeset
for help on using the changeset viewer.