Revision 4740

View differences:

trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/DBLayerDefinition.java
44 44
package com.iver.cit.gvsig.fmap.drivers;
45 45

  
46 46
import java.awt.geom.Rectangle2D;
47
import java.sql.Connection;
47 48

  
48 49
public class DBLayerDefinition extends LayerDefinition {
50
	private Connection conn;
49 51
    private String catalogName;
50 52
    private String tableName;
51 53
    // private String[] fieldNames; // GeometryField not included
......
58 60
    
59 61
    // private int idFieldGeometry = -1;
60 62
    private int idFieldID = -1;
63
	private int dimension = 2;
61 64
    
62 65
    public String getCatalogName() {
63 66
        return catalogName;
......
193 196
        }
194 197
        return resul;
195 198
    }
199
	public Connection getConnection() {
200
		return null;
201
	}
202
	
203
	public void setConnection(Connection connection) {
204
		conn = connection;
205
	}
206
	public int getDimension() {
207
		return dimension;
208
	}
209

  
210
	public void setDimension(int dim) {
211
		dimension = dim;
212
	}
213
	
196 214
}
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/core/ICanReproject.java
65 65
     * Set this variable to tell the driver in which projection
66 66
     * do you want your data. If the driver can reproject to this
67 67
     * new EPSG, it will return true in canReproject.
68
     * NOTE: use String strEPSG = mapCtrl.getViewPort()
69
	                    .getProjection().getAbrev()
70
	                    .substring(5);
68 71
     * Otherwise, it will return false.
69 72
     * @param toEPSG
70 73
     */
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/edition/ShpSchemaManager.java
45 45
*
46 46
* $Id$
47 47
* $Log$
48
* Revision 1.7  2006-03-15 12:12:22  fjp
48
* Revision 1.8  2006-04-05 09:00:02  fjp
49
* Preparando el driver de escritura PostGIS
50
*
51
* Revision 1.7  2006/03/15 12:12:22  fjp
49 52
* Creaci?n desde cero de un tema POR FIN.
50 53
*
51 54
* Revision 1.6  2006/03/14 19:28:57  azabala
......
82 85
public class ShpSchemaManager implements ISchemaManager {
83 86
	public void createOrAlterSchema(ITableDefinition layerDefinition)
84 87
			throws EditionException {
85
		try {
86 88
			SHPLayerDefinition definition =
87 89
				(SHPLayerDefinition) layerDefinition;
88 90

  
......
105 107
			shpWriter.initialize(definition);
106 108
			shpWriter.preProcess();
107 109

  
108
		} catch (IOException e) {
109
			e.printStackTrace();
110
			throw new EditionException(e);
111
		} catch (DriverException e) {
112
			// TODO Auto-generated catch block
113
			e.printStackTrace();
114
		}
115 110

  
116 111
	}
117 112

  
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/edition/writers/shp/ShpWriter.java
137 137
	 * Useful to create a layer from scratch
138 138
	 * Call setFile before using this function
139 139
	 * @param lyrDef
140
	 * @throws IOException
141
	 * @throws DriverException
140
	 * @throws EditionException
142 141
	 */
143
	public void initialize(LayerDefinition lyrDef) throws IOException, DriverException
142
	public void initialize(LayerDefinition lyrDef) throws EditionException
144 143
	{
145 144
		myHeader = DbaseFileHeaderNIO.createDbaseHeader(lyrDef.getFieldsDesc());
146
		initialize(shpFile, lyrDef.getShapeType());
145
		try {
146
			initialize(shpFile, lyrDef.getShapeType());
147
		} catch (IOException e) {
148
			e.printStackTrace();
149
			throw new EditionException(e);
150
		}
147 151
	}
148 152
	
149 153

  
trunk/extensions/extJDBC/src/com/iver/cit/gvsig/fmap/drivers/jdbc/postgis/PostGisDriver.java
52 52
import java.sql.Statement;
53 53
import java.sql.Types;
54 54
import java.util.Hashtable;
55
import java.util.Random;
55
import java.util.Properties;
56 56

  
57 57
import org.apache.log4j.Logger;
58 58
import org.postgis.PGbox2d;
......
70 70
import com.iver.cit.gvsig.fmap.drivers.DriverAttributes;
71 71
import com.iver.cit.gvsig.fmap.drivers.IFeatureIterator;
72 72
import com.iver.cit.gvsig.fmap.drivers.jdbc.WKBParser;
73
import com.iver.cit.gvsig.fmap.layers.XMLException;
73
import com.iver.cit.gvsig.fmap.edition.EditionException;
74
import com.iver.cit.gvsig.fmap.edition.IRowEdited;
75
import com.iver.cit.gvsig.fmap.edition.ISpatialWriter;
76
import com.iver.cit.gvsig.fmap.layers.FLayer;
74 77

  
75 78
/**
76 79
 * @author FJP
......
78 81
 * TODO To change the template for this generated type comment go to Window -
79 82
 * Preferences - Java - Code Generation - Code and Comments
80 83
 */
81
public class PostGisDriver extends DefaultDBDriver implements ICanReproject {
84
public class PostGisDriver extends DefaultDBDriver implements ICanReproject, ISpatialWriter {
82 85
	private static Logger logger = Logger.getLogger(PostGisDriver.class
83 86
			.getName());
84

  
87
	
85 88
	private static int FETCH_SIZE = 5000;
89
	
90
	private PostGISWriter writer;
86 91

  
87 92
	private WKBParser parser = new WKBParser();
88 93

  
......
184 189
	 */
185 190
	public void setData(Connection conn, DBLayerDefinition lyrDef) {
186 191
		this.conn = conn;
192
		// TODO: Deber?amos poder quitar Conneciton de la llamada y meterlo
193
		// en lyrDef desde el principio.
194
		lyrDef.setConnection(conn);
187 195
		setLyrDef(lyrDef);
188 196

  
189 197
		getTableEPSG();
......
721 729
		}
722 730
	}
723 731

  
732
	public void preProcess() throws EditionException {
733
		writer.preProcess();
734
	}
735

  
736
	public void process(IRowEdited row) throws EditionException {
737
		writer.process(row);
738
	}
739

  
740
	public void postProcess() throws EditionException {
741
		writer.postProcess();
742
	}
743

  
744
	public String getCapability(String capability) {
745
		return writer.getCapability(capability);
746
	}
747

  
748
	public void setCapabilities(Properties capabilities) {
749
		writer.setCapabilities(capabilities);
750
	}
751

  
752
	public boolean canWriteAttribute(int sqlType) {
753
		return writer.canWriteAttribute(sqlType);
754
	}
755

  
756
	public boolean canWriteGeometry(int gvSIGgeometryType) {
757
		return writer.canWriteGeometry(gvSIGgeometryType);
758
	}
759

  
760
	public void initialize(FLayer layer) throws EditionException {
761
		writer = new PostGISWriter();
762
		writer.setCreateTable(false);
763
		writer.setWriteAll(false);
764
		// Obtenemos el DBLayerDefinition a partir del driver
765
		
766
		DBLayerDefinition dbLyrDef = getLyrDef(); 
767
		
768
		
769
		writer.initialize(dbLyrDef);
770
	}
771

  
724 772
}
trunk/extensions/extJDBC/src/com/iver/cit/gvsig/fmap/drivers/jdbc/postgis/PostGISWriter.java
1
package com.iver.cit.gvsig.fmap.drivers.jdbc.postgis;
2

  
3
import java.io.IOException;
4
import java.sql.Connection;
5
import java.sql.SQLException;
6
import java.sql.Statement;
7
import java.sql.Types;
8

  
9
import com.iver.cit.gvsig.fmap.DriverException;
10
import com.iver.cit.gvsig.fmap.core.FShape;
11
import com.iver.cit.gvsig.fmap.core.IFeature;
12
import com.iver.cit.gvsig.fmap.drivers.DBLayerDefinition;
13
import com.iver.cit.gvsig.fmap.drivers.LayerDefinition;
14
import com.iver.cit.gvsig.fmap.edition.EditionException;
15
import com.iver.cit.gvsig.fmap.edition.IRowEdited;
16
import com.iver.cit.gvsig.fmap.edition.ISpatialWriter;
17
import com.iver.cit.gvsig.fmap.edition.writers.AbstractWriter;
18
import com.iver.cit.gvsig.fmap.layers.FLayer;
19
import com.iver.cit.gvsig.jdbc_spatial.util.PostGIS;
20

  
21
public class PostGISWriter extends AbstractWriter implements ISpatialWriter {
22

  
23
	private int numRows;
24

  
25
	private DBLayerDefinition lyrDef;
26

  
27
	private Connection conex;
28

  
29
	private Statement st;
30

  
31
	private boolean bCreateTable;
32

  
33
	private boolean bWriteAll;
34

  
35
	/**
36
	 * Useful to create a layer from scratch Call setFile before using this
37
	 * function
38
	 * 
39
	 * @param lyrDef
40
	 * @throws IOException
41
	 * @throws DriverException
42
	 */
43
	public void initialize(LayerDefinition lyrD) throws EditionException {
44
		this.lyrDef = (DBLayerDefinition) lyrD;
45
		conex = lyrDef.getConnection();
46

  
47
		try {
48
			st = conex.createStatement();
49

  
50
			if (bCreateTable) {
51
				try {
52
					st.execute("DROP TABLE " + lyrDef.getTableName() + ";");
53
				} catch (SQLException e1) {
54
					// Si no existe la tabla, no hay que borrarla.
55
				}
56

  
57
				String sqlCreate = PostGIS.getSqlCreateSpatialTable(lyrDef,
58
						lyrDef.getFieldsDesc());
59
				System.out.println("sqlCreate =" + sqlCreate);
60
				st.execute(sqlCreate);
61

  
62
				String sqlAlter = PostGIS.getSqlAlterTable(lyrDef);
63
				System.out.println("sqlAlter =" + sqlAlter);
64
				st.execute(sqlAlter);
65
				// CREATE TABLE PARKS ( PARK_ID int4, PARK_NAME varchar(128),
66
				// PARK_DATE date, PARK_TYPE varchar(2) );
67
				// SELECT AddGeometryColumn('parks_db', 'parks', 'park_geom',
68
				// 128,
69
				// 'MULTIPOLYGON', 2 );
70

  
71
				/*
72
				 * BEGIN; INSERT INTO ROADS_GEOM (ID,GEOM,NAME ) VALUES
73
				 * (1,GeometryFromText('LINESTRING(191232 243118,191108
74
				 * 243242)',-1),'Jeff Rd'); INSERT INTO ROADS_GEOM (ID,GEOM,NAME )
75
				 * VALUES (2,GeometryFromText('LINESTRING(189141 244158,189265
76
				 * 244817)',-1),'Geordie Rd'); COMMIT;
77
				 */
78
			}
79
			conex.setAutoCommit(false);
80

  
81
		} catch (SQLException e) {
82
			e.printStackTrace();
83
			throw new EditionException(e);
84
		}
85

  
86
	}
87

  
88
	public void preProcess() throws EditionException {
89
		numRows = 0;
90

  
91
	}
92

  
93
	public void process(IRowEdited row) throws EditionException {
94
		IFeature feat = (IFeature) row.getLinkedRow();
95
		String sqlInsert;
96
		try {
97
			// System.out.println("Escribiendo numReg=" + numReg + " con
98
			// STATUS=" + row.getStatus());
99
			switch (row.getStatus()) {
100
			case IRowEdited.STATUS_ADDED:
101
				sqlInsert = PostGIS.getSqlInsertFeature(lyrDef, feat);
102
				st.execute(sqlInsert);
103

  
104
				break;
105
			case IRowEdited.STATUS_MODIFIED:
106
				if (bWriteAll) {
107
					sqlInsert = PostGIS.getSqlInsertFeature(lyrDef, feat);
108
					st.execute(sqlInsert);
109
				} else {
110
					String sqlModify = PostGIS
111
							.getSqlModifyFeature(lyrDef, feat);
112
					st.execute(sqlModify);
113
				}
114
				break;
115
			case IRowEdited.STATUS_ORIGINAL:
116
				if (bWriteAll) {
117
					sqlInsert = PostGIS.getSqlInsertFeature(lyrDef, feat);
118
					st.execute(sqlInsert);
119
				}
120
				break;
121
			case IRowEdited.STATUS_DELETED:
122
				String sqlDelete = PostGIS.getSqlDeleteFeature(lyrDef, feat);
123
				st.execute(sqlDelete);
124

  
125
				break;
126
			}
127

  
128
			numRows++;
129
		} catch (SQLException e) {
130
			e.printStackTrace();
131
			throw new EditionException(e);
132
		}
133

  
134
	}
135

  
136
	public void postProcess() throws EditionException {
137
		try {
138
			conex.setAutoCommit(true);
139
		} catch (SQLException e) {
140
			e.printStackTrace();
141
			throw new EditionException(e);
142
		}
143
	}
144

  
145
	public String getName() {
146
		return "PostGIS Writer";
147
	}
148

  
149
	public boolean canWriteGeometry(int gvSIGgeometryType) {
150
		switch (gvSIGgeometryType) {
151
		case FShape.POINT:
152
			return true;
153
		case FShape.LINE:
154
			return true;
155
		case FShape.POLYGON:
156
			return true;
157
		case FShape.ARC:
158
			return false;
159
		case FShape.ELLIPSE:
160
			return false;
161
		case FShape.MULTIPOINT:
162
			return true;
163
		case FShape.TEXT:
164
			return false;
165
		}
166
		return false;
167
	}
168

  
169
	public boolean canWriteAttribute(int sqlType) {
170
		switch (sqlType) {
171
		case Types.DOUBLE:
172
		case Types.FLOAT:
173
		case Types.INTEGER:
174
		case Types.BIGINT:
175
			return true;
176
		case Types.DATE:
177
			return true;
178
		case Types.BIT:
179
		case Types.BOOLEAN:
180
			return true;
181
		case Types.VARCHAR:
182
		case Types.CHAR:
183
		case Types.LONGVARCHAR:
184
			return true; 
185

  
186
		}
187

  
188
		return false;
189
	}
190

  
191
	/**
192
	 * @return Returns the bCreateTable.
193
	 */
194
	public boolean isCreateTable() {
195
		return bCreateTable;
196
	}
197

  
198
	/**
199
	 * @param createTable
200
	 *            The bCreateTable to set.
201
	 */
202
	public void setCreateTable(boolean createTable) {
203
		bCreateTable = createTable;
204
	}
205

  
206
	/**
207
	 * @return Returns the bWriteAll.
208
	 */
209
	public boolean isWriteAll() {
210
		return bWriteAll;
211
	}
212

  
213
	/**
214
	 * @param writeAll
215
	 *            The bWriteAll to set.
216
	 */
217
	public void setWriteAll(boolean writeAll) {
218
		bWriteAll = writeAll;
219
	}
220

  
221
	public void initialize(FLayer layer) throws EditionException {
222
		
223
		
224

  
225
	}
226

  
227
}
0 228

  
trunk/extensions/extJDBC/src/com/iver/cit/gvsig/fmap/drivers/jdbc/postgis/testPostGis.java
43 43
 */
44 44
package com.iver.cit.gvsig.fmap.drivers.jdbc.postgis;
45 45

  
46
import java.awt.Shape;
47
import java.io.InputStream;
48
import java.sql.Blob;
46 49
import java.sql.Connection;
47 50
import java.sql.DriverManager;
48 51
import java.sql.PreparedStatement;
......
51 54
import java.sql.Statement;
52 55
import java.util.Enumeration;
53 56

  
57
import org.postgresql.core.Field;
58
import org.postgresql.fastpath.Fastpath;
59
import org.postgresql.fastpath.FastpathArg;
60
import org.postgresql.largeobject.LargeObjectManager;
61
import org.postgresql.util.PGobject;
62

  
54 63
import com.iver.cit.gvsig.fmap.core.IGeometry;
55 64
import com.iver.cit.gvsig.fmap.drivers.jdbc.WKBParser;
56 65

  
......
75 84
          String dbuser = "postgres";
76 85
          String dbpass = "aquilina";
77 86
    
78
          String dbtable = "provin";
87
          String dbtable = "vias";
79 88
          
80 89
          Connection conn = null; 
81 90
          System.out.println("Creating JDBC connection...");
......
135 144
            /* 
136 145
            * Create a statement and execute a select query. 
137 146
            */
138
              String strSQL = "select AsBinary(the_geom) as geom, nom_provin from " + dbtable;
139
              // String strSQL = "select ASBINARY(the_geom) as geom from " + dbtable;
147
              // String strSQL = "select AsBinary(the_geom) as geom, nom_provin from " + dbtable;
148
              String strSQL = "select ASBINARY(the_geom) as geom from " + dbtable;
140 149
              // strSQL = "select ASTEXT(the_geom), nom_provin as geom from " + dbtable;
141 150
              /* String strSQL = "SELECT gid, rd_3, rd_5, rd_6, rd_10, rd_11, rd_12, rd_13, rd_14,"; 
142 151
              strSQL = strSQL + " rd_15, rd_16, kilometers, cost, metros, AsText(force_2d(the_geom)) FROM vias"; 
......
149 158
              
150 159
              // Statement s = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
151 160
              // s.setFetchSize(5);
152
              int fetchSize = 5;
161
              int fetchSize = 150000;
153 162
            s.execute("declare wkb_cursor binary cursor for " + strSQL);
154
            ResultSet r =   s.executeQuery("fetch forward " + fetchSize + " in wkb_cursor");
163
            ResultSet r =   s.executeQuery("fetch forward " + fetchSize + " in wkb_cursor"); 
155 164
              /// ResultSet r =   s.executeQuery("fetch forward all in wkb_cursor");
156 165
            
157 166
            // String strSQL2 = "select AsBinary(the_geom) as geom, nom_provin from " + dbtable;
......
182 191
                // Object obj = r.getObject(2);
183 192
                byte[] arrayByte = r.getBytes(1);
184 193
                IGeometry gp = parser.parse(arrayByte);
185
                String strAux = r.getString(2);
194
                // String strAux = r.getString(2);
186 195
                // int id = r.getInt(2);
187 196
                // System.out.println("Fila " + id + ":" + obj.toString());
188 197
                id++;
......
190 199
                
191 200
              // PGgeometry geom = (PGgeometry)obj; 
192 201
               // int id = r.getInt(2);
193
              System.out.println("Row " + id + ":" + strAux); 
202
              // System.out.println("Row " + id + ":" + strAux); 
194 203
              // System.out.println(geom.toString()); 
195 204
                // System.out.println("provin=" + r.getString(2));
196
                if ((id % fetchSize) == 0)
205
                /* if ((id % fetchSize) == 0)
197 206
                {
198 207
                    r =   s.executeQuery("fetch forward " + fetchSize + " in wkb_cursor");
199
                }
208
                } */
200 209
                            
201 210
            }
202 211
            // s.execute("end");
......
235 244
            e.printStackTrace(); 
236 245
          }  
237 246
        }
247

  
238 248
      
249
      private static void test3(Connection conn, String dburl, String dbuser, String dbpass, String dbtable)
250
      {          
251
          try 
252
          { 
253
        	  Fastpath  fp;
254
        	  if (conn.getClass().getName().equals("org.postgresql.jdbc2.Connection")) {
255
        		  // ((org.postgresql.Connection) conn).addDataType("geometry", "org.postgis.PGgeometry");
256
        		  // ((org.postgresql.Connection) conn).addDataType("box3d", "org.postgis.PGbox3d");
257
        	  } else {
258
        		  ((org.postgresql.PGConnection) conn).addDataType("geometry", "org.postgis.PGgeometry");
259
        		  ((org.postgresql.PGConnection) conn).addDataType("box3d", "org.postgis.PGbox3d");
260
        		  fp =  ((org.postgresql.PGConnection) conn).getFastpathAPI();
261
        	  } 
262

  
263
              
264

  
265
            /* 
266
            * Create a statement and execute a select query. 
267
            */
268
              String strSQL = "select * from " + dbtable;
269
              // String strSQL = "select ASBINARY(the_geom) as geom from " + dbtable;
270
              // strSQL = "select ASTEXT(the_geom), nom_provin as geom from " + dbtable;
271
              /* String strSQL = "SELECT gid, rd_3, rd_5, rd_6, rd_10, rd_11, rd_12, rd_13, rd_14,"; 
272
              strSQL = strSQL + " rd_15, rd_16, kilometers, cost, metros, AsText(force_2d(the_geom)) FROM vias"; 
273
              strSQL = strSQL + " WHERE TRUE";
274
              */
275
              // PreparedStatement s = conn.prepareStatement(strSQL);
276
              
277
              Statement s = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
278
              // s.execute("begin");
279
              
280
              // Statement s = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
281
              // s.setFetchSize(5);
282
            /*  int fetchSize = 150000;
283
            s.execute("declare wkb_cursor2 binary cursor for " + strSQL);
284
            ResultSet r =   s.executeQuery("fetch forward " + fetchSize + " in wkb_cursor2"); */
285
            
286
            // String strSQL2 = "select AsBinary(the_geom) as geom, nom_provin from " + dbtable;
287
            // PreparedStatement ps = conn.prepareStatement(strSQL2);
288
            // ResultSet r = ps.executeQuery();
289
                        
290
            ResultSet r = s.executeQuery(strSQL);
291
            WKBParser parser = new WKBParser();
292
            long id=0;
293
            /* FastpathArg args[] = new FastpathArg[2];
294
            args[0] = new FastpathArg(fd);
295
            args[1] = new FastpathArg(len);
296
            return fp.getData("loread", args); */  
297
            while( r.next() ) 
298
            { 
299
              /* 
300
              * Retrieve the geometry as an object then cast it to the geometry type. 
301
              * Print things out. 
302
              */ 
303
                Object obj = r.getObject(9);
304
                // fp.
305
            	// final Shape current = (Shape) r.getObject(1);
306
                // byte[] arrayByte = r.getBytes(1);
307
                // String strAux = r.getString(2);
308
                
309
                id++;
310
                // Geometry regeom = PGgeometry.geomFromString(obj.toString());
311
                
312
              // PGgeometry geom = (PGgeometry)obj; 
313
               // int id = r.getInt(2);
314
              // System.out.println("Row " + id + ":" + strAux); 
315
              // System.out.println(geom.toString()); 
316
                // System.out.println("provin=" + r.getString(2));
317
                /* if ((id % fetchSize) == 0)
318
                {
319
                    r =   s.executeQuery("fetch forward " + fetchSize + " in wkb_cursor");
320
                } */
321
                
322
                            
323
            }
324
            // s.execute("end");
325
            s.close();
326
            
327
          } 
328
          catch( Exception e ) 
329
          { 
330
            e.printStackTrace(); 
331
          }  
332
      }
333
      
239 334
}
trunk/extensions/extJDBC/src/com/iver/cit/gvsig/jdbc_spatial/ImportLayer.java
192 192
                        fieldsDescrip);
193 193
                System.out.println("sqlCreate =" + sqlCreate);
194 194
                st.execute(sqlCreate);
195
                int dimension = 2;
195
                dbLayerDef.setDimension(2);
196 196

  
197
                String sqlAlter = PostGIS.getSqlAlterTable(dbLayerDef, strSRID,
198
                        strGeometryFieldType, dimension);
197
                String sqlAlter = PostGIS.getSqlAlterTable(dbLayerDef);
199 198
                System.out.println("sqlAlter =" + sqlAlter);
200 199
                st.execute(sqlAlter);
201 200
                // CREATE TABLE PARKS ( PARK_ID int4, PARK_NAME varchar(128),
trunk/extensions/extJDBC/src/com/iver/cit/gvsig/jdbc_spatial/util/PostGIS.java
49 49
import java.sql.Types;
50 50

  
51 51
import com.hardcode.gdbms.engine.values.Value;
52
import com.hardcode.gdbms.engine.values.ValueWriter;
53
import com.iver.cit.gvsig.fmap.core.FShape;
52 54
import com.iver.cit.gvsig.fmap.core.IFeature;
53 55
import com.iver.cit.gvsig.fmap.drivers.DBLayerDefinition;
54 56
import com.iver.cit.gvsig.fmap.drivers.FieldDescription;
55 57
import com.iver.cit.gvsig.jdbc_spatial.XTypes;
56 58

  
57 59
public class PostGIS {
58
    
59
    public static String toEncode;
60
    
61
    
62
    /**
63
     * Mover esto a IverUtiles
64
     * @param val
65
     * @return
66
     */
67
    public static boolean isNumeric(Value val)
68
    {
69
    	
70
    	switch (val.getSQLType())
71
    	{
72
    	case Types.DOUBLE:
73
    	case Types.FLOAT:
74
    	case Types.INTEGER:
75
    	case Types.SMALLINT:
76
    	case Types.BIGINT:
77
    	case Types.NUMERIC:
78
    	case Types.REAL:
79
    	case Types.TINYINT:
80
    		return true;
81
    	}
82
    	
83
    	return false;
84
    }
85
    
86
    /**
87
     * @param dbLayerDef
88
     * @param fieldTypes (see java.sql.Types)
89
     */
90
    public static String getSqlCreateSpatialTable(DBLayerDefinition dbLayerDef, FieldDescription[] fieldsDescr)
91
    {
92
        
93
        String resul;
94
        boolean bExistGID = false;
95
        for (int i=0; i < dbLayerDef.getFieldNames().length; i++)
96
        {
97
            if (dbLayerDef.getFieldNames()[i].equalsIgnoreCase("gid"))
98
            {
99
                bExistGID = true;
100
                break;
101
            }
102
        }
103
        if (bExistGID) // Usamos el existente y no a?adimos ninguno nosotros
104
            resul = "CREATE TABLE " + dbLayerDef.getTableName() + " (";
105
        else
106
            resul = "CREATE TABLE " + dbLayerDef.getTableName() + " (gid serial PRIMARY KEY, ";
107
        for (int i=0; i < dbLayerDef.getFieldNames().length; i++)
108
        {
109
            int fieldType = fieldsDescr[i].getFieldType();
110
            String strType = XTypes.fieldTypeToString(fieldType);
111
            /* if (fieldType == Types.VARCHAR)             
112
                strType = strType + "(" + fieldsDescr[i].getFieldLength() + ")"; */
113
            if (i==0)
114
                resul = resul + dbLayerDef.getFieldNames()[i] + " " + strType;
115
            else
116
                resul = resul + ", " + dbLayerDef.getFieldNames()[i] + " " + strType;
117
        }
118
        resul = resul + ");";
119
        return resul;
120
    }
121
    public static String getSqlAlterTable(DBLayerDefinition dbLayerDef, String strSRID, String geometryFieldType, int dimension)
122
    {
123
        String result = "SELECT AddGeometryColumn('" + dbLayerDef.getCatalogName() + "', '" +
124
        dbLayerDef.getTableName() + "', '" + dbLayerDef.getFieldGeometry() + "', " +
125
        strSRID + ", '" + geometryFieldType + "', " + dimension + ");";
126
        
127
        return result;
128
    }
129
    
130
    
131
    /**
132
     * From geotools
133
     * Adds quotes to an object for storage in postgis.  The object should be a
134
     * string or a number.  To perform an insert strings need quotes around
135
     * them, and numbers work fine with quotes, so this method can be called
136
     * on unknown objects.
137
     *
138
     * @param value The object to add quotes to.
139
     *
140
     * @return a string representation of the object with quotes.
141
     */
142
    protected static String addQuotes(Object value) {
143
        String retString;
144 60

  
145
        if (value != null) {
146
            retString = "'" + doubleQuote(value) + "'";
147
        } else {
148
            retString = "null";
149
        }
61
	public static String toEncode;
150 62

  
151
        return retString;
152
    }
63
	/**
64
	 * Mover esto a IverUtiles
65
	 * 
66
	 * @param val
67
	 * @return
68
	 */
69
	public static boolean isNumeric(Value val) {
153 70

  
154
    static String  doubleQuote(Object obj) {
155
        String aux = obj.toString().replaceAll("'", "''");
156
        StringBuffer strBuf = new StringBuffer(aux);
157
        ByteArrayOutputStream out = new ByteArrayOutputStream(strBuf.length());
158
        PrintStream printStream = new PrintStream(out);
159
        printStream.print(aux);
160
        String aux2 = "ERROR";
161
        try {
162
            aux2 = out.toString(toEncode);
163
            System.out.println(aux + " " + aux2);
164
        } catch (UnsupportedEncodingException e) {
165
            // TODO Auto-generated catch block
166
            e.printStackTrace();
167
        }                
71
		switch (val.getSQLType()) {
72
		case Types.DOUBLE:
73
		case Types.FLOAT:
74
		case Types.INTEGER:
75
		case Types.SMALLINT:
76
		case Types.BIGINT:
77
		case Types.NUMERIC:
78
		case Types.REAL:
79
		case Types.TINYINT:
80
			return true;
81
		}
168 82

  
169
        return aux2;
170
    }
171
    
172
    /**
173
     * Based in code from JUMP (VividSolutions) and Geotools
174
     * Things to be aware:
175
     * We always will use Spatial Tables with Unique ID.
176
     * IFeature has the same field order than dbLayerDef.getFieldNames()
177
     * @param dbLayerDef
178
     * @param feat
179
     * @return
180
     */
181
    public static String getSqlInsertFeature(DBLayerDefinition dbLayerDef, IFeature feat)
182
    {
183
        StringBuffer sqlBuf = new StringBuffer("INSERT INTO " + dbLayerDef.getTableName() + " (");
184
        String sql = null;
185
        int numAlphanumericFields = dbLayerDef.getFieldNames().length; 
186
        
187
        for (int i = 0; i < numAlphanumericFields; i++) {
188
            String name = dbLayerDef.getFieldNames()[i];
189
            // if (cols.contains(name) && (!name.equals(uniqueCol) || existsUnique)) {
190
                sqlBuf.append(" " + name + ",");
191
            // }
192
        }
193
        sqlBuf.append(" " + dbLayerDef.getFieldGeometry());
194
        // sqlBuf.deleteCharAt(sqlBuf.lastIndexOf(","));
195
        sqlBuf.append(" ) VALUES (");
196
        String insertQueryHead = sqlBuf.toString();
197
        sqlBuf = new StringBuffer(insertQueryHead);
198
        for (int j = 0; j < numAlphanumericFields; j++) {
199
        	if (isNumeric(feat.getAttribute(j)))
200
        		sqlBuf.append( feat.getAttribute(j) + ", ");
201
        	else
202
        		sqlBuf.append( addQuotes(feat.getAttribute(j)) + ", ");
203
        }
204
        sqlBuf.append(
205
                    " GeometryFromText( '"
206
                        + feat.getGeometry().toJTSGeometry().toText()
207
                        + "', "
208
                        + dbLayerDef.getSRID_EPSG()
209
                        + ")");
83
		return false;
84
	}
210 85

  
211
        // sqlBuf.deleteCharAt(sqlBuf.lastIndexOf(","));
212
        sqlBuf.append(" ) ");
213
        sql = sqlBuf.toString();
214
        return sql;
215
    }
216
    static public String getSqlCreateIndex(DBLayerDefinition lyrDef)
217
    {
218
        String indexName = lyrDef.getTableName() + 
219
                "_" + lyrDef.getFieldGeometry() + "_gist";
220
        String sql = "CREATE INDEX \"" + indexName + "\" ON \"" +
221
            lyrDef.getTableName() + "\" USING GIST (\""
222
            + lyrDef.getFieldGeometry() + "\" GIST_GEOMETRY_OPS)";
223
        
224
        return sql;
225
    }
226
    
86
	/**
87
	 * @param dbLayerDef
88
	 * @param fieldTypes
89
	 *            (see java.sql.Types)
90
	 */
91
	public static String getSqlCreateSpatialTable(DBLayerDefinition dbLayerDef,
92
			FieldDescription[] fieldsDescr) {
93

  
94
		String resul;
95
		boolean bExistGID = false;
96
		for (int i = 0; i < dbLayerDef.getFieldNames().length; i++) {
97
			if (dbLayerDef.getFieldNames()[i].equalsIgnoreCase("gid")) {
98
				bExistGID = true;
99
				break;
100
			}
101
		}
102
		if (bExistGID) // Usamos el existente y no a?adimos ninguno nosotros
103
			resul = "CREATE TABLE " + dbLayerDef.getTableName() + " (";
104
		else
105
			resul = "CREATE TABLE " + dbLayerDef.getTableName()
106
					+ " (gid serial PRIMARY KEY, ";
107
		for (int i = 0; i < dbLayerDef.getFieldNames().length; i++) {
108
			int fieldType = fieldsDescr[i].getFieldType();
109
			String strType = XTypes.fieldTypeToString(fieldType);
110
			/*
111
			 * if (fieldType == Types.VARCHAR) strType = strType + "(" +
112
			 * fieldsDescr[i].getFieldLength() + ")";
113
			 */
114
			if (i == 0)
115
				resul = resul + dbLayerDef.getFieldNames()[i] + " " + strType;
116
			else
117
				resul = resul + ", " + dbLayerDef.getFieldNames()[i] + " "
118
						+ strType;
119
		}
120
		resul = resul + ");";
121
		return resul;
122
	}
123

  
124
	public static String getSqlAlterTable(DBLayerDefinition dbLayerDef) {
125
		String strGeometryFieldType;
126
		strGeometryFieldType = "GEOMETRY";
127

  
128
		switch (dbLayerDef.getShapeType()) {
129
		case FShape.POINT:
130
			strGeometryFieldType = XTypes.fieldTypeToString(XTypes.POINT2D);
131
			break;
132
		case FShape.LINE:
133
			strGeometryFieldType = XTypes.fieldTypeToString(XTypes.LINE2D);
134
			break;
135
		case FShape.POLYGON:
136
			strGeometryFieldType = XTypes.fieldTypeToString(XTypes.POLYGON2D);
137
			break;
138
		case FShape.MULTI:
139
			strGeometryFieldType = XTypes.fieldTypeToString(XTypes.MULTI2D);
140
			break;
141
		}
142

  
143
		String result = "SELECT AddGeometryColumn('"
144
				+ dbLayerDef.getCatalogName() + "', '"
145
				+ dbLayerDef.getTableName() + "', '"
146
				+ dbLayerDef.getFieldGeometry() + "', "
147
				+ dbLayerDef.getSRID_EPSG() + ", '" + strGeometryFieldType + "', "
148
				+ dbLayerDef.getDimension() + ");";
149

  
150
		return result;
151
	}
152

  
153
	/**
154
	 * From geotools Adds quotes to an object for storage in postgis. The object
155
	 * should be a string or a number. To perform an insert strings need quotes
156
	 * around them, and numbers work fine with quotes, so this method can be
157
	 * called on unknown objects.
158
	 * 
159
	 * @param value
160
	 *            The object to add quotes to.
161
	 * 
162
	 * @return a string representation of the object with quotes.
163
	 */
164
	protected static String addQuotes(Object value) {
165
		String retString;
166

  
167
		if (value != null) {
168
			retString = "'" + doubleQuote(value) + "'";
169
		} else {
170
			retString = "null";
171
		}
172

  
173
		return retString;
174
	}
175

  
176
	static String doubleQuote(Object obj) {
177
		String aux = obj.toString().replaceAll("'", "''");
178
		StringBuffer strBuf = new StringBuffer(aux);
179
		ByteArrayOutputStream out = new ByteArrayOutputStream(strBuf.length());
180
		PrintStream printStream = new PrintStream(out);
181
		printStream.print(aux);
182
		String aux2 = "ERROR";
183
		try {
184
			aux2 = out.toString(toEncode);
185
			System.out.println(aux + " " + aux2);
186
		} catch (UnsupportedEncodingException e) {
187
			// TODO Auto-generated catch block
188
			e.printStackTrace();
189
		}
190

  
191
		return aux2;
192
	}
193

  
194
	/**
195
	 * Based in code from JUMP (VividSolutions) and Geotools Things to be aware:
196
	 * We always will use Spatial Tables with Unique ID. IFeature has the same
197
	 * field order than dbLayerDef.getFieldNames()
198
	 * 
199
	 * @param dbLayerDef
200
	 * @param feat
201
	 * @return
202
	 */
203
	public static String getSqlInsertFeature(DBLayerDefinition dbLayerDef,
204
			IFeature feat) {
205
		StringBuffer sqlBuf = new StringBuffer("INSERT INTO "
206
				+ dbLayerDef.getTableName() + " (");
207
		String sql = null;
208
		int numAlphanumericFields = dbLayerDef.getFieldNames().length;
209

  
210
		for (int i = 0; i < numAlphanumericFields; i++) {
211
			String name = dbLayerDef.getFieldNames()[i];
212
			// if (cols.contains(name) && (!name.equals(uniqueCol) ||
213
			// existsUnique)) {
214
			sqlBuf.append(" " + name + ",");
215
			// }
216
		}
217
		sqlBuf.append(" " + dbLayerDef.getFieldGeometry());
218
		// sqlBuf.deleteCharAt(sqlBuf.lastIndexOf(","));
219
		sqlBuf.append(" ) VALUES (");
220
		String insertQueryHead = sqlBuf.toString();
221
		sqlBuf = new StringBuffer(insertQueryHead);
222
		for (int j = 0; j < numAlphanumericFields; j++) {
223
			if (isNumeric(feat.getAttribute(j)))
224
				sqlBuf.append(feat.getAttribute(j) + ", ");
225
			else
226
				sqlBuf.append(addQuotes(feat.getAttribute(j)) + ", ");
227
		}
228
		sqlBuf.append(" GeometryFromText( '"
229
				+ feat.getGeometry().toJTSGeometry().toText() + "', "
230
				+ dbLayerDef.getSRID_EPSG() + ")");
231

  
232
		// sqlBuf.deleteCharAt(sqlBuf.lastIndexOf(","));
233
		sqlBuf.append(" ) ");
234
		sql = sqlBuf.toString();
235
		return sql;
236
	}
237

  
238
	static public String getSqlCreateIndex(DBLayerDefinition lyrDef) {
239
		String indexName = lyrDef.getTableName() + "_"
240
				+ lyrDef.getFieldGeometry() + "_gist";
241
		String sql = "CREATE INDEX \"" + indexName + "\" ON \""
242
				+ lyrDef.getTableName() + "\" USING GIST (\""
243
				+ lyrDef.getFieldGeometry() + "\" GIST_GEOMETRY_OPS)";
244

  
245
		return sql;
246
	}
247

  
248
	public static String getSqlModifyFeature(DBLayerDefinition dbLayerDef, IFeature feat) {
249
		/* 
250
		 	UPDATE weather
251
		 	SET temp_hi = temp_hi - 2,  temp_lo = temp_lo - 2
252
		 	WHERE date > '1994-11-28';
253
		 */
254
		StringBuffer sqlBuf = new StringBuffer("UPDATE "
255
				+ dbLayerDef.getTableName() + " SET");
256
		String sql = null;
257
		int numAlphanumericFields = dbLayerDef.getFieldsDesc().length;
258

  
259
		for (int i = 0; i < numAlphanumericFields; i++) {
260
			FieldDescription fldDesc = dbLayerDef.getFieldsDesc()[i];
261
			if (fldDesc != null)
262
			{
263
				String name = fldDesc.getFieldName();
264
				Value val = feat.getAttribute(i);
265
				if (val != null)
266
				{
267
					String strAux = val.getStringValue(ValueWriter.internalValueWriter);
268
					sqlBuf.append(" " + name + " = " + strAux + " ,");
269
				}
270
			}
271
		}
272
		sqlBuf.deleteCharAt(sqlBuf.lastIndexOf(","));
273
		if (feat.getGeometry() != null)
274
		{
275
			sqlBuf.append(", " + dbLayerDef.getFieldGeometry());		
276
			sqlBuf.append(" = ");
277
			sqlBuf.append(" GeometryFromText( '"
278
				+ feat.getGeometry().toJTSGeometry().toText() + "', "
279
				+ dbLayerDef.getSRID_EPSG() + ")");
280
		}
281
		sqlBuf.append(" WHERE ");
282
		sqlBuf.append(dbLayerDef.getFieldID() + " = " + feat.getID());
283
		sql = sqlBuf.toString();
284
		return sql;
285

  
286
	}
287

  
288
	public static String getSqlDeleteFeature(DBLayerDefinition dbLayerDef, IFeature feat) {
289
		// DELETE FROM weather WHERE city = 'Hayward';
290
		StringBuffer sqlBuf = new StringBuffer("DELETE "
291
				+ dbLayerDef.getTableName() + " WHERE ");
292
		String sql = null;
293
		sqlBuf.append(dbLayerDef.getFieldID() + " = " + feat.getID());
294
		sql = sqlBuf.toString();
295

  
296
		return sql;
297
	}
298

  
227 299
}
trunk/extensions/extCAD/src/com/iver/cit/gvsig/gui/cad/MyFinishAction.java
1 1
package com.iver.cit.gvsig.gui.cad;
2 2

  
3 3
import java.io.File;
4
import java.sql.Connection;
5
import java.sql.DriverManager;
6
import java.sql.Statement;
4 7

  
5 8
import jwizardcomponent.FinishAction;
6 9
import jwizardcomponent.JWizardComponents;
7 10

  
11
import org.cresques.cts.IProjection;
12
import org.cresques.cts.ProjectionPool;
13

  
14
import com.hardcode.driverManager.Driver;
8 15
import com.iver.cit.gvsig.CADExtension;
9 16
import com.iver.cit.gvsig.fmap.MapControl;
17
import com.iver.cit.gvsig.fmap.core.ICanReproject;
18
import com.iver.cit.gvsig.fmap.drivers.DBLayerDefinition;
10 19
import com.iver.cit.gvsig.fmap.drivers.FieldDescription;
11 20
import com.iver.cit.gvsig.fmap.drivers.ITableDefinition;
12 21
import com.iver.cit.gvsig.fmap.drivers.SHPLayerDefinition;
13 22
import com.iver.cit.gvsig.fmap.drivers.VectorialDatabaseDriver;
14 23
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver;
15
import com.iver.cit.gvsig.fmap.edition.ISpatialWriter;
24
import com.iver.cit.gvsig.fmap.drivers.VectorialJDBCDriver;
25
import com.iver.cit.gvsig.fmap.drivers.jdbc.postgis.PostGISWriter;
16 26
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter;
17 27
import com.iver.cit.gvsig.fmap.edition.writers.shp.ShpWriter;
18 28
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
......
20 30
import com.iver.cit.gvsig.gui.View;
21 31
import com.iver.cit.gvsig.gui.cad.panels.ChooseGeometryType;
22 32
import com.iver.cit.gvsig.gui.cad.panels.JPanelFieldDefinition;
33
import com.iver.cit.gvsig.gui.cad.panels.PostGISpanel;
23 34
import com.iver.cit.gvsig.gui.cad.panels.ShpPanel;
35
import com.iver.cit.gvsig.jdbc_spatial.gui.jdbcwizard.ConnectionSettings;
24 36

  
25 37
public class MyFinishAction extends FinishAction
26 38
{
......
52 64
			int geometryType = geometryTypePanel.getSelectedGeometryType();
53 65
			FieldDescription[] fieldsDesc = fieldDefinitionPanel.getFieldsDescription();
54 66
			
55
			ISpatialWriter drv = (ISpatialWriter) LayerFactory.getDM().getDriver(selectedDriver);    		
56
			
67
			Driver drv = LayerFactory.getDM().getDriver(selectedDriver);    		
68
			mapCtrl.getMapContext().beginAtomicEvent();
57 69
			if (actionComand.equals("SHP"))
58 70
			{
59 71
	    		ShpPanel shpPanel = (ShpPanel) myWizardComponents.getWizardPanel(2);
......
69 81
    			writer.preProcess();
70 82
    			writer.postProcess();
71 83
	    		
72
				mapCtrl.getMapContext().beginAtomicEvent();
84
				
73 85
                lyr = (FLyrVect) LayerFactory.createLayer(layerName,
74 86
                        (VectorialFileDriver) drv, newFile, mapCtrl.getProjection());
75 87
                                
76 88
			}
77
			else if (drv instanceof VectorialDatabaseDriver)
89
			else if (drv instanceof VectorialJDBCDriver)
78 90
			{
79
				// ConnectionPanel connectionPanel = (ConnectionPanel) myWizardComponents.getWizardPanel(3);
80
				/* ConnectionSettings cs = dlg.getConnSettings();
91
				VectorialJDBCDriver dbDriver = (VectorialJDBCDriver) drv;
92
	    		PostGISpanel postgisPanel = (PostGISpanel) myWizardComponents.getWizardPanel(2);
93
				ConnectionSettings cs = postgisPanel.getConnSettings();
81 94
				if (cs == null)
82 95
					return;
83
				conex = DriverManager.getConnection(cs.getConnectionString(),
96
				Connection conex = DriverManager.getConnection(cs.getConnectionString(),
84 97
						cs.getUser(), cs.getPassw());
85 98

  
86
				st = conex.createStatement();
99
				Statement st = conex.createStatement();
87 100

  
101
				DBLayerDefinition dbLayerDef = new DBLayerDefinition();
88 102
				dbLayerDef.setCatalogName(cs.getDb());
89
				dbLayerDef.setTableName(tableName);
90
				String strGeometryFieldType = "GEOMETRY";
91

  
92
				switch (lyrVect.getShapeType()) {
93
				case FShape.POINT:
94
					strGeometryFieldType = XTypes
95
							.fieldTypeToString(XTypes.POINT2D);
96
					break;
97
				case FShape.LINE:
98
					strGeometryFieldType = XTypes
99
							.fieldTypeToString(XTypes.LINE2D);
100
					break;
101
				case FShape.POLYGON:
102
					strGeometryFieldType = XTypes
103
							.fieldTypeToString(XTypes.POLYGON2D);
104
					break;
105
				case FShape.MULTI:
106
					strGeometryFieldType = XTypes
107
							.fieldTypeToString(XTypes.MULTI2D);
108
					break;
109
				}
110

  
103
				dbLayerDef.setTableName(layerName);
104
				dbLayerDef.setShapeType(geometryType);
111 105
				dbLayerDef.setFieldGeometry("the_geom");
112
				FieldDescription[] fieldsDescrip = new FieldDescription[rsSel
113
						.getFieldNames().length];
114
				dbLayerDef.setFieldNames(rsSel.getFieldNames());
115
				for (int i = 0; i < rsSel.getFieldNames().length; i++) {
116
					fieldsDescrip[i] = new FieldDescription();
117
					fieldsDescrip[i].setFieldType(rsSel.getFieldType(i));
118
					fieldsDescrip[i].setFieldName(rsSel.getFieldName(i));
119
					// TODO: Por ahora le ponemos 200, a falta
120
					// de recompilar GDBMS con la posibilidad
121
					// de obtener el ancho de un campo.
122
					fieldsDescrip[i].setFieldLength(200);
123
					/*
124
					 * if (fieldsDescrip[i].getFieldName().equals("gid")) { int
125
					 * resp = JOptionPane.showConfirmDialog(null,
126
					 * PluginServices.getText(this, "confirm_gid"), "Field GID",
127
					 * JOptionPane.YES_NO_OPTION); if (resp ==
128
					 * JOptionPane.NO_OPTION) return; else { // Quitamos el GID
129
					 * original, y lo sustituiremos por el nuestro } }
130
					 
131
				}
132
				String strSRID = lyrVect.getProjection().getAbrev()
106
				dbLayerDef.setFieldsDesc(fieldsDesc);
107
				String strSRID = mapCtrl.getProjection().getAbrev()
133 108
						.substring(5);
134
				dbLayerDef.setSRID_EPSG(strSRID); */
109
				dbLayerDef.setSRID_EPSG(strSRID); 
110

  
111
    			PostGISWriter writer= (PostGISWriter)LayerFactory.getWM().getWriter("PostGIS Writer");
112
    			writer.setWriteAll(true);
113
    			writer.setCreateTable(true);
114
    			writer.initialize(dbLayerDef);
115

  
116
    			writer.preProcess();
117
    			writer.postProcess();
118
	    		
119
    	        if (dbDriver instanceof ICanReproject)
120
    	        {                    
121
    	            ((ICanReproject)dbDriver).setDestProjection(strSRID);
122
    	        }
123
    	        dbDriver.setData(conex, dbLayerDef);
124
    	        IProjection proj = null; 
125
    	        if (drv instanceof ICanReproject)
126
    	        {                                        
127
    	            proj = ProjectionPool.get("EPSG:" + ((ICanReproject)dbDriver).getSourceProjection()); 
128
    	        }
135 129
				
130
    			lyr = (FLyrVect) LayerFactory.createDBLayer(dbDriver, layerName, proj);
131
				
136 132
			}
137 133
			else // Si no es ni lo uno ni lo otro, 
138 134
			{
trunk/extensions/extCAD/src/com/iver/cit/gvsig/gui/cad/panels/PostGISpanel.java
1
package com.iver.cit.gvsig.gui.cad.panels;
2

  
3
import jwizardcomponent.JWizardComponents;
4
import jwizardcomponent.JWizardPanel;
5
import javax.swing.JPanel;
6

  
7
import com.iver.cit.gvsig.jdbc_spatial.gui.jdbcwizard.ConnectionPanel;
8
import com.iver.cit.gvsig.jdbc_spatial.gui.jdbcwizard.ConnectionSettings;
9

  
10
public class PostGISpanel extends JWizardPanel {
11

  
12
	public PostGISpanel(JWizardComponents wizardComponents) {
13
		super(wizardComponents);
14
		initialize();
15

  
16
	}
17
	
18
	/**
19
	 * 
20
	 */
21
	private static final long serialVersionUID = 1L;
22
	private ConnectionPanel jPanelConex = null;
23

  
24
	/**
25
	 * This method initializes this
26
	 * 
27
	 */
28
	private void initialize() {
29
        this.setSize(new java.awt.Dimension(408,284));
30
        this.add(getJPanelConex(), null);
31
			
32
	}
33

  
34
	/**
35
	 * This method initializes jPanelConex	
36
	 * 	
37
	 * @return javax.swing.JPanel	
38
	 */
39
	private ConnectionPanel getJPanelConex() {
40
		if (jPanelConex == null) {
41
			jPanelConex = new ConnectionPanel();
42
			jPanelConex.setPreferredSize(new java.awt.Dimension(400,300));
43
		}
44
		return jPanelConex;
45
	}
46

  
47
	public ConnectionSettings getConnSettings() {
48
		return getJPanelConex().getConnectionSettings();
49
	}
50

  
51
}  //  @jve:decl-index=0:visual-constraint="10,10"
0 52

  
trunk/extensions/extCAD/src/com/iver/cit/gvsig/NewTheme.java
23 23
import com.iver.cit.gvsig.gui.cad.WizardAndami;
24 24
import com.iver.cit.gvsig.gui.cad.panels.ChooseGeometryType;
25 25
import com.iver.cit.gvsig.gui.cad.panels.JPanelFieldDefinition;
26
import com.iver.cit.gvsig.gui.cad.panels.PostGISpanel;
26 27
import com.iver.cit.gvsig.gui.cad.panels.ShpPanel;
27 28

  
28 29
/**
......
97 98
			}
98 99
			if (actionCommand.equals("POSTGIS"))
99 100
			{
101
				panelChoose.setDriver((ISpatialWriter) writerManager.getDriver("PostGIS JDBC Driver"));
100 102
				wizard.getWizardComponents().addWizardPanel(
101
					new SimpleLabelWizardPanel(wizard
102
							.getWizardComponents(), new JLabel("Done!")));
103
					new PostGISpanel(wizard.getWizardComponents()));
104
				
105
				wizard.getWizardComponents().setFinishAction(
106
						new MyFinishAction(wizard.getWizardComponents(),
107
								vista, actionCommand));
103 108
			}			
104 109
			
105 110
			wizard.getViewInfo().setWidth(540);

Also available in: Unified diff