view gnv/src/main/java/de/intevation/gnv/action/sessionmodel/DefaultSessionModel.java @ 1022:28a0628b11b0

Added license file and license header. gnv/trunk@1258 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 02 Nov 2010 17:15:08 +0000
parents d1ed5c51c0de
children
line wrap: on
line source
/*
 * Copyright (c) 2010 by Intevation GmbH
 *
 * This program is free software under the LGPL (>=v2.1)
 * Read the file LGPL.txt coming with the software for details
 * or visit http://www.gnu.org/licenses/ if it does not exist.
 */

package de.intevation.gnv.action.sessionmodel;

import java.util.Collection;
import java.util.Iterator;
import java.util.Locale;

import org.apache.log4j.Logger;

import de.intevation.gnv.artifactdatabase.objects.ArtifactDescription;
import de.intevation.gnv.artifactdatabase.objects.ArtifactObject;
import de.intevation.gnv.artifactdatabase.objects.ArtifactStatisticsSet;
import de.intevation.gnv.artifactdatabase.objects.OutputMode;
import de.intevation.gnv.artifactdatabase.objects.map.MapService;

/**
 * The default implementation of <code>SessionModel</code> which stores the
 * current artifact object and the digram options selected by the user.
 *
 * @author <a href="mailto:tim.englich@intevation.de">Tim Englich</a>
 *
 */
public class DefaultSessionModel implements SessionModel {



    /**
     * the logger, used to log exceptions and additonaly information
     */
    private static Logger log = Logger.getLogger(DefaultSessionModel.class);

    /**
     * The UID of this Class.
     */
    private static final long serialVersionUID = 3431484439985158311L;

    /**
     * Container for <code>ArtifactFactory</code>-objects.
     */
    private Collection<ArtifactObject> artifactFactories = null;

    /**
     * The selected <code>ArtifactFactory</code>
     */
    private ArtifactObject selectedArtifactFactory = null;

    /**
     * The currently used artifact.
     */
    private ArtifactObject currentArtifact = null;

    /**
     * The Diagrammoptions.
     */
    private DiagrammOptions diagrammOptions = null;

    /**
     * The Container for statistic-values.
     */
    private Collection<ArtifactStatisticsSet> statistics = null;

    /**
     * The Locale that currently should be used.
     */
    private Locale currentLocale;

    /**
     * The Mapservice containing all Layers that should be displayed.
     */
    private MapService localMapService = null;
    /**
     * Constructor
     */
    public DefaultSessionModel() {
        this(null);
    }

    /**
     * Constructor
     * @param currentLocale A locale used to create the user interface.
     */
    public DefaultSessionModel(Locale currentLocale) {
        this.currentLocale = currentLocale;
    }


    public void selectArtifactFactory(String artiFactFactoryId) {
        Collection<ArtifactObject> artifactObjects = this
                .getArtifactFactories();
        if (artifactObjects != null) {
            Iterator<ArtifactObject> unselect = artifactObjects.iterator();
            this.selectedArtifactFactory = null;
            while (unselect.hasNext()) {
                unselect.next().setSelected(false);
            }
            Iterator<ArtifactObject> it = artifactObjects.iterator();
            while (it.hasNext()) {
                ArtifactObject obj = it.next();
                if (obj.getId().equals(artiFactFactoryId)) {
                    obj.setSelected(true);
                    this.selectedArtifactFactory = obj;
                    break;
                }
            }
        }
    }


    public void setArtifacteFactories(
                                Collection<ArtifactObject> artifactFactories) {
        this.artifactFactories = artifactFactories;
    }


    public Collection<ArtifactObject> getArtifactFactories() {
        return this.artifactFactories;
    }


    public ArtifactObject getSelectedArtifactFactory() {
        return this.selectedArtifactFactory;
    }


    public ArtifactObject getCurrentArtifact() {
        return this.currentArtifact;
    }


    public void setCurrentArtifact(ArtifactObject artifact) {
        this.currentArtifact = artifact;
    }


    public DiagrammOptions getDiagrammOptions() {
        return this.diagrammOptions;
    }


    public void setDiagrammOptions(DiagrammOptions diagrammOptions) {
        this.diagrammOptions = diagrammOptions;
    }


    public ArtifactDescription getArtifactDescription() {
        if (this.currentArtifact != null) {
            return (ArtifactDescription) this.currentArtifact;
        }
        return null;
    }


    public OutputMode getOutputMode(String name) {
        ArtifactDescription ad = this.getArtifactDescription();
        if (ad != null) {
            if (ad.getOutputModes() != null) {
                return ad.getOutputModes().get(name);
            }
        }
        return null;
    }


    public void resetModel() {
        log.debug("DefaultSessionModel.resetModel");
        this.selectedArtifactFactory = null;
        this.currentArtifact = null;
        this.diagrammOptions = null;
        this.statistics = null;

    }


    public Collection<ArtifactStatisticsSet> getStatistics() {
        return this.statistics;
    }

    public void setStatistics(Collection<ArtifactStatisticsSet> statistics) {
        this.statistics = statistics;
    }

    public Locale getCurrentLocale() {
        return currentLocale;
    }

    public void setCurrentLocale(Locale currentLocale) {
        this.currentLocale = currentLocale;
    }
    
    public MapService getLocalMapService() {
        return this.localMapService;
    }

    public void setLocalMapService(MapService mapService) {
        this.localMapService = mapService;
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org