svn-gvsig-desktop / tags / v1_0_2_RELEASE / extensions / extJDBC / src / com / iver / cit / gvsig / jdbc_spatial / gui / jdbcwizard / WizardJDBC.java @ 11432
History | View | Annotate | Download (14.7 KB)
1 | 2269 | fjp | package com.iver.cit.gvsig.jdbc_spatial.gui.jdbcwizard; |
---|---|---|---|
2 | |||
3 | import java.awt.BorderLayout; |
||
4 | 10271 | jmvivo | import java.awt.CardLayout; |
5 | import java.awt.FlowLayout; |
||
6 | 2269 | fjp | import java.sql.Connection; |
7 | 10271 | jmvivo | import java.sql.DatabaseMetaData; |
8 | import java.sql.DriverManager; |
||
9 | import java.sql.ResultSet; |
||
10 | import java.sql.ResultSetMetaData; |
||
11 | 2269 | fjp | import java.sql.SQLException; |
12 | 10271 | jmvivo | import java.sql.Statement; |
13 | 2269 | fjp | import java.util.ArrayList; |
14 | 10271 | jmvivo | import java.util.HashMap; |
15 | import java.util.TreeMap; |
||
16 | 2269 | fjp | |
17 | import javax.swing.JOptionPane; |
||
18 | import javax.swing.JPanel; |
||
19 | |||
20 | 3095 | fjp | import org.cresques.cts.IProjection; |
21 | 6703 | jmvivo | import org.gvsig.gui.beans.swing.JButton; |
22 | 3095 | fjp | |
23 | 2269 | fjp | import com.hardcode.driverManager.DriverLoadException; |
24 | import com.iver.andami.PluginServices; |
||
25 | import com.iver.andami.messages.NotificationManager; |
||
26 | 3095 | fjp | import com.iver.cit.gvsig.fmap.core.ICanReproject; |
27 | 7703 | luisw2 | import com.iver.cit.gvsig.fmap.crs.CRSFactory; |
28 | 3251 | fjp | import com.iver.cit.gvsig.fmap.drivers.DBLayerDefinition; |
29 | 2269 | fjp | import com.iver.cit.gvsig.fmap.drivers.VectorialJDBCDriver; |
30 | import com.iver.cit.gvsig.fmap.layers.FLayer; |
||
31 | import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
||
32 | import com.iver.cit.gvsig.gui.WizardPanel; |
||
33 | 10271 | jmvivo | import com.iver.utiles.NotExistInXMLEntity; |
34 | import com.iver.utiles.XMLEntity; |
||
35 | 2269 | fjp | /**
|
36 | 10271 | jmvivo | * @author Fernando Gonz?lez Cort?s
|
37 | 2269 | fjp | */
|
38 | 10271 | jmvivo | public class WizardJDBC extends WizardPanel{ |
39 | 2269 | fjp | |
40 | 10271 | jmvivo | private JPanel pnlWizard = null; |
41 | private JPanel jPanel1 = null; |
||
42 | private JButton btnBack = null; |
||
43 | private JButton btnNext = null; |
||
44 | private ConnectionPanel connectionPanel = null; |
||
45 | private DBLayerDefinitionPanel dbLayerDefinition = null; |
||
46 | private FieldSelection fieldSelection = null; |
||
47 | 8765 | jjdelcerro | |
48 | 10271 | jmvivo | private int step = 0; |
49 | private final int nsteps = 5; |
||
50 | private static final String CONNECTION = "conn"; |
||
51 | private static final String LAYER_DEFINITION = "layerdef"; |
||
52 | private static final String FIELD_SELECTION= "fieldsel"; |
||
53 | private VectorialJDBCDriver driver;
|
||
54 | 8765 | jjdelcerro | |
55 | 10271 | jmvivo | private GeomFieldSelection geomFieldSelection = null; |
56 | private UniqueFieldSelection uniqueFieldSelection = null; |
||
57 | |||
58 | private DatabaseMetaData dbmd = null; |
||
59 | private String catalog = null; |
||
60 | private String selectTable = null; |
||
61 | private String[] theTables = null; |
||
62 | private Connection conex = null; |
||
63 | |||
64 | private HashMap settings = new HashMap(); |
||
65 | /**
|
||
66 | * This is the default constructor
|
||
67 | */
|
||
68 | 2269 | fjp | public WizardJDBC() {
|
69 | super();
|
||
70 | initialize(); |
||
71 | } |
||
72 | /**
|
||
73 | * This method initializes this
|
||
74 | 10271 | jmvivo | *
|
75 | 2269 | fjp | * @return void
|
76 | */
|
||
77 | private void initialize() { |
||
78 | 10271 | jmvivo | setTabName("JDBC");
|
79 | this.setLayout(new BorderLayout()); |
||
80 | this.setSize(300, 270); |
||
81 | this.add(getPnlWizard(), java.awt.BorderLayout.CENTER);
|
||
82 | this.add(getJPanel1(), java.awt.BorderLayout.SOUTH);
|
||
83 | connectionPanel.setDrivers(getDriverNames()); |
||
84 | enableButtons(); |
||
85 | 2269 | fjp | |
86 | 8765 | jjdelcerro | |
87 | 10271 | jmvivo | XMLEntity xml = PluginServices.getPluginServices(this)
|
88 | .getPersistentXML(); |
||
89 | 2269 | fjp | |
90 | 10271 | jmvivo | if (xml == null) { |
91 | xml = new XMLEntity();
|
||
92 | } |
||
93 | 2269 | fjp | |
94 | 10271 | jmvivo | if (!xml.contains("jdbc-connections")) { |
95 | String[] servers = new String[0]; |
||
96 | xml.putProperty("jdbc-connections", servers);
|
||
97 | } |
||
98 | |||
99 | try {
|
||
100 | String[] servers = xml.getStringArrayProperty("jdbc-connections"); |
||
101 | |||
102 | for (int i = 0; i < servers.length; i++) { |
||
103 | ConnectionSettings cs = new ConnectionSettings();
|
||
104 | cs.setFromString(servers[i]); |
||
105 | settings.put(cs.getName(), cs); |
||
106 | } |
||
107 | getConnectionPanel().setSettings(settings); |
||
108 | } catch (NotExistInXMLEntity e) {
|
||
109 | } |
||
110 | |||
111 | 2269 | fjp | } |
112 | 8765 | jjdelcerro | |
113 | 10271 | jmvivo | private String[] getDriverNames(){ |
114 | 2269 | fjp | Class[] classes = new Class[] { VectorialJDBCDriver.class }; |
115 | |||
116 | ArrayList ret = new ArrayList(); |
||
117 | String[] driverNames = LayerFactory.getDM().getDriverNames(); |
||
118 | |||
119 | for (int i = 0; i < driverNames.length; i++) { |
||
120 | boolean is = false; |
||
121 | |||
122 | for (int j = 0; j < classes.length; j++) { |
||
123 | if (LayerFactory.getDM().isA(driverNames[i], classes[j])) {
|
||
124 | ret.add(driverNames[i]); |
||
125 | } |
||
126 | } |
||
127 | } |
||
128 | |||
129 | return (String[]) ret.toArray(new String[0]); |
||
130 | 8765 | jjdelcerro | |
131 | 2269 | fjp | } |
132 | 8765 | jjdelcerro | |
133 | 10271 | jmvivo | private void enableButtons(){ |
134 | getBtnBack().setEnabled(step > 0);
|
||
135 | getBtnNext().setEnabled(step < nsteps - 1);
|
||
136 | 2269 | fjp | } |
137 | 8765 | jjdelcerro | |
138 | 2269 | fjp | /**
|
139 | 10271 | jmvivo | * This method initializes pnlWizard
|
140 | *
|
||
141 | * @return javax.swing.JPanel
|
||
142 | 8765 | jjdelcerro | */
|
143 | 10271 | jmvivo | private JPanel getPnlWizard() { |
144 | if (pnlWizard == null) { |
||
145 | pnlWizard = new JPanel(); |
||
146 | pnlWizard.setLayout(new CardLayout()); |
||
147 | pnlWizard.add(getConnectionPanel(), CONNECTION); |
||
148 | pnlWizard.add(getDbLayerDefinition(), LAYER_DEFINITION); |
||
149 | pnlWizard.add(getFieldSelection(), FIELD_SELECTION); |
||
150 | pnlWizard.add(getGeomFieldSelection(), getGeomFieldSelection().getName()); |
||
151 | pnlWizard.add(getUniqueFieldSelection(), getUniqueFieldSelection().getName()); |
||
152 | 2269 | fjp | } |
153 | 10271 | jmvivo | return pnlWizard;
|
154 | 2269 | fjp | } |
155 | /**
|
||
156 | 10271 | jmvivo | * This method initializes jPanel1
|
157 | *
|
||
158 | * @return javax.swing.JPanel
|
||
159 | 8765 | jjdelcerro | */
|
160 | 10271 | jmvivo | private JPanel getJPanel1() { |
161 | if (jPanel1 == null) { |
||
162 | FlowLayout flowLayout1 = new FlowLayout(FlowLayout.RIGHT); |
||
163 | jPanel1 = new JPanel(); |
||
164 | jPanel1.setLayout(flowLayout1); |
||
165 | jPanel1.setPreferredSize(new java.awt.Dimension(10,30)); |
||
166 | flowLayout1.setHgap(5);
|
||
167 | flowLayout1.setVgap(4);
|
||
168 | jPanel1.add(getBtnBack(), null);
|
||
169 | jPanel1.add(getBtnNext(), null);
|
||
170 | 2269 | fjp | } |
171 | 10271 | jmvivo | return jPanel1;
|
172 | 2269 | fjp | } |
173 | /**
|
||
174 | 10271 | jmvivo | * This method initializes btnBack
|
175 | *
|
||
176 | * @return javax.swing.JButton
|
||
177 | 8765 | jjdelcerro | */
|
178 | 10271 | jmvivo | private JButton getBtnBack() { |
179 | if (btnBack == null) { |
||
180 | btnBack = new JButton(); |
||
181 | btnBack.setText(PluginServices.getText(this, "back")); |
||
182 | //btnBack.setPreferredSize(new java.awt.Dimension(93,18));
|
||
183 | btnBack.addActionListener(new java.awt.event.ActionListener() {
|
||
184 | public void actionPerformed(java.awt.event.ActionEvent e) { |
||
185 | step--; |
||
186 | enableButtons(); |
||
187 | ((CardLayout)pnlWizard.getLayout()).previous(pnlWizard);
|
||
188 | } |
||
189 | }); |
||
190 | 2269 | fjp | } |
191 | 10271 | jmvivo | return btnBack;
|
192 | 2269 | fjp | } |
193 | /**
|
||
194 | 10271 | jmvivo | * This method initializes btnNext
|
195 | *
|
||
196 | * @return javax.swing.JButton
|
||
197 | 8765 | jjdelcerro | */
|
198 | 10271 | jmvivo | private JButton getBtnNext() { |
199 | if (btnNext == null) { |
||
200 | btnNext = new JButton(); |
||
201 | btnNext.setText(PluginServices.getText(this, "next")); |
||
202 | //btnNext.setPreferredSize(new java.awt.Dimension(93,18));
|
||
203 | btnNext.addActionListener(new java.awt.event.ActionListener() {
|
||
204 | public void actionPerformed(java.awt.event.ActionEvent e) { |
||
205 | boolean done = false; |
||
206 | if (step == 0) done = connectionPanel.done(); |
||
207 | else if (step == 1) done = dbLayerDefinition.done(); |
||
208 | else if (step == 2) done = fieldSelection.done(); |
||
209 | else if (step == 3) done = geomFieldSelection.done(); |
||
210 | if (done){
|
||
211 | try {
|
||
212 | if (step == 0){ |
||
213 | catalog = connectionPanel.getDBName(); |
||
214 | theTables = getTableNames(); |
||
215 | dbLayerDefinition.setTables(theTables); |
||
216 | saveConnection(); |
||
217 | } |
||
218 | else if (step == 1) { |
||
219 | fieldSelection.setFields(getTableFields()); |
||
220 | }else if (step == 2) { |
||
221 | geomFieldSelection.setFields(getTableFields()); |
||
222 | }else if (step == 3) { |
||
223 | uniqueFieldSelection.setFields(getTableFields()); |
||
224 | } |
||
225 | step++; |
||
226 | enableButtons(); |
||
227 | ((CardLayout)pnlWizard.getLayout()).next(pnlWizard);
|
||
228 | } catch (SQLException e1) { |
||
229 | NotificationManager.addError(PluginServices.getText(this,"error_conexion"), e1); |
||
230 | } catch (DriverLoadException e1) {
|
||
231 | NotificationManager.addError("No se pudo cargar el driver", e1);
|
||
232 | } |
||
233 | }else{
|
||
234 | JOptionPane.showMessageDialog(WizardJDBC.this, "No estan todos los datos rellenos", "Error", JOptionPane.ERROR_MESSAGE); |
||
235 | 8765 | jjdelcerro | |
236 | 10271 | jmvivo | } |
237 | 2269 | fjp | } |
238 | 10271 | jmvivo | }); |
239 | 2269 | fjp | } |
240 | 10271 | jmvivo | return btnNext;
|
241 | 2269 | fjp | } |
242 | |||
243 | 10271 | jmvivo | private void saveConnection() { |
244 | connectionPanel.saveConnectionSettings(); |
||
245 | 2269 | fjp | |
246 | 10271 | jmvivo | // settings.put(connectionPanel.getSettingsName(), cs);
|
247 | |||
248 | |||
249 | } |
||
250 | |||
251 | private String[] getTableNames() throws SQLException, DriverLoadException { |
||
252 | conex = DriverManager.getConnection(getConnectionString(), connectionPanel.getUser(),
|
||
253 | connectionPanel.getPassword()); |
||
254 | |||
255 | dbmd = conex.getMetaData(); |
||
256 | String[] types = {"TABLE", "VIEW"}; |
||
257 | ResultSet rs = dbmd.getTables(catalog, null, null, types); |
||
258 | TreeMap ret = new TreeMap(); |
||
259 | while (rs.next()){
|
||
260 | ret.put(rs.getString("TABLE_NAME"), rs.getString("TABLE_NAME")); |
||
261 | 2269 | fjp | } |
262 | 10271 | jmvivo | |
263 | return (String[]) ret.keySet().toArray(new String[0]); |
||
264 | 2269 | fjp | } |
265 | 10271 | jmvivo | |
266 | private String[] getTableFields() throws SQLException, DriverLoadException{ |
||
267 | Statement st = conex.createStatement();
|
||
268 | // ResultSet rs = dbmd.getTables(catalog, null, dbLayerDefinition.getTable(), null);
|
||
269 | ResultSet rs = st.executeQuery("select * from " + dbLayerDefinition.getTable() + " LIMIT 1"); |
||
270 | ResultSetMetaData rsmd = rs.getMetaData();
|
||
271 | |||
272 | String[] ret = new String[rsmd.getColumnCount()]; |
||
273 | |||
274 | for (int i = 0; i < ret.length; i++) { |
||
275 | ret[i] = rsmd.getColumnName(i+1);
|
||
276 | 2269 | fjp | } |
277 | 10271 | jmvivo | |
278 | return ret;
|
||
279 | 2269 | fjp | } |
280 | 8765 | jjdelcerro | |
281 | 10271 | jmvivo | /**
|
282 | * This method initializes connectionPanel
|
||
283 | *
|
||
284 | * @return com.iver.cit.gvsig.gui.Panels.ConnectionPanel
|
||
285 | */
|
||
286 | private ConnectionPanel getConnectionPanel() {
|
||
287 | if (connectionPanel == null) { |
||
288 | connectionPanel = new ConnectionPanel();
|
||
289 | connectionPanel.setName("connectionPanel");
|
||
290 | connectionPanel.setDrivers(getDriverNames()); |
||
291 | 2269 | fjp | } |
292 | 10271 | jmvivo | return connectionPanel;
|
293 | 2269 | fjp | } |
294 | 10271 | jmvivo | /**
|
295 | * This method initializes dbLayerDefinition
|
||
296 | *
|
||
297 | * @return com.iver.cit.gvsig.gui.Panels.dbLayerDefinition
|
||
298 | */
|
||
299 | private DBLayerDefinitionPanel getDbLayerDefinition() {
|
||
300 | if (dbLayerDefinition == null) { |
||
301 | dbLayerDefinition = new DBLayerDefinitionPanel();
|
||
302 | dbLayerDefinition.setName("dbLayerDefinition");
|
||
303 | 2269 | fjp | } |
304 | 10271 | jmvivo | return dbLayerDefinition;
|
305 | 2269 | fjp | } |
306 | /**
|
||
307 | 10271 | jmvivo | * This method initializes fieldSelection
|
308 | *
|
||
309 | * @return com.iver.cit.gvsig.gui.Panels.FieldSelection
|
||
310 | 8765 | jjdelcerro | */
|
311 | 10271 | jmvivo | private FieldSelection getFieldSelection() {
|
312 | if (fieldSelection == null) { |
||
313 | fieldSelection = new FieldSelection();
|
||
314 | fieldSelection.setName("fieldSelection");
|
||
315 | 2269 | fjp | } |
316 | 10271 | jmvivo | return fieldSelection;
|
317 | 2269 | fjp | } |
318 | 8765 | jjdelcerro | |
319 | 10271 | jmvivo | public VectorialJDBCDriver getDriver() throws DriverLoadException{ |
320 | if (driver == null){ |
||
321 | driver = (VectorialJDBCDriver) LayerFactory.getDM().getDriver(connectionPanel.getDriver()); |
||
322 | } |
||
323 | 8765 | jjdelcerro | |
324 | 10271 | jmvivo | return driver;
|
325 | } |
||
326 | 8765 | jjdelcerro | |
327 | 10271 | jmvivo | public String getConnectionString() throws DriverLoadException{ |
328 | String connectionString = getDriver().getConnectionStringBeginning() + "//" + connectionPanel.getHost(); |
||
329 | |||
330 | if (connectionPanel.getPort().trim().length() > 0) { |
||
331 | connectionString += (":" + connectionPanel.getPort());
|
||
332 | 2269 | fjp | } else {
|
333 | 10271 | jmvivo | connectionString += (":" + driver.getDefaultPort());
|
334 | 2269 | fjp | } |
335 | |||
336 | 10271 | jmvivo | connectionString += ("/" + connectionPanel.getDBName());
|
337 | |||
338 | return connectionString;
|
||
339 | 2269 | fjp | } |
340 | 8765 | jjdelcerro | |
341 | 10271 | jmvivo | public String getLayerName(){ |
342 | return dbLayerDefinition.getLayerName();
|
||
343 | 2269 | fjp | } |
344 | 8765 | jjdelcerro | |
345 | 10271 | jmvivo | /**
|
346 | * @return ONLY alphanumeric fields. You need to retrieve
|
||
347 | * the geometry fields with getGeometryField();
|
||
348 | * @throws DriverLoadException
|
||
349 | */
|
||
350 | public String[] getFields() throws DriverLoadException{ |
||
351 | String[] fields = fieldSelection.getFields(); |
||
352 | String geomField = geomFieldSelection.getField();
|
||
353 | String[] onlyAlphanumericFields = new String[fields.length-1]; |
||
354 | int newIndex = 0; |
||
355 | for (int i = 0; i < fields.length; i++) { |
||
356 | if (!fields[i].equals(geomField))
|
||
357 | { |
||
358 | onlyAlphanumericFields[newIndex] = fields[i]; |
||
359 | newIndex++; |
||
360 | } |
||
361 | 8765 | jjdelcerro | } |
362 | 10271 | jmvivo | return onlyAlphanumericFields;
|
363 | } |
||
364 | 8765 | jjdelcerro | |
365 | 10271 | jmvivo | /**
|
366 | * @return WhereClause (doesn't check if correct)
|
||
367 | */
|
||
368 | public String getWhereClause() |
||
369 | { |
||
370 | return dbLayerDefinition.getWhereClause();
|
||
371 | 6788 | fjp | } |
372 | 10271 | jmvivo | /**
|
373 | * @return
|
||
374 | */
|
||
375 | public String getUser() { |
||
376 | return connectionPanel.getUser();
|
||
377 | 2269 | fjp | } |
378 | 10271 | jmvivo | /**
|
379 | * @return
|
||
380 | */
|
||
381 | public String getPassword() { |
||
382 | return connectionPanel.getPassword();
|
||
383 | } |
||
384 | /**
|
||
385 | * @return
|
||
386 | */
|
||
387 | public String getTable() { |
||
388 | return dbLayerDefinition.getTable();
|
||
389 | } |
||
390 | |||
391 | /**
|
||
392 | * @return Field ID (Unique Value Field we want to use has key)
|
||
393 | */
|
||
394 | public String getFID() { |
||
395 | return uniqueFieldSelection.getField();
|
||
396 | } |
||
397 | |||
398 | public String getGeomField() |
||
399 | { |
||
400 | return geomFieldSelection.getField();
|
||
401 | } |
||
402 | |||
403 | /**
|
||
404 | * This method initializes geomFieldSelection
|
||
405 | *
|
||
406 | * @return com.iver.cit.gvsig.gui.jdbcwizard.GeomFieldSelection
|
||
407 | */
|
||
408 | private GeomFieldSelection getGeomFieldSelection() {
|
||
409 | if (geomFieldSelection == null) { |
||
410 | geomFieldSelection = new GeomFieldSelection();
|
||
411 | geomFieldSelection.setName("geomFieldSelection");
|
||
412 | 2269 | fjp | } |
413 | 10271 | jmvivo | return geomFieldSelection;
|
414 | 2269 | fjp | } |
415 | 10271 | jmvivo | /**
|
416 | * This method initializes uniqueFieldSelection
|
||
417 | *
|
||
418 | * @return com.iver.cit.gvsig.gui.jdbcwizard.UniqueFieldSelection
|
||
419 | */
|
||
420 | private UniqueFieldSelection getUniqueFieldSelection() {
|
||
421 | if (uniqueFieldSelection == null) { |
||
422 | uniqueFieldSelection = new UniqueFieldSelection();
|
||
423 | uniqueFieldSelection.setName("uniqueFieldSelection");
|
||
424 | uniqueFieldSelection.setWizard(this);
|
||
425 | 2269 | fjp | } |
426 | 10271 | jmvivo | return uniqueFieldSelection;
|
427 | 2269 | fjp | } |
428 | 10271 | jmvivo | public void initWizard() { |
429 | } |
||
430 | 2269 | fjp | |
431 | 10271 | jmvivo | /* (non-Javadoc)
|
432 | * @see com.iver.cit.gvsig.gui.WizardPanel#execute()
|
||
433 | */
|
||
434 | public void execute() { |
||
435 | } |
||
436 | |||
437 | /* (non-Javadoc)
|
||
438 | * @see com.iver.cit.gvsig.gui.WizardPanel#getLayer()
|
||
439 | */
|
||
440 | public FLayer getLayer() {
|
||
441 | WizardJDBC wiz = this;
|
||
442 | //true -> Modo desconectado. Por ahora, no se usa
|
||
443 | IProjection proj = null;
|
||
444 | String dbURL;
|
||
445 | try {
|
||
446 | dbURL = wiz.getConnectionString(); |
||
447 | String user = wiz.getUser();
|
||
448 | String pwd = wiz.getPassword();
|
||
449 | String layerName = wiz.getLayerName();
|
||
450 | String[] fields = wiz.getFields(); |
||
451 | String tableName = wiz.getTable();
|
||
452 | String whereClause = wiz.getWhereClause();
|
||
453 | String fidField = wiz.getFID();
|
||
454 | String geomField = wiz.getGeomField();
|
||
455 | Connection conn = DriverManager.getConnection(dbURL, user, pwd); |
||
456 | conn.setAutoCommit(false);
|
||
457 | |||
458 | VectorialJDBCDriver driver = wiz.getDriver(); |
||
459 | if (dbLayerDefinition.getWorkingArea() != null){ |
||
460 | driver.setWorkingArea(dbLayerDefinition.getWorkingArea()); |
||
461 | } |
||
462 | String strEPSG = getMapCtrl().getViewPort()
|
||
463 | .getProjection().getAbrev() |
||
464 | .substring(5);
|
||
465 | DBLayerDefinition lyrDef = new DBLayerDefinition();
|
||
466 | lyrDef.setName(layerName); |
||
467 | lyrDef.setTableName(tableName); |
||
468 | lyrDef.setWhereClause(whereClause); |
||
469 | lyrDef.setFieldNames(fields); |
||
470 | lyrDef.setFieldGeometry(geomField); |
||
471 | lyrDef.setFieldID(fidField); |
||
472 | if (dbLayerDefinition.getWorkingArea() != null) |
||
473 | lyrDef.setWorkingArea(dbLayerDefinition.getWorkingArea()); |
||
474 | |||
475 | lyrDef.setSRID_EPSG(strEPSG); |
||
476 | if (driver instanceof ICanReproject) |
||
477 | { |
||
478 | ((ICanReproject)driver).setDestProjection(strEPSG); |
||
479 | } |
||
480 | driver.setData(conn, lyrDef); |
||
481 | if (driver instanceof ICanReproject) |
||
482 | { |
||
483 | proj = CRSFactory.getCRS("EPSG:" + ((ICanReproject)driver).getSourceProjection());
|
||
484 | } |
||
485 | |||
486 | if (false){ |
||
487 | FLayer lyr = LayerFactory.createDisconnectedDBLayer(driver, layerName, proj, null);
|
||
488 | if (lyr != null) { |
||
489 | lyr.setVisible(true);
|
||
490 | } |
||
491 | |||
492 | return lyr;
|
||
493 | }else{ // MODO CONECTADO |
||
494 | return LayerFactory.createDBLayer(driver, layerName, proj);
|
||
495 | } |
||
496 | } catch (Exception e) { |
||
497 | e.printStackTrace(); |
||
498 | NotificationManager.addError("Error al cargar la capa.", e);
|
||
499 | } |
||
500 | |||
501 | return null; |
||
502 | } |
||
503 | } |