view gwt-client/src/main/java/org/dive4elements/river/client/client/ui/ParameterList.java @ 9071:a561b882436d

create module bundu (Betrieb & Unterhaltung) incl. original Fixierungsanalyse+Ausgelagerte Wasserspiegellage
author gernotbelger
date Wed, 16 May 2018 11:08:56 +0200
parents 8c3e5682cb60
children 02739b8c010d
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;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

import org.dive4elements.river.client.client.Config;
import org.dive4elements.river.client.client.FLYS;
import org.dive4elements.river.client.client.FLYSConstants;
import org.dive4elements.river.client.client.event.AdvanceHandler;
import org.dive4elements.river.client.client.event.CollectionChangeEvent;
import org.dive4elements.river.client.client.event.CollectionChangeHandler;
import org.dive4elements.river.client.client.event.HasParameterChangeHandler;
import org.dive4elements.river.client.client.event.HasStepBackHandlers;
import org.dive4elements.river.client.client.event.HasStepForwardHandlers;
import org.dive4elements.river.client.client.event.OutputModesChangeEvent;
import org.dive4elements.river.client.client.event.OutputModesChangeHandler;
import org.dive4elements.river.client.client.event.ParameterChangeEvent;
import org.dive4elements.river.client.client.event.ParameterChangeHandler;
import org.dive4elements.river.client.client.event.StepBackEvent;
import org.dive4elements.river.client.client.event.StepBackHandler;
import org.dive4elements.river.client.client.event.StepForwardEvent;
import org.dive4elements.river.client.client.event.StepForwardHandler;
import org.dive4elements.river.client.client.services.AdvanceService;
import org.dive4elements.river.client.client.services.AdvanceServiceAsync;
import org.dive4elements.river.client.client.services.ArtifactService;
import org.dive4elements.river.client.client.services.ArtifactServiceAsync;
import org.dive4elements.river.client.client.services.ReportService;
import org.dive4elements.river.client.client.services.ReportServiceAsync;
import org.dive4elements.river.client.client.services.StepForwardService;
import org.dive4elements.river.client.client.services.StepForwardServiceAsync;
import org.dive4elements.river.client.client.ui.stationinfo.GaugePanel;
import org.dive4elements.river.client.client.ui.stationinfo.InfoPanel;
import org.dive4elements.river.client.client.ui.stationinfo.MeasurementStationPanel;
import org.dive4elements.river.client.shared.model.Artifact;
import org.dive4elements.river.client.shared.model.ArtifactDescription;
import org.dive4elements.river.client.shared.model.BUNDUArtifact;
import org.dive4elements.river.client.shared.model.Collection;
import org.dive4elements.river.client.shared.model.Data;
import org.dive4elements.river.client.shared.model.DataItem;
import org.dive4elements.river.client.shared.model.DataList;
import org.dive4elements.river.client.shared.model.DefaultData;
import org.dive4elements.river.client.shared.model.DefaultDataItem;
import org.dive4elements.river.client.shared.model.ExportMode;
import org.dive4elements.river.client.shared.model.FixAnalysisArtifact;
import org.dive4elements.river.client.shared.model.MINFOArtifact;
import org.dive4elements.river.client.shared.model.OutputMode;
import org.dive4elements.river.client.shared.model.ReportMode;
import org.dive4elements.river.client.shared.model.River;
import org.dive4elements.river.client.shared.model.SINFOArtifact;
import org.dive4elements.river.client.shared.model.UINFOArtifact;
import org.dive4elements.river.client.shared.model.WINFOArtifact;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.smartgwt.client.types.Overflow;
import com.smartgwt.client.types.VerticalAlignment;
import com.smartgwt.client.types.VisibilityMode;
import com.smartgwt.client.util.SC;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.SectionStack;
import com.smartgwt.client.widgets.layout.SectionStackSection;
import com.smartgwt.client.widgets.layout.VLayout;
import com.smartgwt.client.widgets.tab.Tab;
import com.smartgwt.client.widgets.tab.events.TabSelectedHandler;

public class ParameterList extends Tab implements StepBackHandler, StepForwardHandler, ParameterChangeHandler, HasParameterChangeHandler, CollectionChangeHandler, OutputModesChangeHandler, AdvanceHandler {
    private static final long serialVersionUID = 5204784727239299980L;

    public static final String STYLENAME_OLD_PARAMETERS = "oldParameters";

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

    /** The ArtifactService used to communicate with the Artifact server. */
    protected ArtifactServiceAsync artifactService = GWT.create(ArtifactService.class);

    /** The StepForwardService used to put data into an existing artifact. */
    protected StepForwardServiceAsync forwardService = GWT.create(StepForwardService.class);

    /** The StepForwardService used to put data into an existing artifact. */
    protected AdvanceServiceAsync advanceService = GWT.create(AdvanceService.class);

    protected ReportServiceAsync reportService = GWT.create(ReportService.class);

    /** The list of ParameterizationChangeHandler. */
    protected List<ParameterChangeHandler> parameterHandlers;

    protected FLYS flys;

    protected CollectionView cView;

    protected Artifact artifact;

    protected List<DataList> old;
    protected Map<String, Canvas> oldStorage;
    protected DataList current;

    protected UIProvider uiProvider;

    protected VLayout topLayout;
    protected VLayout oldItems;
    protected VLayout currentItems;
    protected VLayout exportModes;
    protected VLayout report;
    protected VLayout helperPanel;
    protected VLayout tablePanel;
    protected InfoPanel infoPanel;
    protected Canvas reportPanel;

    private SectionStack stack;

    public ParameterList(final FLYS flys, final CollectionView cView, final String title) {
        super(title);

        this.cView = cView;
        this.flys = flys;

        this.parameterHandlers = new ArrayList<ParameterChangeHandler>();
        this.old = new ArrayList<DataList>();
        this.oldStorage = new TreeMap<String, Canvas>();
        this.topLayout = new VLayout();
        this.oldItems = new VLayout();
        this.currentItems = new VLayout();
        this.exportModes = new VLayout();
        this.report = new VLayout();

        addParameterChangeHandler(this);

        init();
    }

    public ParameterList(final FLYS flys, final CollectionView cView, final String title, final Artifact artifact) {
        super(title);

        this.cView = cView;
        this.flys = flys;
        this.artifact = artifact;

        this.parameterHandlers = new ArrayList<ParameterChangeHandler>();
        this.old = new ArrayList<DataList>();
        this.oldStorage = new TreeMap<String, Canvas>();
        this.topLayout = new VLayout();
        this.oldItems = new VLayout();
        this.currentItems = new VLayout();
        this.exportModes = new VLayout();
        this.report = new VLayout();

        init();

        addParameterChangeHandler(this);

        setArtifact(artifact, false);
    }

    protected void init() {
        final HLayout rootLayout = new HLayout();
        rootLayout.setMembersMargin(20);

        final VLayout left = new VLayout();

        if (this.old == null || this.old.size() == 0) {
            this.oldItems.setHeight(1);
        }

        this.oldItems.setMembersMargin(10);
        this.oldItems.setStyleName(STYLENAME_OLD_PARAMETERS);
        this.currentItems.setAlign(VerticalAlignment.TOP);

        left.setMembersMargin(20);
        left.setWidth(300);

        left.addMember(this.oldItems);
        left.addMember(this.currentItems);
        left.addMember(this.exportModes);
        left.addMember(this.report);

        this.reportPanel = new Canvas();
        this.reportPanel.setHeight("*");
        this.report.addMember(this.reportPanel);

        rootLayout.addMember(left);
        rootLayout.addMember(createSectionStack());

        this.topLayout.addMember(rootLayout);
        if (this.artifact == null) {
            final Canvas moduleSelection = renderNew();
            moduleSelection.setLayoutAlign(VerticalAlignment.TOP);
            this.currentItems.addMember(moduleSelection);
        }

        setPane(this.topLayout);
    }

    protected SectionStack createSectionStack() {
        this.stack = new SectionStack();
        this.stack.setHeight100();
        this.stack.setCanResizeSections(true);
        this.stack.setVisibilityMode(VisibilityMode.MULTIPLE);
        this.stack.setOverflow(Overflow.SCROLL);

        // This canvas is used to render helper widgets.
        final SectionStackSection helperSection = new SectionStackSection();
        helperSection.setExpanded(false);
        helperSection.setTitle(this.MSG.helperPanelTitle());
        this.helperPanel = new VLayout() {
            @Override
            public void addMember(final Canvas component) {
                super.addMember(component);
                ParameterList.this.stack.expandSection(helperSection.getID());
            }

            @Override
            public void removeMembers(final Canvas[] components) {
                super.removeMembers(components);
                helperSection.setExpanded(false);
            }
        };
        this.helperPanel.setWidth100();
        this.helperPanel.setHeight100();
        helperSection.setItems(this.helperPanel);

        // This canvas is used to render calculation results.
        final SectionStackSection tableSection = new SectionStackSection();
        tableSection.setExpanded(false);
        tableSection.setTitle(this.MSG.calcTableTitle());
        this.tablePanel = new VLayout() {
            @Override
            public void addMember(final Canvas component) {
                super.addMember(component);
                tableSection.setExpanded(true);
                if (ParameterList.this.stack.getSection(InfoPanel.SECTION_ID) != null) {
                    ParameterList.this.stack.getSection(InfoPanel.SECTION_ID).setExpanded(false);
                }
            }

            @Override
            public void removeMembers(final Canvas[] components) {
                super.removeMembers(components);
                tableSection.setExpanded(false);
            }
        };
        this.tablePanel.setHeight100();
        this.tablePanel.setWidth100();
        tableSection.setItems(this.tablePanel);

        this.stack.setSections(helperSection, tableSection);

        return this.stack;
    }

    /** Sets and forwards artifact. */
    protected void setArtifact(final Artifact artifact) {
        setArtifact(artifact, true);
    }

    protected void setArtifact(final Artifact artifact, final boolean forward) {
        final Artifact tmp = this.artifact;
        this.artifact = artifact;

        if (forward) {
            fireParameterChangeEvent(tmp, this.artifact, ParameterChangeEvent.Type.FORWARD);
        } else {
            fireParameterChangeEvent(tmp, this.artifact, ParameterChangeEvent.Type.BACK);
        }
    }

    /**
     * This method registers a new ParameterChangeHandler.
     *
     * @param handler
     *            The new ParameterChangeHandler.
     */
    @Override
    public void addParameterChangeHandler(final ParameterChangeHandler handler) {
        if (handler != null) {
            this.parameterHandlers.add(handler);
        }
    }

    /**
     * This method calls the <code>onParameterChange()</code> method of all
     * registered ParameterChangeHandler.
     */
    protected void fireParameterChangeEvent(final Artifact old, final Artifact newArt, final ParameterChangeEvent.Type type) {
        final ParameterChangeEvent e = new ParameterChangeEvent(old, newArt, type);

        for (final ParameterChangeHandler handler : this.parameterHandlers) {
            handler.onParameterChange(e);
        }
    }

    /**
     * This method creates a Canvas displaying the plugins of FLYS combined with
     * a widget to select a river.
     *
     * @return a Canvas that displays the supported plugins and rivers of FLYS.
     */
    protected Canvas renderNew() {
        final River[] rivers = this.flys.getRivers();
        final DataItem[] items = new DataItem[rivers.length];

        int i = 0;
        for (final River river : rivers) {
            final String name = river.getName();
            final String mUuid = river.getModelUuid();
            items[i++] = new DefaultDataItem(name, null, mUuid);
        }

        final Data data = new DefaultData("river", this.MSG.river_selection(), null, items);

        final LinkSelection widget = new LinkSelection();
        final HasStepForwardHandlers handler = widget;

        widget.setContainer(this.helperPanel);

        handler.addStepForwardHandler(new StepForwardHandler() {
            private static final long serialVersionUID = -6210719844707004860L;

            @Override
            public void onStepForward(final StepForwardEvent event) {
                lockUI();
                final Data[] data = event.getData();

                final DataItem[] moduleItems = data[0].getItems();
                final DataItem[] riversItems = data[1].getItems();

                final String module = moduleItems[0].getStringValue();
                final String river = riversItems[0].getStringValue();

                if (module == null || river == null) {
                    GWT.log("ParameterList.renderNew(): module == null " + "|| river == null");
                    unlockUI();
                    return;
                }
                final String newTitle = moduleItems[0].getLabel();
                setTitle(newTitle);

                final Config config = Config.getInstance();
                final String locale = config.getLocale();

                final Data[] feedData = new Data[] { data[1] };

                ParameterList.this.artifactService.create(locale, module.toLowerCase(), null, new AsyncCallback<Artifact>() {
                    @Override
                    public void onFailure(final Throwable caught) {
                        unlockUI();
                        GWT.log("Could not create the new artifact.");
                        SC.warn(FLYS.getExceptionString(ParameterList.this.MSG, caught));
                    }

                    @Override
                    public void onSuccess(final Artifact artifact) {
                        GWT.log("Successfully created a new artifact.");

                        ParameterList.this.forwardService.go(locale, artifact, feedData, new AsyncCallback<Artifact>() {
                            @Override
                            public void onFailure(final Throwable caught) {
                                unlockUI();
                                GWT.log("Could not feed the artifact.");
                                SC.warn(caught.getMessage());
                            }

                            @Override
                            public void onSuccess(final Artifact artifact) {
                                GWT.log("Successfully feed the artifact.");
                                ParameterList.this.old.clear();
                                ParameterList.this.cView.addArtifactToCollection(artifact);
                                setArtifact(artifact);
                                unlockUI();
                            }
                        });
                    }
                });
            }
        });

        final DataList list = new DataList();
        list.add(data);

        return widget.create(list);
    }

    protected void clearOldData() {
        this.old.clear();
    }

    public void addOldData(final DataList old) {
        addOldData(old, true);
    }

    public void addOldData(final DataList old, final boolean redraw) {
        if (old != null) {
            this.old.add(old);
        }

        refreshOld(redraw);
    }

    public void addOldDatas(final DataList[] old) {
        addOldDatas(old, true);
    }

    public void addOldDatas(final DataList[] old, final boolean redraw) {
        if (old != null && old.length > 0) {
            for (final DataList o : old) {
                if (o == null) {
                    continue;
                }

                if (!exists(o)) {
                    GWT.log("Data '" + o.getLabel() + "' is new.");
                    addOldData(o, false);
                }
            }

            if (redraw) {
                addOldData(null, true);
            }

            return;
        }

        addOldData(null, true);
    }

    public boolean exists(final DataList data) {
        if (data == null) {
            return false;
        }

        final String stateName = data.getState();

        for (final DataList o : this.old) {
            if (stateName.equals(o.getState())) {
                return true;
            }
        }

        return false;
    }

    public void setCurrentData(final DataList current, final UIProvider uiProvider) {
        this.current = current;
        this.uiProvider = uiProvider;

        refreshCurrent();
    }

    public void refreshOld(final boolean redrawAll) {
        if (redrawAll) {
            refreshAllOld();
        } else {
            final DataList dataList = this.old.get(this.old.size() - 1);
            final String state = dataList.getState();

            if (this.oldStorage.get(state) == null) {
                final String provider = dataList.getUIProvider();
                final UIProvider uiprovider = UIProviderFactory.getProvider(provider, this.flys.getCurrentUser());
                ((HasStepBackHandlers) uiprovider).addStepBackHandler(this);

                final Canvas c = uiprovider.createOld(dataList);
                if (c != null) {
                    this.oldStorage.put(dataList.getState(), c);
                    this.oldItems.addMember(c);
                }
            }
        }

        updateOldHeight();
    }

    protected void refreshAllOld() {
        final List<String> not = new ArrayList<String>();

        for (final DataList data : this.old) {
            final String state = data.getState();

            final Canvas c = this.oldStorage.get(state);

            if (c != null) {
                not.add(state);
            }
        }

        final Map<String, Canvas> newOld = new TreeMap<String, Canvas>();

        final Set<Map.Entry<String, Canvas>> entries = this.oldStorage.entrySet();
        for (final Map.Entry<String, Canvas> entry : entries) {
            final String state = entry.getKey();
            final Canvas value = entry.getValue();

            if (not.indexOf(state) < 0) {
                this.oldItems.removeMember(value);
            } else {
                newOld.put(state, value);
            }
        }

        this.oldStorage = newOld;
    }

    protected void updateOldHeight() {
        final int minHeight = this.oldItems.getMinHeight();
        if (minHeight <= 20) {
            this.oldItems.setHeight(20);
        } else {
            this.oldItems.setHeight(minHeight);
        }
    }

    /**
     * Refreshes the part displaying the data of the current state.
     * The UI is created using the UIProvider stored in the Data object.
     */
    public void refreshCurrent() {
        this.currentItems.removeMembers(this.currentItems.getMembers());

        if (this.current != null && this.uiProvider != null) {
            final Canvas c = this.uiProvider.create(this.current);
            final Canvas h = this.uiProvider.createHelpLink(this.current, null, this.flys);

            final HLayout wrapper = new HLayout();
            wrapper.addMember(h);
            wrapper.addMember(c);

            this.currentItems.addMember(wrapper);
        } else if (this.uiProvider != null) {
            final Canvas c = this.uiProvider.create(null);
            c.setLayoutAlign(VerticalAlignment.TOP);

            this.currentItems.addMember(c);
        } else {
            this.currentItems.setHeight(1);
        }

        final Canvas[] members = this.currentItems.getMembers();
        if (members == null || members.length == 0) {
            this.currentItems.setHeight(1);
        } else {
            int height = 0;

            for (final Canvas member : members) {
                height += member.getHeight();
            }

            this.currentItems.setHeight(height);
        }
    }

    /**
     * This method is called if the user clicks on the 'next' button to advance
     * to the next state.
     *
     * @param event
     *            The StepForwardEvent.
     */
    @Override
    public void onStepForward(final StepForwardEvent event) {
        GWT.log("CollectionView - onStepForward()");
        lockUI();

        final Config config = Config.getInstance();
        final String locale = config.getLocale();

        this.forwardService.go(locale, this.artifact, event.getData(), new AsyncCallback<Artifact>() {
            @Override
            public void onFailure(final Throwable caught) {
                unlockUI();
                GWT.log("Could not feed the artifact.");
                SC.warn(FLYS.getExceptionString(ParameterList.this.MSG, caught));
            }

            @Override
            public void onSuccess(final Artifact artifact) {
                GWT.log("Successfully feed the artifact.");
                ParameterList.this.old.clear();

                setArtifact(artifact, true);
                unlockUI();
            }
        });
    }

    /**
     * This method is used to remove all old items from this list after the user
     * has clicked the step back button.
     *
     * @param e
     *            The StepBackEvent that holds the identifier of the target state.
     */
    @Override
    public void onStepBack(final StepBackEvent e) {
        lockUI();
        final String target = e.getTarget();

        final Config config = Config.getInstance();
        final String locale = config.getLocale();

        this.advanceService.advance(locale, this.artifact, target, new AsyncCallback<Artifact>() {
            @Override
            public void onFailure(final Throwable caught) {
                unlockUI();
                GWT.log("Could not go back to '" + target + "'");
                SC.warn(FLYS.getExceptionString(ParameterList.this.MSG, caught));
            }

            @Override
            public void onSuccess(final Artifact artifact) {
                GWT.log("Successfully step back to '" + target + "'");

                ParameterList.this.old.clear();

                setArtifact(artifact, false);
                unlockUI();
            }
        });
    }

    @Override
    public void onAdvance(final String target) {
        final Config config = Config.getInstance();
        final String locale = config.getLocale();

        this.advanceService.advance(locale, this.artifact, target, new AsyncCallback<Artifact>() {
            @Override
            public void onFailure(final Throwable caught) {
                GWT.log("Could not go to '" + target + "'");
                SC.warn(FLYS.getExceptionString(ParameterList.this.MSG, caught));
            }

            @Override
            public void onSuccess(final Artifact artifact) {
                GWT.log("Successfully advanced to '" + target + "'");

                ParameterList.this.old.clear();

                setArtifact(artifact, true);
            }
        });
    }

    /**
     * Implements the onCollectionChange() method to do update the GUI after the
     * parameterization has changed.
     *
     * @param event
     *            The ParameterChangeEvent.
     */
    @Override
    public void onParameterChange(final ParameterChangeEvent event) {
        GWT.log("ParameterList.onParameterChange");

        final Canvas[] c = this.helperPanel.getMembers();
        if (c != null && c.length > 0) {
            this.helperPanel.removeMembers(c);
        }

        final Artifact art = event.getNewValue();
        final ArtifactDescription desc = art.getArtifactDescription();

        final DataList currentData = desc.getCurrentData();
        if (currentData != null) {
            // the user has to enter some attributes
            final String uiProvider = currentData.getUIProvider();
            final UIProvider provider = UIProviderFactory.getProvider(uiProvider, this.flys.getCurrentUser());

            provider.setContainer(this.helperPanel);
            provider.setArtifact(art);
            provider.setCollection(this.cView.getCollection());
            provider.setParameterList(this);

            ((HasStepForwardHandlers) provider).addStepForwardHandler(this);
            ((HasStepBackHandlers) provider).addStepBackHandler(this);

            setCurrentData(currentData, provider);
        } else {
            final String[] reachable = desc.getReachableStates();
            if (reachable != null && reachable.length > 0) {
                // We have reached a final state with the option to step to
                // further to a next state. But in the current state, no user
                // data is required.
                final UIProvider ui = UIProviderFactory.getProvider("continue", null);
                ui.setArtifact(art);
                ui.setCollection(this.cView.getCollection());
                ui.setParameterList(this);

                ((ContinuePanel) ui).addAdvanceHandler(this);

                setCurrentData(null, ui);
            } else {
                // we have reached a final state with no more user input
                setCurrentData(null, null);
            }
        }

        // FIXME: we got a whole artifact framework to separate ui and backend stuff, but in the end.... we have switches over
        // specific datatypes here...
        if (art instanceof WINFOArtifact || art instanceof SINFOArtifact || art instanceof UINFOArtifact || art instanceof FixAnalysisArtifact
                || art instanceof BUNDUArtifact) {
            createGaugePanel();
            renderInfo(desc.getRiver(), desc.getOldData());
        } else if (art instanceof MINFOArtifact) {
            createMeasurementStationPanel();
            renderInfo(desc.getRiver(), desc.getOldData());
        } else {
            removeInfoPanel();
        }

        addOldDatas(desc.getOldData(), event.getType() == ParameterChangeEvent.Type.BACK);
    }

    @Override
    public void onCollectionChange(final CollectionChangeEvent event) {
        final Collection c = event.getNewValue();
        final Map<String, OutputMode> outs = c.getOutputModes();
        final Set<String> keys = outs.keySet();

        final OutputMode[] outputs = new OutputMode[outs.size()];

        int idx = 0;
        for (final String outname : keys) {
            outputs[idx++] = outs.get(outname);
        }

        updateExportModes(c, getExportModes(outputs));
        updateReportModes(c, getReportModes(outputs));
    }

    @Override
    public void onOutputModesChange(final OutputModesChangeEvent event) {

        final Collection c = this.cView.getCollection();

        if (c != null) {
            final OutputMode[] outs = event.getOutputModes();
            updateExportModes(c, getExportModes(outs));
            updateReportModes(c, getReportModes(outs));
        }
    }

    protected List<ReportMode> getReportModes(final OutputMode[] outs) {

        final List<ReportMode> reports = new ArrayList<ReportMode>();

        if (outs == null || outs.length == 0) {
            return reports;
        }

        for (final OutputMode out : outs) {
            if (out instanceof ReportMode) {
                reports.add((ReportMode) out);
            }
        }

        return reports;
    }

    protected List<ExportMode> getExportModes(final OutputMode[] outs) {
        final List<ExportMode> exports = new ArrayList<ExportMode>();

        if (outs == null || outs.length == 0) {
            return exports;
        }

        for (final OutputMode out : outs) {
            if (out instanceof ExportMode) {
                exports.add((ExportMode) out);
            }
        }

        return exports;
    }

    protected void updateExportModes(final Collection c, final List<ExportMode> exports) {
        final int num = exports != null ? exports.size() : 0;
        GWT.log("Update export modes: " + num);

        this.exportModes.removeMembers(this.exportModes.getMembers());

        if (exports.size() > 0) {
            this.exportModes.addMember(new ExportPanel(c, exports));
        } else {
            this.exportModes.setHeight(1);
        }
    }

    protected void updateReportModes(final Collection c, final List<ReportMode> reports) {
        final int num = reports != null ? reports.size() : 0;
        GWT.log("Update report modes: " + num);

        if (num == 0) {
            this.reportPanel.setContents("");
            return;
        }

        final Config config = Config.getInstance();
        final String locale = config.getLocale();

        final String cid = c.identifier();

        for (final ReportMode report : reports) {
            GWT.log("report '" + report.toString() + "'");

            this.reportService.report(cid, locale, report.getName(), new AsyncCallback<String>() {
                @Override
                public void onFailure(final Throwable caught) {
                    SC.warn(FLYS.getExceptionString(ParameterList.this.MSG, caught));
                }

                @Override
                public void onSuccess(final String msg) {
                    setReportMessage(msg);
                }
            });
        }
    }

    /** Sets content of reportPanel. */
    protected void setReportMessage(String msg) {
        GWT.log("returned from service: " + msg);
        if (msg == null) {
            msg = "";
        }
        this.reportPanel.setContents(msg);
    }

    /**
     * Adds a table to the parameterlist to show calculated data.
     *
     * @param table
     *            The table data panel.
     */
    public void setTable(final TableDataPanel table) {
        removeTable();

        final Canvas c = table.create();
        c.setHeight100();
        c.setWidth100();

        this.tablePanel.addMember(c);
    }

    public boolean hasTable() {
        final Canvas[] members = this.tablePanel.getMembers();

        return members != null && members.length > 0;
    }

    /**
     * Removes the table from the parameter list.
     */
    public void removeTable() {
        final Canvas[] members = this.tablePanel.getMembers();

        if (members != null && members.length > 0) {
            this.tablePanel.removeMembers(members);
        }
    }

    public void registerCollectionViewTabHandler(final TabSelectedHandler tsh) {
        this.cView.registerTabHandler(tsh);
    }

    protected void lockUI() {
        this.cView.lockUI();
    }

    protected void unlockUI() {
        this.cView.unlockUI();
    }

    private void createGaugePanel() {
        GWT.log("ParameterList - createGaugePanel");
        if (this.infoPanel == null) {
            this.infoPanel = new GaugePanel(this.flys);
            this.infoPanel.setWidth100();
            this.infoPanel.setHeight100();
        }
    }

    private void createMeasurementStationPanel() {
        GWT.log("ParameterList - createMeasurementStationPanel");
        if (this.infoPanel == null) {
            this.infoPanel = new MeasurementStationPanel(this.flys);
            this.infoPanel.setWidth100();
            this.infoPanel.setHeight100();
        }
    }

    private void showInfoPanel() {
        GWT.log("ParameterList - showInfoPanel");

        /* Don't add InfoPanel twice */
        SectionStackSection info = this.stack.getSection(InfoPanel.SECTION_ID);
        if (info == null) {
            info = new SectionStackSection();
            info.setTitle(this.infoPanel.getSectionTitle());
            info.setID(InfoPanel.SECTION_ID);
            info.setName(InfoPanel.SECTION_ID);
            info.setItems(this.infoPanel);
            this.stack.addSection(info, 0);
        }

        info.setExpanded(true);
    }

    private void hideInfoPanel() {
        GWT.log("ParameterList - hideInfoPanel");

        if (this.infoPanel != null) {
            this.infoPanel.hide();
        }
    }

    private void removeInfoPanel() {
        GWT.log("ParameterList - removeInfoPanel");
        final SectionStackSection exists = this.stack.getSection(InfoPanel.SECTION_ID);
        if (exists != null) {
            this.stack.removeSection(InfoPanel.SECTION_ID);
        }
    }

    private void renderInfo(final String river, final DataList[] data) {
        GWT.log("ParameterList - renderInfo");

        if (river != null) {
            showInfoPanel();
            this.infoPanel.setRiver(river);
            this.infoPanel.setData(data);
        } else {
            GWT.log("ParameterList - renderInfo no river");
            hideInfoPanel();
        }
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org