Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / wizards / JDBCWizard.java @ 2183

History | View | Annotate | Download (12 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.gui.wizards;
48

    
49
import com.iver.andami.PluginServices;
50
import com.iver.andami.Utilities;
51

    
52
import com.iver.cit.gvsig.fmap.layers.FLayer;
53
import com.iver.cit.gvsig.gui.WizardPanel;
54
import com.iver.cit.gvsig.gui.wms.LayerInfo;
55
import com.iver.cit.gvsig.gui.wms.LayerListModel;
56
import com.iver.cit.gvsig.gui.wms.LayerTreeModel;
57
import com.iver.cit.gvsig.gui.wms.WizardData;
58
import com.iver.cit.gvsig.gui.wms.WizardDataSource;
59
import com.iver.cit.gvsig.gui.wms.WizardListener;
60
import com.iver.cit.gvsig.gui.wms.WizardListenerSupport;
61

    
62
import com.iver.utiles.NotExistInXMLEntity;
63
import com.iver.utiles.XMLEntity;
64
import com.iver.utiles.swing.JComboBox;
65

    
66
import org.apache.log4j.Logger;
67

    
68
import java.awt.geom.Rectangle2D;
69

    
70
import java.net.MalformedURLException;
71
import java.net.URL;
72

    
73
import java.util.ArrayList;
74
import java.util.HashSet;
75
import java.util.Iterator;
76
import java.util.TreeSet;
77

    
78
import javax.swing.DefaultComboBoxModel;
79
import javax.swing.DefaultListModel;
80
import javax.swing.JPanel;
81
import javax.swing.JTextField;
82
import javax.swing.tree.TreePath;
83

    
84

    
85
import javax.swing.JLabel;
86
import java.awt.BorderLayout;
87
import java.awt.CardLayout;
88
import java.awt.GridLayout;
89
import javax.swing.JPasswordField;
90
/**
91
 * DOCUMENT ME!
92
 *
93
 * @author Fernando Gonz?lez Cort?s
94
 */
95
public class JDBCWizard extends WizardPanel {
96
        private static Logger logger = Logger.getLogger(JDBCWizard.class.getName());
97
        private int page = 0;
98
        private boolean conectado = false;
99
        private javax.swing.JPanel jContentPane = null;
100
        private JComboBox cmbHost = null;
101
        private javax.swing.JPanel panelPage1 = null;
102
        private LayerListModel selectedLayersModel = new LayerListModel();
103
        private javax.swing.JPanel jPanel1 = null;
104
        private WizardListenerSupport listenerSupport = new WizardListenerSupport();
105
        private WizardDataSource dataSource;
106
        private JPanel jPanel = null;
107
        private JLabel jLabel = null;
108
        private JTextField jTxtUser = null;
109
        private JLabel jLabel1 = null;
110
        private JPasswordField jTxtPassword = null;
111
        private JLabel jLabel2 = null;
112
        private JTextField jTxtNomTabla = null;
113
        private JLabel jLabel3 = null;
114
        private JTextField jTxtSqlFields = null;
115
        private JLabel jLabel4 = null;
116
        private JTextField jTxtSqlWhere = null;
117
        /**
118
         * This is the default constructor
119
         */
120
        public JDBCWizard() {
121
                super();
122
                initialize();
123
        }
124

    
125
        /**
126
         * This method initializes this
127
         */
128
        private void initialize() {
129
                this.setSize(510, 311);
130
                this.setLayout(null);
131
                this.setPreferredSize(new java.awt.Dimension(750, 320));
132
                this.setVisible(true);
133
                this.add(getPanelPage1(), null);
134
                
135
                listenerSupport.callStateChanged(true);
136
                // activarVisualizarBotones();
137
        }
138

    
139

    
140

    
141
        /**
142
         * DOCUMENT ME!
143
         *
144
         * @param host DOCUMENT ME!
145
         */
146
        private void addHost(String host) {
147
                host = host.trim();
148

    
149
                DefaultComboBoxModel model = (DefaultComboBoxModel) getTxtHost()
150
                                                                                                                                .getModel();
151

    
152
                if (model.getIndexOf(host) < 0) {
153
                        model.addElement(host);
154

    
155
                        PluginServices ps = PluginServices.getPluginServices(this);
156
                        XMLEntity xml = ps.getPersistentXML();
157

    
158
                        try {
159
                                String[] servers = xml.getStringArrayProperty("wms-servers");
160
                                String[] newServers = new String[servers.length + 1];
161
                                System.arraycopy(servers, 0, newServers, 0, servers.length);
162
                                newServers[servers.length] = host;
163
                                xml.putProperty("jdbc-servers", newServers);
164
                        } catch (NotExistInXMLEntity e) {
165
                                xml.putProperty("jdbc-servers", new String[] { host });
166
                        }
167

    
168
                        ps.setPersistentXML(xml);
169
                }
170
        }
171

    
172
        /**
173
         * DOCUMENT ME!
174
         */
175
        private void rellenarControles() {
176
                try {
177
                        String host = cmbHost.getModel().getSelectedItem().toString();
178

    
179
                        // if (!host.endsWith("?")) {
180
                        //         host += "?";
181
                        // }
182

    
183
                        WizardData data = dataSource.detalles(new URL(host));
184

    
185
                        addHost(host);
186
                        conectado = true;
187
                        // activarVisualizarBotones();
188
                } catch (Exception e) {
189
                        listenerSupport.callError(e);
190
                }
191
        }
192

    
193
        
194
        /**
195
         * This method initializes txtHost
196
         *
197
         * @return javax.swing.JTextField
198
         */
199
        private javax.swing.JComboBox getTxtHost() {
200
                if (cmbHost == null) {
201
                        cmbHost = new JComboBox();
202
                        cmbHost.setModel(new DefaultComboBoxModel());
203
                        cmbHost.setPreferredSize(new java.awt.Dimension(350, 20));
204
                        cmbHost.setEditable(true);
205

    
206
                        XMLEntity xml = PluginServices.getPluginServices(this)
207
                                                                                  .getPersistentXML();
208
                        if (xml == null)
209
                                xml = new XMLEntity();
210
                        String[] servers = null;
211
                        if (!xml.contains("jdbc-servers")) {
212
                                servers = new String[2];
213
                                servers[0] = "jdbc:postgresql://localhost/latin1";
214
                                servers[1] = "jdbc:mysql://192.168.0.198/test";
215

    
216
                                xml.putProperty("jdbc-servers", servers);
217
                        }
218

    
219
                        try {
220
                                servers = xml.getStringArrayProperty("jdbc-servers");
221

    
222
                                for (int i = 0; i < servers.length; i++) {
223
                                        ((DefaultComboBoxModel) cmbHost.getModel()).addElement(servers[i]);
224
                                }
225
                        } catch (NotExistInXMLEntity e) {
226
                        }
227
                }
228

    
229
                return cmbHost;
230
        }
231

    
232
        /**
233
         * This method initializes panelPage1
234
         *
235
         * @return javax.swing.JPanel
236
         */
237
        private javax.swing.JPanel getPanelPage1() {
238
                if (panelPage1 == null) {
239
                        panelPage1 = new javax.swing.JPanel();
240
                        panelPage1.setLayout(new BorderLayout());
241
                        panelPage1.setPreferredSize(new java.awt.Dimension(480, 220));
242
                        panelPage1.setVisible(true);
243
                        panelPage1.setBounds(15, 5, 480, 262);
244
                        panelPage1.add(getJPanel1(), java.awt.BorderLayout.NORTH);
245
                        panelPage1.add(getJPanel(), java.awt.BorderLayout.CENTER);
246
                }
247

    
248
                return panelPage1;
249
        }
250

    
251
        /**
252
         * This method initializes jPanel1
253
         *
254
         * @return javax.swing.JPanel
255
         */
256
        private javax.swing.JPanel getJPanel1() {
257
                if (jPanel1 == null) {
258
                        jPanel1 = new javax.swing.JPanel();
259
                        jPanel1.add(getTxtHost(), null);
260
                        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(
261
                                        null, PluginServices.getText(this, "Cadena de conexi?n"),
262
                                        javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
263
                                        javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
264
                }
265

    
266
                return jPanel1;
267
        }
268

    
269
        /**
270
         * DOCUMENT ME!
271
         *
272
         * @param listener
273
         */
274
        public void addWizardListener(WizardListener listener) {
275
                listenerSupport.addWizardListener(listener);
276
        }
277

    
278
        /**
279
         * DOCUMENT ME!
280
         *
281
         * @param listener
282
         */
283
        public void removeWizardListener(WizardListener listener) {
284
                listenerSupport.removeWizardListener(listener);
285
        }
286

    
287
        /**
288
         * DOCUMENT ME!
289
         *
290
         * @return
291
         */
292
        public WizardDataSource getDataSource() {
293
                return dataSource;
294
        }
295

    
296
        /**
297
         * DOCUMENT ME!
298
         *
299
         * @param source
300
         */
301
        public void setDataSource(WizardDataSource source) {
302
                dataSource = source;
303
        }
304

    
305

    
306

    
307

    
308

    
309
        public String getUrlConnect() {
310
                        return cmbHost.getModel().getSelectedItem().toString();
311
        }
312

    
313
        /**
314
         * DOCUMENT ME!
315
         *
316
         * @return Nombre de la capa que aparece en el TOC.
317
         */
318
        public String getLayerName() {
319
                return jTxtNomTabla.getText();
320
        }
321
        public String getUser() {
322
                return jTxtUser.getText();
323
        }
324
        public String getPassword() {
325
                return jTxtPassword.getText();
326
        }
327
        public String getSqlFields()
328
        {
329
            return jTxtSqlFields.getText();
330
        }
331
        public String getSqlWhere()
332
        {
333
            return jTxtSqlWhere.getText();
334
        }
335
        
336
        /**
337
         * This method initializes jPanel        
338
         *         
339
         * @return javax.swing.JPanel        
340
         */    
341
        private JPanel getJPanel() {
342
                if (jPanel == null) {
343
                        jPanel = new JPanel();
344
                        jLabel = new JLabel();
345
                        jLabel1 = new JLabel();
346
                        jLabel2 = new JLabel();
347
                        jLabel3 = new JLabel();
348
                        jLabel4 = new JLabel();
349
                        jPanel.setLayout(null);
350
                        jLabel.setText("Usuario:");
351
                        jLabel.setName("jLabel");
352
                        jLabel.setSize(80, 19);
353
                        jLabel.setLocation(151, 12);
354
                        jLabel1.setBounds(149, 41, 82, 19);
355
                        jLabel1.setText("Contrase?a:");
356
                        jLabel2.setBounds(121, 67, 110, 20);
357
                        jLabel2.setText("Nombre de la tabla:");
358
                        jLabel3.setBounds(26, 96, 205, 22);
359
                        jLabel3.setText("Campos a recuperar (Primero the_geom):");
360
                        jLabel4.setBounds(125, 130, 106, 22);
361
                        jLabel4.setText("Cl?usula Where:");
362
                        jPanel.add(jLabel, null);
363
                        jPanel.add(getJTxtUser(), null);
364
                        jPanel.add(jLabel1, null);
365
                        jPanel.add(getJTxtPassword(), null);
366
                        jPanel.add(jLabel2, null);
367
                        jPanel.add(getJTxtNomTabla(), null);
368
                        jPanel.add(jLabel3, null);
369
                        jPanel.add(getJTxtSqlFields(), null);
370
                        jPanel.add(jLabel4, null);
371
                        jPanel.add(getJTxtSqlWhere(), null);
372
                }
373
                return jPanel;
374
        }
375
        /**
376
         * This method initializes jTextField        
377
         *         
378
         * @return javax.swing.JTextField        
379
         */    
380
        private JTextField getJTxtUser() {
381
                if (jTxtUser == null) {
382
                        jTxtUser = new JTextField();
383
                        jTxtUser.setName("jTextField");
384
                        jTxtUser.setColumns(0);
385
                        jTxtUser.setBounds(241, 12, 169, 19);
386
                        jTxtUser.setText("postgres");
387
                        jTxtUser.addFocusListener(new java.awt.event.FocusListener() { 
388
                                public void focusLost(java.awt.event.FocusEvent e) {
389
                                    listenerSupport.callStateChanged(true);
390
                                        System.out.println("focusLost()"); // TODO Auto-generated Event stub focusLost()
391
                                }
392
                                public void focusGained(java.awt.event.FocusEvent e) {} 
393
                        });
394
                }
395
                return jTxtUser;
396
        }
397
        /**
398
         * This method initializes jPasswordField        
399
         *         
400
         * @return javax.swing.JPasswordField        
401
         */    
402
        private JPasswordField getJTxtPassword() {
403
                if (jTxtPassword == null) {
404
                        jTxtPassword = new JPasswordField();
405
                        jTxtPassword.setBounds(241, 39, 169, 20);
406
                }
407
                return jTxtPassword;
408
        }
409
        /**
410
         * This method initializes jTextField        
411
         *         
412
         * @return javax.swing.JTextField        
413
         */    
414
        private JTextField getJTxtNomTabla() {
415
                if (jTxtNomTabla == null) {
416
                        jTxtNomTabla = new JTextField();
417
                        jTxtNomTabla.setBounds(241, 66, 169, 20);
418
                }
419
                return jTxtNomTabla;
420
        }
421
        /**
422
         * This method initializes jTextField        
423
         *         
424
         * @return javax.swing.JTextField        
425
         */    
426
        private JTextField getJTxtSqlFields() {
427
                if (jTxtSqlFields == null) {
428
                        jTxtSqlFields = new JTextField();
429
                        jTxtSqlFields.setBounds(241, 96, 169, 24);
430
                        jTxtSqlFields.setText("ASBINARY(the_geom, 'XDR')");
431
                }
432
                return jTxtSqlFields;
433
        }
434
        /**
435
         * This method initializes jTextField        
436
         *         
437
         * @return javax.swing.JTextField        
438
         */    
439
        private JTextField getJTxtSqlWhere() {
440
                if (jTxtSqlWhere == null) {
441
                        jTxtSqlWhere = new JTextField();
442
                        jTxtSqlWhere.setBounds(241, 129, 169, 24);
443
                }
444
                return jTxtSqlWhere;
445
        }
446

    
447
    /* (non-Javadoc)
448
     * @see com.iver.cit.gvsig.gui.WizardPanel#execute()
449
     */
450
    public void execute() {
451
        // TODO Auto-generated method stub
452
        
453
    }
454

    
455
    /* (non-Javadoc)
456
     * @see com.iver.cit.gvsig.gui.WizardPanel#getLayer()
457
     */
458
    public FLayer getLayer() {
459
        // TODO Auto-generated method stub
460
        return null;
461
    }
462

    
463
    /* (non-Javadoc)
464
     * @see com.iver.cit.gvsig.gui.WizardPanel#initWizard()
465
     */
466
    public void initWizard() {
467
        // TODO Auto-generated method stub
468
        
469
    }
470
      }
471

    
472
//  @jve:decl-index=0:visual-constraint="10,10"
473
//  @jve:visual-info  decl-index=0 visual-constraint="16,10"
474
//  @jve:visual-info  decl-index=0 visual-constraint="10,10"
475
//  @jve:visual-info  decl-index=0 visual-constraint="10,10"
476
//        @jve:visual-info  decl-index=0 visual-constraint="10,10"