view flys-client/src/main/java/de/intevation/flys/client/client/ui/fixation/FixFunctionSelect.java @ 4253:a1bc5b8cff0f

Refactor GaugePanel to create it's own SectionStackSection The GaugePanel constructor now creates a SectionStackSection instead of using a provided one. Improve the rendering of the GaugePanel by having access to the SmartGWT wrapper (WidgetCanvas) object for the GWT Tree (GaugeTree) directly. Add methods to close and open the section. Also add a getter for the section.
author Björn Ricks <bjoern.ricks@intevation.de>
date Thu, 25 Oct 2012 13:52:58 +0200
parents 84a48acabd78
children
line wrap: on
line source
package de.intevation.flys.client.client.ui.fixation;

import com.smartgwt.client.types.VerticalAlignment;
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.SelectItem;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.VLayout;

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.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;

public class FixFunctionSelect extends FixationPanel {
    private static final Map<String, String> funcDesc = new HashMap<String, String>();

    static {
        funcDesc.put("log", "W(Q) = m*ln(Q + b)");
        funcDesc.put("linear", "W(Q) = m * Q + b");
        funcDesc.put("log-linear", "W(Q) = a*ln(m*Q+b)");
        funcDesc.put("exp", "W(Q) = m * a^Q + b");
        funcDesc.put("quad", "W(Q) = n*Q^2+m*Q+b");
        funcDesc.put("pow", "W(Q) = a * Q^c + d");
        funcDesc.put("sq-pow", "S(Q) = a * Q^b");
    }

    /** The combobox.*/
    protected DynamicForm form;

    @Override
    public Canvas createWidget(DataList data) {
        VLayout layout   = new VLayout();
        layout.setAlign(VerticalAlignment.TOP);
        layout.setHeight(25);

        LinkedHashMap initial = new LinkedHashMap();

        form = new DynamicForm();

        int size = data.size();

        for (int i = 0; i < size; i++) {
            Data d = data.get(i);

            Label label = new Label(d.getDescription());
            label.setValign(VerticalAlignment.TOP);
            label.setHeight(20);
            label.setWidth(400);

            SelectItem combobox = new SelectItem(d.getLabel());
            combobox.setWidth(250);

            LinkedHashMap<String, String> funcTypes = new LinkedHashMap<String, String>();

            boolean  defaultSet = false;
            boolean  first      = true;

            DataItem def      = d.getDefault();
            String   defValue = def != null ? def.getStringValue() : null;

            if (defValue != null && defValue.length() > 0) {
                initial.put(d.getLabel(), def.getStringValue());
                defaultSet = true;
            }

            // I was here. Me 2.
            for (DataItem item: d.getItems()) {
                if (!defaultSet && first) {
                    initial.put(d.getLabel(), item.getStringValue());
                    first = false;
                }

                funcTypes.put(item.getStringValue(), item.getLabel());
            }

            label.setWidth(50);
            combobox.setValueMap(funcTypes);
            combobox.setShowTitle(false);
            form.setItems(combobox);

            layout.addMember(label);
            layout.addMember(form);
        }

        form.setValues(initial);

        layout.setAlign(VerticalAlignment.TOP);

        return layout;
    }


    @Override
    public Canvas createOld(DataList dataList) {
        HLayout layout  = new HLayout();
        VLayout vLayout = new VLayout();
        layout.setWidth("400px");

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

        int size = dataList.size();
        for (int i = 0; i < size; i++) {
            Data data        = dataList.get(i);
            DataItem[] items = data.getItems();

            for (DataItem item: items) {
                HLayout hLayout = new HLayout();

                String desc = funcDesc.containsKey(item.getLabel()) ?
                        funcDesc.get(item.getLabel()) : item.getLabel();
                hLayout.addMember(label);
                hLayout.addMember(new Label(desc));

                vLayout.addMember(hLayout);
                vLayout.setWidth("130px");
            }
        }

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

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

        return layout;
    }


    @Override
    public Data[] getData() {
        Map values    = form.getValues();
        Iterator keys = values.keySet().iterator();

        Data[] list = new Data[values.size()];
        int       i = 0;

        while (keys.hasNext()) {
            String fieldname = (String) keys.next();
            String selection = (String) values.get(fieldname);

            DataItem item    = new DefaultDataItem(fieldname, null, selection);

            list[i++] = new DefaultData(
                fieldname, null, null, new DataItem[] { item });
        }

        return list;
    }


    @Override
    public void setValues(String cid, boolean checked) {
    }

    @Override
    public boolean renderCheckboxes() {
        return false;
    }

    @Override
    public void success() {
    }

}

http://dive4elements.wald.intevation.org