view gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/VegetationzonesTableEditPanel.java @ 9523:d421c2bf0195

Allow to edit colors in vegetation zones
author gernotbelger
date Mon, 01 Oct 2018 17:08:50 +0200
parents e2da9c8a7c57
children 8cf2968dd4f9
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 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.Canvas;
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
        form1.setFields(this.vegzone, this.start, this.end, colorPicker);

        add.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(final ClickEvent ce) {

                handleAddClicked(elements, colorPicker);
            }
        });

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

    protected void handleAddClicked(final ListGrid elements, final ColorItem colorPicker) {
        final String v1 = VegetationzonesTableEditPanel.this.start.getValueAsString();
        final String v2 = VegetationzonesTableEditPanel.this.end.getValueAsString();
        final String v3 = VegetationzonesTableEditPanel.this.vegzone.getValueAsString();
        final String v4 = colorPicker.getValueAsString();

        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);
        updateValidationMsgLabel();
        final String sortField = elements.getSortField();
        if (sortField != null) {
            elements.toggleSort(sortField);
            elements.toggleSort(sortField); // HACK. has to be. otherwise normalizer won't be called :-(
        }
    }

    @Override
    protected Canvas createHelper(final DataList data) {
        return null;
    }
}

http://dive4elements.wald.intevation.org