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: Adjustment in the construction of titles to show to user.
Date Mon, 04 Nov 2019 22:55:19 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 eff5800  Adjustment in the construction of titles to show to user.
eff5800 is described below

commit eff5800f669e2f91c096a384e61e0a690f1d4da2
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Mon Nov 4 23:54:46 2019 +0100

    Adjustment in the construction of titles to show to user.
---
 .../org/apache/sis/gui/metadata/MetadataTree.java  |  6 ++++
 .../internal/jaxb/referencing/SC_SingleCRS.java    |  2 +-
 .../java/org/apache/sis/referencing/CommonCRS.java |  4 +--
 .../apache/sis/referencing/IdentifiedObjects.java  | 37 ++++++++++++++--------
 4 files changed, 32 insertions(+), 17 deletions(-)

diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/metadata/MetadataTree.java
b/application/sis-javafx/src/main/java/org/apache/sis/gui/metadata/MetadataTree.java
index 19b52e6..f5b043a 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/gui/metadata/MetadataTree.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/metadata/MetadataTree.java
@@ -33,6 +33,7 @@ import javafx.scene.control.TreeTableColumn;
 import javafx.scene.control.TreeTableColumn.CellDataFeatures;
 import org.opengis.metadata.Metadata;
 import org.opengis.util.InternationalString;
+import org.opengis.util.ControlledVocabulary;
 import org.opengis.referencing.IdentifiedObject;
 import org.apache.sis.metadata.AbstractMetadata;
 import org.apache.sis.metadata.MetadataStandard;
@@ -40,6 +41,7 @@ import org.apache.sis.metadata.ValueExistencePolicy;
 import org.apache.sis.referencing.IdentifiedObjects;
 import org.apache.sis.util.collection.TreeTable;
 import org.apache.sis.util.collection.TableColumn;
+import org.apache.sis.util.iso.Types;
 
 
 /**
@@ -128,6 +130,7 @@ public class MetadataTree extends TreeTableView<TreeTable.Node>
{
         nameColumn .setCellValueFactory(MetadataTree::getPropertyName);
         valueColumn.setCellValueFactory(MetadataTree::getPropertyValue);
 
+        setShowRoot(false);
         setColumnResizePolicy(CONSTRAINED_RESIZE_POLICY);
         getColumns().setAll(nameColumn, valueColumn);
         contentProperty.addListener(MetadataTree::applyChange);
@@ -287,6 +290,9 @@ public class MetadataTree extends TreeTableView<TreeTable.Node>
{
         if (value instanceof IdentifiedObject) {
             value = IdentifiedObjects.getDisplayName((IdentifiedObject) value, view.textLocale);
         }
+        if (value instanceof ControlledVocabulary) {
+            value = Types.getCodeTitle((ControlledVocabulary) value);
+        }
         if (value instanceof InternationalString) {
             value = ((InternationalString) value).toString(view.textLocale);
         }
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/SC_SingleCRS.java
b/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/SC_SingleCRS.java
index 79135da..b5180f8 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/SC_SingleCRS.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/SC_SingleCRS.java
@@ -96,7 +96,7 @@ public final class SC_SingleCRS extends PropertyType<SC_SingleCRS, SingleCRS>
{
     public void setElement(final AbstractCRS crs) {
         if (!(crs instanceof SingleCRS)) {
             throw new IllegalArgumentException(Errors.format(Errors.Keys.UnexpectedValueInElement_2,
-                    "baseCRS", IdentifiedObjects.getName(crs, null)));
+                    "baseCRS", IdentifiedObjects.getDisplayName(crs, null)));
         }
         metadata = (SingleCRS) crs;
         if (crs.getCoordinateSystem()    == null) incomplete("coordinateSystem");
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/CommonCRS.java
b/core/sis-referencing/src/main/java/org/apache/sis/referencing/CommonCRS.java
index f266bdb..a8df281 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/CommonCRS.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/CommonCRS.java
@@ -494,7 +494,7 @@ public enum CommonCRS {
             single = CRS.getHorizontalComponent(crs);
             if (single == null) {
                 throw new IllegalArgumentException(Resources.format(
-                        Resources.Keys.NonHorizontalCRS_1, IdentifiedObjects.getName(crs,
null)));
+                        Resources.Keys.NonHorizontalCRS_1, IdentifiedObjects.getDisplayName(crs,
null)));
             }
         }
         final Datum datum = single.getDatum();
@@ -503,7 +503,7 @@ public enum CommonCRS {
             if (c != null) return c;
         }
         throw new IllegalArgumentException(Errors.format(
-                Errors.Keys.UnsupportedDatum_1, IdentifiedObjects.getName(datum, null)));
+                Errors.Keys.UnsupportedDatum_1, IdentifiedObjects.getDisplayName(datum, null)));
     }
 
     /**
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/IdentifiedObjects.java
b/core/sis-referencing/src/main/java/org/apache/sis/referencing/IdentifiedObjects.java
index bf616ce..7958c2f 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/IdentifiedObjects.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/IdentifiedObjects.java
@@ -354,14 +354,19 @@ public final class IdentifiedObjects extends Static {
     }
 
     /**
-     * Returns a name that can be used for display purpose. This method returns the first
non-blank
+     * Returns a name that can be used for display purpose. This method checks the non-blank
      * {@linkplain AbstractIdentifiedObject#getName() name},
      * {@linkplain AbstractIdentifiedObject#getAlias() alias} or
      * {@linkplain AbstractIdentifiedObject#getIdentifiers() identifier}, in that order.
-     * The name should never be missing, but this method nevertheless fallbacks on aliases
and identifiers
-     * as a safety against incomplete implementations. If an identifier implements {@link
GenericName}
-     * (as with {@link NamedIdentifier}), its {@link GenericName#toInternationalString()
toInternationalString()}
-     * method will be used.
+     * If the primary name seems to be the {@linkplain CharSequences#isAcronymForWords acronym}
of an alias,
+     * then the alias is returned. For example if the name is <cite>"WGS 84"</cite>
and an alias is
+     * <cite>"World Geodetic System 1984"</cite>, then that later alias is returned.
+     *
+     * <div class="note"><b>Note:</b>
+     * the name should never be missing, but this method nevertheless
+     * fallbacks on identifiers as a safety against incomplete implementations.
+     * If an identifier implements {@link GenericName} (as with {@link NamedIdentifier}),
+     * its {@link GenericName#toInternationalString() toInternationalString()} method will
be used.</div>
      *
      * @param  object  the identified object, or {@code null}.
      * @param  locale  the locale for the name to return, or {@code null} for the default.
@@ -374,19 +379,23 @@ public final class IdentifiedObjects extends Static {
             return null;
         }
         String name = toString(object.getName(), locale);
-alt:    if (name == null) {
-            for (final GenericName c : nonNull(object.getAlias())) {
-                name = toString(c, locale);
-                if (name != null) break alt;
+        for (final GenericName c : nonNull(object.getAlias())) {
+            final String alias = toString(c, locale);
+            if (alias != null) {
+                if (name == null || CharSequences.isAcronymForWords(name, alias)) {
+                    return alias;
+                }
+                final String unlocalized = c.toString();
+                if (!alias.equals(unlocalized) && CharSequences.isAcronymForWords(name,
unlocalized)) {
+                    return alias;           // Select the localized version instead of `unlocalized`.
+                }
             }
+        }
+        if (name == null) {
             for (final Identifier id : nonNull(object.getIdentifiers())) {
                 name = toString(id, locale);
-                if (name != null) break alt;
+                if (name != null) break;
             }
-            return null;
-        }
-        if (name.indexOf(' ') < 0) {
-            name = CharSequences.camelCaseToSentence(name).toString();
         }
         return name;
     }


Mime
View raw message