sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] branch geoapi-4.0 updated: Add scroll pane and more dynamic inclusion/exclusion of sections in metadata overview.
Date Sat, 02 Nov 2019 22:00:09 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


The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
     new 3cbf651  Add scroll pane and more dynamic inclusion/exclusion of sections in metadata
overview.
3cbf651 is described below

commit 3cbf651524b58e46b83d4b6633414bfd70538a65
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Sat Nov 2 22:56:32 2019 +0100

    Add scroll pane and more dynamic inclusion/exclusion of sections in metadata overview.
---
 .../main/java/org/apache/sis/gui/dataset/Form.java | 19 ++++-
 .../apache/sis/gui/dataset/MetadataOverview.java   | 93 ++++++++++++----------
 2 files changed, 70 insertions(+), 42 deletions(-)

diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/Form.java b/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/Form.java
index 8dd90e9..df9dc5f 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/Form.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/Form.java
@@ -122,6 +122,8 @@ abstract class Form<T> extends GridPane implements EventHandler<ActionEvent>
{
     /**
      * Sets the information from the given metadata. Subclasses extract the collection of
interest
      * and delegate to the {@link #setInformation(Collection, IntFunction)} method.
+     *
+     * @param  metadata  the metadata to show, or {@code null}.
      */
     abstract void setInformation(Metadata metadata);
 
@@ -199,6 +201,7 @@ abstract class Form<T> extends GridPane implements EventHandler<ActionEvent>
{
     private void update(final int index) {
         rowsEnd = rowsStart;
         buildContent(information[index]);
+        setRowSpan(pagination, nextRowIndex());              // For avoiding to interfer
with getRowCount().
         final ObservableList<Node> children = getChildren();
         children.subList(rowsEnd, children.size()).clear();
         setRowSpan(pagination, getRowCount());
@@ -229,7 +232,7 @@ abstract class Form<T> extends GridPane implements EventHandler<ActionEvent>
{
             valueCtrl = (Label) children.get(rowsEnd + 1);
             labelCtrl.setText(label);
         } else {
-            final int row = (rowsEnd - rowsStart) / NUM_CHILD_PER_ROW;
+            final int row = nextRowIndex();
             labelCtrl = new Label(label);
             valueCtrl = new Label();
             labelCtrl.setLabelFor(valueCtrl);
@@ -244,6 +247,20 @@ abstract class Form<T> extends GridPane implements EventHandler<ActionEvent>
{
     }
 
     /**
+     * Returns the index of the next row in the grid pane.
+     */
+    final int nextRowIndex() {
+        return (rowsEnd - rowsStart) / NUM_CHILD_PER_ROW;
+    }
+
+    /**
+     * Returns {@code true} if this form contains no data.
+     */
+    boolean isEmpty() {
+        return rowsStart == rowsEnd;
+    }
+
+    /**
      * Returns the locale-dependent object to use for writing numbers.
      * Subclasses should return some cached instance.
      */
diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/MetadataOverview.java
b/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/MetadataOverview.java
index 6e19310..00e1e09 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/MetadataOverview.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/MetadataOverview.java
@@ -32,6 +32,7 @@ import javafx.geometry.HPos;
 import javafx.scene.Node;
 import javafx.scene.canvas.Canvas;
 import javafx.scene.canvas.GraphicsContext;
+import javafx.scene.control.ScrollPane;
 import javafx.scene.control.TitledPane;
 import javafx.scene.image.Image;
 import javafx.scene.layout.Region;
@@ -96,7 +97,7 @@ final class MetadataOverview {
      * This is similar to {@link javafx.scene.control.Accordion} except that we allow an
arbitrary amount
      * of titled panes to be opened in same time.
      */
-    private final VBox panes;
+    private final ScrollPane content;
 
     /**
      * The locale to use for international strings.
@@ -136,12 +137,6 @@ final class MetadataOverview {
     private boolean worldMapLoaded;
 
     /**
-     * The metadata to show, or {@code null} if none.
-     * This is set by {@link #setMetadata(Metadata)}.
-     */
-    private Metadata metadata;
-
-    /**
      * If the metadata can not be obtained, the reason.
      *
      * @todo show in this control.
@@ -156,12 +151,23 @@ final class MetadataOverview {
     private int selectionCounter;
 
     /**
+     * The pane where to show information about resource identification, spatial representation,
etc.
+     * Those panes will be added in the {@link #content} when we determined that they are
not empty.
+     */
+    private final TitledPane[] information;
+
+    /**
      * Creates an initially empty metadata overview.
      */
     MetadataOverview(final Locale locale) {
         textLocale   = locale;
         formatLocale = Locale.getDefault(Locale.Category.FORMAT);
-        panes        = new VBox();
+        information  = new TitledPane[] {
+            new TitledPane("Resource identification", new IdentificationInfo()),
+            new TitledPane("Spatial representation",  new RepresentationInfo())
+        };
+        content = new ScrollPane(new VBox());
+        content.setFitToWidth(true);
     }
 
     /**
@@ -171,7 +177,7 @@ final class MetadataOverview {
      * @return the region to show.
      */
     public final Region getView() {
-        return panes;
+        return content;
     }
 
     /**
@@ -218,7 +224,7 @@ final class MetadataOverview {
                     }
                 }
 
-                /** Invoked when an error occurred while fetching metadata. à*/
+                /** Invoked when an error occurred while fetching metadata. */
                 @Override protected void failed() {
                     setMetadata((Metadata) null);
                     failure = getException();
@@ -231,30 +237,26 @@ final class MetadataOverview {
     /**
      * Sets the content of this pane to the given metadata.
      *
-     * @param  md  the metadata to show, or {@code null}.
+     * @param  metadata  the metadata to show, or {@code null}.
      */
-    public void setMetadata(final Metadata md) {
+    public void setMetadata(final Metadata metadata) {
         assert Platform.isFxApplicationThread();
-        metadata = md;
-        failure  = null;
-        final ObservableList<Node> children = panes.getChildren();
-        children.clear();
-        if (md != null) {
-            addIfNonEmpty(children, "Identification info",    new IdentificationInfo(), md);
-            addIfNonEmpty(children, "Spatial representation", new RepresentationInfo(), md);
-        }
-    }
-
-    /**
-     * Adds the given pane to the list of children if the pane is non-null and non-empty.
-     * If added, a {@link TitledPane} is created with the given title.
-     */
-    private static void addIfNonEmpty(final ObservableList<Node> children, final String
title,
-            final Form<?> pane, final Metadata md)
-    {
-        if (pane != null && !pane.getChildren().isEmpty()) {
-            pane.setInformation(md);
-            children.add(new TitledPane(title, pane));
+        failure = null;
+        final ObservableList<Node> children = ((VBox) content.getContent()).getChildren();
+        int i = 0;
+        for (TitledPane pane : information) {
+            final Form<?> info = (Form<?>) pane.getContent();
+            info.setInformation(metadata);
+            final boolean isEmpty   = info.isEmpty();
+            final boolean isPresent = (i < children.size()) && children.get(i)
== pane;
+            if (isEmpty == isPresent) {     // Should not be present if empty, or should
be present if non-empty.
+                if (isEmpty) {
+                    children.remove(i);
+                } else {
+                    children.add(i, pane);
+                }
+            }
+            if (!isEmpty) i++;
         }
     }
 
@@ -296,7 +298,6 @@ final class MetadataOverview {
                 assert getChildren().get(1) == extentOnMap;
                 getChildren().set(1, extentOnMap = new Canvas());
                 setColumnSpan(extentOnMap, NUM_CHILD_PER_ROW);
-                setRowIndex(extentOnMap, 0);
                 setHalignment(extentOnMap, HPos.CENTER);
             }
         }
@@ -309,6 +310,14 @@ final class MetadataOverview {
         }
 
         /**
+         * Returns {@code true} if this form contains no data.
+         */
+        @Override
+        boolean isEmpty() {
+            return super.isEmpty() && isWorldMapEmpty();
+        }
+
+        /**
          * Returns the format to use for writing numbers.
          */
         @Override
@@ -321,7 +330,7 @@ final class MetadataOverview {
          */
         @Override
         void setInformation(final Metadata metadata) {
-            setInformation(nonNull(metadata.getIdentificationInfo()), Identification[]::new);
+            setInformation(nonNull(metadata == null ? null : metadata.getIdentificationInfo()),
Identification[]::new);
         }
 
         /**
@@ -425,7 +434,7 @@ final class MetadataOverview {
                 text = IdentifiedObjects.toString(identifier);
             }
             addRow("Extent:", text);
-            setRowIndex(extentOnMap, getRowCount());
+            setRowIndex(extentOnMap, nextRowIndex());
         }
 
         /**
@@ -527,11 +536,13 @@ final class MetadataOverview {
         @Override
         void setInformation(final Metadata metadata) {
             referenceSystem = null;
-            setInformation(nonNull(metadata.getSpatialRepresentationInfo()), SpatialRepresentation[]::new);
-            for (final ReferenceSystem rs : nonNull(metadata.getReferenceSystemInfo())) {
-                if (rs != null) {
-                    referenceSystem = rs;
-                    break;
+            setInformation(nonNull(metadata == null ? null : metadata.getSpatialRepresentationInfo()),
SpatialRepresentation[]::new);
+            if (metadata != null) {
+                for (final ReferenceSystem rs : nonNull(metadata.getReferenceSystemInfo()))
{
+                    if (rs != null) {
+                        referenceSystem = rs;
+                        break;
+                    }
                 }
             }
         }
@@ -565,7 +576,7 @@ final class MetadataOverview {
     /**
      * @todo
      */
-    private void createContact() {
+    private void createContact(final Metadata metadata) {
         for (final Responsibility contact : nonNull(metadata.getContacts())) {
             for (final Party party : nonNull(contact.getParties())) {
                 final String name = string(party.getName());


Mime
View raw message