view flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapPrintSettingsPanel.java @ 4472:dc7e41efd5ba

Work (in progress) on a print settings dialog. Add Wheregroups WMS to printing whitelist.
author Christian Lins <christian.lins@intevation.de>
date Sat, 10 Nov 2012 00:53:28 +0100
parents
children 6db783627137
line wrap: on
line source
package de.intevation.flys.client.client.ui.map;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;

import com.smartgwt.client.util.SC;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.fields.ButtonItem;
import com.smartgwt.client.widgets.form.fields.SelectItem;
import com.smartgwt.client.widgets.form.fields.TextItem;
import com.smartgwt.client.widgets.form.fields.events.ClickEvent;
import com.smartgwt.client.widgets.form.fields.events.ClickHandler;

import de.intevation.flys.client.client.Config;
import de.intevation.flys.client.client.FLYSConstants;
import de.intevation.flys.client.client.services.CollectionAttributeService;
import de.intevation.flys.client.client.services.CollectionAttributeServiceAsync;
import de.intevation.flys.client.shared.model.Collection;
import de.intevation.flys.client.shared.model.OutputSettings;
import de.intevation.flys.client.shared.model.Property;
import de.intevation.flys.client.shared.model.PropertySetting;
import de.intevation.flys.client.shared.model.Settings;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

public class MapPrintSettingsPanel extends Canvas {

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

    /** CollectionAttribute Update Service. */
    protected CollectionAttributeServiceAsync updater =
        GWT.create(CollectionAttributeService.class);

    protected Collection collection;
    protected Settings settings;
    protected TextItem pageTitle = new TextItem();

    public MapPrintSettingsPanel(Collection collection) {
        this.collection = collection;
        initLayout();

        this.settings = collection.getSettings("print-settings");
        if (settings == null) {
            settings = new OutputSettings();
        }
        else {
            List<Property> properties = settings.getSettings("default");
            for (Property prop : properties) {
                PropertySetting props = (PropertySetting)prop;
                if (props.getName().equals("page-format")) {

                }
                else if (props.getName().equals("page-title")) {
                    this.pageTitle.setValue(props.getValue());
                    GWT.log(props.getName() + "=" + props.getValue());
                }
            }
        }
    }

    protected void initLayout() {
        this.pageTitle.setTitle("Seitentitel:");

        DynamicForm df = new DynamicForm();
        df.setFields(
               createPageFormatSelectItem(),
               this.pageTitle,
               createSaveSettingsButtonItem()
               );
        addChild(df);
    }

    protected SelectItem createPageFormatSelectItem() {
        LinkedHashMap values = new LinkedHashMap();
        values.put("din_a4", "DIN A4");
        values.put("din_a0", "DIN A0");

        SelectItem selItem = new SelectItem();
        selItem.setTitle("Seitenformat:");
        selItem.setValueMap(values);
        selItem.setDefaultToFirstOption(true);

        return selItem;
    }

    protected ButtonItem createSaveSettingsButtonItem() {
        ButtonItem btn = new ButtonItem();
        btn.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                updateCollection();
            }
        });
        btn.setTitle("Speichern");
        return btn;
    }

    protected void updateCollection() {
        final Config config = Config.getInstance();
        final String loc    = config.getLocale();

        GWT.log("MapPrintSettingsPanel.updateCollection via RPC now");

        List<Property> properties = new ArrayList<Property>();
        properties.add(new PropertySetting("page-title", this.pageTitle.getValueAsString()));
        settings.setSettings("default", properties);

        collection.addSettings("print-settings", settings);
        updater.update(collection, loc, new AsyncCallback<Collection>() {
            @Override
            public void onFailure(Throwable caught) {
                GWT.log("Could not update collection attributes.");
                SC.warn(MSG.getString(caught.getMessage()));
            }
            @Override
            public void onSuccess(Collection collection) {
                GWT.log("MapPrintSettings: collection attributes updated");
            }
        });
    }
}

http://dive4elements.wald.intevation.org