sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 01/03: When an alert is shown for an error, the dialog box owner should be the application window. It help to keep the dialog on the same screen than the application.
Date Fri, 23 Oct 2020 14:40:32 GMT
This is an automated email from the ASF dual-hosted git repository.

desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git

commit 8336928c3d82813e11d9e55ff83e104366377313
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Fri Oct 23 10:46:03 2020 +0200

    When an alert is shown for an error, the dialog box owner should be the application window.
    It help to keep the dialog on the same screen than the application.
---
 .../apache/sis/gui/coverage/CoverageCanvas.java    |  2 +-
 .../org/apache/sis/gui/coverage/GridError.java     |  2 +-
 .../java/org/apache/sis/gui/coverage/GridView.java |  5 +-
 .../org/apache/sis/gui/dataset/CopyAction.java     |  2 +-
 .../apache/sis/gui/dataset/ResourceExplorer.java   |  2 +-
 .../org/apache/sis/gui/dataset/ResourceTree.java   | 11 +--
 .../java/org/apache/sis/gui/map/MapCanvas.java     |  4 +-
 .../main/java/org/apache/sis/gui/map/MapMenu.java  |  2 +-
 .../java/org/apache/sis/gui/map/StatusBar.java     |  2 +-
 .../sis/gui/metadata/StandardMetadataTree.java     |  4 +-
 .../org/apache/sis/gui/referencing/CRSChooser.java |  2 +-
 .../gui/referencing/RecentReferenceSystems.java    |  2 +-
 .../apache/sis/internal/gui/ExceptionReporter.java | 87 ++++++++++++++++------
 .../apache/sis/internal/gui/ResourceLoader.java    |  6 +-
 14 files changed, 91 insertions(+), 42 deletions(-)

diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageCanvas.java
b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageCanvas.java
index 4766527..3ccff0c 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageCanvas.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/CoverageCanvas.java
@@ -424,7 +424,7 @@ public class CoverageCanvas extends MapCanvasAWT {
                 @Override protected void failed() {
                     final Throwable ex = getException();
                     errorOccurred(ex);
-                    ExceptionReporter.canNotUseResource(ex);
+                    ExceptionReporter.canNotUseResource(fixedPane, ex);
                 }
 
                 /**
diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/GridError.java
b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/GridError.java
index 629a718..c801f79 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/GridError.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/GridError.java
@@ -116,7 +116,7 @@ final class GridError extends VBox {
      * Invoked when the user click on the "details" button.
      */
     private void showDetails() {
-        ExceptionReporter.show(Resources.format(Resources.Keys.ErrorDataAccess), header,
exception);
+        ExceptionReporter.show(this, Resources.format(Resources.Keys.ErrorDataAccess), header,
exception);
     }
 
     /**
diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/GridView.java
b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/GridView.java
index 14dc571..5593346 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/GridView.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/coverage/GridView.java
@@ -382,10 +382,11 @@ public class GridView extends Control {
         protected void failed() {
             terminated(null);
             final GridCoverageResource resource = request.resource;
+            final GridView owner = GridView.this;
             if (resource instanceof StoreListeners) {
-                ExceptionReporter.canNotReadFile(((StoreListeners) resource).getSourceName(),
getException());
+                ExceptionReporter.canNotReadFile(owner, ((StoreListeners) resource).getSourceName(),
getException());
             } else {
-                ExceptionReporter.canNotUseResource(getException());
+                ExceptionReporter.canNotUseResource(owner, getException());
             }
         }
 
diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/CopyAction.java
b/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/CopyAction.java
index acdc442..206c014 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/CopyAction.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/CopyAction.java
@@ -68,7 +68,7 @@ final class CopyAction implements EventHandler<ActionEvent> {
         try {
             path = URIDataStore.location(resource);
         } catch (DataStoreException e) {
-            ExceptionReporter.show(null, null, e);
+            ExceptionReporter.show(cell, null, null, e);
             return;
         }
         /*
diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/ResourceExplorer.java
b/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/ResourceExplorer.java
index bf7b835..226a2e5 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/ResourceExplorer.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/ResourceExplorer.java
@@ -235,7 +235,7 @@ public class ResourceExplorer extends WindowManager {
         /** Invoked if the tabs can not be built. */
         @Override protected void failed() {
             builder = null;
-            ExceptionReporter.show(this);
+            ExceptionReporter.show(getView(), this);
         }
 
         /** Should never happen, but defined as a safety. */
diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/ResourceTree.java
b/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/ResourceTree.java
index cc923b7..b498e1d 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/ResourceTree.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/ResourceTree.java
@@ -199,7 +199,7 @@ public class ResourceTree extends TreeView<Resource> {
                     addResource(existing);
                 } else {
                     loader.setOnSucceeded((event) -> addResource((Resource) event.getSource().getValue()));
-                    loader.setOnFailed(ExceptionReporter::show);
+                    loader.setOnFailed((event) -> ExceptionReporter.show(this, event));
                     BackgroundThreads.execute(loader);
                 }
             }
@@ -236,7 +236,7 @@ public class ResourceTree extends TreeView<Resource> {
                 final int start = url.lastIndexOf('/', url.length() - 2) + 1;
                 int stop = url.indexOf('?', start);
                 if (stop <= 0) stop = url.length();
-                ExceptionReporter.canNotReadFile(url.substring(start, stop), e);
+                ExceptionReporter.canNotReadFile(this, url.substring(start, stop), e);
             }
         }
         event.setDropCompleted(success);
@@ -268,7 +268,7 @@ public class ResourceTree extends TreeView<Resource> {
     public void removeAndClose(final Resource resource) {
         if (findOrRemove(resource, true)) {
             if (resource instanceof DataStore) {
-                ResourceLoader.removeAndClose((DataStore) resource);
+                ResourceLoader.removeAndClose((DataStore) resource, this);
             }
         }
     }
@@ -480,8 +480,9 @@ public class ResourceTree extends TreeView<Resource> {
                         more = new Button(Styles.ERROR_DETAILS_ICON);
                         more.setOnAction((e) -> {
                             final Resources localized = tree.localized();
-                            ExceptionReporter.show(localized.getString(Resources.Keys.ErrorDetails),
-                                                   localized.getString(Resources.Keys.CanNotReadResource),
failure);
+                            ExceptionReporter.show(tree,
+                                    localized.getString(Resources.Keys.ErrorDetails),
+                                    localized.getString(Resources.Keys.CanNotReadResource),
failure);
                         });
                     }
                 } else {
diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/map/MapCanvas.java b/application/sis-javafx/src/main/java/org/apache/sis/gui/map/MapCanvas.java
index dc66142..a1fdf82 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/gui/map/MapCanvas.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/map/MapCanvas.java
@@ -615,7 +615,7 @@ public abstract class MapCanvas extends PlanarCanvas {
             } catch (Exception e) {
                 errorOccurred(e);
                 final Resources i18n = Resources.forLocale(getLocale());
-                ExceptionReporter.show(null, i18n.getString(Resources.Keys.CanNotUseRefSys_1,
projection), e);
+                ExceptionReporter.show(fixedPane, null, i18n.getString(Resources.Keys.CanNotUseRefSys_1,
projection), e);
             }
         }
 
@@ -671,7 +671,7 @@ public abstract class MapCanvas extends PlanarCanvas {
             errorOccurred(e);
             final Locale locale = getLocale();
             final Resources i18n = Resources.forLocale(locale);
-            ExceptionReporter.show(null, i18n.getString(Resources.Keys.CanNotUseRefSys_1,
+            ExceptionReporter.show(fixedPane, null, i18n.getString(Resources.Keys.CanNotUseRefSys_1,
                                    IdentifiedObjects.getDisplayName(crs, locale)), e);
         }
     }
diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/map/MapMenu.java b/application/sis-javafx/src/main/java/org/apache/sis/gui/map/MapMenu.java
index 4e4f41c..79e3045 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/gui/map/MapMenu.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/map/MapMenu.java
@@ -166,7 +166,7 @@ public class MapMenu extends ContextMenu {
                 content.putString(text);
                 Clipboard.getSystemClipboard().setContent(content);
             } catch (TransformException | RuntimeException e) {
-                ExceptionReporter.show(((MenuItem) event.getSource()).getText(), null, e);
+                ExceptionReporter.show(getOwnerWindow(), ((MenuItem) event.getSource()).getText(),
null, e);
             }
         });
         getItems().add(coordinates);
diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/map/StatusBar.java b/application/sis-javafx/src/main/java/org/apache/sis/gui/map/StatusBar.java
index 876db5d..a640b73 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/gui/map/StatusBar.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/map/StatusBar.java
@@ -1286,7 +1286,7 @@ public class StatusBar extends Widget implements EventHandler<MouseEvent>
{
             }
             final String alert = text;
             more = new Button(Styles.ERROR_DETAILS_ICON);
-            more.setOnAction((e) -> ExceptionReporter.show(
+            more.setOnAction((e) -> ExceptionReporter.show(getView(),
                     Resources.forLocale(locale).getString(Resources.Keys.ErrorDetails), alert,
details));
         }
         message.setVisible(text != null);
diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/metadata/StandardMetadataTree.java
b/application/sis-javafx/src/main/java/org/apache/sis/gui/metadata/StandardMetadataTree.java
index 0558e6a..10832ba 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/gui/metadata/StandardMetadataTree.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/metadata/StandardMetadataTree.java
@@ -228,8 +228,8 @@ public class StandardMetadataTree extends MetadataTree {
                         }
                     } catch (Exception e) {
                         final Resources localized = Resources.forLocale(((MetadataTree) getTreeTableView()).getLocale());
-                        ExceptionReporter.show(localized.getString(Resources.Keys.ErrorExportingData),
-                                               localized.getString(Resources.Keys.CanNotCreateXML),
e);
+                        ExceptionReporter.show(this, localized.getString(Resources.Keys.ErrorExportingData),
+                                                     localized.getString(Resources.Keys.CanNotCreateXML),
e);
                         return;
                     }
                     content.putString(text);
diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/referencing/CRSChooser.java
b/application/sis-javafx/src/main/java/org/apache/sis/gui/referencing/CRSChooser.java
index 8ff7d95..03a5200 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/gui/referencing/CRSChooser.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/referencing/CRSChooser.java
@@ -417,7 +417,7 @@ public class CRSChooser extends Dialog<CoordinateReferenceSystem>
{
             if (code != null) try {
                 return getAuthorityCodes().getFactory().createCoordinateReferenceSystem(code.code);
             } catch (FactoryException e) {
-                ExceptionReporter.canNotCreateCRS(code.code, e);
+                ExceptionReporter.canNotCreateCRS(getOwner(), code.code, e);
             }
         }
         return null;
diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/referencing/RecentReferenceSystems.java
b/application/sis-javafx/src/main/java/org/apache/sis/gui/referencing/RecentReferenceSystems.java
index 269cac7..95b74fb 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/gui/referencing/RecentReferenceSystems.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/referencing/RecentReferenceSystems.java
@@ -556,7 +556,7 @@ public class RecentReferenceSystems {
 
                 /** Should never happen. */
                 @Override protected void failed() {
-                    ExceptionReporter.show(this);
+                    ExceptionReporter.show(null, this);
                 }
 
                 /** Sets the {@link ChoiceBox} content to the list computed in background
thread. */
diff --git a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/ExceptionReporter.java
b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/ExceptionReporter.java
index f3b621e..c0591c0 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/ExceptionReporter.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/ExceptionReporter.java
@@ -25,6 +25,9 @@ import javafx.concurrent.WorkerStateEvent;
 import javafx.event.ActionEvent;
 import javafx.geometry.Insets;
 import javafx.geometry.Pos;
+import javafx.stage.Window;
+import javafx.scene.Node;
+import javafx.scene.Scene;
 import javafx.scene.control.Alert;
 import javafx.scene.control.ContextMenu;
 import javafx.scene.control.DialogPane;
@@ -33,6 +36,7 @@ import javafx.scene.control.Menu;
 import javafx.scene.input.Clipboard;
 import javafx.scene.input.ClipboardContent;
 import javafx.scene.layout.Region;
+import org.apache.sis.gui.Widget;
 import org.apache.sis.util.Classes;
 
 
@@ -49,7 +53,7 @@ import org.apache.sis.util.Classes;
  * @since   1.1
  * @module
  */
-public final class ExceptionReporter {
+public final class ExceptionReporter extends Widget {
     /**
      * The margin to use for the stack trace. We add some spaces on the top and left sides.
      */
@@ -70,7 +74,6 @@ public final class ExceptionReporter {
      *
      * @param  exception  the error to report.
      */
-    @SuppressWarnings("ThisEscapedInObjectConstruction")
     public ExceptionReporter(final Throwable exception) {
         this.exception = exception;
         trace = new Label(getStackTrace(exception));
@@ -111,22 +114,40 @@ public final class ExceptionReporter {
      *
      * @return the stack trace viewer.
      */
+    @Override
     public final Region getView() {
         return trace;
     }
 
     /**
+     * Returns the window where is located the given JavaFX control.
+     *
+     * @param  control  the JavaFX control for which to get the window.
+     * @return window containing the given control, or {@code null} if none.
+     */
+    private static Window getWindow(final Node control) {
+        if (control != null) {
+            final Scene scene = control.getScene();
+            if (scene != null) {
+                return scene.getWindow();
+            }
+        }
+        return null;
+    }
+
+    /**
      * Shows the reporter for the exception that occurred during a task.
      *
+     * @param  owner  control in the window which will own the dialog, or {@code null} if
unknown.
      * @param  event  an event for the task where an error occurred.
      */
-    public static void show(final WorkerStateEvent event) {
+    public static void show(final Node owner, final WorkerStateEvent event) {
         final Worker<?> worker = event.getSource();
         final Throwable exception = worker.getException();
         if (worker instanceof ResourceLoader) {
-            canNotReadFile(((ResourceLoader) worker).getFileName(), exception);
+            canNotReadFile(owner, ((ResourceLoader) worker).getFileName(), exception);
         } else {
-            show((short) 0, (short) 0, null, exception);
+            show(getWindow(owner), (short) 0, (short) 0, null, exception);
         }
     }
 
@@ -134,55 +155,62 @@ public final class ExceptionReporter {
      * Shows the reporter for a failure to read a file.
      * This method does nothing if the exception is null.
      *
+     * @param  owner      control in the window which will own the dialog, or {@code null}
if unknown.
      * @param  file       the file that can not be read.
      * @param  exception  the error that occurred.
      */
-    public static void canNotReadFile(final String file, final Throwable exception) {
-        show(Resources.Keys.ErrorOpeningFile, Resources.Keys.CanNotReadFile_1, new Object[]
{file}, exception);
+    public static void canNotReadFile(final Node owner, final String file, final Throwable
exception) {
+        show(getWindow(owner), Resources.Keys.ErrorOpeningFile, Resources.Keys.CanNotReadFile_1,
new Object[] {file}, exception);
     }
 
     /**
      * Shows the reporter for a failure to close a file.
      * This method does nothing if the exception is null.
      *
+     * @param  owner      control in the window which will own the dialog, or {@code null}
if unknown.
      * @param  file       the file that can not be closed.
      * @param  exception  the error that occurred.
      */
-    public static void canNotCloseFile(final String file, final Throwable exception) {
-        show(Resources.Keys.ErrorClosingFile, Resources.Keys.CanNotClose_1, new Object[]
{file}, exception);
+    public static void canNotCloseFile(final Node owner, final String file, final Throwable
exception) {
+        show(getWindow(owner), Resources.Keys.ErrorClosingFile, Resources.Keys.CanNotClose_1,
new Object[] {file}, exception);
     }
 
     /**
      * Shows the reporter for a failure to create a CRS.
      * This method does nothing if the exception is null.
      *
+     * @param  owner      the owner window of the dialog, or {@code null} if none.
      * @param  code       code of the CRS that can not be created.
      * @param  exception  the error that occurred.
      */
-    public static void canNotCreateCRS(final String code, final Throwable exception) {
-        show(Resources.Keys.ErrorCreatingCRS, Resources.Keys.CanNotCreateCRS_1, new Object[]
{code}, exception);
+    public static void canNotCreateCRS(final Window owner, final String code, final Throwable
exception) {
+        show(owner, Resources.Keys.ErrorCreatingCRS, Resources.Keys.CanNotCreateCRS_1, new
Object[] {code}, exception);
     }
 
     /**
      * Shows the reporter for a failure to use a store resource.
      * This method does nothing if the exception is null.
      *
+     * @param  owner      control in the window which will own the dialog, or {@code null}
if unknown.
      * @param  exception  the error that occurred.
      */
-    public static void canNotUseResource(final Throwable exception) {
-        show(Resources.Keys.ErrorDataAccess, Resources.Keys.ErrorDataAccess, new Object[0],
exception);
+    public static void canNotUseResource(final Node owner, final Throwable exception) {
+        show(getWindow(owner), Resources.Keys.ErrorDataAccess, Resources.Keys.ErrorDataAccess,
new Object[0], exception);
     }
 
     /**
      * Constructs and shows the exception reporter. The title and text are keys from the
{@link Resources}.
      * If the title and/or text are 0, then the {@link Alert} default title and text will
be used.
      *
+     * @param owner       the owner window of the dialog, or {@code null} if none.
      * @param title       {@link Resources.Keys} of the title, or 0 if unknown.
      * @param text        {@link Resources.Keys} of the text (possibly with arguments), or
0 if unknown.
      * @param arguments   the arguments for creating the text identified by the {@code text}
key.
      * @param exception   the exception to report, or {@code null} if none.
      */
-    private static void show(final short title, final short text, final Object[] arguments,
final Throwable exception) {
+    private static void show(final Window owner, final short title,
+            final short text, final Object[] arguments, final Throwable exception)
+    {
         if (exception != null) {
             String t = null, h = null;
             if ((title | text) != 0) {
@@ -190,7 +218,7 @@ public final class ExceptionReporter {
                 if (title != 0) t = resources.getString(title);
                 if (text  != 0) h = resources.getString(text, arguments);
             }
-            show(t, h, exception);
+            show(owner, t, h, exception);
         }
     }
 
@@ -198,13 +226,28 @@ public final class ExceptionReporter {
      * Constructs and shows the exception reporter.
      * This method can be invoked from any thread.
      *
-     * @param title      the window the title, or {@code null} if none.
+     * @param owner      control in the window which will own the dialog, or {@code null}
if unknown.
+     * @param title      the window title, or {@code null} if none.
+     * @param text       the text in the dialog box, or {@code null} if none.
+     * @param exception  the exception to report.
+     */
+    public static void show(final Node owner, final String title, final String text, final
Throwable exception) {
+        show(getWindow(owner), title, text, exception);
+    }
+
+    /**
+     * Constructs and shows the exception reporter.
+     * This method can be invoked from any thread.
+     * All other {@code show(…)} methods in this class ultimately delegate to this method.
+     *
+     * @param owner      the owner window of the dialog, or {@code null} if none.
+     * @param title      the window title, or {@code null} if none.
      * @param text       the text in the dialog box, or {@code null} if none.
      * @param exception  the exception to report.
      */
-    public static void show(final String title, final String text, final Throwable exception)
{
+    public static void show(final Window owner, final String title, final String text, final
Throwable exception) {
         if (!Platform.isFxApplicationThread()) {
-            Platform.runLater(() -> show(title, text, exception));
+            Platform.runLater(() -> show(owner, title, text, exception));
             return;
         }
         String message = exception.getLocalizedMessage();
@@ -215,6 +258,7 @@ public final class ExceptionReporter {
         if (title != null) alert.setTitle(title);
         if (text  != null) alert.setHeaderText(text);
         alert.setContentText(message);
+        alert.initOwner(owner);
         final DialogPane pane = alert.getDialogPane();
         pane.setExpandableContent(new ExceptionReporter(exception).trace);
         pane.setPrefWidth(650);
@@ -224,10 +268,11 @@ public final class ExceptionReporter {
     /**
      * Constructs and shows the exception reporter for the given task.
      *
-     * @param  task  the task that failed.
+     * @param  owner  control in the window which will own the dialog, or {@code null} if
unknown.
+     * @param  task   the task that failed.
      */
-    public static void show(final Task<?> task) {
-        show(task.getTitle(), null, task.getException());
+    public static void show(final Node owner, final Task<?> task) {
+        show(owner, task.getTitle(), null, task.getException());
     }
 
     /**
diff --git a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/ResourceLoader.java
b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/ResourceLoader.java
index 29db505..988a820 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/ResourceLoader.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/ResourceLoader.java
@@ -29,6 +29,7 @@ import java.util.stream.Stream;
 import javafx.concurrent.Task;
 import javafx.event.EventHandler;
 import javafx.application.Platform;
+import javafx.scene.Node;
 import org.apache.sis.storage.Resource;
 import org.apache.sis.storage.StorageConnector;
 import org.apache.sis.storage.DataStoreException;
@@ -189,10 +190,11 @@ public final class ResourceLoader extends Task<Resource> {
      * has been removed from the cache, the close action is performed in a background thread.
      *
      * @param  toClose  the data store to remove from the cache and to close.
+     * @param  owner    the node invoking this method, used if a dialog must be shown.
      * @return {@code true} if the value has been removed from the cache, or {@code false}
      *         if it has not been found. Note that the data store is closed in all cases.
      */
-    public static boolean removeAndClose(final DataStore toClose) {
+    public static boolean removeAndClose(final DataStore toClose, final Node owner) {
         /*
          * A simpler code would be as below, but can not be used at this time because our
          * Cache.entrySet() implementation does not support the Iterator.remove() operation.
@@ -210,7 +212,7 @@ public final class ResourceLoader extends Task<Resource> {
                 toClose.close();
             } catch (final Throwable e) {
                 Platform.runLater(() -> {
-                    ExceptionReporter.canNotCloseFile(toClose.getDisplayName(), e);
+                    ExceptionReporter.canNotCloseFile(owner, toClose.getDisplayName(), e);
                 });
             }
         });


Mime
View raw message