Statistics
| Revision:

root / branches / v10 / extensions / extSDE / src / com / iver / cit / gvsig / sde / gui / sdewizard / WizardSDEOld.java @ 10942

History | View | Annotate | Download (15.1 KB)

1
/*
2
 * Created on 23-abr-2004
3
 *
4
 * To change the template for this generated file go to
5
 * Window>Preferences>Java>Code Generation>Code and Comments
6
 */
7
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
8
 *
9
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
10
 *
11
 * This program is free software; you can redistribute it and/or
12
 * modify it under the terms of the GNU General Public License
13
 * as published by the Free Software Foundation; either version 2
14
 * of the License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU General Public License
22
 * along with this program; if not, write to the Free Software
23
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
24
 *
25
 * For more information, contact:
26
 *
27
 *  Generalitat Valenciana
28
 *   Conselleria d'Infraestructures i Transport
29
 *   Av. Blasco Ib??ez, 50
30
 *   46010 VALENCIA
31
 *   SPAIN
32
 *
33
 *      +34 963862235
34
 *   gvsig@gva.es
35
 *      www.gvsig.gva.es
36
 *
37
 *    or
38
 *
39
 *   IVER T.I. S.A
40
 *   Salamanca 50
41
 *   46005 Valencia
42
 *   Spain
43
 *
44
 *   +34 963163400
45
 *   dac@iver.es
46
 */
47
package com.iver.cit.gvsig.sde.gui.sdewizard;
48

    
49
import java.awt.BorderLayout;
50

    
51
import javax.swing.JLabel;
52
import javax.swing.JPanel;
53
import javax.swing.JPasswordField;
54
import javax.swing.JTextField;
55

    
56
import org.apache.log4j.Logger;
57
import org.cresques.cts.IProjection;
58

    
59
import com.hardcode.driverManager.DriverLoadException;
60
import com.iver.andami.PluginServices;
61
import com.iver.cit.gvsig.fmap.core.ICanReproject;
62
import com.iver.cit.gvsig.fmap.crs.CRSFactory;
63
import com.iver.cit.gvsig.fmap.drivers.DBLayerDefinition;
64
import com.iver.cit.gvsig.fmap.drivers.VectorialDatabaseDriver;
65
import com.iver.cit.gvsig.fmap.drivers.VectorialSDEDriver;
66
import com.iver.cit.gvsig.fmap.drivers.sde.ArcSdeDriver;
67
import com.iver.cit.gvsig.fmap.drivers.sde.SDELayerDefinition;
68
import com.iver.cit.gvsig.fmap.layers.FLayer;
69
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
70
import com.iver.cit.gvsig.gui.WizardPanel;
71
import com.iver.cit.gvsig.gui.wizards.LayerListModel;
72
import com.iver.cit.gvsig.gui.wizards.WizardDataSource;
73
import com.iver.cit.gvsig.gui.wizards.WizardListener;
74
import com.iver.cit.gvsig.gui.wizards.WizardListenerSupport;
75

    
76
/**
77
 * DOCUMENT ME!
78
 * @author   Fernando Gonz?lez Cort?s
79
 */
80
public class WizardSDEOld extends WizardPanel {
81
        private static Logger logger = Logger.getLogger(WizardSDE.class.getName());
82
        private int page = 0;
83
        private boolean conectado = false;
84
        private javax.swing.JPanel jContentPane = null;
85
        /**
86
         * @uml.property  name="panelPage1"
87
         */
88
        private javax.swing.JPanel panelPage1 = null;
89
        private LayerListModel selectedLayersModel = new LayerListModel();
90
        /**
91
         * @uml.property  name="jPanel1"
92
         */
93
        private javax.swing.JPanel jPanel1 = null;
94
        private WizardListenerSupport listenerSupport = new WizardListenerSupport();
95
        private WizardDataSource dataSource;
96
        /**
97
         * @uml.property  name="jPanel"
98
         */
99
        private JPanel jPanel = null;
100
        private JLabel jLabel = null;
101
        /**
102
         * @uml.property  name="jTxtUser"
103
         */
104
        private JTextField jTxtUser = null;
105
        private JLabel jLabel1 = null;
106
        /**
107
         * @uml.property  name="jTxtPassword"
108
         */
109
        private JPasswordField jTxtPassword = null;
110
        private JLabel jLabel2 = null;
111
        /**
112
         * @uml.property  name="jTxtNomTabla"
113
         */
114
        private JTextField jTxtNomTabla = null;
115
        private JLabel jLabel4 = null;
116
        /**
117
         * @uml.property  name="jTxtSqlWhere"
118
         */
119
        private JTextField jTxtSqlWhere = null;
120
    /**
121
         * @uml.property  name="jTxtHost"
122
         */
123
    private JTextField jTxtHost = null;
124
    private JLabel jLabel5 = null;
125
    private JLabel jLabel6 = null;
126
    /**
127
         * @uml.property  name="jTxtPort"
128
         */
129
    private JTextField jTxtPort = null;
130
    private JTextField jTxtSchema = null;
131
    private JLabel jLabel3 = null;
132
    /**
133
         * @uml.property  name="jTxtEsquema"
134
         */
135
    private JTextField jTxtEsquema = null;
136
        /**
137
         * This is the default constructor
138
         */
139
        public WizardSDEOld() {
140
                super();
141
                initialize();
142
        }
143

    
144
        /**
145
         * This method initializes this
146
         */
147
        private void initialize() {
148
                setTabName("ArcSDE");
149
                this.setSize(510, 311);
150
                this.setLayout(null);
151
                this.setPreferredSize(new java.awt.Dimension(750, 320));
152
                this.setVisible(true);
153
                this.add(getPanelPage1(), null);
154

    
155
                listenerSupport.callStateChanged(true);
156
                // activarVisualizarBotones();
157
        }
158

    
159

    
160

    
161

    
162

    
163

    
164
        /**
165
         * This method initializes panelPage1
166
         * @return  javax.swing.JPanel
167
         * @uml.property  name="panelPage1"
168
         */
169
        private javax.swing.JPanel getPanelPage1() {
170
                if (panelPage1 == null) {
171
                        panelPage1 = new javax.swing.JPanel();
172
                        panelPage1.setLayout(new BorderLayout());
173
                        panelPage1.setPreferredSize(new java.awt.Dimension(480, 220));
174
                        panelPage1.setVisible(true);
175
                        panelPage1.setBounds(15, 5, 480, 262);
176
                        panelPage1.add(getJPanel1(), java.awt.BorderLayout.NORTH);
177
                        panelPage1.add(getJPanel(), java.awt.BorderLayout.CENTER);
178
                }
179

    
180
                return panelPage1;
181
        }
182

    
183
        /**
184
         * This method initializes jPanel1
185
         * @return  javax.swing.JPanel
186
         * @uml.property  name="jPanel1"
187
         */
188
        private javax.swing.JPanel getJPanel1() {
189
                if (jPanel1 == null) {
190
                        jLabel6 = new JLabel();
191
                        jLabel6.setText("Puerto:");
192
                        jLabel6.setPreferredSize(new java.awt.Dimension(94,15));
193
                        jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
194
                        jLabel5 = new JLabel();
195
                        jLabel5.setText("Host:");
196
                        jLabel5.setPreferredSize(new java.awt.Dimension(95,15));
197
                        jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
198
                        jPanel1 = new javax.swing.JPanel();
199
                        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(
200
                                        null, PluginServices.getText(this, "Servidor ArcSDE"),
201
                                        javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
202
                                        javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
203

    
204
            jPanel1.add(jLabel5, null);
205
                        jPanel1.add(getJTxtHost(), null);
206

    
207
            jPanel1.add(jLabel6, null);
208
            jPanel1.add(getJTxtPort(), null);
209
                }
210

    
211
                return jPanel1;
212
        }
213

    
214
        /**
215
         * DOCUMENT ME!
216
         *
217
         * @param listener
218
         */
219
        public void addWizardListener(WizardListener listener) {
220
                listenerSupport.addWizardListener(listener);
221
        }
222

    
223
        /**
224
         * DOCUMENT ME!
225
         *
226
         * @param listener
227
         */
228
        public void removeWizardListener(WizardListener listener) {
229
                listenerSupport.removeWizardListener(listener);
230
        }
231

    
232
        /**
233
         * DOCUMENT ME!
234
         * @return
235
         * @uml.property  name="dataSource"
236
         */
237
        public WizardDataSource getDataSource() {
238
                return dataSource;
239
        }
240

    
241
        /**
242
         * DOCUMENT ME!
243
         * @param  source
244
         * @uml.property  name="dataSource"
245
         */
246
        public void setDataSource(WizardDataSource source) {
247
                dataSource = source;
248
        }
249

    
250

    
251

    
252

    
253

    
254
        public String getHost() {
255
                        return getJTxtHost().getText();
256
        }
257

    
258
    public String getSchema() {
259
        return getJTxtEsquema().getText();
260
    }
261
        /**
262
         * DOCUMENT ME!
263
         *
264
         * @return Nombre de la capa que aparece en el TOC.
265
         */
266
        public String getLayerName() {
267
                return jTxtNomTabla.getText();
268
        }
269
        public String getUser() {
270
                return jTxtUser.getText();
271
        }
272
        public String getPassword() {
273
                return jTxtPassword.getText();
274
        }
275
        public String getPort()
276
        {
277
            return jTxtPort.getText();
278
        }
279
        public String getSqlWhere()
280
        {
281
            return jTxtSqlWhere.getText();
282
        }
283

    
284
        /**
285
         * This method initializes jPanel
286
         * @return  JPanel
287
         * @uml.property  name="jPanel"
288
         */
289
        private JPanel getJPanel() {
290
                if (jPanel == null) {
291
                        jPanel = new JPanel();
292
                        jLabel = new JLabel();
293
                        jLabel1 = new JLabel();
294
                        jLabel2 = new JLabel();
295
                        jLabel4 = new JLabel();
296
                        jPanel.setLayout(null);
297
                        jLabel.setText("Usuario:");
298
                        jLabel.setName("jLabel");
299
                        jLabel.setSize(80, 19);
300
                        jLabel.setLocation(151, 12);
301
                        jLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
302
                        jLabel1.setBounds(149, 41, 82, 19);
303
                        jLabel1.setText("Contrase?a:");
304
                        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
305
                        jLabel2.setBounds(122, 98, 110, 20);
306
                        jLabel2.setText("Nombre de la tabla:");
307
                        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
308
                        jLabel4.setBounds(125, 130, 106, 22);
309
                        jLabel4.setText("Cl?usula Where:");
310
                        jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
311
                        jPanel.add(jLabel, null);
312
                        jPanel.add(getJTxtUser(), null);
313
                        jPanel.add(jLabel1, null);
314
                        jPanel.add(getJTxtPassword(), null);
315
            jPanel.add(getJTxtEsquema(), null);
316
                        jPanel.add(jLabel2, null);
317
                        jPanel.add(getJTxtNomTabla(), null);
318
                        jPanel.add(jLabel4, null);
319
                        jPanel.add(getJTxtSqlWhere(), null);
320
                }
321
                return jPanel;
322
        }
323
        /**
324
         * This method initializes jTextField
325
         * @return  javax.swing.JTextField
326
         * @uml.property  name="jTxtUser"
327
         */
328
        private JTextField getJTxtUser() {
329
                if (jTxtUser == null) {
330
                        jTxtUser = new JTextField();
331
                        jTxtUser.setName("jTextField");
332
                        jTxtUser.setColumns(0);
333
                        jTxtUser.setBounds(241, 12, 169, 19);
334
                        jTxtUser.setText("sde");
335
                        jTxtUser.addFocusListener(new java.awt.event.FocusListener() {
336
                                public void focusLost(java.awt.event.FocusEvent e) {
337
                                    listenerSupport.callStateChanged(true);
338
                                        System.out.println("focusLost()"); // TODO Auto-generated Event stub focusLost()
339
                                }
340
                                public void focusGained(java.awt.event.FocusEvent e) {}
341
                        });
342
                }
343
                return jTxtUser;
344
        }
345
        /**
346
         * This method initializes jPasswordField
347
         * @return  javax.swing.JPasswordField
348
         * @uml.property  name="jTxtPassword"
349
         */
350
        private JPasswordField getJTxtPassword() {
351
                if (jTxtPassword == null) {
352
                        jTxtPassword = new JPasswordField();
353
                        jTxtPassword.setBounds(241, 39, 169, 20);
354
                        jTxtPassword.setText("iver");
355
            jTxtPassword.addFocusListener(new java.awt.event.FocusListener() {
356
                public void focusLost(java.awt.event.FocusEvent e) {
357
                    listenerSupport.callStateChanged(true);
358
                    System.out.println("focusLost()"); // TODO Auto-generated Event stub focusLost()
359
                }
360
                public void focusGained(java.awt.event.FocusEvent e) {}
361
            });
362
                }
363
                return jTxtPassword;
364
        }
365
        /**
366
         * This method initializes jTextField
367
         * @return  javax.swing.JTextField
368
         * @uml.property  name="jTxtNomTabla"
369
         */
370
        private JTextField getJTxtNomTabla() {
371
                if (jTxtNomTabla == null) {
372
                        jTxtNomTabla = new JTextField();
373
                        jTxtNomTabla.setBounds(241, 99, 169, 20);
374
                        jTxtNomTabla.setText("TEXTOS");
375
                }
376
                return jTxtNomTabla;
377
        }
378
        /**
379
         * This method initializes jTextField
380
         * @return  javax.swing.JTextField
381
         * @uml.property  name="jTxtSqlWhere"
382
         */
383
        private JTextField getJTxtSqlWhere() {
384
                if (jTxtSqlWhere == null) {
385
                        jTxtSqlWhere = new JTextField();
386
                        jTxtSqlWhere.setBounds(241, 129, 169, 24);
387
                }
388
                return jTxtSqlWhere;
389
        }
390

    
391
    /**
392
         * This method initializes jTextField
393
         * @return  javax.swing.JTextField
394
         * @uml.property  name="jTxtHost"
395
         */
396
    private JTextField getJTxtHost() {
397
            if (jTxtHost == null) {
398
                    jTxtHost = new JTextField();
399
                    jTxtHost.setText("192.168.0.114");
400
                    jTxtHost.setPreferredSize(new java.awt.Dimension(143,20));
401
            }
402
            return jTxtHost;
403
    }
404

    
405
    /**
406
         * This method initializes jTextField
407
         * @return  javax.swing.JTextField
408
         * @uml.property  name="jTxtPort"
409
         */
410
    private JTextField getJTxtPort() {
411
            if (jTxtPort == null) {
412
                    jTxtPort = new JTextField();
413
                    jTxtPort.setText("5151");
414
            }
415
            return jTxtPort;
416
    }
417

    
418
    /**
419
         * This method initializes jTextField
420
         * @return  javax.swing.JTextField
421
         * @uml.property  name="jTxtEsquema"
422
         */
423
    private JTextField getJTxtEsquema() {
424
            if (jTxtEsquema == null) {
425
                    jTxtEsquema = new JTextField();
426
                    jTxtEsquema.setBounds(241, 69, 168, 20);
427
                    jTxtEsquema.setText("ProvinciasPruebas");
428
            }
429
            return jTxtEsquema;
430
    }
431

    
432
        public void initWizard() {
433
        }
434

    
435
        /* (non-Javadoc)
436
         * @see com.iver.cit.gvsig.gui.WizardPanel#execute()
437
         */
438
        public void execute() {
439
        }
440

    
441
        /* (non-Javadoc)
442
         * @see com.iver.cit.gvsig.gui.WizardPanel#getLayer()
443
         */
444
//        public FLayer getLayer() {
445
//                WizardSDE arcsde_wizard = this;
446
//        String dbHost = arcsde_wizard.getHost();
447
//        String port = arcsde_wizard.getPort();
448
//        String user = arcsde_wizard.getUser();
449
//        String pwd = arcsde_wizard.getPassword();
450
//        // String layerName = arcsde_wizard.getLayerName();
451
//        // String fields = StringUtilities.getComaSeparated(wiz.getFields());
452
//        String tableName = arcsde_wizard.getLayerName();
453
//        String schema = arcsde_wizard.getSchema();
454
//        String whereClause = "";
455
//        String [] fields = null;
456
//
457
//        // VectorialDatabaseDriver driver;
458
//        // try {
459
//            // driver = (VectorialDatabaseDriver) LayerFactory.getDM().getDriver("ArcSDE driver");
460
//            ArcSdeDriver driver = new ArcSdeDriver();
461
//            // ArcSdeDriver drv = (ArcSdeDriver) driver;
462
//            driver.setData(dbHost, Integer.parseInt(port), schema, user, pwd, tableName, fields, whereClause);
463
//
464
//            return LayerFactory.createDBLayer(driver, tableName, null);
465
//        /* } catch (DriverLoadException e) {
466
//            // TODO Auto-generated catch block
467
//            e.printStackTrace();
468
//            return null;
469
//        } */
470
//
471
//        }
472
        public FLayer getLayer() {
473
                IProjection proj = null;
474
                WizardSDEOld arcsde_wizard = this;
475
        String dbHost = arcsde_wizard.getHost();
476
        String port = arcsde_wizard.getPort();
477
        String user = arcsde_wizard.getUser();
478
        String pwd = arcsde_wizard.getPassword();
479
        String layerName = arcsde_wizard.getLayerName();
480
        // String fields = StringUtilities.getComaSeparated(wiz.getFields());
481
        String tableName = arcsde_wizard.getLayerName();
482
        String schema = arcsde_wizard.getSchema();
483
        String whereClause = "";
484
        String [] fields = new String[]{"SHAPE","OBJECTID"};
485

    
486
        String strEPSG = getMapCtrl().getViewPort()
487
                    .getProjection().getAbrev()
488
                    .substring(5);
489

    
490
        SDELayerDefinition lyrDef = new SDELayerDefinition();
491
        lyrDef.setHost(dbHost);
492
        lyrDef.setPort(port);
493
        lyrDef.setSchema(schema);
494
        lyrDef.setUser(user);
495
        lyrDef.setPassword(pwd);
496
        lyrDef.setName(layerName);
497
        lyrDef.setTableName(tableName);
498
        lyrDef.setWhereClause(whereClause);
499
        lyrDef.setFieldNames(new String[]{"SHAPE","OBJECTID","AREA","PERIMETER","CODMUNI","MUNI_","MUNI_ID","CODPROV","CODAUTO","CODCOMAR"});
500
        lyrDef.setFieldGeometry("SHAPE");
501
        lyrDef.setFieldID("OBJECTID");
502
        lyrDef.setSRID_EPSG(strEPSG);
503
        ArcSdeDriver driver = new ArcSdeDriver();
504
        if (driver instanceof ICanReproject){
505
            ((ICanReproject)driver).setDestProjection(strEPSG);
506
        }
507
                driver.setData(null, lyrDef);
508
//            driver.setData(dbHost, Integer.parseInt(port), schema, user, pwd, tableName, fields, whereClause);
509
                if (driver instanceof ICanReproject)
510
            {
511
                proj = CRSFactory.getCRS("EPSG:" + ((ICanReproject)driver).getSourceProjection());
512
            }
513
            return LayerFactory.createDBLayer(driver, tableName, proj);
514
        /* } catch (DriverLoadException e) {
515
            // TODO Auto-generated catch block
516
            e.printStackTrace();
517
            return null;
518
        } */
519

    
520
        }
521

    
522

    
523

    
524

    
525

    
526

    
527

    
528

    
529
}
530

    
531