view flys-client/src/main/java/de/intevation/flys/client/client/ui/DatacagePairWidget.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 1755a1bfe5ce
children 5e6e89f19a37
line wrap: on
line source
package de.intevation.flys.client.client.ui;

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

import com.smartgwt.client.widgets.Button;

import com.smartgwt.client.widgets.layout.VLayout;
import com.smartgwt.client.widgets.layout.HLayout;

import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.events.ClickEvent;

import com.smartgwt.client.widgets.grid.ListGrid;

import de.intevation.flys.client.shared.model.Artifact;
import de.intevation.flys.client.shared.model.User;
import de.intevation.flys.client.shared.model.ToLoad;

import de.intevation.flys.client.client.FLYSConstants;


/**
 * Widget showing two Datacages and a add-this-button.
 * Insert a record into a listgrid when add-this-button clicked.
 */
public class DatacagePairWidget
extends      VLayout
{
    /** i18n resource. */
    protected FLYSConstants MSG =
        GWT.create(FLYSConstants.class);

    /** The "remote" ListGrid to insert data to when add-button is clicked. */
    protected ListGrid grid;

    /** First (upper) DataCage Grid. */
    protected DatacageWidget firstDatacageWidget;

    /** Second (lower) DataCage Grid. */
    protected DatacageWidget secondDatacageWidget;


    /**
     *
     * @param artifact Artifact to query datacage with.
     * @param user     User to query datacage with.
     * @param outs     outs to query datacage with.
     * @param grid     Grid into which to insert selection of pairs.
     */
    public DatacagePairWidget(Artifact artifact,
         User user,
         String outs,
         ListGrid grid) {
        this.grid = grid;

        HLayout hLayout      = new HLayout();
        firstDatacageWidget  = new DatacageWidget(
            artifact,
            user,
            outs,
            "load-system:true",
            false);
        secondDatacageWidget = new DatacageWidget(
            artifact,
            user,
            outs,
            "load-system:true",
            false);
        firstDatacageWidget.setIsMutliSelectable(false);
        secondDatacageWidget.setIsMutliSelectable(false);

        hLayout.addMember(firstDatacageWidget);
        hLayout.addMember(secondDatacageWidget);

        // TODO: icon
        Button plusBtn = new Button(MSG.datacage_add_pair());
        plusBtn.setAutoFit(true);
        plusBtn.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                plusClicked();
            }
        });

        addMember(hLayout);
        addMember(plusBtn);
    }


    /**
     * Callback for add-button.
     * Fires to load for every selected element and handler.
     */
    public void plusClicked() {
        ToLoad toLoad1 = firstDatacageWidget.getSelection();
        ToLoad toLoad2 = secondDatacageWidget.getSelection();

        // TODO further sanitize (toRecommendations.length)
        if (toLoad1 == null || toLoad2 == null) {
            return;
        }

        grid.addData(new RecommendationPairRecord(
            toLoad1.toRecommendations().get(0),
            toLoad2.toRecommendations().get(0)));
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org