svn-gvsig-desktop / tags / v1_1_Build_1000 / extensions / extJDBC / src / com / iver / cit / gvsig / jdbc_spatial / DlgConnection.java @ 11885
History | View | Annotate | Download (5.92 KB)
1 |
/*
|
---|---|
2 |
* Created on 26-oct-2005
|
3 |
*
|
4 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
5 |
*
|
6 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
7 |
*
|
8 |
* 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 |
*
|
13 |
* 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 |
*
|
18 |
* 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 |
*
|
22 |
* 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 |
*
|
34 |
* or
|
35 |
*
|
36 |
* IVER T.I. S.A
|
37 |
* Salamanca 50
|
38 |
* 46005 Valencia
|
39 |
* Spain
|
40 |
*
|
41 |
* +34 963163400
|
42 |
* dac@iver.es
|
43 |
*/
|
44 |
package com.iver.cit.gvsig.jdbc_spatial; |
45 |
|
46 |
import java.awt.BorderLayout; |
47 |
import java.awt.event.ActionListener; |
48 |
import java.util.ArrayList; |
49 |
import java.util.HashMap; |
50 |
|
51 |
import javax.swing.JButton; |
52 |
import javax.swing.JDialog; |
53 |
import javax.swing.JOptionPane; |
54 |
import javax.swing.JPanel; |
55 |
|
56 |
import org.gvsig.gui.beans.AcceptCancelPanel; |
57 |
|
58 |
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 |
|
91 |
if (!xml.contains("jdbc-connections")) { |
92 |
String[] servers = new String[0]; |
93 |
xml.putProperty("jdbc-connections", servers);
|
94 |
} |
95 |
|
96 |
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 |
*
|
112 |
* @return void
|
113 |
*/
|
114 |
private void initialize() { |
115 |
this.setSize(320, 332); |
116 |
this.setTitle(PluginServices.getText(this, "database_connection")); |
117 |
this.setContentPane(getJContentPane());
|
118 |
setPreferences(); |
119 |
jConnPanel.setDrivers(getDriverNames()); |
120 |
} |
121 |
|
122 |
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 |
|
140 |
} |
141 |
|
142 |
/**
|
143 |
* This method initializes jContentPane
|
144 |
*
|
145 |
* @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 |
|
154 |
} |
155 |
return jContentPane;
|
156 |
} |
157 |
|
158 |
/**
|
159 |
* This method initializes jPanel
|
160 |
*
|
161 |
* @return javax.swing.JPanel
|
162 |
*/
|
163 |
private ConnectionPanel getJConnPanel() {
|
164 |
if (jConnPanel == null) { |
165 |
jConnPanel = new ConnectionPanel();
|
166 |
} |
167 |
return jConnPanel;
|
168 |
} |
169 |
|
170 |
|
171 |
|
172 |
/**
|
173 |
* 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 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
181 |
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 |
connSettings = jConnPanel.getConnectionSettings(); |
187 |
dispose(); |
188 |
} |
189 |
}; |
190 |
|
191 |
ActionListener cancelAction = new java.awt.event.ActionListener() { |
192 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
193 |
connSettings = null;
|
194 |
dispose(); |
195 |
} |
196 |
}; |
197 |
jPanel1 = new AcceptCancelPanel(okAction, cancelAction);
|
198 |
|
199 |
|
200 |
} |
201 |
return jPanel1;
|
202 |
} |
203 |
|
204 |
|
205 |
public ConnectionSettings getConnSettings() {
|
206 |
return connSettings;
|
207 |
} |
208 |
|
209 |
} // @jve:decl-index=0:visual-constraint="10,10"
|