Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / addlayer / fileopen / vectorial / VectorialFileOpen.java @ 21743

History | View | Annotate | Download (4.75 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 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
package com.iver.cit.gvsig.addlayer.fileopen.vectorial;
20

    
21
import java.io.File;
22
import java.util.ArrayList;
23
import java.util.Comparator;
24
import java.util.Iterator;
25
import java.util.TreeSet;
26

    
27
import org.cresques.cts.IProjection;
28
import org.gvsig.data.DataManager;
29
import org.gvsig.data.DataStoreParameters;
30
import org.gvsig.data.InitializeException;
31
import org.gvsig.data.ReadException;
32
import org.gvsig.data.datastores.vectorial.file.FileStoreParameters;
33
import org.gvsig.data.vectorial.FeatureStore;
34
import org.gvsig.fmap.geom.primitive.Envelope;
35
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException;
36
import org.gvsig.fmap.mapcontext.layers.FLayer;
37
import org.gvsig.fmap.mapcontext.layers.LayerFactory;
38
import org.gvsig.fmap.mapcontrol.MapControl;
39

    
40
import com.iver.andami.messages.NotificationManager;
41
import com.iver.cit.gvsig.AddLayer;
42
import com.iver.cit.gvsig.addlayer.fileopen.AbstractFileOpen;
43
/**
44
 * Clase que indicar? que ficheros puede tratar al panel de apertura de ficheros
45
 *
46
 * @version 04/09/2007
47
 * @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
48
 */
49
public class VectorialFileOpen extends AbstractFileOpen{
50

    
51
        /**
52
         * Constructor de FileOpenRaster
53
         */
54
        public VectorialFileOpen() {
55
                TreeSet filters = new TreeSet(new Comparator() {
56
                        public int compare(Object o1, Object o2) {
57
                                VectorialFileFilter dff1 = (VectorialFileFilter) o1;
58
                                VectorialFileFilter dff2 = (VectorialFileFilter) o2;
59

    
60
                                return dff1.featureStore.getName().compareTo(dff2.featureStore.getName());
61
                        }
62
                });
63

    
64
//                Class[] driverClasses = new Class[] { FeatureStore.class };
65
//                String[] driverNames = LayerFactory.getDM().getDriverNames();
66
                VectorialFileFilter auxF=null;
67
//                try {
68
//                        for (int i = 0; i < driverNames.length; i++) {
69
//                                System.err.println("DRIVER " + i + " : " + driverNames[i]);
70
                                boolean is = false;
71
//                                for (int j = 0; j < driverClasses.length; j++) {
72
//                                        if (i == 0)
73
//                                                System.err.println("DRIVER CLASS " + j + " : " + driverClasses[j].toString());
74
//                                        if (LayerFactory.getDM().isA(driverNames[i], driverClasses[j]))
75
                                                is = true;
76
//                                }
77
                                if (is) {
78
                                        DataManager dm=DataManager.getManager();
79
                                        try {
80
                                                auxF = new VectorialFileFilter(dm.getRegisters()[0]);
81
                                        } catch (InitializeException e) {
82
                                                // TODO Auto-generated catch block
83
                                                e.printStackTrace();
84
                                        }
85
                                        filters.add(auxF);
86
                                }
87
//                        }
88
                        Iterator i = filters.iterator();
89
                        while (i.hasNext()) {
90
                                VectorialFileFilter element = (VectorialFileFilter) i.next();
91
                                getFileFilter().add(element);
92
                        }
93
//                } catch (DriverLoadException e1) {
94
//                        NotificationManager.addError("No se pudo acceder a los drivers", e1);
95
//                }
96

    
97
        }
98

    
99
        /*
100
         * (non-Javadoc)
101
         * @see org.gvsig.raster.gui.wizards.IFileOpen#execute(java.io.File[])
102
         */
103
        public Envelope createLayer(File file, MapControl mapControl, String name, IProjection proj) {
104
                FLayer lyr = null;
105
//                FeatureStore store = null;
106

    
107
                // all catched errors will be saved here, to show user at the end of the method
108
                ArrayList errors = new ArrayList();
109

    
110
                // try to load the drivers referenced by the file dialog
111
//                try {
112
                        DataManager dm=DataManager.getManager();
113
                        DataStoreParameters params=null;
114
                        try {
115
                                params = dm.createDataStoreParameters(name);
116
                        } catch (InitializeException e1) {
117
                                errors.add(e1);
118
                        }
119
//                        store = (FeatureStore)dm.createDataStore(params);
120
//                } catch (DriverLoadException e) {
121
//                        errors.add(e);
122
//                }
123

    
124
                // Envelope de cada fichero seleccionado por el usuario
125
                String layerName = file.getName();
126
                try {
127

    
128
                        if (params instanceof FileStoreParameters) {
129
                                ((FileStoreParameters)params).setFile(file);
130
                                lyr = LayerFactory.createLayer(layerName,params, proj);
131
                        }
132

    
133
                        if (lyr != null) {
134
                                AddLayer.checkProjection(lyr, mapControl.getViewPort());
135
                                mapControl.getMapContext().getLayers().addLayer(lyr);
136

    
137
                                return lyr.getFullEnvelope();
138
                        }
139
                } catch (LoadLayerException e) {
140
                        errors.add(e);
141
                } catch (ReadException e) {
142
                        errors.add(e);
143
                }
144
                return null;
145
        }
146
}