view gwt-client/src/main/java/org/dive4elements/river/client/client/ui/chart/NaviChartRecordHandler.java @ 9420:2c8ba17b807e

i10n navi chart record handler
author gernotbelger
date Fri, 17 Aug 2018 09:41:40 +0200
parents 05405292a7ca
children
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.FLYSConstants;
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.google.gwt.core.client.GWT;
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;

    private final FLYSConstants msg = GWT.create(FLYSConstants.class);

    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(" (") //
                    .append(this.msg.naviThemeOutOfRange()) //
                    .append(")") //
                    .toString();
        }

        return description;
    }
}

http://dive4elements.wald.intevation.org