Statistics
| Revision:

svn-gvsig-desktop / tags / v1_0_2_Build_892 / extensions / extJDBC / src / com / iver / cit / gvsig / jdbc_spatial / DlgConnection.java @ 10278

History | View | Annotate | Download (5.92 KB)

1 3207 fjp
/*
2
 * Created on 26-oct-2005
3
 *
4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5 6566 jaume
 *
6 3207 fjp
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
7 6566 jaume
 *
8 3207 fjp
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12 6566 jaume
 *
13 3207 fjp
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17 6566 jaume
 *
18 3207 fjp
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21 6566 jaume
 *
22 3207 fjp
 * For more information, contact:
23
 *
24
 *  Generalitat Valenciana
25
 *   Conselleria d'Infraestructures i Transport
26
 *   Av. Blasco Ib??ez, 50
27
 *   46010 VALENCIA
28
 *   SPAIN
29
 *
30
 *      +34 963862235
31
 *   gvsig@gva.es
32
 *      www.gvsig.gva.es
33 6566 jaume
 *
34 3207 fjp
 *    or
35 6566 jaume
 *
36 3207 fjp
 *   IVER T.I. S.A
37
 *   Salamanca 50
38
 *   46005 Valencia
39
 *   Spain
40 6566 jaume
 *
41 3207 fjp
 *   +34 963163400
42
 *   dac@iver.es
43
 */
44
package com.iver.cit.gvsig.jdbc_spatial;
45
46
import java.awt.BorderLayout;
47 6566 jaume
import java.awt.event.ActionListener;
48 3207 fjp
import java.util.ArrayList;
49
import java.util.HashMap;
50
51 6566 jaume
import javax.swing.JButton;
52 3207 fjp
import javax.swing.JDialog;
53 6566 jaume
import javax.swing.JOptionPane;
54
import javax.swing.JPanel;
55 3207 fjp
56 6566 jaume
import org.gvsig.gui.beans.AcceptCancelPanel;
57
58 3207 fjp
import com.iver.andami.PluginServices;
59
import com.iver.cit.gvsig.fmap.drivers.VectorialJDBCDriver;
60
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
61
import com.iver.cit.gvsig.jdbc_spatial.gui.jdbcwizard.ConnectionPanel;
62
import com.iver.cit.gvsig.jdbc_spatial.gui.jdbcwizard.ConnectionSettings;
63
import com.iver.utiles.NotExistInXMLEntity;
64
import com.iver.utiles.XMLEntity;
65
66
public class DlgConnection extends JDialog {
67
68
    private JPanel jContentPane = null;
69
    private ConnectionPanel jConnPanel = null;
70
    private JButton jBtnOK = null;
71
    private JPanel jPanel1 = null;
72
    private JButton jBtnCancel = null;
73
    private ConnectionSettings connSettings = null;
74
75
    /**
76
     * This is the default constructor
77
     */
78
    public DlgConnection() {
79
        super();
80
        initialize();
81
    }
82
83
    private void setPreferences()
84
    {
85
        XMLEntity xml = PluginServices.getPluginServices(this).getPersistentXML();
86
87
        if (xml == null) {
88
            xml = new XMLEntity();
89
        }
90 6566 jaume
91 3207 fjp
        if (!xml.contains("jdbc-connections")) {
92
            String[] servers = new String[0];
93
            xml.putProperty("jdbc-connections", servers);
94
        }
95 6566 jaume
96 3207 fjp
        try {
97
            String[] servers = xml.getStringArrayProperty("jdbc-connections");
98
            HashMap settings = new HashMap();
99
            for (int i = 0; i < servers.length; i++) {
100
                ConnectionSettings cs = new ConnectionSettings();
101
                cs.setFromString(servers[i]);
102
                settings.put(cs.getName(), cs);
103
            }
104
            getJConnPanel().setSettings(settings);
105
        } catch (NotExistInXMLEntity e) {
106
        }
107
108
    }
109
    /**
110
     * This method initializes this
111 6566 jaume
     *
112 3207 fjp
     * @return void
113
     */
114
    private void initialize() {
115
        this.setSize(320, 332);
116 6566 jaume
        this.setTitle(PluginServices.getText(this, "database_connection"));
117 3207 fjp
        this.setContentPane(getJContentPane());
118
        setPreferences();
119
        jConnPanel.setDrivers(getDriverNames());
120
    }
121 6566 jaume
122 3207 fjp
    private String[] getDriverNames(){
123
        Class[] classes = new Class[] { VectorialJDBCDriver.class };
124
125
        ArrayList ret = new ArrayList();
126
        String[] driverNames = LayerFactory.getDM().getDriverNames();
127
128
        for (int i = 0; i < driverNames.length; i++) {
129
            boolean is = false;
130
131
            for (int j = 0; j < classes.length; j++) {
132
                if (LayerFactory.getDM().isA(driverNames[i], classes[j])) {
133
                    ret.add(driverNames[i]);
134
                }
135
            }
136
        }
137
138
        return (String[]) ret.toArray(new String[0]);
139 6566 jaume
140 3207 fjp
    }
141
142
    /**
143
     * This method initializes jContentPane
144 6566 jaume
     *
145 3207 fjp
     * @return javax.swing.JPanel
146
     */
147
    private JPanel getJContentPane() {
148
        if (jContentPane == null) {
149
            jContentPane = new JPanel();
150
            jContentPane.setLayout(new BorderLayout());
151
            jContentPane.add(getJConnPanel(), java.awt.BorderLayout.CENTER);
152
            jContentPane.add(getJPanel1(), java.awt.BorderLayout.SOUTH);
153 6566 jaume
154 3207 fjp
        }
155
        return jContentPane;
156
    }
157
158
    /**
159 6566 jaume
     * This method initializes jPanel
160
     *
161
     * @return javax.swing.JPanel
162
     */
163 3207 fjp
    private ConnectionPanel getJConnPanel() {
164
            if (jConnPanel == null) {
165
                    jConnPanel = new ConnectionPanel();
166
            }
167
            return jConnPanel;
168
    }
169
170 6566 jaume
171
172 3207 fjp
    /**
173 6566 jaume
     * This method initializes jPanel1
174
     *
175
     * @return javax.swing.JPanel
176
     */
177
    private JPanel getJPanel1() {
178
            if (jPanel1 == null) {
179
                    ActionListener okAction = new java.awt.event.ActionListener() {
180 3207 fjp
                public void actionPerformed(java.awt.event.ActionEvent e) {
181 6566 jaume
                        if (!jConnPanel.done()) {
182
                                JOptionPane.showMessageDialog(DlgConnection.this, "No estan todos los datos rellenos", "Error", JOptionPane.ERROR_MESSAGE);
183
                                return;
184
                        }
185
                        jConnPanel.saveConnectionSettings();
186 3207 fjp
                    connSettings = jConnPanel.getConnectionSettings();
187
                    dispose();
188
                }
189 6566 jaume
                    };
190 3207 fjp
191 6566 jaume
            ActionListener cancelAction = new java.awt.event.ActionListener() {
192 3207 fjp
                            public void actionPerformed(java.awt.event.ActionEvent e) {
193
                    connSettings = null;
194
                                    dispose();
195
                            }
196 6566 jaume
                    };
197
                    jPanel1 = new AcceptCancelPanel(okAction, cancelAction);
198
199
200 3207 fjp
            }
201 6566 jaume
            return jPanel1;
202 3207 fjp
    }
203
204 6566 jaume
205 3207 fjp
    public ConnectionSettings getConnSettings() {
206
        return connSettings;
207
    }
208
209
}  //  @jve:decl-index=0:visual-constraint="10,10"