view gwt-client/src/main/java/org/dive4elements/river/client/client/ui/chart/NaviChartRecordHandler.java @ 9416:05405292a7ca

Navigationtheme panel now shows themes of dWt and WQ charts grayed out, if the current station is outside the valid range of the theme.
author gernotbelger
date Thu, 16 Aug 2018 16:28:03 +0200
parents
children 2c8ba17b807e
line wrap: on
line source
/** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
 * Software engineering by
 *  Björnsen Beratende Ingenieure GmbH
 *  Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
 *
 * This file is Free Software under the GNU AGPL (>=v3)
 * and comes with ABSOLUTELY NO WARRANTY! Check out the
 * documentation coming with Dive4Elements River for details.
 */
package org.dive4elements.river.client.client.ui.chart;

import org.dive4elements.river.client.client.ui.CollectionView;
import org.dive4elements.river.client.client.ui.IThemeRecordHandler;
import org.dive4elements.river.client.shared.model.AttributedTheme;
import org.dive4elements.river.client.shared.model.FacetRecord;
import org.dive4elements.river.client.shared.model.Theme;

import com.smartgwt.client.widgets.grid.CellFormatter;
import com.smartgwt.client.widgets.grid.ListGridRecord;

/**
 * @author Gernot Belger
 */
final class NaviChartRecordHandler implements IThemeRecordHandler, CellFormatter {

    private static final String STYLE_CLASS_NAVI_CHART_GRAYED = "naviChartGrayed";
    private final CollectionView collectionView;

    public NaviChartRecordHandler(final CollectionView collectionView) {
        this.collectionView = collectionView;
    }

    private boolean checkOutsideRange(final FacetRecord facetRecord) {

        final Theme theme = facetRecord.getTheme();
        if (!(theme instanceof AttributedTheme))
            return false;

        final double currentKm = this.collectionView.getCurrentKm();

        final AttributedTheme aTheme = (AttributedTheme) theme;

        final Double startKm = aTheme.getAttrAsDouble("startKm");
        final Double endKm = aTheme.getAttrAsDouble("endKm");
        if (startKm == null || endKm == null)
            return false;

        final double fromKm = startKm < endKm ? startKm : endKm;
        final double toKm = startKm < endKm ? endKm : startKm;

        return currentKm < fromKm || currentKm > toKm;
    }

    @Override
    public void handle(final FacetRecord facetRecord) {

        final boolean isOutsideRange = checkOutsideRange(facetRecord);
        if (isOutsideRange)
            facetRecord.set_baseStyle(STYLE_CLASS_NAVI_CHART_GRAYED);
        else
            facetRecord.set_baseStyle(null);
    }

    @Override
    public String format(final Object value, final ListGridRecord record, final int rowNum, final int colNum) {

        if (!(record instanceof FacetRecord))
            return null;

        final FacetRecord facetRecord = (FacetRecord) record;
        final String description = facetRecord.getName();

        final boolean isOutsideRange = checkOutsideRange(facetRecord);
        if (isOutsideRange) {
            return new StringBuilder(description) //
                    .append(" (") //
                    // FIXME: i10n
                    .append("auß. Gültigkeitsbereich") //
                    .append(")") //
                    .toString();
        }

        return description;
    }
}

http://dive4elements.wald.intevation.org