view gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/VegetationzonesTableEditPanel.java @ 9069:1ffd38826175

access uinfo.vegetationzones+inundation_duration
author gernotbelger
date Tue, 15 May 2018 12:00:26 +0200
parents a5cf8d7bff3c
children 611a523fc42f
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.core.client.GWT;
import com.smartgwt.client.types.ListGridFieldType;
import com.smartgwt.client.widgets.Button;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.Label;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.validator.IsIntegerValidator;
import com.smartgwt.client.widgets.form.validator.IsStringValidator;
import com.smartgwt.client.widgets.grid.ListGridField;
import com.smartgwt.client.widgets.grid.ListGridRecord;
import com.smartgwt.client.widgets.grid.events.RecordClickEvent;
import com.smartgwt.client.widgets.grid.events.RecordClickHandler;
import com.smartgwt.client.widgets.layout.HLayout;

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

    @Override
    public Canvas createWidget(final DataList data) {

        final HLayout fields = new HLayout();
        final HLayout fields2 = new HLayout();

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

        data.add(VegetationzonesTablePanel.getDummyData());

        final Label title = new Label(data.get(0).getDescription());
        title.setHeight("35px"); // orig:25

        this.vegzone = PanelHelper.createItem("uinfo_vegetation_zone_label", this.MSG.uinfo_vegetation_zone_label(), 200, new IsStringValidator());
        this.start = PanelHelper.createItem("uinfo_vegetation_zones_from", this.MSG.uinfo_vegetation_zones_from(), 40, new IsIntegerValidator());
        this.end = PanelHelper.createItem("uinfo_vegetation_zones_to", this.MSG.uinfo_vegetation_zones_to(), 40, new IsIntegerValidator());

        final DynamicForm form1 = new DynamicForm();
        final DynamicForm form2 = new DynamicForm();
        form2.setNumCols(5);
        form1.setNumCols(7);
        form1.setFields(this.vegzone);
        form2.setFields(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();
                if (v1 == null || v2 == null || v3 == null) {
                    return;
                }
                try {
                    final double test = Double.valueOf(v1);
                    final double test2 = Double.valueOf(v2);
                    // TODO: MAKE MESSAGE, Apply Format (1.000,00)
                }
                catch (final Exception e) {
                    e.printStackTrace();
                    return;
                }

                final ListGridRecord r = new ListGridRecord();
                r.setAttribute("vegzone", v3);
                r.setAttribute("from", v1);
                r.setAttribute("to", v2);
                VegetationzonesTableEditPanel.this.elements.addData(r);
            }
        });

        final Label sel = new Label(this.MSG.select());
        sel.setHeight(25);
        this.elements.setWidth(450); // 185
        this.elements.setHeight(300); // 120
        this.elements.setShowHeaderContextMenu(false);
        this.elements.setCanReorderFields(false);
        this.elements.setCanSort(false);
        this.elements.setCanEdit(false);
        final ListGridField vegzone = new ListGridField("vegzone", this.MSG.uinfo_vegetation_zones_label());
        final ListGridField from = new ListGridField("from", this.MSG.uinfo_vegetation_zones_from());
        final ListGridField to = new ListGridField("to", this.MSG.uinfo_vegetation_zones_to());
        vegzone.setWidth(285);
        from.setWidth(70);
        to.setWidth(70);

        addDataInit(data);

        final ListGridField removeField = new ListGridField("_removeRecord", "Remove Record") {
            {
                setType(ListGridFieldType.ICON);
                setIcon(GWT.getHostPageBaseURL() + VegetationzonesTableEditPanel.this.MSG.removeFeature());
                setCanEdit(false);
                setCanFilter(false);
                setCanSort(false);
                setCanGroupBy(false);
                setCanFreeze(false);
                setWidth(25);
            }
        };

        this.elements.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());
            }
        });

        this.elements.setFields(vegzone, from, to, removeField);

        fields.addMember(form1);
        fields2.addMember(form2);

        this.tableLayout.addMember(this.elements);
        this.root.addMember(title);
        this.root.addMember(this.input);
        this.root.addMember(this.tableLayout);
        this.root.addMember(PanelHelper.getSpacer(10));
        this.root.addMember(fields);
        this.root.addMember(fields2);
        this.root.addMember(PanelHelper.getSpacer(10));
        this.root.addMember(add);
        this.root.addMember(PanelHelper.getSpacer(20));

        return this.root;
    }

}

http://dive4elements.wald.intevation.org