Statistics
| Revision:

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

History | View | Annotate | Download (15 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.sde.ArcSdeDriver;
66
import com.iver.cit.gvsig.fmap.drivers.sde.utils.SDELayerDefinition;
67
import com.iver.cit.gvsig.fmap.layers.FLayer;
68
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
69
import com.iver.cit.gvsig.gui.WizardPanel;
70
import com.iver.cit.gvsig.gui.wizards.LayerListModel;
71
import com.iver.cit.gvsig.gui.wizards.WizardDataSource;
72
import com.iver.cit.gvsig.gui.wizards.WizardListener;
73
import com.iver.cit.gvsig.gui.wizards.WizardListenerSupport;
74

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

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

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

    
158

    
159

    
160

    
161

    
162

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

    
179
                return panelPage1;
180
        }
181

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

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

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

    
210
                return jPanel1;
211
        }
212

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

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

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

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

    
249

    
250

    
251

    
252

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

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

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

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

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

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

    
431
        public void initWizard() {
432
        }
433

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

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

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

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

    
519
        }
520

    
521

    
522

    
523

    
524

    
525

    
526

    
527

    
528
}
529

    
530