Revision 21743 branches/v2_0_0_prep/applications/appgvSIG/src/com/iver/cit/gvsig/addlayer/fileopen/vectorial/VectorialFileOpen.java

View differences:

VectorialFileOpen.java
18 18
 */
19 19
package com.iver.cit.gvsig.addlayer.fileopen.vectorial;
20 20

  
21
import java.awt.geom.Rectangle2D;
22 21
import java.io.File;
23 22
import java.util.ArrayList;
24 23
import java.util.Comparator;
......
26 25
import java.util.TreeSet;
27 26

  
28 27
import org.cresques.cts.IProjection;
29
import org.gvsig.fmap.drivers.reading.VectorialFileDriver;
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;
30 36
import org.gvsig.fmap.mapcontext.layers.FLayer;
31 37
import org.gvsig.fmap.mapcontext.layers.LayerFactory;
32 38
import org.gvsig.fmap.mapcontrol.MapControl;
33 39

  
34
import com.hardcode.driverManager.Driver;
35
import com.hardcode.driverManager.DriverLoadException;
36
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
37 40
import com.iver.andami.messages.NotificationManager;
38 41
import com.iver.cit.gvsig.AddLayer;
39 42
import com.iver.cit.gvsig.addlayer.fileopen.AbstractFileOpen;
......
54 57
				VectorialFileFilter dff1 = (VectorialFileFilter) o1;
55 58
				VectorialFileFilter dff2 = (VectorialFileFilter) o2;
56 59

  
57
				return dff1.driver.getName().compareTo(dff2.driver.getName());
60
				return dff1.featureStore.getName().compareTo(dff2.featureStore.getName());
58 61
			}
59 62
		});
60 63

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

  
88 97
	}
89 98

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

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

  
101 110
		// try to load the drivers referenced by the file dialog
102
		try {
103
			driver = LayerFactory.getDM().getDriver(driverName);
104
		} catch (DriverLoadException e) {
105
			errors.add(e);
106
		}
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
//		}
107 123

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

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

  
116 133
			if (lyr != null) {
......
119 136

  
120 137
				return lyr.getFullEnvelope();
121 138
			}
122
		} catch (ReadDriverException e) {
139
		} catch (LoadLayerException e) {
123 140
			errors.add(e);
141
		} catch (ReadException e) {
142
			errors.add(e);
124 143
		}
125 144
		return null;
126 145
	}

Also available in: Unified diff