it.geosdi.era.client.controllo.PrintingController.java Source code

Java tutorial

Introduction

Here is the source code for it.geosdi.era.client.controllo.PrintingController.java

Source

/*
 *  GeoSDI ERA - The new era of webGIS
 *  http://code.google.com/p/geosdiera/
 * ====================================================================
 *
 * Copyright (C) 2008-2009 GeoSDI Group (CNR IMAA).
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. 
 *
 * ====================================================================
 *
 * This software consists of voluntary contributions made by developers
 * of GeoSDI Group.  For more information on GeoSDI, please see
 * <http://www.geosdi.org/>.
 *
 */
package it.geosdi.era.client.controllo;

import it.geosdi.era.client.AppEvents;
import it.geosdi.era.client.Costanti;
import it.geosdi.era.client.ERAMessages;
import it.geosdi.era.client.core.GestoreMappa;
import it.geosdi.era.client.form.print.PrintEraForm;
import it.geosdi.era.client.utility.model.printing.PrintEraBean;

import com.extjs.gxt.ui.client.Registry;
import com.extjs.gxt.ui.client.mvc.AppEvent;
import com.extjs.gxt.ui.client.mvc.Controller;
import com.google.gwt.core.client.GWT;
import com.google.gwt.http.client.URL;
import com.google.gwt.user.client.Window;

/**
 * @author giuseppe
 * 
 */
public class PrintingController extends Controller {

    /** Internationalization **/
    protected static ERAMessages messages = GWT.create(ERAMessages.class);

    private PrintEraForm printEraForm;
    private GestoreMappa managerMap;

    public PrintingController() {
        registerEventTypes(AppEvents.InitPrint, AppEvents.SendRequestForPrinting);
    }

    public void initialize() {
        this.printEraForm = new PrintEraForm(this);
        this.managerMap = Registry.get(Costanti.MAPPA_OPEN_LAYERS);
    }

    @Override
    public void handleEvent(AppEvent<?> event) {
        switch (event.type) {
        case AppEvents.InitPrint:
            onShowEraPrint();
            break;
        case AppEvents.SendRequestForPrinting:
            onCloseEraPrint();
            onSendRequestForPrinting(event);
            break;
        }
    }

    private void onSendRequestForPrinting(AppEvent<?> event) {
        String url = GWT.getHostPageBaseURL() + "pdf/print.pdf?spec="
                + URL.encode(((PrintEraBean) event.data).toStringJSON());

        Window.open(url, "_blank", "");
    }

    private void onShowEraPrint() {
        this.printEraForm.show();
    }

    private void onCloseEraPrint() {
        this.printEraForm.close();
    }

    /**
     * @return the managerMap
     */
    public GestoreMappa getManagerMap() {
        return managerMap;
    }
}