view gwt-client/src/main/java/org/dive4elements/river/client/client/ui/PanelHelper.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 d89976700474
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;

import com.google.gwt.user.client.ui.Label;
import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.types.ListGridFieldType;
import com.smartgwt.client.widgets.form.fields.IntegerItem;
import com.smartgwt.client.widgets.form.fields.TextItem;
import com.smartgwt.client.widgets.form.validator.IntegerRangeValidator;
import com.smartgwt.client.widgets.form.validator.IsIntegerValidator;
import com.smartgwt.client.widgets.form.validator.Validator;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridField;
import com.smartgwt.client.widgets.grid.SortNormalizer;
import com.smartgwt.client.widgets.grid.events.RecordClickEvent;
import com.smartgwt.client.widgets.grid.events.RecordClickHandler;
import com.smartgwt.client.widgets.layout.VLayout;

/**
 * @author Domenico Nardi Tironi
 *
 */
public class PanelHelper {

    public PanelHelper() {

    }

    public static final TextItem createItem(final String identifier, final String title, final String width, final Validator... validator) {
        final TextItem item = new TextItem(identifier, title);
        item.setWidth(width);
        item.setWrapTitle(false);
        item.setValidators(validator);
        return item;
    }

    public static final IntegerItem createIntegerItem(final String identifier, final String title, final String width, final Validator... validator) {
        final IntegerItem item = new IntegerItem(identifier, title);
        item.setWidth(width);
        item.setWrapTitle(false);
        item.setValidators(validator);
        return item;
    }

    public static VLayout getSpacer(final int height) {
        final VLayout spacer = new VLayout();
        spacer.setHeight(height);
        return spacer;
    }

    public static TextItem createItem(final String title) {
        final TextItem inputItem = new TextItem(title);

        final boolean hideTitle = title == null || title.isEmpty();
        inputItem.setShowTitle(!hideTitle);
        // final CustomValidator validator = new CustomValidator() {
        // @Override
        // protected boolean condition(final Object value) {
        // return validate().size() > 0 ? false : true;
        // }
        // };
        inputItem.setValidators(new IsIntegerValidator()); // Validator hat keinen sichtbaren Effekt.
        inputItem.setWidth(60);
        return inputItem;

    }

    public static final ListGridField createRemoveField(final ListGrid table, final String icon) {
        final ListGridField removeField = new ListGridField("_removeRecord", "Remove Record") {
            {
                setType(ListGridFieldType.ICON);
                setIcon(icon);
                setCanEdit(false);
                setCanFilter(false);
                setCanSort(false);
                setCanGroupBy(false);
                setCanFreeze(false);
                setWidth(25);
                setCanDragResize(false);
                super.setCanToggle(false);
            }
        };
        table.addRecordClickHandler(new RecordClickHandler() {
            @Override
            public void onRecordClick(final RecordClickEvent event) {
                // Just handle remove-clicks
                if (!event.getField().getName().equals(removeField.getName())) {
                    return;
                }
                event.getViewer().removeData(event.getRecord());
            }
        });

        return removeField;
    }

    public static final ListGridField createIntTableField(final String key, final String msg, final boolean canSort, final SortNormalizer normalizer,
            final IntegerRangeValidator validators) {
        final ListGridField intField = new ListGridField(key, msg);
        intField.setType(ListGridFieldType.INTEGER);
        intField.setValidators(validators);
        intField.setWidth(90);
        intField.setAlign(Alignment.RIGHT);
        intField.setSortNormalizer(normalizer);
        intField.setCanSort(canSort);
        intField.setCanDragResize(false);

        return intField;
    }

    public static final Label getValidationLabel() {
        final Label label = new Label();
        label.setHeight("15px");
        label.getElement().getStyle().setColor("red");
        return label;
    }

}

http://dive4elements.wald.intevation.org