view gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/VegetationzonesTableEditPanel.java @ 9261:22a3999fd536

klasse vergessen
author gernotbelger
date Tue, 17 Jul 2018 17:51:43 +0200
parents 431f1c269be5
children 4a6cc7c6716a
line wrap: on
line source
/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
 * Software engineering by Intevation GmbH
 *
 * 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.uinfo;

import org.dive4elements.river.client.client.ui.PanelHelper;
import org.dive4elements.river.client.shared.model.DataList;
import org.dive4elements.river.client.shared.model.VegetationZone;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.smartgwt.client.util.SC;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.fields.ColorItem;
import com.smartgwt.client.widgets.form.fields.TextItem;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridRecord;
import com.smartgwt.client.widgets.layout.Layout;
import com.smartgwt.client.widgets.layout.VLayout;

public class VegetationzonesTableEditPanel extends AbstractVegZonesTablePanel {
    private static final long serialVersionUID = 1L;

    private TextItem vegzone;

    private TextItem start;

    private TextItem end;

    @Override
    public void createWidget(final Layout root, final DataList data) {

        final ListGrid elements = super.createTable(root, data, "420", true);

        this.vegzone = PanelHelper.createItem("uinfo_vegetation_zone_label", this.MSG.uinfo_vegetation_zone_label(), "*");
        this.vegzone.setColSpan(4);
        this.start = PanelHelper.createIntegerItem("uinfo_vegetation_zones_from", this.MSG.uinfo_vegetation_zones_from(), "*");
        this.end = PanelHelper.createIntegerItem("uinfo_vegetation_zones_to", this.MSG.uinfo_vegetation_zones_to(), "*");
        final VLayout fields = new VLayout();

        final ColorItem colorPicker = new ColorItem();
        colorPicker.setTitle(this.MSG.uinfo_vegetation_zone_color());

        colorPicker.setShowTitle(true);
        colorPicker.setShowValueIconOnly(false);
        colorPicker.setShowPickerIcon(true);
        colorPicker.setColSpan(2);
        colorPicker.setWidth(110);

        final Button add = new Button(this.MSG.add_date()); // TODO: make key more generic or change to more specific

        final DynamicForm form1 = new DynamicForm();

        form1.setNumCols(4); // für Layout untereinander muss 2 eingestellt werden
        if (VegetationZone.HAS_COLORS_EDITABLE)
            form1.setFields(this.vegzone, this.start, this.end, colorPicker);
        else
            form1.setFields(this.vegzone, this.start, this.end);

        add.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(final ClickEvent ce) {
                final String v1 = VegetationzonesTableEditPanel.this.start.getValueAsString();
                final String v2 = VegetationzonesTableEditPanel.this.end.getValueAsString();
                final String v3 = VegetationzonesTableEditPanel.this.vegzone.getValueAsString();
                final String v4 = VegetationZone.HAS_COLORS_EDITABLE ? colorPicker.getValueAsString() : "#ffffff";
                final String message = validate(v1, v2, v3, v4);
                if (message != null) {
                    SC.warn(message);
                    return;
                }

                final ListGridRecord r = new ListGridRecord();
                r.setAttribute("vegzone", v3);
                r.setAttribute("from", v1);
                r.setAttribute("to", v2);
                r.setAttribute("color", v4);
                elements.addData(r);
                validateRangeOverlap();
                final String sortField = elements.getSortField();
                if (sortField != null) {
                    elements.toggleSort(sortField);
                    elements.toggleSort(sortField); // HACK. has to be. otherwise normalizer won't be called :-(
                }
            }
        });

        fields.addMember(form1);

        root.addMember(fields);
        root.addMember(PanelHelper.getSpacer(10));
        root.addMember(add);

    }

}

http://dive4elements.wald.intevation.org