sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 02/03: Add a button for getting more information about an error while loading resources. Fix exceptions in netCDF reader which occurred when a variable is not a coverage.
Date Tue, 07 Apr 2020 17:01:41 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 b3ba51b0e78a774a18890f88ff65dcf22eaf2d41
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Tue Apr 7 14:09:39 2020 +0200

    Add a button for getting more information about an error while loading resources.
    Fix exceptions in netCDF reader which occurred when a variable is not a coverage.
---
 .../org/apache/sis/gui/dataset/ResourceTree.java   | 20 ++++++--
 .../org/apache/sis/internal/gui/Resources.java     | 10 ++++
 .../apache/sis/internal/gui/Resources.properties   |  2 +
 .../sis/internal/gui/Resources_fr.properties       |  2 +
 .../java/org/apache/sis/internal/gui/Styles.java   |  5 ++
 .../java/org/apache/sis/internal/netcdf/Grid.java  | 10 ++++
 .../org/apache/sis/internal/netcdf/Variable.java   | 54 +++++++++++-----------
 7 files changed, 74 insertions(+), 29 deletions(-)

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 7a73429..8be8853 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
@@ -30,6 +30,7 @@ import javafx.application.Platform;
 import javafx.concurrent.Task;
 import javafx.collections.ObservableList;
 import javafx.event.ActionEvent;
+import javafx.scene.control.Button;
 import javafx.scene.control.ContextMenu;
 import javafx.scene.control.TreeCell;
 import javafx.scene.control.TreeItem;
@@ -441,15 +442,27 @@ public class ResourceTree extends TreeView<Resource> {
             super.updateItem(resource, empty);          // Mandatory according JavaFX documentation.
             Color color = Styles.NORMAL_TEXT;
             String text = null;
+            Button more = null;
             if (!empty) {
                 if (resource == PseudoResource.LOADING) {
                     color = Styles.LOADING_TEXT;
-                    if (tree != null) text = tree.localized.getString(Resources.Keys.Loading);
+                    if (tree != null) {
+                        text = tree.localized.getString(Resources.Keys.Loading);
+                    }
                 } else if (resource instanceof Unloadable) {
                     color = Styles.ERROR_TEXT;
-                    if (tree != null) text = tree.string(((Unloadable) resource).failure);
+                    if (tree != null) {
+                        final Throwable failure = ((Unloadable) resource).failure;
+                        text = tree.string(failure);
+                        more = new Button(Styles.ERROR_DETAILS);
+                        more.setOnAction((e) -> ExceptionReporter.show(
+                                tree.localized.getString(Resources.Keys.ErrorDetails),
+                                tree.localized.getString(Resources.Keys.CanNotReadResource),
failure));
+                    }
                 } else {
-                    if (tree != null) text = tree.getTitle(resource, true);
+                    if (tree != null) {
+                        text = tree.getTitle(resource, true);
+                    }
                 }
             }
             setTextFill(isSelected() ? Styles.SELECTED_TEXT : color);
@@ -461,6 +474,7 @@ public class ResourceTree extends TreeView<Resource> {
              */
             if (tree != null) {
                 setText(text);
+                setGraphic(more);
                 ContextMenu menu = null;
                 if (tree.findOrRemove(resource, false)) {
                     menu = getContextMenu();
diff --git a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources.java
b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources.java
index ff0a748..1356c30 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources.java
@@ -96,6 +96,11 @@ public final class Resources extends IndexedResourceBundle {
         public static final short CanNotReadFile_1 = 5;
 
         /**
+         * A resource contained in the file can not be read. The cause is given below.
+         */
+        public static final short CanNotReadResource = 55;
+
+        /**
          * Cell geometry:
          */
         public static final short CellGeometry = 15;
@@ -161,6 +166,11 @@ public final class Resources extends IndexedResourceBundle {
         public static final short ErrorDataAccess = 40;
 
         /**
+         * Details about error
+         */
+        public static final short ErrorDetails = 56;
+
+        /**
          * Error exporting data
          */
         public static final short ErrorExportingData = 48;
diff --git a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources.properties
b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources.properties
index d9f07a1..dd5714f 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources.properties
+++ b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources.properties
@@ -27,6 +27,7 @@ CanNotReadFile_1       = Can not open \u201c{0}\u201d.
 CanNotClose_1          = Can not close \u201c{0}\u201d. Data may be lost.
 CanNotCreateCRS_1      = Can not create reference system \u201c{0}\u201d.
 CanNotCreateXML        = Can not create XML document.
+CanNotReadResource     = A resource contained in the file can not be read. The cause is given
below.
 CellGeometry           = Cell geometry:
 Close                  = Close
 Copy                   = Copy
@@ -38,6 +39,7 @@ Data                   = Data
 Date                   = Date:
 Dimensions             = Dimensions:
 Display                = Display
+ErrorDetails           = Details about error
 ErrorExportingData     = Error exporting data
 ErrorOpeningFile       = Error opening file
 ErrorClosingFile       = Error closing file
diff --git a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources_fr.properties
b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources_fr.properties
index 4b7c231..c8cd341 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources_fr.properties
+++ b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources_fr.properties
@@ -32,6 +32,7 @@ CanNotReadFile_1       = Ne peut pas ouvrir \u00ab\u202f{0}\u202f\u00bb.
 CanNotClose_1          = Ne peut pas fermer \u00ab\u202f{0}\u202f\u00bb. Il pourrait y avoir
une perte de donn\u00e9es.
 CanNotCreateCRS_1      = Ne peut pas cr\u00e9er le syst\u00e8me de r\u00e9f\u00e9rence \u00ab\u202f{0}\u202f\u00bb.
 CanNotCreateXML        = Ne peut pas cr\u00e9er le document XML.
+CanNotReadResource     = Une ressource contenue dans le fichier ne peut pas \u00eatre lue.
La cause est donn\u00e9e ci-dessous.
 CellGeometry           = G\u00e9om\u00e9trie des cellules\u00a0:
 Close                  = Fermer
 Copy                   = Copier
@@ -43,6 +44,7 @@ Data                   = Donn\u00e9es
 Date                   = Date\u00a0:
 Dimensions             = Dimensions\u00a0:
 Display                = Affichage
+ErrorDetails           = D\u00e9tails \u00e0 propos de l\u2019erreur
 ErrorExportingData     = Erreur \u00e0 l\u2019exportation de donn\u00e9es
 ErrorOpeningFile       = Erreur \u00e0 l\u2019ouverture du fichier
 ErrorClosingFile       = Erreur \u00e0 la fermeture du fichier
diff --git a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Styles.java
b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Styles.java
index 8e6f5e7..a7c1379 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Styles.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Styles.java
@@ -101,6 +101,11 @@ public final class Styles {
             new Background(new BackgroundFill(Color.LIGHTPINK, null, null));
 
     /**
+     * The Unicode character to put in a button for requesting more information about an
error.
+     */
+    public static final String ERROR_DETAILS = "ℹ";
+
+    /**
      * Do not allow instantiation of this class.
      */
     private Styles() {
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Grid.java b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Grid.java
index dce6940..8b65d06 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Grid.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Grid.java
@@ -472,6 +472,16 @@ findFree:       for (int srcDim : axis.sourceDimensions) {
                 }
             }
             /*
+             * If at least one `sourceDimensions` is undefined, the variable is maybe not
a grid.
+             * It happens for example if the variable is a trajectory, in which case we have
two
+             * CRS dimensions (e.g. latitude and longitude) but only one variable dimension;
+             * the first CRS dimension has been associated to that variable and the other
CRS
+             * dimension is orphan.
+             */
+            for (final int s : sourceDimensions) {
+                if (s < 0) return null;
+            }
+            /*
              * Final transform, as the concatenation of the non-linear transforms followed
by the affine transform.
              * We concatenate the affine transform last because it may change axis order.
              */
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Variable.java
b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Variable.java
index bcee136..31e3238 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Variable.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Variable.java
@@ -720,35 +720,37 @@ public abstract class Variable extends Node {
                  * needs to be applied.
                  */
                 GridGeometry grid = info.getGridGeometry(decoder);
-                if (grid.isDefined(GridGeometry.EXTENT)) {
-                    GridExtent extent = grid.getExtent();
-                    final long[] sizes = new long[extent.getDimension()];
-                    boolean needsResize = false;
-                    for (int i=sizes.length; --i >= 0;) {
-                        final int d = (sizes.length - 1) - i;               // Convert "natural
order" index into netCDF index.
-                        sizes[i] = dimensions.get(d).length();
-                        if (!needsResize) {
-                            needsResize = (sizes[i] != extent.getSize(i));
+                if (grid != null) {
+                    if (grid.isDefined(GridGeometry.EXTENT)) {
+                        GridExtent extent = grid.getExtent();
+                        final long[] sizes = new long[extent.getDimension()];
+                        boolean needsResize = false;
+                        for (int i=sizes.length; --i >= 0;) {
+                            final int d = (sizes.length - 1) - i;               // Convert
"natural order" index into netCDF index.
+                            sizes[i] = dimensions.get(d).length();
+                            if (!needsResize) {
+                                needsResize = (sizes[i] != extent.getSize(i));
+                            }
                         }
-                    }
-                    if (needsResize) {
-                        final double[] dataToGridIndices = adjustment.dataToGridIndices();
-                        if (dataToGridIndices == null || dataToGridIndices.length < sizes.length)
{
-                            warning(Variable.class, "getGridGeometry", Resources.Keys.ResamplingIntervalNotFound_2,
getFilename(), getName());
-                            return null;
+                        if (needsResize) {
+                            final double[] dataToGridIndices = adjustment.dataToGridIndices();
+                            if (dataToGridIndices == null || dataToGridIndices.length <
sizes.length) {
+                                warning(Variable.class, "getGridGeometry", Resources.Keys.ResamplingIntervalNotFound_2,
getFilename(), getName());
+                                return null;
+                            }
+                            extent = extent.resize(sizes);
+                            grid = grid.derive().resize(extent, dataToGridIndices).build();
                         }
-                        extent = extent.resize(sizes);
-                        grid = grid.derive().resize(extent, dataToGridIndices).build();
                     }
-                }
-                /*
-                 * At this point we finished to build a grid geometry from the information
provided by axes.
-                 * If there is grid mapping attributes (e.g. "EPSG_code", "ESRI_pe_string",
"GeoTransform",
-                 * "spatial_ref", etc.), substitute some parts of the grid geometry by the
parts built from
-                 * those attributes.
-                 */
-                if (gridMapping != null) {
-                    grid = gridMapping.adaptGridCRS(this, grid, info.getAnchor());
+                    /*
+                     * At this point we finished to build a grid geometry from the information
provided by axes.
+                     * If there is grid mapping attributes (e.g. "EPSG_code", "ESRI_pe_string",
"GeoTransform",
+                     * "spatial_ref", etc.), substitute some parts of the grid geometry by
the parts built from
+                     * those attributes.
+                     */
+                    if (gridMapping != null) {
+                        grid = gridMapping.adaptGridCRS(this, grid, info.getAnchor());
+                    }
                 }
                 gridGeometry = grid;
             } else if (gridMapping != null) {


Mime
View raw message