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
The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
new 7e1fe6f Show the exception in the table when an error occurred while
loading the data.
7e1fe6f is described below
commit 7e1fe6f5e613c251c261a6f8fa2ebea10ddb1ba9
Author: Martin Desruisseaux <[email protected]>
AuthorDate: Thu Nov 7 09:59:01 2019 +0100
Show the exception in the table when an error occurred while loading the
data.
---
.../org/apache/sis/gui/dataset/FeatureList.java | 3 ++
.../org/apache/sis/gui/dataset/FeatureLoader.java | 50 ++++++++++++----------
.../org/apache/sis/gui/dataset/FeatureTable.java | 33 ++++++++++++--
.../org/apache/sis/gui/dataset/ResourceTree.java | 3 ++
.../apache/sis/internal/gui/ExceptionReporter.java | 2 +
ide-project/NetBeans/nbproject/project.properties | 2 +-
6 files changed, 65 insertions(+), 28 deletions(-)
diff --git
a/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/FeatureList.java
b/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/FeatureList.java
index 9d4144e..1842ff3 100644
---
a/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/FeatureList.java
+++
b/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/FeatureList.java
@@ -246,6 +246,9 @@ final class FeatureList extends ObservableListBase<Feature>
{
* If we can not load more features stop the reading process.
*
* @todo Add some message in the widget for warning the user.
+ * Proposal: set MAXIMUM_ROWS to MAX_INTEGER - 1 and reserve the
last table row for a message.
+ * That row would span all columns. That row could also be used for
exception message when the
+ * exception did not happened at the file beginning.
*/
private void checkOverflow() {
if (validCount >= MAXIMUM_ROWS) {
diff --git
a/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/FeatureLoader.java
b/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/FeatureLoader.java
index 2e6bc27..c147cc9 100644
---
a/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/FeatureLoader.java
+++
b/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/FeatureLoader.java
@@ -194,7 +194,10 @@ final class FeatureLoader extends Task<Boolean> implements
Consumer<Feature> {
try {
get(); // Wait for the task to stop
before to close the stream.
} catch (InterruptedException | CancellationException e) {
- // Someone does not want to let us wait before closing.
+ /*
+ * Someone does not want to let us wait before closing. But log
the exception so that
+ * if a ClosedChannelException happens in another thread, we can
understand why.
+ */
FeatureTable.recoverableException("interrupt", e);
} catch (ExecutionException e) {
error = e.getCause();
@@ -215,21 +218,14 @@ final class FeatureLoader extends Task<Boolean>
implements Consumer<Feature> {
}
/**
- * Returns the list where to add features.
- * All methods on the returned list shall be invoked from JavaFX thread.
- */
- private FeatureList destination() {
- return (FeatureList) table.getItems();
- }
-
- /**
* Invoked in JavaFX thread after new feature instances are ready.
* This method adds the new rows in the table and prepares another
* task for loading the next batch of features when needed.
*/
@Override
protected void succeeded() {
- final FeatureList addTo = destination();
+ super.succeeded();
+ final FeatureList addTo = table.getFeatureList();
if (addTo.isCurrentLoader(this)) {
final boolean hasMore = getValue();
if (initializer != null) {
@@ -256,14 +252,30 @@ final class FeatureLoader extends Task<Boolean>
implements Consumer<Feature> {
/**
* Invoked in JavaFX thread when a loading process has been cancelled or
failed.
- * This method closes the {@link FeatureLoader} if it did not closed
itself,
- * then eventually shows the error in the table area.
*
* @see FeatureTable#interrupt()
*/
@Override
protected void cancelled() {
- final FeatureList addTo = destination();
+ super.cancelled();
+ stop("cancelled");
+ }
+
+ /**
+ * Invoked in JavaFX thread when a loading process failed.
+ */
+ @Override
+ protected void failed() {
+ super.failed();
+ stop("failed");
+ }
+
+ /**
+ * Closes the {@link FeatureLoader} if it did not closed itself,
+ * then eventually shows the error in the table area.
+ */
+ private void stop(final String caller) {
+ final FeatureList addTo = table.getFeatureList();
final boolean isCurrentLoader = addTo.isCurrentLoader(this);
if (isCurrentLoader) {
addTo.setNextPage(null);
@@ -285,23 +297,15 @@ final class FeatureLoader extends Task<Boolean>
implements Consumer<Feature> {
}
if (exception != null) {
if (isCurrentLoader) {
- exception.printStackTrace(); // TODO: write somewhere
in the widget.
+ table.setException(exception);
} else {
// Since we moved to other data, not appropriate anymore for
current widget.
- FeatureTable.unexpectedException("cancelled", exception);
+ FeatureTable.unexpectedException(caller, exception);
}
}
}
/**
- * Invoked in JavaFX thread when a loading process failed.
- */
- @Override
- protected void failed() {
- cancelled();
- }
-
- /**
* Invoked when the feature type may have been found. If the given type is
non-null,
* then this method delegates to {@link
FeatureTable#setFeatureType(FeatureType)} in
* the JavaFX thread. This will erase the previous content and prepare new
columns.
diff --git
a/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/FeatureTable.java
b/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/FeatureTable.java
index c26e143..6b2c219 100644
---
a/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/FeatureTable.java
+++
b/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/FeatureTable.java
@@ -24,15 +24,19 @@ import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.beans.property.ReadOnlyObjectWrapper;
import javafx.beans.value.ObservableValue;
+import javafx.scene.layout.StackPane;
+import javafx.scene.layout.Region;
+import javafx.geometry.Pos;
import javafx.util.Callback;
import org.opengis.feature.Feature;
import org.opengis.feature.FeatureType;
import org.opengis.feature.PropertyType;
import org.opengis.util.InternationalString;
import org.apache.sis.internal.util.Strings;
-import org.apache.sis.storage.FeatureSet;
import org.apache.sis.internal.system.Modules;
import org.apache.sis.util.logging.Logging;
+import org.apache.sis.storage.FeatureSet;
+import org.apache.sis.internal.gui.ExceptionReporter;
/**
@@ -83,6 +87,14 @@ public class FeatureTable extends TableView<Feature> {
}
/**
+ * Returns the list where to add features.
+ * All methods on the returned list shall be invoked from JavaFX thread.
+ */
+ final FeatureList getFeatureList() {
+ return (FeatureList) getItems();
+ }
+
+ /**
* Sets the features to show in this table. This method loads an arbitrary
amount of
* features in a background thread. It does not load all features if the
feature set
* is large, unless the user scroll down.
@@ -96,10 +108,11 @@ public class FeatureTable extends TableView<Feature> {
* @param features the features to show in this table, or {@code null}
if none.
*/
public void setFeatures(final FeatureSet features) {
- final FeatureList items = (FeatureList) getItems();
+ final FeatureList items = getFeatureList();
if (!items.setFeatures(this, features)) {
featureType = null;
getColumns().clear();
+ setPlaceholder(null);
}
}
@@ -109,7 +122,8 @@ public class FeatureTable extends TableView<Feature> {
* determined from the given type.
*/
final void setFeatureType(final FeatureType type) {
- ((FeatureList) getItems()).clearUnsafe();
+ setPlaceholder(null);
+ getFeatureList().clearUnsafe();
if (type != null && !type.equals(featureType)) {
final Collection<? extends PropertyType> properties =
type.getProperties(true);
final List<TableColumn<Feature,?>> columns = new
ArrayList<>(properties.size());
@@ -177,7 +191,18 @@ public class FeatureTable extends TableView<Feature> {
* This method returns immediately; the release of resources happens in a
background thread.
*/
public void interrupt() {
- ((FeatureList) getItems()).interrupt();
+ getFeatureList().interrupt();
+ }
+
+ /**
+ * Replaces the table content by an exception message.
+ * This method is invoked after a loading process failed.
+ */
+ final void setException(final Throwable exception) {
+ getFeatureList().clearUnsafe();
+ final Region trace = new ExceptionReporter(exception).getView();
+ StackPane.setAlignment(trace, Pos.TOP_LEFT);
+ setPlaceholder(trace);
}
/**
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 f3b7593..47b6167 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
@@ -75,6 +75,9 @@ import org.apache.sis.internal.util.Strings;
* of {@link DataStore}). There is not yet a mechanism for keeping it open if
the resource is shared
* by another {@link ResourceTree} instance.
*
+ * @todo Listen to warnings and save log records in a separated collection for
each data store.
+ * Add to the contextual menu an option for viewing the log records of
selected data store.
+ *
* @author Johann Sorel (Geomatys)
* @author Martin Desruisseaux (Geomatys)
* @version 1.1
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 326c2de..d48274f 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
@@ -23,6 +23,7 @@ import javafx.concurrent.WorkerStateEvent;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
+import javafx.geometry.Pos;
import javafx.scene.control.Alert;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.DialogPane;
@@ -64,6 +65,7 @@ public final class ExceptionReporter implements
EventHandler<ActionEvent> {
*/
public ExceptionReporter(final Throwable exception) {
trace = new Label(getStackTrace(exception));
+ trace.setAlignment(Pos.TOP_LEFT);
trace.setPadding(MARGIN);
final Resources localized = Resources.getInstance();
diff --git a/ide-project/NetBeans/nbproject/project.properties
b/ide-project/NetBeans/nbproject/project.properties
index 2a6c05b..70c2c30 100644
--- a/ide-project/NetBeans/nbproject/project.properties
+++ b/ide-project/NetBeans/nbproject/project.properties
@@ -31,7 +31,7 @@ work.dir.to.root = ../..
#
includes = **
excludes =
-main.class =
+main.class = org.apache.sis.gui.DataViewer
manifest.file = manifest.mf
project.license = apache20
project.licensePath = ../LicenseHeader.txt