view flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapThemePanel.java @ 1303:84c50f1d939b

Added the option for the MapThemePanel to listen to Theme move events. flys-client/trunk@2936 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 11 Oct 2011 11:50:58 +0000
parents e50da1f74e58
children 8a93fb299e64
line wrap: on
line source
package de.intevation.flys.client.client.ui.map;

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

import com.smartgwt.client.types.ListGridFieldType;
import com.smartgwt.client.widgets.grid.ListGridField;
import com.smartgwt.client.widgets.layout.VLayout;

import de.intevation.flys.client.shared.model.Collection;
import de.intevation.flys.client.shared.model.Theme;
import de.intevation.flys.client.shared.model.OutputMode;

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


/**
 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
 */
public class MapThemePanel extends ThemePanel {

    public interface ActivateCallback {
        void activate(Theme theme, boolean activate);
    }


    public interface ThemeMovedCallback {
        void onThemeMoved(Theme theme, int oldIdx, int newIdx);
    }



    private FLYSConstants MSG = GWT.create(FLYSConstants.class);


    protected ActivateCallback   activateCallback;
    protected ThemeMovedCallback themeMovedCallback;


    public static final String GRID_FIELD_ACTIVE = "active";
    public static final String GRID_FIELD_NAME   = "name";


    protected MapOutputTab mapOut;


    public MapThemePanel(
        Collection         collection,
        OutputMode         mode,
        ActivateCallback   activateCallback
    ) {
        this(collection, mode, activateCallback, null);
    }


    public MapThemePanel(
        Collection         collection,
        OutputMode         mode,
        ActivateCallback   activateCallback,
        ThemeMovedCallback themeMovedCallback
    ) {
        super(collection, mode);

        this.activateCallback   = activateCallback;
        this.themeMovedCallback = themeMovedCallback;

        initGrid();
        initLayout();

        updateGrid();
    }


    protected void initLayout() {
        setWidth100();
        setHeight100();

        VLayout layout = new VLayout();
        layout.setWidth100();
        layout.setHeight100();

        layout.addMember(list);
        layout.addMember(navigation);

        addChild(layout);
    }


    protected void initGrid() {
        list.setCanEdit(true);
        list.setCanSort(false);
        list.setShowRecordComponents(false);
        list.setShowRecordComponentsByCell(true);
        list.setShowHeader(true);
        list.setShowHeaderContextMenu(false);
        list.setWidth100();
        list.setHeight100();

        list.addEditCompleteHandler(this);

        ListGridField active = new ListGridField(GRID_FIELD_ACTIVE, " ", 20);
        active.setType(ListGridFieldType.BOOLEAN);

        ListGridField name = new ListGridField(
            GRID_FIELD_NAME, MSG.chart_themepanel_header_themes());
        name.setType(ListGridFieldType.TEXT);

        list.setFields(active, name);
    }


    @Override
    public void activateTheme(Theme theme, boolean active) {
        if (activateCallback != null) {
            activateCallback.activate(theme, active);
        }

        theme.setActive(active ? 1 : 0);
    }


    @Override
    protected void fireThemeMoved(Theme theme, int oldIdx, int newIdx) {
        if (themeMovedCallback != null) {
            themeMovedCallback.onThemeMoved(theme, oldIdx, newIdx);
        }
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org