view flys-client/src/main/java/de/intevation/flys/client/client/ui/DoubleInputPanel.java @ 4198:1cdbd8a0c994

Added two new tables ClickableQDTable and ClickableWTable and made Ws and Qs clickable in historical discharge calculation. The new tables define listener interfaces (clicked lower or upper icon) to listen to user clicks. In addition to this, there is an enum ClickMode with NONE, SINGLE and RANGE options, which allows to specifiy, which icons are displayed in the tables. NONE means no icon for user clicks, SINGLE has 1 icon, RANGE 2 icons for lower and upper.
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 22 Oct 2012 13:31:25 +0200
parents 360e22afb98b
children 8cec61ac5160
line wrap: on
line source
package de.intevation.flys.client.client.ui;

import com.google.gwt.core.client.GWT;
import com.google.gwt.i18n.client.NumberFormat;

import com.smartgwt.client.util.SC;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.Label;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.fields.TextItem;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.VLayout;

import de.intevation.flys.client.client.FLYSConstants;
import de.intevation.flys.client.shared.model.Data;
import de.intevation.flys.client.shared.model.DataItem;
import de.intevation.flys.client.shared.model.DataList;
import de.intevation.flys.client.shared.model.DefaultData;
import de.intevation.flys.client.shared.model.DefaultDataItem;

import java.util.ArrayList;
import java.util.List;

/**
 * This UIProvider creates a panel for location or distance input.
 *
 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
 */
public class DoubleInputPanel
extends      AbstractUIProvider
{

    private static final long serialVersionUID = 2006773072352563622L;

    /** The message class that provides i18n strings. */
    protected FLYSConstants MSG = GWT.create(FLYSConstants.class);

    private TextItem inputPanel;

    private double value;


    public DoubleInputPanel() {
    }


    @Override
    public Canvas create(DataList list) {
        VLayout layout = new VLayout();

        Canvas helper = createHelper();
        this.helperContainer.addMember(helper);

        Canvas submit = getNextButton();
        Canvas widget = createWidget(list);

        layout.addMember(widget);
        layout.addMember(submit);
        return layout;
    }


    /** Create a labelled input-panel. */
    public Canvas createWidget(DataList data) {
        VLayout layout = new VLayout();

        Label title = new Label(data.get(0).getDescription());
        title.setHeight("25px");

        DataItem defaultItem = data.get(0).getDefault();

        DynamicForm form = new DynamicForm();
        inputPanel = new TextItem();
        inputPanel.setTitle("outliers");
        inputPanel.setShowTitle(false);

        if (defaultItem != null) {
            inputPanel.setValue(defaultItem.getStringValue());
        }

        form.setFields(inputPanel);

        layout.addMember(title);
        layout.addMember(form);

        return layout;
    }

    protected Canvas createHelper() {
        return new VLayout();
    }


    /** Create canvas to show previously entered value. */
    @Override
    public Canvas createOld(DataList dataList) {
        List<Data> items = dataList.getAll();

        Data d = getData(items, "outliers");
        DataItem[] item = d.getItems();

        String v = item[0].getLabel();

        Label old = new Label(v);
        old.setWidth(130);

        HLayout layout = new HLayout();
        layout.setWidth("400px");

        Label label = new Label(dataList.getLabel());
        label.setWidth("200px");

        Canvas back = getBackButton(dataList.getState());

        layout.addMember(label);
        layout.addMember(old);
        layout.addMember(back);

        return layout;
    }


    /**
     * This method returns the selected data.
     *
     * @return the selected/inserted data.
     */
    @Override
    public Data[] getData() {
        List<Data> data = new ArrayList<Data>();

        boolean valid = saveDataValues();
        if(valid) {

            String vs = Double.valueOf(this.value).toString();
            DataItem item = new DefaultDataItem("outliers", "outliers", vs);
            data.add(new DefaultData(
                "outliers",
                null,
                null,
                new DataItem[] { item }));
        }

        return data.toArray(new Data[data.size()]);
    }


    protected boolean saveDataValues() {
        String st = inputPanel.getValueAsString();
        if (st == null) {
            SC.warn("fehler... TODO");
            return false;
        }

        try {
            NumberFormat nf = NumberFormat.getDecimalFormat();
            double d = nf.parse(st);
            this.value = d;
        }
        catch(NumberFormatException nfe) {
            SC.warn("fehler... nfe... TODO");
            return false;
        }
        return true;
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org