Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extCatalogYNomenclator / src / es / gva / cit / gvsig / catalogClient / loaders / LayerLoader.java @ 10626

History | View | Annotate | Download (4.36 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
*
3
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
*
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
7
* as published by the Free Software Foundation; either version 2
8
* of the License, or (at your option) any later version.
9
*
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
* GNU General Public License for more details.
14
*
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
*
19
* For more information, contact:
20
*
21
*  Generalitat Valenciana
22
*   Conselleria d'Infraestructures i Transport
23
*   Av. Blasco Ib??ez, 50
24
*   46010 VALENCIA
25
*   SPAIN
26
*
27
*      +34 963862235
28
*   gvsig@gva.es
29
*      www.gvsig.gva.es
30
*
31
*    or
32
*
33
*   IVER T.I. S.A
34
*   Salamanca 50
35
*   46005 Valencia
36
*   Spain
37
*
38
*   +34 963163400
39
*   dac@iver.es
40
*/
41
package es.gva.cit.gvsig.catalogClient.loaders;
42

    
43
import java.lang.reflect.InvocationTargetException;
44
import java.util.TreeMap;
45

    
46
import com.iver.andami.PluginServices;
47
import com.iver.cit.gvsig.exceptions.layers.LoadLayerException;
48
import com.iver.cit.gvsig.fmap.MapContext;
49
import com.iver.cit.gvsig.fmap.MapContext.LayerEventListener;
50
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
51
import com.iver.cit.gvsig.fmap.layers.FLayer;
52
import com.iver.cit.gvsig.fmap.layers.FLayers;
53
import com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent;
54
import com.iver.cit.gvsig.fmap.layers.LayerCollectionListener;
55
import com.iver.cit.gvsig.gui.WizardPanel;
56
import com.iver.cit.gvsig.project.documents.view.gui.View;
57

    
58

    
59
import es.gva.cit.catalogClient.schemas.discoverer.Resource;
60

    
61
/**
62
 * This class has to be inherited by all the classes
63
 * that have to load a layer in the current view
64
 * @author Jorge Piera Llodra (piera_jor@gva.es)
65
 */
66
public abstract class LayerLoader {
67
        private static TreeMap loadersPool = new TreeMap();
68

    
69
        static {
70
                LayerLoader.addLoader(Resource.WMS, WMSLayerLoader.class);
71
                LayerLoader.addLoader(Resource.POSTGIS, PostgisLayerLoader.class);
72
                LayerLoader.addLoader(Resource.WCS, WCSLayerLoader.class);
73
                LayerLoader.addLoader(Resource.WEBSITE, LinkLoader.class);
74
                LayerLoader.addLoader(Resource.DOWNLOAD, LinkLoader.class);
75
                LayerLoader.addLoader(Resource.WFS, WFSLayerLoader.class);
76
                LayerLoader.addLoader(Resource.ARCIMS_IMAGE, ARCIMSLayerLoader.class);
77
                LayerLoader.addLoader(Resource.ARCIMS_VECTORIAL, ARCIMSLayerLoader.class);
78
        }
79

    
80
        public static void addLoader(String key, Class loader) {
81
                LayerLoader.loadersPool.put(key, loader);
82
        }
83

    
84
        public static LayerLoader getLoader(Resource resource) throws IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {
85
                if (LayerLoader.loadersPool.containsKey(resource.getType())) {
86
                        Class llClass = (Class) LayerLoader.loadersPool.get(resource.getType());
87
                        Class [] args = {Resource.class};
88
                        Object [] params = {resource};
89
                        return (LayerLoader) llClass.getConstructor(args).newInstance(params);
90
                }
91
                return null;
92
        }
93

    
94
        private Resource resource = null;
95

    
96
        public LayerLoader(Resource resource){
97
                this.resource = resource;
98
        }
99

    
100
        abstract public void loadLayer() throws LoadLayerException;
101

    
102
        /**
103
         * It returns the error message
104
         * @return
105
         * Error Message
106
         */
107
        abstract protected String getErrorMessage();
108

    
109
        /**
110
         * It returns the window title for an window error message
111
         * @return
112
         * Window title
113
         */
114
        abstract protected String getWindowMessage();
115

    
116
        /**
117
     * It adds a new layer to the current view
118
     * @param lyr
119
     * Layer lo load
120
     */
121
    protected void addLayerToView(FLayer lyr) {
122
                View theView =
123
                        (View) PluginServices.getMDIManager().getActiveWindow();
124

    
125
                if (lyr != null) {
126
                        theView.getMapControl().getMapContext().beginAtomicEvent();
127
                        theView.getMapControl().getMapContext().getLayers().addLayer(lyr);
128
                        theView.getMapControl().getMapContext().endAtomicEvent();
129
                        lyr.setActive(true);
130
                        PluginServices.getMainFrame().enableControls();
131
                }
132
        }
133

    
134
        public Resource getResource() {
135
                return resource;
136
        }
137

    
138
        public void setResource(Resource resource) {
139
                this.resource = resource;
140
        }
141

    
142

    
143

    
144

    
145

    
146

    
147
}