view flys-client/src/main/java/de/intevation/flys/client/client/ui/ModuleSelection.java @ 522:2e02db03e576

Removed needless imports. flys-client/trunk@2001 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 25 May 2011 11:30:46 +0000
parents e92f7ef455d6
children 3adfb0f88eca
line wrap: on
line source
package de.intevation.flys.client.client.ui;

import java.util.LinkedHashMap;

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

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.RadioGroupItem;
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 de.intevation.flys.client.client.FLYSConstants;

/**
 * The ModuleSelection combines the river selection and the module selection in
 * one widget. It will display a vertical splitted widget - the upper part will
 * render checkboxes for each module, the lower one will display a combobox at
 * the left and a map panel on the right to choose the river.
 *
 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
 */
public class ModuleSelection extends MapSelection {

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


    /** Constant field name for the plugin selection.*/
    public static final String FIELD_PLUGIN = "plugin";

    /** Constant value for the WINFO plugin.*/
    public static final String FIELD_PLUGIN_WINFO = "winfo";

    /** Constant value for the MINFO plugin.*/
    public static final String FIELD_PLUGIN_MINFO = "minfo";

    /** Constant value for the MAP plugin.*/
    public static final String FIELD_PLUGIN_MAP   = "map";

    /** Constant value for the CHART plugin.*/
    public static final String FIELD_PLUGIN_CHART = "chart";

    /** Constant value for the FIX plugin.*/
    public static final String FIELD_PLUGIN_FIX   = "fix";


    /** The module checkboxes.*/
    protected RadioGroupItem radio;


    /**
     * The default constructor.
     */
    public ModuleSelection() {
    }


    /**
     * This method returns a widget that renders the checkboxes for each module
     * and the MapSelection that lets the user choose the river.
     *
     * @param data The provided rivers.
     *
     * @return the module selection combined with the river selection.
     */
    public Canvas create(DataList data) {
        VLayout newLayout = new VLayout();
        newLayout.setMembersMargin(10);
        newLayout.setAlign(VerticalAlignment.TOP);
        Canvas moduleSelection = createWidget();

        moduleSelection.setHeight(100);
        newLayout.setHeight(70);
        newLayout.addMember(moduleSelection);

        return newLayout;
    }


    /**
     * Creates a widget that displays a checkbox for each module.
     *
     * @return a widget with checkboxes.
     */
    protected Canvas createWidget() {
        HLayout layout = new HLayout();

        Label      label = new Label(MESSAGES.module_selection());
        DynamicForm form = new DynamicForm();

        radio = new RadioGroupItem("plugin");

        label.setWidth(50);
        label.setHeight(25);

        LinkedHashMap values = new LinkedHashMap();
        values.put(FIELD_PLUGIN_WINFO, messages.winfo());
        values.put(FIELD_PLUGIN_MINFO, messages.minfo());
        values.put(FIELD_PLUGIN_FIX, messages.fix());
        values.put(FIELD_PLUGIN_CHART, messages.chart());
        values.put(FIELD_PLUGIN_MAP, messages.map());

        radio.setShowTitle(false);
        radio.setVertical(true);
        radio.setValueMap(values);

        LinkedHashMap initial = new LinkedHashMap();
        initial.put(FIELD_PLUGIN, FIELD_PLUGIN_WINFO);

        form.setFields(radio);
        form.setValues(initial);

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

        return layout;
    }


    /**
     * This method prepares the data of two widgets - the module selection and
     * the river selection. The returning field will contain the Data that
     * represents the module selection at first position, the second position
     * stores the Data object that represents the river selection.
     *
     * @return the Data that was chosen in this widget.
     */
    protected Data[] getData() {

        String module = radio.getValueAsString();

        DataItem[] items = new DefaultDataItem[1];
        items[0]         = new DefaultDataItem(module, module, module);

        Data       data  = new DefaultData("module", null, null, items);

        return new Data[] {data};
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org