Statistics
| Revision:

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

History | View | Annotate | Download (11.3 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.gui.WizardPanel;
53
import com.iver.cit.gvsig.gui.wms.LayerInfo;
54
import com.iver.cit.gvsig.gui.wms.LayerListModel;
55
import com.iver.cit.gvsig.gui.wms.LayerTreeModel;
56
import com.iver.cit.gvsig.gui.wms.WizardData;
57
import com.iver.cit.gvsig.gui.wms.WizardDataSource;
58
import com.iver.cit.gvsig.gui.wms.WizardListener;
59
import com.iver.cit.gvsig.gui.wms.WizardListenerSupport;
60

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

    
65
import org.apache.log4j.Logger;
66

    
67
import java.awt.geom.Rectangle2D;
68

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

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

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

    
83

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

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

    
138

    
139

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

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

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

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

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

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

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

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

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

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

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

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

    
214
                                xml.putProperty("jdbc-servers", servers);
215
                        // }
216

    
217
                        try {
218
                                servers = xml.getStringArrayProperty("jdbc-servers");
219

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

    
227
                return cmbHost;
228
        }
229

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

    
246
                return panelPage1;
247
        }
248

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

    
264
                return jPanel1;
265
        }
266

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

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

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

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

    
303

    
304

    
305

    
306

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

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

    
444
//  @jve:decl-index=0:visual-constraint="10,10"
445
//  @jve:visual-info  decl-index=0 visual-constraint="16,10"
446
//  @jve:visual-info  decl-index=0 visual-constraint="10,10"
447
//  @jve:visual-info  decl-index=0 visual-constraint="10,10"
448
//        @jve:visual-info  decl-index=0 visual-constraint="10,10"