Revision 4740 trunk/extensions/extCAD/src/com/iver/cit/gvsig/gui/cad/MyFinishAction.java
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 |
{ |
Also available in: Unified diff