Statistics
| Revision:

gvsig-catalog / org.gvsig.catalog / branches / org.gvsig.catalog-CSW2.0.2 / org.gvsig.catalog / org.gvsig.catalog.extension / src / main / java / org / gvsig / catalog / loaders / GvSigLayerLoader.java @ 62

History | View | Annotate | Download (4.47 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 org.gvsig.catalog.loaders;
42

    
43
import java.util.Map;
44

    
45
import org.gvsig.andami.PluginServices;
46
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel;
47
import org.gvsig.catalog.schemas.Resource;
48
import org.gvsig.fmap.dal.DALLocator;
49
import org.gvsig.fmap.dal.DataManager;
50
import org.gvsig.fmap.dal.DataStoreParameters;
51
import org.gvsig.fmap.dal.exception.InitializeException;
52
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
53
import org.gvsig.fmap.mapcontext.MapContextLocator;
54
import org.gvsig.fmap.mapcontext.MapContextManager;
55
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException;
56
import org.gvsig.fmap.mapcontext.layers.FLayer;
57
import org.gvsig.tools.ToolsLocator;
58
import org.gvsig.tools.extensionpoint.ExtensionPoint;
59
import org.gvsig.tools.extensionpoint.ExtensionPointManager;
60

    
61

    
62
/**
63
 * This class has to be inherited by all the classes
64
 * that have to load a layer in the current view
65
 * @author Jorge Piera Llodra (piera_jor@gva.es)
66
 */
67
public abstract class GvSigLayerLoader extends LayerLoader{
68
    private static final MapContextManager MAP_CONTEXT_MANAGER = 
69
        MapContextLocator.getMapContextManager();
70
    protected static final DataManager DATA_MANAGER =
71
        DALLocator.getDataManager();
72
    private static final ExtensionPointManager EXTENSION_POINT_MANAGER =
73
        ToolsLocator.getExtensionPointManager();
74

    
75
    /**
76
     * @param resource
77
     */
78
    public GvSigLayerLoader(Resource resource) {
79
        super(resource);                
80
    }
81

    
82
    public void loadLayer() throws LayerLoaderException {
83
        FLayer layer;
84
        try{
85
            if (hasSpecificLayer()){
86
                layer = createLayerFromExtensionPoint();       
87
            }else{
88
                layer = createLayerFromParameters();                 
89
            }
90
        } catch (Exception e) {
91
                e.printStackTrace();
92
            throw new LayerLoaderException(e.getMessage(), e, getWindowMessage());
93
        } 
94
        if (layer != null){
95
            addLayerToView(layer);
96
        }
97
    }        
98

    
99
    private FLayer createLayerFromParameters() throws InitializeException, ProviderNotRegisteredException, LoadLayerException{
100
        DataStoreParameters dataStoreParameters = createDataStoreParameters();    
101
        return MAP_CONTEXT_MANAGER.createLayer(getLayerName(), dataStoreParameters);    
102
    }
103

    
104
    private FLayer createLayerFromExtensionPoint() throws Exception{
105
        DataStoreParameters dataStoreParameters = createDataStoreParameters();            
106
        ExtensionPoint extensionPoint = EXTENSION_POINT_MANAGER.get("CatalogLayers");
107
        return (FLayer)extensionPoint.create(extensionPointName(), new Object[]{dataStoreParameters});
108
    }
109

    
110
    /**
111
     * It adds a new layer to the current view
112
     * @param lyr
113
     * Layer lo load
114
     */
115
    private void addLayerToView(FLayer lyr) {
116
        AbstractViewPanel theView = 
117
            (AbstractViewPanel) PluginServices.getMDIManager().getActiveWindow();
118
        theView.getMapControl().getMapContext().getLayers().addLayer(lyr);                        
119
    }        
120

    
121
    protected abstract boolean hasSpecificLayer();
122

    
123
    protected String extensionPointName(){
124
        return null;
125
    }
126

    
127
    protected abstract DataStoreParameters createDataStoreParameters() throws InitializeException, ProviderNotRegisteredException;
128
       
129
    protected abstract String getLayerName();
130
}