view gwt-client/src/main/java/org/dive4elements/river/client/client/ui/minfo/BedHeightsDatacagePanel.java @ 8870:c26fb37899ca

Introduced groups for modules. Modules marked with the same group-id, will be put together in the ui. Also using now the localization info from the server instead of localizing the modules again on the client side.
author gernotbelger
date Wed, 07 Feb 2018 11:59:13 +0100
parents 28df64078f27
children e3c2ae1887e8
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.minfo;

import java.util.List;

import org.dive4elements.river.client.client.ui.AbstractPairRecommendationPanel;
import org.dive4elements.river.client.client.ui.DatacageWidget;
import org.dive4elements.river.client.client.ui.DefaultDatacageTwinPanelInfo;
import org.dive4elements.river.client.client.ui.RecommendationPairRecord;
import org.dive4elements.river.client.client.ui.WaterlevelTwinPanelValidator;
import org.dive4elements.river.client.shared.model.DataList;
import org.dive4elements.river.client.shared.model.ToLoad;
import org.dive4elements.river.client.shared.model.User;

import com.google.gwt.core.client.GWT;
import com.smartgwt.client.util.SC;
import com.smartgwt.client.widgets.Button;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.layout.VLayout;
import com.smartgwt.client.widgets.tree.TreeNode;

public class BedHeightsDatacagePanel
extends      AbstractPairRecommendationPanel {

    public BedHeightsDatacagePanel(User user) {
    	// FIXME: This will lead to a bad error message in English (i.e. contains something about waterlevels), for M-Info/Bed-Differences calculation
    	// BUT: this is the behavior of 3.2.1 (because of sloppy derivation), so we do not change it now
        super(user, new WaterlevelTwinPanelValidator(), new DefaultDatacageTwinPanelInfo("bedheight", null), new DefaultDatacageTwinPanelInfo("bedheight", null) );
    }

    @Override
    protected Canvas createChooserWidgets(final Canvas widget, final DataList dataList, final User user, final ListGrid differencesList) {
        GWT.log("createData()");

        Canvas submit = getNextButton();

        final DatacageWidget datacage = new DatacageWidget(
            this.artifact, user, "minfo_diff_panel", "load-system:true", false);

        Button plusBtn = new Button(msg().datacage_add_pair());
        plusBtn.setAutoFit(true);
        plusBtn.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                plusClicked(datacage, differencesList);
            }
        });

        VLayout layout       = new VLayout();
        VLayout helperLayout = new VLayout();
        helperLayout.addMember(datacage);
        helperLayout.addMember(plusBtn);

        layout.addMember(widget);
        layout.addMember(submit);
        layout.setMembersMargin(10);
        this.helperContainer.addMember(helperLayout);

        return layout;
    }

    /**
     * Callback for add-button.
     * Fires to load for every selected element and handler.
     * @param differencesList 
     */
    protected final static void plusClicked( final DatacageWidget datacage, ListGrid differencesList ) {
        List<TreeNode> selection = datacage.getPlainSelection();

        if (selection == null || selection.isEmpty()) {
            SC.say(msg().warning());
            return;
        }

        for (TreeNode node : selection) {
            ToLoad toLoad1 = new ToLoad();
            ToLoad toLoad2 = new ToLoad();

            String factory = node.getAttribute("factory");
            if (factory != null) { // we need at least a factory
                String artifact    = node.getAttribute("artifact-id");
                String out         = node.getAttribute("out");
                String name        = node.getAttribute("facet");
                String ids         = node.getAttribute("ids");
                String info        = node.getAttribute("info");
                String targetOut   = node.getAttribute("target_out");

                String[] splitIds = ids.split("#");
                String[] splitInfo = info.split("#");
                toLoad1.add(artifact,
                     factory,
                     out,
                     name,
                     splitIds[0],
                     splitInfo[0],
                     targetOut);
                toLoad2.add(artifact,
                     factory,
                     out,
                     name,
                     splitIds[1],
                     splitInfo[1],
                     targetOut);
            }
            differencesList.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