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 eae7522921b6c7a54a9b74e208fc7d9cc55d95f5
Author: Martin Desruisseaux <martin.desruisse...@geomatys.com>
AuthorDate: Wed Oct 27 11:24:31 2021 +0200

    Remove a background thread that does not seem to be necessary anymore.
---
 .../apache/sis/gui/dataset/ResourceExplorer.java   | 73 +---------------------
 .../org/apache/sis/gui/dataset/package-info.java   |  6 +-
 .../apache/sis/internal/gui/BackgroundThreads.java |  7 ---
 3 files changed, 5 insertions(+), 81 deletions(-)

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 b19331f..aed5ecf 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
@@ -49,7 +49,6 @@ import org.apache.sis.util.collection.TableColumn;
 import org.apache.sis.util.resources.Vocabulary;
 import org.apache.sis.internal.gui.Resources;
 import org.apache.sis.internal.gui.BackgroundThreads;
-import org.apache.sis.internal.gui.ExceptionReporter;
 import org.apache.sis.internal.gui.LogHandler;
 
 
@@ -58,7 +57,7 @@ import org.apache.sis.internal.gui.LogHandler;
  *
  * @author  Smaniotto Enzo (GSoC)
  * @author  Martin Desruisseaux (Geomatys)
- * @version 1.1
+ * @version 1.2
  * @since   1.1
  * @module
  */
@@ -133,12 +132,6 @@ public class ResourceExplorer extends WindowManager {
     private double dividerPosition;
 
     /**
-     * Used for building {@link #viewTab} and {@link #tableTab} when first 
needed.
-     * This is {@code null} the rest of the time.
-     */
-    private transient DataTabBuilder builder;
-
-    /**
      * Creates a new panel for exploring resources.
      */
     public ResourceExplorer() {
@@ -197,58 +190,6 @@ public class ResourceExplorer extends WindowManager {
          */
         viewTab .selectedProperty().addListener((p,o,n) -> dataTabShown(n, 
true));
         tableTab.selectedProperty().addListener((p,o,n) -> dataTabShown(n, 
false));
-        /*
-         * Optional execution in advance of a potentially slow operation. If 
`PRELOAD` is `false`,
-         * then the data tabs will be initialized only the first time that one 
of those tabs is
-         * visible at the same time that a resource is selected in the 
resources explorer.
-         */
-        if (BackgroundThreads.PRELOAD) {
-            builder = new DataTabBuilder(null);
-            BackgroundThreads.execute(builder);
-        }
-    }
-
-    /**
-     * A background task for building the content of {@link #viewTab} and 
{@link #tableTab} when first needed.
-     * This task does not load data, it is only for building the GUI. This 
operation is longer for those tabs
-     * when built for the first time.
-     */
-    private final class DataTabBuilder extends Task<CoverageExplorer> {
-        /**
-         * The resource to show after construction is completed, or {@code 
null} if none.
-         */
-        volatile Resource resource;
-
-        /**
-         * Creates a new data tabs builder. The given resource will be shown 
after
-         * the tabs are ready, unless {@link #resource} is modified after 
construction.
-         */
-        DataTabBuilder(final Resource resource) {
-            this.resource = resource;
-        }
-
-        /** Builds the tabs GUI components in a background thread. */
-        @Override protected CoverageExplorer call() {
-            return new CoverageExplorer();
-        }
-
-        /** Shows the resource after the tabs GUI are built. */
-        @Override protected void succeeded() {
-            builder  = null;
-            coverage = getValue();
-            updateDataTab(resource, true);
-        }
-
-        /** Invoked if the tabs can not be built. */
-        @Override protected void failed() {
-            builder = null;
-            ExceptionReporter.show(getView(), this);
-        }
-
-        /** Should never happen, but defined as a safety. */
-        @Override protected void cancelled() {
-            builder = null;
-        }
     }
 
     /**
@@ -369,14 +310,6 @@ public class ResourceExplorer extends WindowManager {
      *                   if the given resource is an aggregate.
      */
     private void updateDataTab(final Resource resource, boolean fallback) {
-        /*
-         * If tabs are being built in a background thread, wait for 
construction to finish.
-         * The builder will callback this `updateDataTab(resource, true)` 
method when ready.
-         */
-        if (builder != null) {
-            builder.resource = resource;
-            return;
-        }
         Region       image = null;
         Region       table = null;
         FeatureSet   data  = null;
@@ -384,9 +317,7 @@ public class ResourceExplorer extends WindowManager {
         CoverageExplorer.View type = null;
         if (resource instanceof GridCoverageResource) {
             if (coverage == null) {
-                builder = new DataTabBuilder(resource);
-                BackgroundThreads.execute(builder);
-                return;
+                coverage = new CoverageExplorer();
             }
             grid  = new ImageRequest((GridCoverageResource) resource, null, 
null);
             image = coverage.getDataView(CoverageExplorer.View.IMAGE);
diff --git 
a/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/package-info.java
 
b/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/package-info.java
index 318155f..67ae30e 100644
--- 
a/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/package-info.java
+++ 
b/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/package-info.java
@@ -18,13 +18,13 @@
 /**
  * Widgets about data store resources and their metadata.
  * Those widgets can show a hierarchical collection of {@link 
org.apache.sis.storage.Resource}s in a tree,
- * and show their content in other panel when a resource is selected. The 
resources can optionally be loaded
- * from a file in background thread.
+ * and show their content in other panel when a resource is selected.
+ * The resources can optionally be loaded from a file in background thread.
  *
  * @author  Smaniotto Enzo (GSoC)
  * @author  Johann Sorel (Geomatys)
  * @author  Martin Desruisseaux (Geomatys)
- * @version 1.1
+ * @version 1.2
  * @since   1.1
  * @module
  */
diff --git 
a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/BackgroundThreads.java
 
b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/BackgroundThreads.java
index c2e9316..1251829 100644
--- 
a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/BackgroundThreads.java
+++ 
b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/BackgroundThreads.java
@@ -53,13 +53,6 @@ import org.apache.sis.util.logging.Logging;
 @SuppressWarnings("serial")                         // Not intended to be 
serialized.
 public final class BackgroundThreads extends AtomicInteger implements 
ThreadFactory {
     /**
-     * Whether to allow the application to prepare in a background thread some 
GUI component
-     * before they are actually needed. It allows faster user experience, at 
the cost of CPU
-     * and memory consumption that may not be needed.
-     */
-    public static final boolean PRELOAD = true;
-
-    /**
      * The executor for background tasks. This is actually an {@link 
ExecutorService} instance,
      * but only the {@link Executor} method should be used according JavaFX 
documentation.
      */

Reply via email to