Revision 43891

View differences:

branches/org.gvsig.desktop-2018a/org.gvsig.desktop.library/org.gvsig.fmap.control/src/main/java/org/gvsig/fmap/mapcontrol/swing/dynformfield/CoordinateReferenceSystem/JDynFormFieldCoordinateReferenceSystem.java
16 16
import org.gvsig.app.gui.panels.CRSSelectPanelFactory;
17 17
import org.gvsig.app.gui.panels.crs.ISelectCrsPanel;
18 18
import org.gvsig.tools.dataTypes.CoercionException;
19
import org.gvsig.tools.dynform.JDynForm.DynFormContext;
19 20
import org.gvsig.tools.dynform.JDynFormField;
20 21
import org.gvsig.tools.dynform.spi.dynformfield.AbstractJDynFormField;
21 22
import org.gvsig.tools.dynform.spi.dynformfield.JCustomTextField;
......
30 31
    protected IProjection currentValue = null;
31 32
    protected JTextField jtext = null;
32 33
    protected JButton jbutton = null;
33

  
34
    protected DynFormContextWithTargetCRS context;
35
    
34 36
    public JDynFormFieldCoordinateReferenceSystem(DynObject parameters,
35 37
            ServiceManager serviceManager) {
36 38
        super(parameters, serviceManager);
37 39
        this.assignedValue = (IProjection) this.getParameterValue();
40
        DynFormContext theContext = this.getForm().getContext();
41
        if( theContext instanceof DynFormContextWithTargetCRS ) {
42
            this.context = (DynFormContextWithTargetCRS)theContext;
43
        }
38 44
    }
39 45

  
46
    @Override
40 47
    public Object getAssignedValue() {
41 48
        return this.assignedValue;
42 49
    }
43 50

  
51
    @Override
44 52
    public void initComponent() {
53
        // 
54
        // TODO: Aqui comprobar si hay context y presentar CRS o CRS+Transformacio
55
        //
45 56
        this.contents = new JPanel();
46 57
        this.contents.setLayout(new BorderLayout());
47 58

  
......
50 61
        this.jtext.setEditable(false);
51 62
        this.jbutton = new JButton("...");
52 63
        this.jbutton.addActionListener(new ActionListener() {
64
            @Override
53 65
            public void actionPerformed(ActionEvent e) {
54 66
                onClickBrowse();
55 67
            }
......
65 77
        fireFieldEnterEvent();
66 78
        this.problemIndicator().restore();
67 79

  
80
        // TODO: Aqui comprobar si tenemos context y de tenerlo presentar
81
        // el dialogo con transformacion, y si no, el de sin transformacion.
82
        // A la vuelta del dialogo con transformacion, meter la transformacion
83
        // en el context y actualizar el jtext
84
        
68 85
        ISelectCrsPanel csSelect = CRSSelectPanelFactory.getUIFactory().getSelectCrsPanel(this.currentValue, true);
69 86
        ToolsSwingLocator.getWindowManager().showWindow((JComponent) csSelect, Messages.getText("selecciona_sistema_de_referencia"), MODE.DIALOG);
70 87
        if (csSelect.isOkPressed()) {
......
73 90
        }
74 91
    }
75 92

  
93
    @Override
76 94
    public boolean hasValidValue() {
77 95
        return true;
78 96
    }
79 97

  
98
    @Override
80 99
    public void focusGained(FocusEvent arg0) {
81 100
        fireFieldEnterEvent();
82 101
        this.problemIndicator().restore();
83 102
    }
84 103

  
104
    @Override
85 105
    public void focusLost(FocusEvent arg0) {
86 106
        fireFieldExitEvent();
87 107
    }
88 108

  
109
    @Override
89 110
    public void setValue(Object value) {
90 111
        IProjection x = null;
91 112
        try {
92 113
            x = (IProjection) this.getDefinition().getDataType().coerce(value);
93 114
        } catch (CoercionException e) {
94
            throw new IllegalFieldValue(this, e.getMessage());
115
            throw new AbstractJDynFormField.IllegalFieldValue(this, e.getMessage());
95 116
        }
96 117
        this.currentValue = x;
97 118
        if (x != null) {
......
100 121
        this.assignedValue = x;
101 122
    }
102 123

  
124
    @Override
103 125
    public Object getValue() {
104 126
        return this.currentValue;
105 127
    }
branches/org.gvsig.desktop-2018a/org.gvsig.desktop.library/org.gvsig.fmap.control/src/main/java/org/gvsig/fmap/mapcontrol/swing/dynformfield/CoordinateReferenceSystem/DynFormContextWithTargetCRS.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24

  
25
package org.gvsig.fmap.mapcontrol.swing.dynformfield.CoordinateReferenceSystem;
26

  
27
import org.cresques.cts.ICoordTrans;
28
import org.cresques.cts.IProjection;
29
import org.gvsig.tools.dynform.JDynForm.DynFormContext;
30

  
31
/**
32
 *
33
 * @author jjdelcerro
34
 */
35
public interface DynFormContextWithTargetCRS extends DynFormContext {
36
    
37
    public IProjection getTargetCRS();
38
    
39
    public ICoordTrans getCoordTrans();
40
    
41
    public void setCoordTrans(ICoordTrans coordTrans);
42
}
branches/org.gvsig.desktop-2018a/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.impl/src/main/java/org/gvsig/fmap/mapcontext/raster/impl/MapContextRasterLibrary.java
31 31
import org.gvsig.fmap.mapcontext.MapContextLibrary;
32 32
import org.gvsig.fmap.mapcontext.MapContextLocator;
33 33
import org.gvsig.fmap.mapcontext.MapContextManager;
34
import org.gvsig.fmap.mapcontext.layers.LayerFactory;
35 34
import org.gvsig.raster.lib.buffer.api.BufferLocator;
36 35
import org.gvsig.raster.lib.buffer.api.OperationManager;
37 36
import org.gvsig.raster.lib.legend.api.RasterLegendLocator;
......
83 82

  
84 83
    @Override
85 84
    protected void doInitialize() throws LibraryException {
86
        LayerFactory.getInstance().registerLayerToUseForStore(
87
                RasterStore.class, DefaultRasterLayer.class);
88
        RasterLegendLocator.registerRasterLegendManager(DefaultRasterLegendManager.class);
85
         RasterLegendLocator.registerRasterLegendManager(DefaultRasterLegendManager.class);
89 86

  
90 87
    }
91 88

  
92 89
    @Override
93 90
    protected void doPostInitialize() throws LibraryException {
91
        MapContextManager manager = MapContextLocator.getMapContextManager();
92
        manager.registerLayer(RasterStore.class, DefaultRasterLayer.class);
93
        
94 94
        Caller caller = new DefaultCaller();
95 95
        caller.add( new DefaultRasterLayer.RegisterPersistence() );
96 96

  
branches/org.gvsig.desktop-2018a/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/main/java/org/gvsig/fmap/mapcontext/exceptions/CantRetrieveLayerByStoreException.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24

  
25
package org.gvsig.fmap.mapcontext.exceptions;
26

  
27
/**
28
 *
29
 * @author jjdelcerro
30
 */
31
public class CantRetrieveLayerByStoreException extends LoadLayerException {
32
    
33
    /**
34
     *
35
     */
36
    private static final long serialVersionUID = 1442450896900126712L;
37

  
38
    public CantRetrieveLayerByStoreException(String layerName, String storeName) {
39
        super(
40
                "Can't retrieve the class layer of %(layer) to use for store %(store).", 
41
                null, 
42
                "_Cant_retrieve_the_class_leyer_of_XlayerX_to_use_for_store_XstoreX", 
43
                serialVersionUID
44
        );
45
        setValue("layer", layerName);
46
        setValue("store", storeName);
47
    }
48
    
49
}
branches/org.gvsig.desktop-2018a/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/main/java/org/gvsig/fmap/mapcontext/MapContextLibrary.java
34 34
import org.gvsig.fmap.mapcontext.layers.FLayerStatus;
35 35
import org.gvsig.fmap.mapcontext.layers.FLayers;
36 36
import org.gvsig.fmap.mapcontext.layers.FLyrDefault;
37
import org.gvsig.fmap.mapcontext.layers.LayerFactory;
38 37
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
39 38
import org.gvsig.fmap.mapcontext.layers.vectorial.ReprojectDefaultGeometry;
40 39
import org.gvsig.fmap.mapcontext.tools.persistence.ColorPersistenceFactory;
......
43 42
import org.gvsig.fmap.mapcontext.tools.persistence.Point2DPersistenceFactory;
44 43
import org.gvsig.fmap.mapcontext.tools.persistence.Rectangle2DPersistenceFactory;
45 44
import org.gvsig.raster.lib.legend.api.RasterLegendLocator;
46
import org.gvsig.tools.ToolsLocator;
47 45
import org.gvsig.tools.library.AbstractLibrary;
48 46
import org.gvsig.tools.library.LibraryException;
49 47
import org.gvsig.tools.locator.ReferenceNotRegisteredException;
50
import org.gvsig.tools.persistence.PersistenceManager;
48
import org.gvsig.tools.util.Callable;
51 49
import org.gvsig.tools.util.Caller;
52 50
import org.gvsig.tools.util.impl.DefaultCaller;
53 51

  
54 52
/**
55 53
 * Library for the MapContext library API.
56
 * @author jmvivo
57 54
 */
58 55
public class MapContextLibrary extends AbstractLibrary {
59
	final static private Logger LOG = LoggerFactory.getLogger(FLyrDefault.class);
60 56

  
57
    final static private Logger LOG = LoggerFactory.getLogger(FLyrDefault.class);
58

  
59
    @Override
61 60
    public void doRegistration() {
62 61
        registerAsAPI(MapContextLibrary.class);
63 62
        require(DALLibrary.class);
64 63
        require(CompatLibrary.class);
65 64
    }
66 65

  
67
	protected void doInitialize() throws LibraryException {
68
		LayerFactory.getInstance().registerLayerToUseForStore(
69
				FeatureStore.class, FLyrVect.class);
70
	}
66
    @Override
67
    protected void doInitialize() throws LibraryException {
68
    }
71 69

  
72
	protected void doPostInitialize() throws LibraryException {
73
            Caller caller = new DefaultCaller();
70
    @Override
71
    protected void doPostInitialize() throws LibraryException {
72
        Caller caller = new DefaultCaller();
74 73

  
75
            MapContextManager manager = MapContextLocator.getMapContextManager();
74
        MapContextManager manager = MapContextLocator.getMapContextManager();
76 75

  
77
            if (manager == null) {
78
                    throw new ReferenceNotRegisteredException(
79
                                    MapContextLocator.MAPCONTEXT_MANAGER_NAME,
80
                                    MapContextLocator.getInstance());
81
            }
76
        if (manager == null) {
77
            throw new ReferenceNotRegisteredException(
78
                    MapContextLocator.MAPCONTEXT_MANAGER_NAME,
79
                    MapContextLocator.getInstance());
80
        }
82 81

  
83
            caller.add( new FLyrDefault.RegisterMetadata() );
84
            caller.add( new DefaultMapContextDrawer.RegisterMapContextDrawer() );
82
        caller.add(new RegisterDefaultVectorialLayer());
83
        caller.add(new FLyrDefault.RegisterMetadata());
84
        caller.add(new DefaultMapContextDrawer.RegisterMapContextDrawer());
85 85

  
86
            caller.add( new ViewPort.RegisterPersistence() );
87
            caller.add( new ExtendedPropertiesHelper.RegisterPersistence() );
88
            caller.add( new MapContext.RegisterPersistence() );
89
            caller.add( new ExtentHistory.RegisterPersistence() );
90
            caller.add( new ReprojectDefaultGeometry.RegisterPersistence() );
91
            caller.add( new FLayerStatus.RegisterPersistence() );
92
            caller.add( new FLyrDefault.RegisterPersistence() );
93
            caller.add( new FLyrVect.RegisterPersistence() );
94
            caller.add( new FLayers.RegisterPersistence() );
86
        caller.add(new ViewPort.RegisterPersistence());
87
        caller.add(new ExtendedPropertiesHelper.RegisterPersistence());
88
        caller.add(new MapContext.RegisterPersistence());
89
        caller.add(new ExtentHistory.RegisterPersistence());
90
        caller.add(new ReprojectDefaultGeometry.RegisterPersistence());
91
        caller.add(new FLayerStatus.RegisterPersistence());
92
        caller.add(new FLyrDefault.RegisterPersistence());
93
        caller.add(new FLyrVect.RegisterPersistence());
94
        caller.add(new FLayers.RegisterPersistence());
95 95

  
96
            caller.add( new ColorPersistenceFactory.RegisterPersistence() );
97
            caller.add( new Point2DPersistenceFactory.RegisterPersistence() );
98
            caller.add( new FontPersistenceFactory.RegisterPersistence() );
99
            caller.add( new Rectangle2DPersistenceFactory.RegisterPersistence() );
100
            caller.add( new DimensionPersistenceFactory.RegisterPersistence() );
96
        caller.add(new ColorPersistenceFactory.RegisterPersistence());
97
        caller.add(new Point2DPersistenceFactory.RegisterPersistence());
98
        caller.add(new FontPersistenceFactory.RegisterPersistence());
99
        caller.add(new Rectangle2DPersistenceFactory.RegisterPersistence());
100
        caller.add(new DimensionPersistenceFactory.RegisterPersistence());
101 101

  
102
            if( !caller.call() ) {
103
                    throw new LibraryException(MapContextLibrary.class, caller.getExceptions());
104
            }
102
        if (!caller.call()) {
103
            throw new LibraryException(MapContextLibrary.class, caller.getExceptions());
104
        }
105 105

  
106
            // Validate there is any implementation registered.
107
            if (!RasterLegendLocator.getInstance().exists(
106
        // Validate there is any implementation registered.
107
        if (!RasterLegendLocator.getInstance().exists(
108 108
                RasterLegendLocator.RASTER_LEGEND_MANAGER_NAME)) {
109
                throw new ReferenceNotRegisteredException(
109
            throw new ReferenceNotRegisteredException(
110 110
                    RasterLegendLocator.RASTER_LEGEND_MANAGER_NAME, RasterLegendLocator.getInstance());
111
            }
111
        }
112 112

  
113
    }
113 114

  
114
	}
115
    private static class RegisterDefaultVectorialLayer implements Callable {
115 116

  
117
        @Override
118
        public Object call() throws Exception {
119
            MapContextManager manager = MapContextLocator.getMapContextManager();
120
            manager.registerLayer(FeatureStore.class, FLyrVect.class);
121
            return true;
122
        }
123

  
124
    }
116 125
}
branches/org.gvsig.desktop-2018a/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/main/java/org/gvsig/fmap/mapcontext/MapContextManager.java
31 31
import java.awt.Font;
32 32
import java.io.File;
33 33
import java.util.List;
34
import org.cresques.cts.ICoordTrans;
34 35

  
35 36
import org.cresques.cts.IProjection;
36 37

  
......
63 64
 */
64 65
public interface MapContextManager extends Observable {
65 66

  
67
        public interface CreateLayerParameters {
68
        
69
            public DataStoreParameters getDataParameters(); 
70

  
71
            public boolean useCache();
72

  
73
            public ICoordTrans getCoordTrans();            
74
        }
75
        
66 76
        public static final String GET_DEFAULT_CRS = "MAPCONTEXTMANAGER_GET_DEFAULT_CRS";
67 77
        public static final String CREATE_LEGEND = "MAPCONTEXTMANAGER_CREATE_LEGEND";
68 78
        public static final String CREATE_MAPCONTEXT_DRAWER = "MAPCONTEXTMANAGER_CREATE_MAPCONTEXT_DRAWER";
......
84 94

  
85 95

  
86 96
	public MapContext createMapContext();
87
	
97
	      
98
        public boolean registerLayer(
99
                Class<? extends DataStore> dataStoreClass,
100
                Class<? extends FLayer> layerClass) ;
101
        
88 102
	/**
89 103
	 * Create a new layer from the data parameters passed as parameter.
90 104
	 * 
......
98 112
	public FLayer createLayer(String layerName,
99 113
			DataStoreParameters parameters) throws LoadLayerException;
100 114

  
115
        public FLayer createLayer(
116
                String layerName, 
117
                CreateLayerParameters parameters
118
            ) throws LoadLayerException;
119

  
101 120
	/**
102 121
	 * Create a layer from a {@link DataStore}.
103 122
	 * 
......
111 130
	public FLayer createLayer(String layerName, DataStore store)
112 131
			throws LoadLayerException;
113 132

  
133
        public FLayer createLayer(
134
                String layerName, 
135
                DataStore store, 
136
                CreateLayerParameters parameters
137
            ) throws LoadLayerException;
138

  
114 139
	/**
115 140
	 * Create a layer to be used as the {@link GraphicLayer}.
116 141
	 * 
branches/org.gvsig.desktop-2018a/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/main/java/org/gvsig/fmap/mapcontext/BaseCreateLayerParameters.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.fmap.mapcontext;
25

  
26
import org.cresques.cts.ICoordTrans;
27
import org.gvsig.fmap.dal.DataStoreParameters;
28

  
29
/**
30
 *
31
 * @author jjdelcerro
32
 */
33
public class BaseCreateLayerParameters implements MapContextManager.CreateLayerParameters {
34

  
35
    private DataStoreParameters dataStoreParameters;
36
    private boolean useCache;
37
    private ICoordTrans coordTrans;
38

  
39
    public BaseCreateLayerParameters() {
40
        
41
    }
42
    
43
    public BaseCreateLayerParameters(DataStoreParameters dataStoreParameters,boolean useCache,ICoordTrans coordTrans) {
44
        this.coordTrans = coordTrans;
45
        this.dataStoreParameters = dataStoreParameters;
46
        this.useCache = useCache;
47
    }
48

  
49
    @Override
50
    public DataStoreParameters getDataParameters() {
51
        return this.dataStoreParameters;
52
    }
53

  
54
    @Override
55
    public boolean useCache() {
56
        return this.useCache;
57
    }
58

  
59
    @Override
60
    public ICoordTrans getCoordTrans() {
61
        return this.coordTrans;
62
    }
63
    
64
    /**
65
     * @param dataStoreParameters the dataStoreParameters to set
66
     */
67
    public void setDataStoreParameters(DataStoreParameters dataStoreParameters) {
68
        this.dataStoreParameters = dataStoreParameters;
69
    }
70

  
71
    /**
72
     * @param useCache the useCache to set
73
     */
74
    public void setUseCache(boolean useCache) {
75
        this.useCache = useCache;
76
    }
77

  
78
    /**
79
     * @param coordTrans the coordTrans to set
80
     */
81
    public void setCoordTrans(ICoordTrans coordTrans) {
82
        this.coordTrans = coordTrans;
83
    }
84
}
branches/org.gvsig.desktop-2018a/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/main/java/org/gvsig/fmap/mapcontext/layers/LayerFactory.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.fmap.mapcontext.layers;
25

  
26
import java.util.HashMap;
27
import java.util.Iterator;
28
import java.util.Map;
29
import java.util.Map.Entry;
30

  
31
import org.cresques.cts.IProjection;
32
import org.gvsig.fmap.dal.DALLocator;
33
import org.gvsig.fmap.dal.DataManager;
34
import org.gvsig.fmap.dal.DataStore;
35
import org.gvsig.fmap.dal.DataStoreParameters;
36
import org.gvsig.fmap.dal.exception.InitializeException;
37
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
38
import org.gvsig.fmap.dal.feature.FeatureStore;
39
import org.gvsig.fmap.mapcontext.MapContextManager;
40
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException;
41
import org.gvsig.fmap.mapcontext.layers.operations.SingleLayer;
42

  
43
/**
44
 * Crea un adaptador del driver que se le pasa como par?metro en los m?todos
45
 * createLayer. Si hay memoria suficiente se crea un FLyrMemory que pasa todas
46
 * las features del driver a memoria
47
 */
48
public class LayerFactory {
49
//	final static private Logger logger = LoggerFactory.getLogger(LayerFactory.class);
50

  
51
	private static LayerFactory instance = null;
52

  
53

  
54

  
55
	public static LayerFactory getInstance() {
56
		if (instance == null) {
57
			instance = new LayerFactory();
58
		}
59
		return instance;
60
	}
61

  
62
	/**
63
	 * Guarda registro de que clase de capa debe usar para un determinado Store
64
	 *
65
	 * como clave usamos el nombre de registro del dataStore
66
	 */
67
	private Map layersToUseForStore = new HashMap();
68

  
69
	/**
70
	 * Registra que clase tiene que usar para un {@link DataStore} determinado. <br>
71
	 * Por defecto, si el
72
	 *
73
	 *
74
	 * @param dataStoreName
75
	 *            Nombre de registro del {@link DataStore} dentro del
76
	 *            {@link DataManager}
77
	 * @param layerClassToUse
78
	 *            clase que implementa {@link SingleLayer}
79
	 * @return
80
	 */
81

  
82
	public boolean registerLayerToUseForStore(String dataStoreName,
83
			Class layerClassToUse) {
84

  
85
		DataManager dm = DALLocator.getDataManager();
86
		DataStoreParameters dsparams;
87
		try {
88
			dsparams = dm.createStoreParameters(dataStoreName);
89
		} catch (InitializeException e) {
90
			e.printStackTrace();
91
			return false;
92
		} catch (ProviderNotRegisteredException e) {
93
			e.printStackTrace();
94
			return false;
95
		}
96
		if (!layerClassToUse.isAssignableFrom(SingleLayer.class)) {
97
			return false;
98
		}
99
		this.layersToUseForStore.put(dsparams.getDataStoreName(),
100
				layerClassToUse);
101

  
102
		return true;
103
	}
104

  
105
	public boolean registerLayerToUseForStore(Class storeClass,
106
			Class layerClassToUse) {
107

  
108
//		DataManager dm = DALLocator.getDataManager();
109
		if (!DataStore.class.isAssignableFrom(storeClass)) {
110
			return false;
111
		}
112

  
113
		if (!SingleLayer.class.isAssignableFrom(layerClassToUse)
114
				|| !FLayer.class.isAssignableFrom(layerClassToUse)) {
115
			return false;
116
		}
117
		this.layersToUseForStore.put(storeClass,
118
				layerClassToUse);
119

  
120
		return true;
121
	}
122

  
123
	private Class getLayerClassFor(DataStore store) {
124
		Class result = (Class) this.layersToUseForStore.get(store.getName());
125
		if (result == null) {
126
			Iterator iter = this.layersToUseForStore.entrySet().iterator();
127
			Map.Entry entry;
128
			Class key;
129
			while (iter.hasNext()) {
130
				entry = (Entry) iter.next();
131
				if (entry.getKey() instanceof Class) {
132
					key = (Class) entry.getKey();
133
					if (key.isAssignableFrom(store.getClass())) {
134
						result = (Class) entry.getValue();
135
						break;
136
					}
137
				}
138
			}
139
		}
140
		return result;
141

  
142
	}
143

  
144

  
145

  
146
	/**
147
	 * @deprecated to be removed in gvSIG 2.1
148
	 * @see {@link MapContextManager}.
149
	 */
150
	public FLayer createLayer(String layerName,
151
			DataStoreParameters storeParameters) throws LoadLayerException {
152
		// Se obtiene el driver que lee
153
		try{
154
			DataManager dataManager=DALLocator.getDataManager();
155
			DataStore dataStore=dataManager.openStore(storeParameters.getDataStoreName(), storeParameters);
156
			return createLayer(layerName, dataStore);
157
		}catch (Exception e) {
158
			throw new LoadLayerException(layerName,e);
159
		}
160
	}
161

  
162
	/**
163
	 * @deprecated to be removed in gvSIG 2.1
164
	 * @see {@link MapContextManager}.
165
	 */
166
	public FLayer createLayer(String layerName, DataStore dataStore) throws LoadLayerException{
167
		try{	
168
			Class layerClass = this.getLayerClassFor(dataStore);
169
			if (layerClass == null) {
170
				throw new CantRetrieveLayerByStoreException(layerName,dataStore.getName());
171
			}
172
			FLayer layer;
173
			try {
174
				layer = (FLayer) layerClass.newInstance();
175
			} catch (InstantiationException e) {
176
				throw new LoadLayerException(layerName, e);
177
			} catch (IllegalAccessException e) {
178
				throw new LoadLayerException(layerName, e);
179
			}
180

  
181
			layer.setName(layerName);
182
			((SingleLayer) layer).setDataStore(dataStore);
183
			IProjection proj = (IProjection)dataStore.getDynValue(FeatureStore.METADATA_CRS);
184
			if (proj != null) {
185
				layer.setProjection(proj);
186
			}
187
			layer.load();
188
			return layer;
189
		} catch (Exception e) {
190
			throw new LoadLayerException(layerName,e);
191
		}
192
	}
193
	
194
	private class CantRetrieveLayerByStoreException extends LoadLayerException {
195

  
196
		/**
197
		 * 
198
		 */
199
		private static final long serialVersionUID = 1442450896900126712L;
200

  
201
		CantRetrieveLayerByStoreException(String layerName, String storeName) {
202
			super(
203
				"Can't retrieve the class leyer of %(layer) to use for store %(store).",
204
				null,
205
				"_Cant_retrieve_the_class_leyer_of_XlayerX_to_use_for_store_XstoreX",
206
				serialVersionUID
207
			);
208
			setValue("layer", layerName);
209
			setValue("store", storeName);
210
		}
211
	}
212

  
213
}
branches/org.gvsig.desktop-2018a/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/main/java/org/gvsig/fmap/mapcontext/impl/DefaultMapContextManager.java
39 39
import java.util.Map;
40 40
import org.apache.commons.io.IOUtils;
41 41
import org.apache.commons.lang3.StringUtils;
42
import org.cresques.cts.ICoordTrans;
42 43

  
43 44
import org.cresques.cts.IProjection;
44 45
import org.gvsig.fmap.crs.CRSFactory;
46
import org.gvsig.fmap.dal.DALLocator;
47
import org.gvsig.fmap.dal.DataManager;
45 48
import org.gvsig.fmap.dal.DataServerExplorer;
46 49
import org.gvsig.fmap.dal.DataStore;
47 50
import org.gvsig.fmap.dal.DataStoreParameters;
51
import org.gvsig.fmap.dal.DataStoreProviderFactory;
48 52
import org.gvsig.fmap.dal.exception.DataException;
49 53
import org.gvsig.fmap.dal.feature.FeatureStore;
50 54
import org.gvsig.fmap.dal.feature.FeatureType;
......
57 61
import org.gvsig.fmap.mapcontext.MapContextManager;
58 62
import org.gvsig.fmap.mapcontext.MapContextRuntimeException;
59 63
import org.gvsig.fmap.mapcontext.ViewPort;
64
import org.gvsig.fmap.mapcontext.exceptions.CantRetrieveLayerByStoreException;
60 65
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException;
61 66
import org.gvsig.fmap.mapcontext.layers.DefaultLayerInformationBuilder;
62 67
import org.gvsig.fmap.mapcontext.layers.FLayer;
63
import org.gvsig.fmap.mapcontext.layers.LayerFactory;
64 68
import org.gvsig.fmap.mapcontext.layers.LayerInformationBuilder;
69
import org.gvsig.fmap.mapcontext.layers.operations.SingleLayer;
65 70
import org.gvsig.fmap.mapcontext.layers.vectorial.GraphicLayer;
66 71
import org.gvsig.fmap.mapcontext.layers.vectorial.impl.DefaultGraphicLayer;
67 72
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend;
......
82 87
import org.gvsig.raster.lib.legend.api.colorinterpretation.ColorInterpretation;
83 88
import org.gvsig.tools.ToolsLocator;
84 89
import org.gvsig.tools.dispose.DisposeUtils;
90
import org.gvsig.tools.dynobject.DynObject;
85 91
import org.gvsig.tools.dynobject.exception.DynMethodException;
86 92
import org.gvsig.tools.dynobject.exception.DynMethodNotSupportedException;
93
import org.gvsig.tools.folders.FoldersManager;
87 94
import org.gvsig.tools.observer.Notification;
88 95
import org.gvsig.tools.observer.ObservableHelper;
89 96
import org.gvsig.tools.observer.Observer;
......
108 115
    private final Map<String, Class<ILegendReader>> legendReaders = new LinkedHashMap<>();
109 116

  
110 117
    private final Map<String, Map<Class<ILegend>,Class<ILegendWriter>>> legendWriters = new LinkedHashMap<>();
118
    
119
    private final Map<Class<? extends DataStore>,Class<? extends FLayer>> layerClassFromStoreClass = new HashMap<>();
111 120

  
121
    private final Map<String,String> iconLayers = new HashMap(); //  (Map<String storeProviderName, String iconName>)
122

  
112 123
    private String defaultVectorLegend;
113 124

  
114
    private ObservableHelper observableHelper = new ObservableHelper();
125
    private final ObservableHelper observableHelper = new ObservableHelper();
115 126

  
116 127
    private File colorTableLibraryFolder = null;
117 128
    private String defaultRasterLegend;
118 129

  
130
    @Override
119 131
    public MapContext createMapContext() {
120 132
        MapContext mapcontext = new MapContext(new ViewPort());
121 133
        return (MapContext) notifyObservers(CREATE_MAPCONTEXT, mapcontext).getValue();
122 134
    }
123 135

  
136
    @Override
124 137
    public SymbolManager getSymbolManager() {
125 138
        return MapContextLocator.getSymbolManager();
126 139
    }
......
129 142
        return getSymbolManager().getSymbolPreferences();
130 143
    }
131 144

  
145
    @Override
132 146
    public String getSymbolLibraryPath() {
133 147
        return getSymbolPreferences().getSymbolLibraryPath();
134 148
    }
135 149

  
150
    @Override
136 151
    public void setSymbolLibraryPath(String symbolLibraryPath) {
137 152
        getSymbolPreferences().setSymbolLibraryPath(symbolLibraryPath);
138 153
    }
139 154

  
155
    @Override
140 156
    public void resetSymbolLibraryPath() {
141 157
        getSymbolPreferences().resetSymbolLibraryPath();
142 158
    }
143 159

  
160
    @Override
144 161
    public Color getDefaultSymbolColor() {
145 162
        return getSymbolPreferences().getDefaultSymbolColor();
146 163
    }
147 164

  
165
    @Override
148 166
    public Color getDefaultSymbolFillColor() {
149 167
        return getSymbolPreferences().getDefaultSymbolFillColor();
150 168
    }
151 169

  
170
    @Override
152 171
    public Font getDefaultSymbolFont() {
153 172
        return getSymbolPreferences().getDefaultSymbolFont();
154 173
    }
......
157 176
        return getSymbolPreferences().getSymbolFileExtension();
158 177
    }
159 178

  
179
    @Override
160 180
    public boolean isDefaultSymbolFillColorAleatory() {
161 181
        return getSymbolPreferences().isDefaultSymbolFillColorAleatory();
162 182
    }
163 183

  
184
    @Override
164 185
    public void resetDefaultSymbolColor() {
165 186
        getSymbolPreferences().resetDefaultSymbolColor();
166 187
    }
167 188

  
189
    @Override
168 190
    public void resetDefaultSymbolFillColor() {
169 191
        getSymbolPreferences().resetDefaultSymbolFillColor();
170 192
    }
171 193

  
194
    @Override
172 195
    public void resetDefaultSymbolFillColorAleatory() {
173 196
        getSymbolPreferences().resetDefaultSymbolFillColorAleatory();
174 197
    }
175 198

  
199
    @Override
176 200
    public void resetDefaultSymbolFont() {
177 201
        getSymbolPreferences().resetDefaultSymbolFont();
178 202
    }
179 203

  
204
    @Override
180 205
    public void setDefaultSymbolColor(Color defaultSymbolColor) {
181 206
        getSymbolPreferences().setDefaultSymbolColor(defaultSymbolColor);
182 207
    }
183 208

  
209
    @Override
184 210
    public void setDefaultSymbolFillColor(Color defaultSymbolFillColor) {
185 211
        getSymbolPreferences().setDefaultSymbolFillColor(defaultSymbolFillColor);
186 212
    }
187 213

  
214
    @Override
188 215
    public void setDefaultSymbolFillColorAleatory(
189 216
            boolean defaultSymbolFillColorAleatory) {
190 217
        getSymbolPreferences().setDefaultSymbolFillColorAleatory(
191 218
                defaultSymbolFillColorAleatory);
192 219
    }
193 220

  
221
    @Override
194 222
    public void setDefaultSymbolFont(Font defaultSymbolFont) {
195 223
        getSymbolPreferences().setDefaultSymbolFont(defaultSymbolFont);
196 224
    }
......
199 227
        getSymbolPreferences().setSymbolFileExtension(extension);
200 228
    }
201 229

  
230
    @Override
202 231
    public int getDefaultCartographicSupportMeasureUnit() {
203 232
        return getSymbolPreferences().getDefaultCartographicSupportMeasureUnit();
204 233
    }
205 234

  
235
    @Override
206 236
    public void setDefaultCartographicSupportMeasureUnit(
207 237
            int defaultCartographicSupportMeasureUnit) {
208 238
        getSymbolPreferences().setDefaultCartographicSupportMeasureUnit(
209 239
                defaultCartographicSupportMeasureUnit);
210 240
    }
211 241

  
242
    @Override
212 243
    public int getDefaultCartographicSupportReferenceSystem() {
213 244
        return getSymbolPreferences().getDefaultCartographicSupportReferenceSystem();
214 245
    }
215 246

  
247
    @Override
216 248
    public void setDefaultCartographicSupportReferenceSystem(
217 249
            int defaultCartographicSupportReferenceSystem) {
218 250
        getSymbolPreferences().setDefaultCartographicSupportReferenceSystem(
219 251
                defaultCartographicSupportReferenceSystem);
220 252
    }
221 253

  
254
    @Override
222 255
    public MapContextDrawer createMapContextDrawerInstance(Class drawerClazz)
223 256
            throws MapContextException {
224 257
        return createMapContextDrawerInstance(drawerClazz, "NONE");
225 258
    }
226 259

  
260
    @Override
227 261
    public MapContextDrawer createDefaultMapContextDrawerInstance()
228 262
            throws MapContextException {
229 263

  
......
242 276
        }
243 277
    }
244 278

  
279
    @Override
245 280
    public void setDefaultMapContextDrawer(Class drawerClazz)
246 281
            throws MapContextException {
247 282

  
......
250 285
        notifyObservers(SET_MAPCONTEXT_DRAWER, drawerClazz);
251 286
    }
252 287

  
288
    @Override
253 289
    public void validateMapContextDrawer(Class drawerClazz)
254 290
            throws MapContextException {
255 291
        if (!MapContextDrawer.class.isAssignableFrom(drawerClazz)) {
......
510 546
            throws Exception {
511 547

  
512 548
        Iterator kiter = clsToWtr.keySet().iterator();
513
        Object oitem = null;
514
        Class citem = null;
549
        Object oitem;
550
        Class<ILegendWriter> citem;
515 551
        while (kiter.hasNext()) {
516 552
            oitem = kiter.next();
517 553
            if (oitem instanceof Class) {
......
520 556
                    /*
521 557
                     * Found superclass/superinterface
522 558
                     */
523
                    citem = (Class) clsToWtr.get(oitem);
559
                    citem = clsToWtr.get(oitem);
524 560
                    return (ILegendWriter) citem.newInstance();
525 561
                }
526 562
            }
......
533 569

  
534 570
    // =============================================================
535 571

  
572
    @Override
536 573
    public IMultiLayerSymbol createMultiLayerSymbol(int shapeType)
537 574
            throws MapContextRuntimeException {
538 575
        IMultiLayerSymbol symbol = getSymbolManager().createMultiLayerSymbol(shapeType);
539 576
        return (IMultiLayerSymbol) notifyObservers(CREATE_SYMBOL, symbol).getValue();
540 577
    }
541 578

  
579
    @Override
542 580
    public IMultiLayerSymbol createMultiLayerSymbol(String symbolName)
543 581
            throws MapContextRuntimeException {
544 582
        IMultiLayerSymbol symbol = getSymbolManager().createMultiLayerSymbol(symbolName);
545 583
        return (IMultiLayerSymbol) notifyObservers(CREATE_SYMBOL, symbol).getValue();
546 584
    }
547 585

  
586
    @Override
548 587
    public ISymbol createSymbol(int shapeType, Color color)
549 588
            throws MapContextRuntimeException {
550 589
        ISymbol symbol = getSymbolManager().createSymbol(shapeType, color);
551 590
        return (ISymbol) notifyObservers(CREATE_SYMBOL, symbol).getValue();
552 591
    }
553 592

  
593
    @Override
554 594
    public ISymbol createSymbol(int shapeType)
555 595
            throws MapContextRuntimeException {
556 596
        ISymbol symbol = getSymbolManager().createSymbol(shapeType);
557 597
        return (ISymbol) notifyObservers(CREATE_SYMBOL, symbol).getValue();
558 598
    }
559 599

  
600
    @Override
560 601
    public ISymbol createSymbol(String symbolName, Color color)
561 602
            throws MapContextRuntimeException {
562 603
        ISymbol symbol = getSymbolManager().createSymbol(symbolName, color);
563 604
        return (ISymbol) notifyObservers(CREATE_SYMBOL, symbol).getValue();
564 605
    }
565 606

  
607
    @Override
566 608
    public ISymbol createSymbol(String symbolName)
567 609
            throws MapContextRuntimeException {
568 610
        ISymbol symbol = getSymbolManager().createSymbol(symbolName);
569 611
        return (ISymbol) notifyObservers(CREATE_SYMBOL, symbol).getValue();
570 612
    }
571 613

  
614
    @Override
572 615
    public IWarningSymbol getWarningSymbol(String message, String symbolDesc,
573 616
            int symbolDrawExceptionType) throws MapContextRuntimeException {
574 617
        return getSymbolManager().getWarningSymbol(message, symbolDesc,
......
586 629
        return (ISymbol[]) notifyObservers(LOAD_SYMBOLS, symbols).getValue();
587 630
    }
588 631

  
632
    @Override
589 633
    public void registerMultiLayerSymbol(String symbolName, Class symbolClass)
590 634
            throws MapContextRuntimeException {
591 635
        getSymbolManager().registerMultiLayerSymbol(symbolName, symbolClass);
592 636
        notifyObservers(REGISTER_MULTILAYER_SYMBOL, symbolName, symbolClass);
593 637
    }
594 638

  
639
    @Override
595 640
    public void registerMultiLayerSymbol(String symbolName, int[] shapeTypes,
596 641
            Class symbolClass) throws MapContextRuntimeException {
597 642
        getSymbolManager().registerMultiLayerSymbol(symbolName, shapeTypes,
......
599 644
        notifyObservers(REGISTER_MULTILAYER_SYMBOL, symbolName, symbolClass, shapeTypes);
600 645
    }
601 646

  
647
    @Override
602 648
    public void registerSymbol(String symbolName, Class symbolClass)
603 649
            throws MapContextRuntimeException {
604 650
        getSymbolManager().registerSymbol(symbolName, symbolClass);
605 651
        notifyObservers(REGISTER_SYMBOL, symbolName, symbolClass);
606 652
    }
607 653

  
654
    @Override
608 655
    public void registerSymbol(String symbolName, int[] shapeTypes,
609 656
            Class symbolClass) throws MapContextException {
610 657
        getSymbolManager().registerSymbol(symbolName, shapeTypes, symbolClass);
......
621 668
        getSymbolManager().saveSymbol(symbol, fileName, folder);
622 669
    }
623 670

  
624
    public FLayer createLayer(String layerName, DataStoreParameters parameters)
671
    @Override
672
    public boolean registerLayer(
673
        Class<? extends DataStore> dataStoreClass,
674
        Class<? extends FLayer> layerClass) 
675
    {
676
        this.layerClassFromStoreClass.put(dataStoreClass, layerClass);
677
        return true;
678
    }    
679
    
680
    private Class<? extends FLayer> getLayerClassFromDataStoreClass(
681
            Class<? extends DataStore> dataStoreClass) {
682
        Class<? extends FLayer> layerClass = this.layerClassFromStoreClass.get(dataStoreClass);
683
        if( layerClass!=null ) {
684
            return layerClass;
685
        }
686
        for (Map.Entry<Class<? extends DataStore>, Class<? extends FLayer>> entry : layerClassFromStoreClass.entrySet()) {
687
            Class<? extends DataStore>  currentDataStoreClass = entry.getKey();
688
            layerClass = entry.getValue();
689
            if( currentDataStoreClass.isAssignableFrom(dataStoreClass) ) {
690
                return layerClass;
691
            }
692
        }
693
        return null;
694
    }
695
    
696
    @Override
697
    public FLayer createLayer(String layerName, DataStoreParameters dataParameters)
625 698
            throws LoadLayerException {
626
        FLayer layer = LayerFactory.getInstance().createLayer(layerName, parameters);
627
        return (FLayer) notifyObservers(CREATE_LAYER, layer).getValue();
699
        try {
700
            DataManager dataManager = DALLocator.getDataManager();
701
            DataStore dataStore = dataManager.openStore(
702
                    dataParameters.getDataStoreName(), 
703
                    dataParameters
704
            );
705
            return this.createLayer(layerName, dataStore, null);
706
        } catch (Exception e) {
707
            throw new LoadLayerException(layerName, e);
708
        }
628 709
    }
629 710

  
630 711
    @Override
631
    public FLayer createLayer(String layerName, DataStore store)
712
    public FLayer createLayer(String layerName, DataStore dataStore)
632 713
            throws LoadLayerException {
633
        FLayer layer = LayerFactory.getInstance().createLayer(layerName, store);
634
        return (FLayer) notifyObservers(CREATE_LAYER, layer).getValue();
714
        return this.createLayer(layerName, dataStore, null);
635 715
    }
636 716

  
717

  
637 718
    @Override
719
    public FLayer createLayer(String layerName, CreateLayerParameters parameters) throws LoadLayerException {
720
        try {
721
            DataManager dataManager = DALLocator.getDataManager();
722
            DataStoreParameters dataParameters = parameters.getDataParameters();
723
            DataStore dataStore = dataManager.openStore(
724
                    dataParameters.getDataStoreName(), 
725
                    dataParameters
726
            );
727
            return this.createLayer(layerName, dataStore, parameters);
728
        } catch (Exception e) {
729
            throw new LoadLayerException(layerName, e);
730
        }
731
    }    
732
    
733
    @Override
734
    public FLayer createLayer(String layerName, DataStore dataStore, CreateLayerParameters parameters) throws LoadLayerException {
735
        try {
736
            boolean useCache = false;
737
            ICoordTrans coordTrans = null;
738
            IProjection projection = (IProjection) dataStore.getDynValue(FeatureStore.METADATA_CRS);
739
            
740
            if( parameters!=null ) {
741
                if( parameters.getDataParameters()!=dataStore.getParameters() ) {
742
                    throw new IllegalArgumentException("The dataStore parameters are not the same of the store pased to create layer.");
743
                }
744
                useCache = parameters.useCache();
745
                
746
                coordTrans = parameters.getCoordTrans();
747
                // TODO: Aqui comprobacion de que si hay transformacion es adecuada
748
                // para la proyeccion del store.
749
            }
750
            
751
            if( useCache ) {
752
                DataStoreProviderFactory factory = dataStore.getProviderFactory();
753
                if( factory.isTiledSupported() != DataStoreProviderFactory.NO ) {
754
                    if( !factory.getClass().getSimpleName().equals("TileProviderFactory")) {
755
                        DataManager dataManager = DALLocator.getDataManager();
756
                        DynObject tileParameters = dataManager.createStoreParameters("TileCache");
757
                        File cacheFolder;
758
                        FoldersManager folderManager = ToolsLocator.getFoldersManager();
759
                        File applicationHome = folderManager.get("ApplicationHome");
760
                        if( applicationHome==null ) {
761
                            cacheFolder = folderManager.getTemporaryFile("gvsig_rcache");
762
                        } else {
763
                            cacheFolder = new File(applicationHome, "gvsig_rcache");
764
                        }
765
                        if (tileParameters.getDynClass().getDynField("rootFolder") != null) {
766
                            tileParameters.setDynValue("rootFolder", cacheFolder);
767
                        }
768
                        try {
769
                            dataStore.useCache("TileCache", tileParameters);
770
                        } catch (DataException e) {
771
                            logger.warn("Can't cache the layer.", e);
772
                        }
773
                    }
774
                }
775
            }
776
            
777
            Class<? extends FLayer> layerClass = this.getLayerClassFromDataStoreClass(dataStore.getClass());
778
            if (layerClass == null) {
779
                throw new CantRetrieveLayerByStoreException(layerName, dataStore.getName());
780
            }
781
            FLayer layer;
782
            try {
783
                layer = (FLayer) layerClass.newInstance();
784
            } catch (InstantiationException | IllegalAccessException e) {
785
                throw new LoadLayerException(layerName, e);
786
            }
787

  
788
            layer.setName(layerName);
789
            ((SingleLayer) layer).setDataStore(dataStore);
790
            if (projection != null) {
791
                layer.setProjection(projection);
792
                if( coordTrans != null ) {
793
                    layer.setCoordTrans(coordTrans);
794
                }
795
            }
796
            layer.load();
797
            return (FLayer) notifyObservers(CREATE_LAYER, layer).getValue();
798
        } catch (Exception e) {
799
            throw new LoadLayerException(layerName, e);
800
        }
801
    }
802

  
803

  
804
    @Override
638 805
    public ILegend getLegend(DataStore dataStore) {
639 806
        ILegend legend = null;
640 807

  
......
756 923
            }
757 924
            Object value = method.invoke(instance, params);
758 925
            return value;
759
        } catch (NoSuchMethodException ex) {
926
        } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
760 927
            return null;
761
        } catch (SecurityException ex) {
762
            return null;
763
        } catch (IllegalAccessException ex) {
764
            return null;
765
        } catch (IllegalArgumentException ex) {
766
            return null;
767
        } catch (InvocationTargetException ex) {
768
            return null;
769 928
        }
770 929
    }
771 930

  
......
788 947
        }
789 948
    }
790 949

  
791
    private Map iconLayers = new HashMap(); //  (Map<String storeProviderName, String iconName>)
792

  
950
    @Override
793 951
    public void registerIconLayer(String storeProviderName, String iconName) {
794 952
        if (storeProviderName == null || iconName == null) {
795 953
            logger.info("registerIconLayer, storeProviderName or iconName are null");
......
830 988
    /* (non-Javadoc)
831 989
     * @see org.gvsig.fmap.mapcontext.MapContextManager#getDefaultCRS()
832 990
     */
991
    @Override
833 992
    public IProjection getDefaultCRS() {
834 993
        IProjection crs = CRSFactory.getCRS("EPSG:4326");
835 994
        return (IProjection) notifyObservers(GET_DEFAULT_CRS, crs).getValue();
......
843 1002
        return this.observableHelper.notifyObservers(this, LOAD_LAYER, layer);
844 1003
    }
845 1004

  
1005
    @Override
846 1006
    public void addObserver(Observer o) {
847 1007
        this.observableHelper.addObserver(o);
848 1008
    }
849 1009

  
1010
    @Override
850 1011
    public void deleteObserver(Observer o) {
851 1012
        this.observableHelper.deleteObserver(o);
852 1013
    }
853 1014

  
1015
    @Override
854 1016
    public void deleteObservers() {
855 1017
        this.observableHelper.deleteObservers();
856 1018
    }
......
867 1029
        return this.observableHelper.notifyObservers(this, type, value1, value2, value3);
868 1030
    }
869 1031

  
1032
    @Override
870 1033
    public File getColorTableLibraryFolder() {
871 1034
        if (this.colorTableLibraryFolder == null) {
872 1035
            // Provide a default value to the location for the color
......
881 1044
        return this.colorTableLibraryFolder;
882 1045
    }
883 1046

  
1047
    @Override
884 1048
    public void setColorTableLibraryFolder(File colorTableLibraryFolder) {
885 1049
        this.colorTableLibraryFolder = colorTableLibraryFolder;
886 1050
    }
branches/org.gvsig.desktop-2018a/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/extension/InitializeApplicationExtension.java
60 60
import org.gvsig.tools.ToolsLocator;
61 61
import org.gvsig.tools.dynobject.DynObject;
62 62
import org.gvsig.tools.evaluator.sqljep.SQLJEPEvaluatorFactory;
63
import org.gvsig.tools.folders.FoldersManager;
63 64
import org.gvsig.tools.i18n.I18nManager;
64 65
import org.slf4j.Logger;
65 66
import org.slf4j.LoggerFactory;
......
74 75
    @Override
75 76
    public void initialize() {
76 77

  
78
        PluginsManager pluginsManager = PluginsLocator.getManager();
77 79
        DALLocator.getDataManager().registerDefaultEvaluator(new SQLJEPEvaluatorFactory());
78 80
            
79 81
        DALLocator.registerFeatureTypeDefinitionsManager(DefaultFeatureTypeDefinitionsManager.class);
......
81 83
        InfoListener.initializeExtensionPoint();
82 84

  
83 85
        registerIcons();
86
        
87
        FoldersManager folderManager = ToolsLocator.getFoldersManager();
88
        folderManager.set("ApplicationHome", pluginsManager.getApplicationHomeFolder());
84 89

  
85 90
    }
86 91

  
branches/org.gvsig.desktop-2018a/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/gui/WizardPanel.java
43 43
import org.gvsig.fmap.mapcontext.MapContext;
44 44
import org.gvsig.fmap.mapcontext.MapContextLocator;
45 45
import org.gvsig.fmap.mapcontext.MapContextManager;
46
import org.gvsig.fmap.mapcontext.MapContextManager.CreateLayerParameters;
46 47
import org.gvsig.fmap.mapcontext.layers.FLayer;
47 48
import org.gvsig.fmap.mapcontrol.MapControl;
48 49
import org.gvsig.fmap.mapcontrol.MapControlCreationException;
......
197 198
    }
198 199

  
199 200
    protected void doAddLayer(
200
            final String layerName, final DataStoreParameters parameters) {
201
            final String layerName, final CreateLayerParameters layerParameters) {
201 202
        final boolean b_isMapControlAvail = this.isMapControlAvailable();
202 203
        final MapControl mapControl = this.getMapCtrl();
203 204
        final MapContext mapContext = this.getMapContext();
......
205 206
        final MapContextManager manager
206 207
                = MapContextLocator.getMapContextManager();
207 208

  
209
        final DataStoreParameters parameters = layerParameters.getDataParameters();
210

  
208 211
        logger.info("addLayer('{}',...)", layerName);
209 212
        Thread task = new Thread(new Runnable() {
210 213

  
......
308 311
     * creating the panel from the AddLayer extension.
309 312
     */
310 313
    protected void doAddLayer(final MapControl mapControl,
311
            final String layerName, final DataStoreParameters parameters) {
314
            final String layerName, final CreateLayerParameters parameters) {
312 315
        this.setMapCtrl(mapControl);
313 316
        doAddLayer(layerName, parameters);
314 317
    }
branches/org.gvsig.desktop-2018a/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/addlayer/AddLayerDialog.java
229 229
        }
230 230
    }
231 231

  
232
    /**
233
     * Devuelve la ultima proyecci?n usada
234
     *
235
     * @return
236
     */
237
    public static IProjection getLastProjection() {
238
        if (proj == null) {
239
            proj = DefaultProject.getDefaultProjection();
240
        }
241
        return proj;
242
    }
232
//    /**
233
//     * Devuelve la ultima proyecci?n usada
234
//     *
235
//     * @return
236
//     */
237
//    public static IProjection getLastProjection() {
238
//        if (proj == null) {
239
//            proj = DefaultProject.getDefaultProjection();
240
//        }
241
//        return proj;
242
//    }
243
//
244
//    /**
245
//     * Define la ultima proyeccion
246
//     *
247
//     * @param proj
248
//     */
249
//    public static void setLastProjection(IProjection proj) {
250
//        AddLayerDialog.proj = proj;
251
//    }
243 252

  
244
    /**
245
     * Define la ultima proyeccion
246
     *
247
     * @param proj
248
     */
249
    public static void setLastProjection(IProjection proj) {
250
        AddLayerDialog.proj = proj;
251
    }
252

  
253 253
    @Override
254 254
    public Object getWindowProfile() {
255 255
        return WindowInfo.DIALOG_PROFILE;
branches/org.gvsig.desktop-2018a/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/fmap/dal/serverexplorer/filesystem/swing/FilesystemExplorerWizardPanel.java
24 24
import org.gvsig.app.ApplicationLocator;
25 25
import org.gvsig.app.ApplicationManager;
26 26
import org.gvsig.app.gui.WizardPanel;
27
import org.gvsig.app.gui.wizards.WizardListener;
28
import org.gvsig.app.gui.wizards.WizardListenerSupport;
29 27
import org.gvsig.app.prepareAction.PrepareContext;
30 28
import org.gvsig.app.prepareAction.PrepareContextView_v1;
31 29
import org.gvsig.app.project.documents.view.toc.actions.LayerErrorsPanel;
......
43 41
import org.gvsig.fmap.mapcontext.MapContext;
44 42
import org.gvsig.fmap.mapcontext.MapContextLocator;
45 43
import org.gvsig.fmap.mapcontext.MapContextManager;
44
import org.gvsig.fmap.mapcontext.MapContextManager.CreateLayerParameters;
46 45
import org.gvsig.fmap.mapcontext.layers.FLayer;
47 46
import org.gvsig.fmap.mapcontrol.MapControl;
48 47
import org.gvsig.tools.ToolsLocator;
......
79 78
    private static String lastPath = null;
80 79
    private FilesystemExplorerWizardPanelController panel = null;
81 80
    private boolean tabularOnly;
82

  
81
    
83 82
    /**
84 83
     *
85 84
     */
......
91 90
        super();
92 91
        this.tabularOnly = tabularOnly;
93 92
        this.addAncestorListener(new AncestorListener() {
93
            @Override
94 94
            public void ancestorAdded(AncestorEvent ae) {
95 95
                initExplorer();
96 96
                initFilters();
97 97
                updatePanel();
98 98
            }
99
            @Override
99 100
            public void ancestorRemoved(AncestorEvent ae) {
100 101
                dispose();
101 102
            }
......
150 151
        }
151 152
        String layerName;
152 153

  
153
        for (DataStoreParameters params : this.getParameters()) {
154
        for (CreateLayerParameters layerParams : this.getLoadLayerParameters()) {
154 155
            IProjection proj = this.getMapCtrl().getProjection();
155 156

  
156 157
            // Buscamos por el parametro de la proyeccion
157 158
            // que sean obligatorios y est?n a null
158 159
            // y le ponemos la proyeccion de la vista
160
            DataStoreParameters params = layerParams.getDataParameters();
159 161
            DynField[] fields = params.getDynClass().getDynFields();
160 162
            int crsfields = 0;
161 163
            DynField crsfield = null;
......
180 182

  
181 183
            layerName = ((FilesystemStoreParameters) params).getFile().getName();
182 184

  
183
            this.doAddLayer(layerName, params);
185
            this.doAddLayer(layerName, layerParams);
184 186
        }
185 187
    }
186 188

  
......
206 208

  
207 209
    @Override
208 210
    public DataStoreParameters[] getParameters() {
209
        return this.panel.getParameters();
211
        // TODO: Habria que ver si podemos eliminar este metodo.
212
        CreateLayerParameters[] layerParameters = this.panel.getCreateLayerParameters();
213
        DataStoreParameters[] dataParameters = new DataStoreParameters[layerParameters.length];
214
        for (int i = 0; i < dataParameters.length; i++) {
215
            DataStoreParameters dataParameter = layerParameters[i].getDataParameters();
216
        }
217
        return dataParameters;
210 218
    }
219
    
220
    public CreateLayerParameters[] getLoadLayerParameters() {
221
        return this.panel.getCreateLayerParameters();
222
    }
211 223

  
212 224
    /**
213 225
     * @param files
......
236 248
    private void initFilters() {
237 249
        if (this.filters == null) {
238 250
            int mode = FilesystemServerExplorer.MODE_ALL;
239
            this.filters = new ArrayList<MyFileFilter>();
251
            this.filters = new ArrayList<>();
240 252
            if (this.getMapCtrl() == null) {
241 253
                mode = FilesystemServerExplorer.MODE_FEATURE;
242 254
            } else {
......
258 270
        }
259 271
    }
260 272

  
261
    boolean isTiled(DataStoreParameters parameters){
262
        return this.panel.isTiled(parameters);
263
    }
264

  
265 273
    @Override
266
    protected void doAddLayer(final String layerName, final DataStoreParameters parameters) {
274
    protected void doAddLayer(final String layerName, final CreateLayerParameters layerParameters) {
267 275
        final boolean b_isMapControlAvail = this.isMapControlAvailable();
268 276
        final MapControl mapControl = this.getMapCtrl();
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff