    001    //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/branches/2.4_testing/src/org/deegree/portal/context/LayerGroup.java $
    002    /*----------------------------------------------------------------------------
    003     This file is part of deegree, http://deegree.org/
    004     Copyright (C) 2001-2009 by:
    005     - Department of Geography, University of Bonn -
    006     and
    007     - lat/lon GmbH -
    008
    009     This library is free software; you can redistribute it and/or modify it under
    010     the terms of the GNU Lesser General Public License as published by the Free
    011     Software Foundation; either version 2.1 of the License, or (at your option)
    012     any later version.
    013     This library is distributed in the hope that it will be useful, but WITHOUT
    014     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    015     FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
    016     details.
    017     You should have received a copy of the GNU Lesser General Public License
    018     along with this library; if not, write to the Free Software Foundation, Inc.,
    019     59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
    020
    021     Contact information:
    022
    023     lat/lon GmbH
    024     Aennchenstr. 19, 53177 Bonn
    025     Germany
    026     http://lat-lon.de/
    027
    028     Department of Geography, University of Bonn
    029     Prof. Dr. Klaus Greve
    030     Postfach 1147, 53001 Bonn
    031     Germany
    032     http://www.geographie.uni-bonn.de/deegree/
    033
    034     e-mail: info@deegree.org
    035     ----------------------------------------------------------------------------*/
    036    package org.deegree.portal.context;
    037
    038    import java.util.ArrayList;
    039    import java.util.Collections;
    040    import java.util.List;
    041
    042    /**
    043     * TODO add class documentation here
    044     *
    045     * @author <a href="mailto:name@deegree.org">Andreas Poth</a>
    046     * @author last edited by: $Author: apoth $
    047     *
    048     * @version $Revision: 20973 $, $Date: 2009-11-23 16:54:36 +0100 (Mo, 23. Nov 2009) $
    049     */
    050    public class LayerGroup extends MapModelEntry {
    051
    052        private boolean expanded;
    053
    054        private List<MMLayer> layers;
    055
    056        private List<LayerGroup> layerGroups;
    057
    058        private List<MapModelEntry> entries;
    059
    060        /**
    061         *
    062         * @param identifier
    063         * @param title
    064         * @param hidden
    065         * @param expanded
    066         * @param parent
    067         * @param owner
    068         */
    069        public LayerGroup( String identifier, String title, boolean hidden, boolean expanded, LayerGroup parent,
    070                           MapModel owner ) {
    071            super( identifier, title, hidden, parent, owner );
    072            layers = new ArrayList<MMLayer>();
    073            layerGroups = new ArrayList<LayerGroup>();
    074            entries = new ArrayList<MapModelEntry>();
    075            this.expanded = expanded;
    076        }
    077
    078        /**
    079         *
    080         * @param layer
    081         * @param antecessor
    082         * @param first
    083         */
    084        public void insert( MMLayer layer, MapModelEntry antecessor, boolean first ) {
    085            if ( layer.getParent() == null || !layer.getParent().equals( parent ) ) {
    086                layers.remove( layer );
    087                layers.add( layer );
    088                layer.setParent( this );
    089                int i = 0;
    090                while ( i < entries.size() && !entries.get( i ).equals( antecessor ) ) {
    091                    i++;
    092                }
    093                if ( i >= entries.size() - 1 ) {
    094                    if ( first && antecessor == null ) {
    095                        entries.add( 0, layer );
    096                    } else {
    097                        entries.add( layer );
    098                    }
    099                } else {
    100                    if ( first && antecessor == null ) {
    101                        entries.add( 0, layer );
    102                    } else {
    103                        entries.add( i + 1, layer );
    104                    }
    105                }
    106            }
    107        }
    108
    109        /**
    110         *
    111         * @param layerGroup
    112         * @param antecessor
    113         * @param first
    114         */
    115        public void insert( LayerGroup layerGroup, MapModelEntry antecessor, boolean first ) {
    116            if ( layerGroup.getParent() == null || !layerGroup.getParent().equals( parent ) ) {
    117                // register as child
    118                layerGroups.add( layerGroup );
    119                // that this a parent
    120                layerGroup.setParent( this );
    121
    122                int i = 0;
    123                if ( entries.size() > 0 ) {
    124                    while ( i < entries.size() && !entries.get( i ).equals( antecessor ) ) {
    125                        i++;
    126                    }
    127                }
    128                if ( i >= entries.size() - 1 ) {
    129                    if ( first && antecessor == null ) {
    130                        entries.add( 0, layerGroup );
    131                    } else {
    132                        entries.add( layerGroup );
    133                    }
    134                } else {
    135                    if ( first && antecessor == null ) {
    136                        entries.add( 0, layerGroup );
    137                    } else {
    138                        entries.add( i + 1, layerGroup );
    139                    }
    140                }
    141            }
    142        }
    143
    144        /**
    145         *
    146         * @param layer
    147         */
    148        public void addLayer( MMLayer layer ) {
    149            if ( !layers.contains( layer ) ) {
    150                layers.add( layer );
    151                entries.add( layer );
    152            }
    153        }
    154
    155        /**
    156         *
    157         * @param layerGroup
    158         */
    159        public void addLayerGroup( LayerGroup layerGroup ) {
    160            layerGroups.add( layerGroup );
    161            entries.add( layerGroup );
    162        }
    163
    164        /**
    165         * @return the layerGroups
    166         */
    167        public List<LayerGroup> getLayerGroups() {
    168            return Collections.unmodifiableList( layerGroups );
    169        }
    170
    171        /**
    172         * @return the layers
    173         */
    174        public List<MMLayer> getLayers() {
    175            return Collections.unmodifiableList( layers );
    176        }
    177
    178        /**
    179         * @return the entries
    180         */
    181        public List<MapModelEntry> getMapModelEntries() {
    182            return Collections.unmodifiableList( entries );
    183        }
    184
    185        /**
    186         * @return the expanded
    187         */
    188        public boolean isExpanded() {
    189            return expanded;
    190        }
    191
    192        /**
    193         * @param expanded
    194         *            the expanded to set
    195         */
    196        public void setExpanded( boolean expanded ) {
    197            this.expanded = expanded;
    198        }
    199
    200        /**
    201         *
    202         * @param layer
    203         */
    204        public void removeLayer( MMLayer layer ) {
    205            layers.remove( layer );
    206            entries.remove( layer );
    207            layer.setParent( null );
    208        }
    209
    210        /**
    211         *
    212         * @param layerGroup
    213         */
    214        public void removeLayerGroup( LayerGroup layerGroup ) {
    215            layerGroups.remove( layerGroup );
    216            entries.remove( layerGroup );
    217            layerGroup.setParent( null );
    218        }
    219
    220    }