root / branches / v2_0_0_prep / extensions / extOracleSpatial / src / es / prodevelop / cit / gvsig / jdbc_spatial / NewOracleSpatialTableFinishAction.java @ 29395
History | View | Annotate | Download (5.12 KB)
1 |
package es.prodevelop.cit.gvsig.jdbc_spatial; |
---|---|
2 |
|
3 |
import java.awt.geom.Rectangle2D; |
4 |
import java.sql.Types; |
5 |
import java.util.ArrayList; |
6 |
|
7 |
import jwizardcomponent.FinishAction; |
8 |
import jwizardcomponent.JWizardComponents; |
9 |
|
10 |
import org.apache.log4j.Logger; |
11 |
|
12 |
import com.hardcode.driverManager.Driver; |
13 |
import com.iver.andami.PluginServices; |
14 |
import com.iver.andami.ui.mdiManager.IWindow; |
15 |
import com.iver.cit.gvsig.fmap.MapContext; |
16 |
import com.iver.cit.gvsig.fmap.ViewPort; |
17 |
import com.iver.cit.gvsig.fmap.core.ICanReproject; |
18 |
import com.iver.cit.gvsig.fmap.crs.CRSFactory; |
19 |
import com.iver.cit.gvsig.fmap.drivers.DBLayerDefinition; |
20 |
import com.iver.cit.gvsig.fmap.drivers.FieldDescription; |
21 |
import com.iver.cit.gvsig.fmap.drivers.IConnection; |
22 |
import com.iver.cit.gvsig.fmap.drivers.db.utils.ConnectionWithParams; |
23 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
24 |
import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
25 |
|
26 |
import es.prodevelop.cit.gvsig.fmap.drivers.jdbc.oracle.OracleSpatialDriver; |
27 |
import es.prodevelop.cit.gvsig.fmap.drivers.jdbc.oracle.OracleSpatialWriter; |
28 |
import es.prodevelop.cit.gvsig.jdbc_spatial.gui.jdbcwizard.NewOracleSpatialTableWizard; |
29 |
import es.prodevelop.cit.gvsig.jdbc_spatial.gui.jdbcwizard.RepeatedChooseGeometryTypePanel; |
30 |
import es.prodevelop.cit.gvsig.jdbc_spatial.gui.jdbcwizard.RepeatedFieldDefinitionPanel; |
31 |
|
32 |
public class NewOracleSpatialTableFinishAction extends FinishAction { |
33 |
|
34 |
private static Logger logger = Logger.getLogger(NewOracleSpatialTableFinishAction.class.getName()); |
35 |
private NewOracleSpatialTableWizard connectionPanel;
|
36 |
private RepeatedChooseGeometryTypePanel geoTypePanel;
|
37 |
private RepeatedFieldDefinitionPanel fieldsPanel;
|
38 |
private MapContext theMapContext;
|
39 |
private IWindow closeThis;
|
40 |
|
41 |
|
42 |
// ...
|
43 |
|
44 |
public NewOracleSpatialTableFinishAction(
|
45 |
JWizardComponents wc, |
46 |
IWindow closeit, |
47 |
NewOracleSpatialTableWizard connPanel, |
48 |
MapContext mc) { |
49 |
|
50 |
super(wc);
|
51 |
theMapContext = mc; |
52 |
closeThis = closeit; |
53 |
connectionPanel = connPanel; |
54 |
geoTypePanel = (RepeatedChooseGeometryTypePanel) wc.getWizardPanel(0);
|
55 |
fieldsPanel = (RepeatedFieldDefinitionPanel) wc.getWizardPanel(1);
|
56 |
} |
57 |
|
58 |
public void performAction() { |
59 |
|
60 |
PluginServices.getMDIManager().closeWindow(closeThis); |
61 |
|
62 |
ViewPort vp = theMapContext.getViewPort(); |
63 |
|
64 |
DBLayerDefinition lyr_def = new DBLayerDefinition();
|
65 |
|
66 |
FieldDescription[] flds = fieldsPanel.getFieldsDescription();
|
67 |
FieldDescription[] flds_new = getValidFields(flds);
|
68 |
|
69 |
lyr_def.setFieldsDesc(flds_new); |
70 |
|
71 |
String table_name = geoTypePanel.getLayerName().toUpperCase();
|
72 |
lyr_def.setTableName(table_name); |
73 |
String usr = connectionPanel.getConnectionWithParams().getUser();
|
74 |
lyr_def.setUser(usr.toUpperCase()); |
75 |
String epsg_code = vp.getProjection().getAbrev();
|
76 |
lyr_def.setSRID_EPSG(epsg_code.substring(5));
|
77 |
|
78 |
lyr_def.setFieldID(OracleSpatialDriver.ORACLE_ID_FIELD); |
79 |
lyr_def.setFieldGeometry(OracleSpatialDriver.DEFAULT_GEO_FIELD); |
80 |
lyr_def.setWhereClause("");
|
81 |
|
82 |
Rectangle2D extent = vp.getAdjustedExtent();
|
83 |
if (extent == null) { |
84 |
int h = vp.getImageHeight();
|
85 |
int w = vp.getImageWidth();
|
86 |
extent = new Rectangle2D.Double(0, 0, w, h); |
87 |
} |
88 |
IConnection iconn = connectionPanel.getConnectionWithParams().getConnection(); |
89 |
|
90 |
// --------------------------------------------------------------------
|
91 |
// -------------------------------------------------------------------
|
92 |
// --------------------------------------------------------------------
|
93 |
theMapContext.beginAtomicEvent(); |
94 |
|
95 |
OracleSpatialWriter.createEmptyTable(lyr_def, iconn, extent); |
96 |
OracleSpatialDriver oracleDrv = new OracleSpatialDriver();
|
97 |
oracleDrv.setData(iconn, lyr_def); |
98 |
FLyrVect lyr = (FLyrVect) LayerFactory.createDBLayer( |
99 |
oracleDrv, |
100 |
table_name, |
101 |
vp.getProjection()); |
102 |
|
103 |
lyr.setVisible(true);
|
104 |
theMapContext.getLayers().addLayer(lyr); |
105 |
theMapContext.endAtomicEvent(); |
106 |
// --------------------------------------------------------------------
|
107 |
// --------------------------------------------------------------------
|
108 |
// --------------------------------------------------------------------
|
109 |
|
110 |
} |
111 |
|
112 |
private boolean validFieldName(FieldDescription f_desc) { |
113 |
|
114 |
if ((f_desc.getFieldName().compareToIgnoreCase(OracleSpatialDriver.DEFAULT_ID_FIELD_CASE_SENSITIVE) == 0) |
115 |
|| (f_desc.getFieldName().compareToIgnoreCase(OracleSpatialDriver.ORACLE_ID_FIELD) == 0)) {
|
116 |
return false; |
117 |
} |
118 |
return true; |
119 |
} |
120 |
|
121 |
private FieldDescription[] getValidFields(FieldDescription[] ff) { |
122 |
|
123 |
// remove GID, ROWID
|
124 |
ArrayList aux = new ArrayList(); |
125 |
|
126 |
// rowid
|
127 |
FieldDescription row_fld = new FieldDescription();
|
128 |
row_fld.setFieldName(OracleSpatialDriver.ORACLE_ID_FIELD); |
129 |
row_fld.setFieldType(Types.VARCHAR);
|
130 |
aux.add(row_fld); |
131 |
|
132 |
|
133 |
for (int i=0; i<ff.length; i++) { |
134 |
if (validFieldName(ff[i])) {
|
135 |
aux.add(ff[i]); |
136 |
} |
137 |
} |
138 |
|
139 |
|
140 |
// gid
|
141 |
FieldDescription gid_fld = new FieldDescription();
|
142 |
gid_fld.setFieldName(OracleSpatialDriver.DEFAULT_ID_FIELD_CASE_SENSITIVE); |
143 |
gid_fld.setFieldType(Types.INTEGER);
|
144 |
aux.add(gid_fld); |
145 |
|
146 |
return (FieldDescription[]) aux.toArray(new FieldDescription[0]); |
147 |
// -------
|
148 |
} |
149 |
|
150 |
} |