void buildContent()

in optional/src/org.apache.sis.gui/main/org/apache/sis/gui/metadata/IdentificationInfo.java [270:442]


    void buildContent(final Identification info) {
        mapWasVisible = !isWorldMapEmpty();
        isWorld = false;
        clearWorldMap();
        String text = null;
        final Citation citation = info.getCitation();
        if (citation != null) {
            text = owner.string(citation.getTitle());
            if (text == null) {
                text = Citations.getIdentifier(citation);
            }
        }
        if (text == null) {
            text = owner.vocabulary.getString(Vocabulary.Keys.Untitled);
        } else if (CharSequences.isUnicodeIdentifier(text)) {
            text = CharSequences.camelCaseToSentence(text).toString();
        }
        title.setText(text);
        /*
         * Identifiers as a comma-separated list on a single line. Each identifier
         * is formatted as "codespace:code" or only "code" if there is no codespace.
         */
        if (citation != null) {
            final StringJoiner buffer = new StringJoiner(", ");
            for (final Identifier id : citation.getIdentifiers()) {
                buffer.add(IdentifiedObjects.toString(id));
            }
            if (buffer.length() != 0) {
                addLine(Vocabulary.Keys.Identifiers, buffer.toString());
            }
        }
        /*
         * The abstract, or if there is no abstract the purpose, or if no purpose the credit as a fallback.
         * We use those fallback because they can provide some hints about the product.
         * The topic category (climatology, health, etc.) follows.
         */
        short label = Vocabulary.Keys.Abstract;
        text = owner.string(info.getAbstract());
        if (text == null) {
            label = Vocabulary.Keys.Purpose;
            text = owner.string(info.getPurpose());
            if (text == null) {
                for (final String c : nonNull(info.getCredits())) {
                    text = c;
                    if (text != null) {
                        label = Vocabulary.Keys.Credit;
                        break;
                    }
                }
            }
        }
        addLine(label, text);
        /*
         * Topic category.
         */
        final DataIdentification dataInfo = (info instanceof DataIdentification) ? (DataIdentification) info : null;
        if (dataInfo != null) {
            addLine(Vocabulary.Keys.TopicCategory, owner.string(nonNull(dataInfo.getTopicCategories())));
            addLine(Vocabulary.Keys.TypeOfResource, owner.string(nonNull(dataInfo.getSpatialRepresentationTypes())));
        }
        /*
         * Resource format. Current implementation shows only the first format found.
         */
        for (final Format format : nonNull(info.getResourceFormats())) {
            text = owner.string(format.getSpecification());
            if (text != null) {
                addLine(Vocabulary.Keys.Format, text);
                break;
            }
        }
        /*
         * Select a single, arbitrary date. We take the release or publication date if available.
         * If no publication date is found, fallback on the creation date. If no creation date is
         * found neither, fallback on the first date regardless its type.
         */
        if (citation != null) {
            Date date = null;
            label = Vocabulary.Keys.Date;
            for (final CitationDate c : nonNull(citation.getDates())) {
                final Date cd = c.getDate();
                if (cd != null) {
                    final DateType type = c.getDateType();
                    if (type == DateType.PUBLICATION || type == DateType.valueOf("RELEASED")) {
                        label = Vocabulary.Keys.PublicationDate;
                        date  = cd;
                        break;                      // Take the first publication or release date.
                    }
                    final boolean isCreation = (type == DateType.CREATION);
                    if (date == null || isCreation) {
                        label = isCreation ? Vocabulary.Keys.CreationDate : Vocabulary.Keys.Date;
                        date  = cd;     // Fallback date: creation date, or the first date otherwise.
                    }
                }
            }
            addLine(label, owner.format(date));
        }
        /*
         * Fetch the first description about the spatio-temporal extent, then draw all geographic bounding boxes
         * on a world map. If the bounding box encompasses the whole world, replace it by a "World" description.
         * The reason is that drawing a box over the whole world is not very informative; it rather looks like a
         * border around the image.
         */
        text = null;
        Identifier identifier = null;
        Range<Date> timeRange = null;
        Range<Double> heights = null;
        for (final Extent extent : nonNull(dataInfo != null ? dataInfo.getExtents() : null)) {
            if (extent != null) {
                if (text == null) {
                    text = owner.string(extent.getDescription());
                }
                for (final GeographicExtent ge : nonNull(extent.getGeographicElements())) {
                    if (identifier == null && ge instanceof GeographicDescription) {
                        identifier = ((GeographicDescription) ge).getGeographicIdentifier();
                    }
                    if (!isWorld && ge instanceof GeographicBoundingBox) {
                        isWorld = drawOnMap((GeographicBoundingBox) ge);
                    }
                }
                try {
                    final MeasurementRange<Double> v = Extents.getVerticalRange(extent);
                    if (v != null) heights = (heights != null) ? heights.union(v) : v;
                } catch (InvalidMetadataException e) {
                    // `MetadataSummary` is (indirectly) the public caller of this method.
                    Logging.recoverableException(LOGGER, MetadataSummary.class, "setMetadata", e);
                }
                final Range<Date> t = Extents.getTimeRange(extent);
                if (t != null) timeRange = (timeRange != null) ? timeRange.union(t) : t;
            }
        }
        if (text == null) {
            text = IdentifiedObjects.toString(identifier);
        }
        if (isWorld) {
            clearWorldMap();
            if (text == null) {
                text = owner.vocabulary.getString(Vocabulary.Keys.World);
            }
        }
        /*
         * Write the temporal, vertical and geographic extents fetched above.
         */
        addLine(Vocabulary.Keys.Extent, text);
        if (timeRange != null) {
            label = Vocabulary.Keys.StartDate;
            Date t = timeRange.getMinValue();
            if (t == null) {
                t = timeRange.getMaxValue();
                label = Vocabulary.Keys.EndDate;
            }
            addLine(label, owner.format(t));
        }
        if (heights != null) {
            final Double min = heights.getMinValue();
            final Double max = heights.getMaxValue();
            if (min != null || max != null) {
                final var b = new StringBuffer(20);
                if (min != null && max != null && !min.equals(max)) {
                    owner.formats.formatPair(min, " … ", max, b);
                } else {
                    owner.format(min != null ? min : max, b);
                }
                if (heights instanceof MeasurementRange<?>) {
                    final Unit<?> unit = ((MeasurementRange<?>) heights).unit();
                    if (unit != null) {
                        owner.format(unit, b.append(' '));
                    }
                }
                addLine(Vocabulary.Keys.Height, b.toString());
            }
        }
        setRowIndex(extentOnMap, nextRowIndex());
    }