Closes all opened windows, stopping all background JavaScript processing. The WebClient is not really usable after this - you have to create a new one or use WebClient.reset() instead. {@inheritDoc}
()
| 2265 | * {@inheritDoc} |
| 2266 | */ |
| 2267 | @Override |
| 2268 | public void close() { |
| 2269 | // avoid attaching new windows to the js engine |
| 2270 | if (scriptEngine_ != null) { |
| 2271 | scriptEngine_.prepareShutdown(); |
| 2272 | } |
| 2273 | |
| 2274 | // stop the CurrentWindowTracker from making sure there is still one window available |
| 2275 | currentWindowTracker_ = new CurrentWindowTracker(this, false); |
| 2276 | |
| 2277 | // Hint: a new TopLevelWindow may be opened by some JS script while we are closing the others |
| 2278 | // but the prepareShutdown() call will prevent the new window form getting js support |
| 2279 | List<WebWindow> windows = new ArrayList<>(windows_); |
| 2280 | for (final WebWindow window : windows) { |
| 2281 | if (window instanceof TopLevelWindow topLevelWindow) { |
| 2282 | |
| 2283 | try { |
| 2284 | topLevelWindow.close(true); |
| 2285 | } |
| 2286 | catch (final Exception e) { |
| 2287 | LOG.error("Exception while closing a TopLevelWindow", e); |
| 2288 | } |
| 2289 | } |
| 2290 | else if (window instanceof DialogWindow dialogWindow) { |
| 2291 | |
| 2292 | try { |
| 2293 | dialogWindow.close(); |
| 2294 | } |
| 2295 | catch (final Exception e) { |
| 2296 | LOG.error("Exception while closing a DialogWindow", e); |
| 2297 | } |
| 2298 | } |
| 2299 | } |
| 2300 | |
| 2301 | // second round, none of the remaining windows should be registered to |
| 2302 | // the js engine because of prepareShutdown() |
| 2303 | windows = new ArrayList<>(windows_); |
| 2304 | for (final WebWindow window : windows) { |
| 2305 | if (window instanceof TopLevelWindow topLevelWindow) { |
| 2306 | |
| 2307 | try { |
| 2308 | topLevelWindow.close(true); |
| 2309 | } |
| 2310 | catch (final Exception e) { |
| 2311 | LOG.error("Exception while closing a TopLevelWindow", e); |
| 2312 | } |
| 2313 | } |
| 2314 | else if (window instanceof DialogWindow dialogWindow) { |
| 2315 | |
| 2316 | try { |
| 2317 | dialogWindow.close(); |
| 2318 | } |
| 2319 | catch (final Exception e) { |
| 2320 | LOG.error("Exception while closing a DialogWindow", e); |
| 2321 | } |
| 2322 | } |
| 2323 | } |
| 2324 |