Revision 14006
branches/v10/extensions/extOracleSpatial/src/es/prodevelop/cit/gvsig/jdbc_spatial/SingleJDBCConnectionExtension.java | ||
---|---|---|
47 | 47 |
|
48 | 48 |
import com.iver.cit.gvsig.fmap.drivers.jdbc.utils.ConnectionWithParams; |
49 | 49 |
import com.iver.cit.gvsig.fmap.drivers.jdbc.utils.SingleJDBCConnectionManager; |
50 |
import com.iver.cit.gvsig.jdbc_spatial.gui.jdbcwizard.ConnectionSettings; |
|
50 | 51 |
|
51 | 52 |
import com.iver.utiles.NotExistInXMLEntity; |
52 | 53 |
import com.iver.utiles.XMLEntity; |
53 | 54 |
|
54 |
import es.prodevelop.cit.gvsig.jdbc_spatial.gui.jdbcwizard.ConnectionSettings; |
|
55 | 55 |
import es.prodevelop.cit.gvsig.jdbc_spatial.gui.jdbcwizard.JDBConnectionManagerDialog; |
56 | 56 |
|
57 | 57 |
import org.apache.log4j.Logger; |
branches/v10/extensions/extOracleSpatial/src/es/prodevelop/cit/gvsig/jdbc_spatial/gui/jdbcwizard/ConnectionSettings.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2006 Prodevelop and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* Prodevelop Integraci?n de Tecnolog?as SL |
|
34 |
* Conde Salvatierra de ?lava , 34-10 |
|
35 |
* 46004 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963 510 612 |
|
39 |
* +34 963 510 968 |
|
40 |
* gis@prodevelop.es |
|
41 |
* http://www.prodevelop.es |
|
42 |
*/ |
|
43 |
package es.prodevelop.cit.gvsig.jdbc_spatial.gui.jdbcwizard; |
|
44 |
|
|
45 |
import com.hardcode.driverManager.DriverLoadException; |
|
46 |
|
|
47 |
import com.iver.cit.gvsig.fmap.drivers.DefaultDBDriver; |
|
48 |
import com.iver.cit.gvsig.fmap.drivers.VectorialJDBCDriver; |
|
49 |
import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
|
50 |
|
|
51 |
|
|
52 |
/** |
|
53 |
* |
|
54 |
* Utility class. Keeps connection parameters. |
|
55 |
* |
|
56 |
* @author jldominguez |
|
57 |
* @author Fernando Gonz?lez Cort?s |
|
58 |
*/ |
|
59 |
public class ConnectionSettings { |
|
60 |
private String host; |
|
61 |
private String port; |
|
62 |
private String db; |
|
63 |
private String driver; |
|
64 |
private String user; |
|
65 |
private String name; |
|
66 |
private String passw = null; |
|
67 |
|
|
68 |
public String getDb() { |
|
69 |
return db; |
|
70 |
} |
|
71 |
|
|
72 |
public void setDb(String db) { |
|
73 |
this.db = db; |
|
74 |
} |
|
75 |
|
|
76 |
public String getDriver() { |
|
77 |
return driver; |
|
78 |
} |
|
79 |
|
|
80 |
public void setDriver(String driver) { |
|
81 |
this.driver = driver; |
|
82 |
} |
|
83 |
|
|
84 |
public String getHost() { |
|
85 |
return host; |
|
86 |
} |
|
87 |
|
|
88 |
public void setHost(String host) { |
|
89 |
this.host = host; |
|
90 |
} |
|
91 |
|
|
92 |
public String getPort() { |
|
93 |
return port; |
|
94 |
} |
|
95 |
|
|
96 |
public void setPort(String port) { |
|
97 |
this.port = port; |
|
98 |
} |
|
99 |
|
|
100 |
public String getUser() { |
|
101 |
return user; |
|
102 |
} |
|
103 |
|
|
104 |
public void setUser(String user) { |
|
105 |
this.user = user; |
|
106 |
} |
|
107 |
|
|
108 |
public void setName(String name) { |
|
109 |
this.name = name; |
|
110 |
} |
|
111 |
|
|
112 |
public String getName() { |
|
113 |
return name; |
|
114 |
} |
|
115 |
|
|
116 |
public String toString() { |
|
117 |
return host + "," + port + "," + db + "," + driver + "," + user + "," + |
|
118 |
name; |
|
119 |
} |
|
120 |
|
|
121 |
public void setFromString(String _str) throws Exception { |
|
122 |
String str = _str; |
|
123 |
if (str.endsWith(",")) str = str + " "; |
|
124 |
if (str.startsWith(",")) str = " " + str; |
|
125 |
|
|
126 |
String[] values = str.split(","); |
|
127 |
host = values[0]; |
|
128 |
port = values[1]; |
|
129 |
db = values[2]; |
|
130 |
driver = values[3]; |
|
131 |
user = values[4]; |
|
132 |
name = values[5]; |
|
133 |
|
|
134 |
if (values.length == 7) { |
|
135 |
passw = values[6]; |
|
136 |
} |
|
137 |
} |
|
138 |
|
|
139 |
public String getPassw() { |
|
140 |
return passw; |
|
141 |
} |
|
142 |
|
|
143 |
public void setPassw(String passw) { |
|
144 |
this.passw = passw; |
|
145 |
} |
|
146 |
|
|
147 |
public String getConnectionString() throws DriverLoadException { |
|
148 |
VectorialJDBCDriver vecDriver = (VectorialJDBCDriver) LayerFactory.getDM() |
|
149 |
.getDriver(getDriver()); |
|
150 |
|
|
151 |
if (vecDriver instanceof DefaultDBDriver) { |
|
152 |
return ((DefaultDBDriver) vecDriver).getConnectionString(getHost(), |
|
153 |
getPort(), getDb(), getUser(), getPassw()); |
|
154 |
} |
|
155 |
|
|
156 |
String connectionString = vecDriver.getConnectionStringBeginning() + |
|
157 |
"//" + getHost(); |
|
158 |
connectionString += (":" + getPort()); |
|
159 |
connectionString += ("/" + getDb()); |
|
160 |
|
|
161 |
return connectionString; |
|
162 |
} |
|
163 |
} |
branches/v10/extensions/extOracleSpatial/src/com/iver/cit/gvsig/jdbc_spatial/gui/jdbcwizard/ConnectionPanel.java | ||
---|---|---|
1 |
package com.iver.cit.gvsig.jdbc_spatial.gui.jdbcwizard; |
|
2 |
|
|
3 |
import java.awt.BorderLayout; |
|
4 |
import java.awt.FlowLayout; |
|
5 |
import java.awt.event.ActionEvent; |
|
6 |
import java.awt.event.ActionListener; |
|
7 |
import java.util.HashMap; |
|
8 |
import java.util.Iterator; |
|
9 |
|
|
10 |
import javax.swing.DefaultComboBoxModel; |
|
11 |
import javax.swing.JLabel; |
|
12 |
import javax.swing.JPanel; |
|
13 |
import javax.swing.JPasswordField; |
|
14 |
import javax.swing.JTextField; |
|
15 |
|
|
16 |
import com.hardcode.driverManager.DriverLoadException; |
|
17 |
import com.iver.andami.PluginServices; |
|
18 |
import com.iver.cit.gvsig.fmap.drivers.VectorialJDBCDriver; |
|
19 |
import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
|
20 |
import com.iver.utiles.NotExistInXMLEntity; |
|
21 |
import com.iver.utiles.XMLEntity; |
|
22 |
import com.iver.utiles.swing.JComboBox; |
|
23 |
import com.iver.utiles.swing.wizard.Step; |
|
24 |
import com.iver.utiles.swing.wizard.WizardControl; |
|
25 |
|
|
26 |
|
|
27 |
/** |
|
28 |
* DOCUMENT ME! |
|
29 |
* |
|
30 |
* @author Fernando Gonz?lez Cort?s |
|
31 |
*/ |
|
32 |
public class ConnectionPanel extends JPanel implements Step { |
|
33 |
private static String passw = null; |
|
34 |
|
|
35 |
private JPanel jPanelLabels = null; |
|
36 |
private JLabel jLabel = null; |
|
37 |
private JTextField txtHost = null; |
|
38 |
private JPanel jPanelTexts = null; |
|
39 |
private JTextField txtPort = null; |
|
40 |
private JLabel jLabel1 = null; |
|
41 |
private JLabel jLabel2 = null; |
|
42 |
private JTextField txtUser = null; |
|
43 |
private JLabel jLabel3 = null; |
|
44 |
private JPasswordField txtPassword = null; |
|
45 |
private JLabel jLabel4 = null; |
|
46 |
private JTextField txtBD = null; |
|
47 |
private JLabel jLabel5 = null; |
|
48 |
private JComboBox cmbDriver = null; |
|
49 |
private JLabel jLabel6 = null; |
|
50 |
private com.iver.utiles.swing.JComboBox cmbName = null; |
|
51 |
private HashMap cs = new HashMap(); |
|
52 |
|
|
53 |
private JPanel jPanel = null; |
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
/** |
|
58 |
* This is the default constructor |
|
59 |
*/ |
|
60 |
public ConnectionPanel() { |
|
61 |
super(); |
|
62 |
initialize(); |
|
63 |
} |
|
64 |
|
|
65 |
/** |
|
66 |
* This method initializes this |
|
67 |
*/ |
|
68 |
private void initialize() { |
|
69 |
this.setLayout(null); |
|
70 |
this.setSize(335, 240); |
|
71 |
this.add(getJPanel(), null); |
|
72 |
|
|
73 |
if (passw != null) |
|
74 |
txtPassword.setText(passw); |
|
75 |
|
|
76 |
} |
|
77 |
|
|
78 |
/** |
|
79 |
* This method initializes jPanel |
|
80 |
* |
|
81 |
* @return javax.swing.JPanel |
|
82 |
*/ |
|
83 |
private JPanel getJPanelLabels() { |
|
84 |
if (jPanelLabels == null) { |
|
85 |
FlowLayout flowLayout3 = new FlowLayout(); |
|
86 |
flowLayout3.setVgap(15); |
|
87 |
jLabel5 = new JLabel(); |
|
88 |
jLabel4 = new JLabel(); |
|
89 |
jLabel3 = new JLabel(); |
|
90 |
jLabel2 = new JLabel(); |
|
91 |
jLabel1 = new JLabel(); |
|
92 |
jLabel = new JLabel(); |
|
93 |
jPanelLabels = new JPanel(); |
|
94 |
jPanelLabels.setLayout(flowLayout3); |
|
95 |
jPanelLabels.setName("jPanelLabels"); |
|
96 |
jPanelLabels.setPreferredSize(new java.awt.Dimension(150,400)); |
|
97 |
jLabel.setText(PluginServices.getText(this, "host") + ":"); |
|
98 |
jLabel.setPreferredSize(new java.awt.Dimension(140,19)); |
|
99 |
jLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); |
|
100 |
jLabel.setName("jLabel"); |
|
101 |
jLabel1.setText(PluginServices.getText(this, "puerto")+":"); |
|
102 |
jLabel1.setPreferredSize(new java.awt.Dimension(140,19)); |
|
103 |
jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); |
|
104 |
jLabel1.setName("jLabel1"); |
|
105 |
jLabel2.setText(PluginServices.getText(this, "usuario")+":"); |
|
106 |
jLabel2.setName("jLabel2"); |
|
107 |
jLabel2.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT); |
|
108 |
jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); |
|
109 |
jLabel2.setPreferredSize(new java.awt.Dimension(140,19)); |
|
110 |
jLabel3.setText(PluginServices.getText(this, "password")+":"); |
|
111 |
jLabel3.setName("jLabel3"); |
|
112 |
jLabel3.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT); |
|
113 |
jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); |
|
114 |
jLabel3.setPreferredSize(new java.awt.Dimension(140,19)); |
|
115 |
jLabel4.setText(PluginServices.getText(this, "bd")+":"); |
|
116 |
jLabel4.setName("jLabel4"); |
|
117 |
jLabel4.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT); |
|
118 |
jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); |
|
119 |
jLabel4.setPreferredSize(new java.awt.Dimension(140,19)); |
|
120 |
jLabel5.setText(PluginServices.getText(this, "driver")+":"); |
|
121 |
jLabel5.setName("jLabel5"); |
|
122 |
jLabel5.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT); |
|
123 |
jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); |
|
124 |
jLabel5.setPreferredSize(new java.awt.Dimension(140,19)); |
|
125 |
jPanelLabels.add(getJLabel6(), null); |
|
126 |
jPanelLabels.add(jLabel, null); |
|
127 |
jPanelLabels.add(jLabel1, null); |
|
128 |
jPanelLabels.add(jLabel2, null); |
|
129 |
jPanelLabels.add(jLabel3, null); |
|
130 |
jPanelLabels.add(jLabel4, null); |
|
131 |
jPanelLabels.add(jLabel5, null); |
|
132 |
|
|
133 |
} |
|
134 |
|
|
135 |
return jPanelLabels; |
|
136 |
} |
|
137 |
|
|
138 |
/** |
|
139 |
* This method initializes txtHost |
|
140 |
* |
|
141 |
* @return javax.swing.JTextField |
|
142 |
*/ |
|
143 |
private JTextField getTxtHost() { |
|
144 |
if (txtHost == null) { |
|
145 |
txtHost = new JTextField(); |
|
146 |
txtHost.setPreferredSize(new java.awt.Dimension(170, 19)); |
|
147 |
txtHost.setName("txtHost"); |
|
148 |
} |
|
149 |
|
|
150 |
return txtHost; |
|
151 |
} |
|
152 |
|
|
153 |
/** |
|
154 |
* This method initializes jPanel1 |
|
155 |
* |
|
156 |
* @return javax.swing.JPanel |
|
157 |
*/ |
|
158 |
private JPanel getJPanelTexts() { |
|
159 |
if (jPanelTexts == null) { |
|
160 |
FlowLayout flowLayout2 = new FlowLayout(FlowLayout.LEFT); |
|
161 |
flowLayout2.setVgap(15); |
|
162 |
jPanelTexts = new JPanel(); |
|
163 |
jPanelTexts.setLayout(flowLayout2); |
|
164 |
jPanelTexts.setPreferredSize(new java.awt.Dimension(200,400)); |
|
165 |
|
|
166 |
jPanelTexts.setName("jPanelText"); |
|
167 |
jPanelTexts.add(getCmbName(), null); |
|
168 |
jPanelTexts.add(getTxtHost(), null); |
|
169 |
jPanelTexts.add(getTxtPort(), null); |
|
170 |
jPanelTexts.add(getTxtUser(), null); |
|
171 |
jPanelTexts.add(getTxtPassword(), null); |
|
172 |
jPanelTexts.add(getTxtBD(), null); |
|
173 |
jPanelTexts.add(getCmbDriver(), null); |
|
174 |
} |
|
175 |
|
|
176 |
return jPanelTexts; |
|
177 |
} |
|
178 |
|
|
179 |
/** |
|
180 |
* This method initializes txtPort |
|
181 |
* |
|
182 |
* @return javax.swing.JTextField |
|
183 |
*/ |
|
184 |
private JTextField getTxtPort() { |
|
185 |
if (txtPort == null) { |
|
186 |
txtPort = new JTextField(); |
|
187 |
txtPort.setPreferredSize(new java.awt.Dimension(40, 19)); |
|
188 |
txtPort.setName("txtPort"); |
|
189 |
txtPort.setText("3306"); |
|
190 |
txtPort.setHorizontalAlignment(javax.swing.JTextField.LEFT); |
|
191 |
} |
|
192 |
|
|
193 |
return txtPort; |
|
194 |
} |
|
195 |
|
|
196 |
/** |
|
197 |
* This method initializes txtUser |
|
198 |
* |
|
199 |
* @return javax.swing.JTextField |
|
200 |
*/ |
|
201 |
private JTextField getTxtUser() { |
|
202 |
if (txtUser == null) { |
|
203 |
txtUser = new JTextField(); |
|
204 |
txtUser.setPreferredSize(new java.awt.Dimension(170, 19)); |
|
205 |
txtUser.setName("txtUser"); |
|
206 |
} |
|
207 |
|
|
208 |
return txtUser; |
|
209 |
} |
|
210 |
|
|
211 |
/** |
|
212 |
* This method initializes txtPassword |
|
213 |
* |
|
214 |
* @return javax.swing.JTextField |
|
215 |
*/ |
|
216 |
private JPasswordField getTxtPassword() { |
|
217 |
if (txtPassword == null) { |
|
218 |
txtPassword = new JPasswordField(); |
|
219 |
txtPassword.setPreferredSize(new java.awt.Dimension(170, 19)); |
|
220 |
txtPassword.setName("txtPassword"); |
|
221 |
} |
|
222 |
|
|
223 |
return txtPassword; |
|
224 |
} |
|
225 |
|
|
226 |
/** |
|
227 |
* This method initializes txtBD |
|
228 |
* |
|
229 |
* @return javax.swing.JTextField |
|
230 |
*/ |
|
231 |
private JTextField getTxtBD() { |
|
232 |
if (txtBD == null) { |
|
233 |
txtBD = new JTextField(); |
|
234 |
txtBD.setPreferredSize(new java.awt.Dimension(170, 19)); |
|
235 |
txtBD.setName("txtBD"); |
|
236 |
} |
|
237 |
|
|
238 |
return txtBD; |
|
239 |
} |
|
240 |
|
|
241 |
/** |
|
242 |
* DOCUMENT ME! |
|
243 |
* |
|
244 |
* @return DOCUMENT ME! |
|
245 |
*/ |
|
246 |
public String getHost() { |
|
247 |
return getTxtHost().getText(); |
|
248 |
} |
|
249 |
|
|
250 |
/** |
|
251 |
* DOCUMENT ME! |
|
252 |
* |
|
253 |
* @return DOCUMENT ME! |
|
254 |
*/ |
|
255 |
public String getPort() { |
|
256 |
return getTxtPort().getText(); |
|
257 |
} |
|
258 |
|
|
259 |
/** |
|
260 |
* DOCUMENT ME! |
|
261 |
* |
|
262 |
* @return DOCUMENT ME! |
|
263 |
*/ |
|
264 |
public String getUser() { |
|
265 |
return getTxtUser().getText(); |
|
266 |
} |
|
267 |
|
|
268 |
/** |
|
269 |
* DOCUMENT ME! |
|
270 |
* |
|
271 |
* @return DOCUMENT ME! |
|
272 |
*/ |
|
273 |
public String getSettingsName() { |
|
274 |
return getCmbName().getSelectedItem().toString(); |
|
275 |
} |
|
276 |
|
|
277 |
/** |
|
278 |
* DOCUMENT ME! |
|
279 |
* |
|
280 |
* @return DOCUMENT ME! |
|
281 |
*/ |
|
282 |
public String getPassword() { |
|
283 |
passw = String.copyValueOf(getTxtPassword().getPassword()); |
|
284 |
return passw; |
|
285 |
} |
|
286 |
|
|
287 |
/** |
|
288 |
* DOCUMENT ME! |
|
289 |
* |
|
290 |
* @return DOCUMENT ME! |
|
291 |
*/ |
|
292 |
public String getDBName() { |
|
293 |
return getTxtBD().getText(); |
|
294 |
} |
|
295 |
|
|
296 |
/** |
|
297 |
* DOCUMENT ME! |
|
298 |
* |
|
299 |
* @param drivers DOCUMENT ME! |
|
300 |
*/ |
|
301 |
public void setDrivers(String[] drivers) { |
|
302 |
DefaultComboBoxModel model = new DefaultComboBoxModel(); |
|
303 |
|
|
304 |
for (int i = 0; i < drivers.length; i++) { |
|
305 |
model.addElement(drivers[i]); |
|
306 |
} |
|
307 |
|
|
308 |
getCmbDriver().setModel(model); |
|
309 |
|
|
310 |
//Para que refresque el textbox del puerto |
|
311 |
if (drivers.length > 0) |
|
312 |
cmbDriver.setSelectedIndex(0); |
|
313 |
|
|
314 |
} |
|
315 |
|
|
316 |
|
|
317 |
/** |
|
318 |
* @return ConnectionSettings based on values in this panel |
|
319 |
*/ |
|
320 |
public ConnectionSettings getConnectionSettings() |
|
321 |
{ |
|
322 |
ConnectionSettings cs = new ConnectionSettings(); |
|
323 |
cs.setDb(getDBName()); |
|
324 |
cs.setDriver(getDriver()); |
|
325 |
cs.setHost(getHost()); |
|
326 |
cs.setPort(getPort()); |
|
327 |
cs.setUser(getUser()); |
|
328 |
cs.setPassw(getPassword()); |
|
329 |
cs.setName(getSettingsName()); |
|
330 |
return cs; |
|
331 |
} |
|
332 |
|
|
333 |
/** |
|
334 |
* Makes persistent the connection settings of this panel. |
|
335 |
*/ |
|
336 |
public void saveConnectionSettings() |
|
337 |
{ |
|
338 |
ConnectionSettings cs = new ConnectionSettings(); |
|
339 |
cs.setDb(getDBName()); |
|
340 |
cs.setDriver(getDriver()); |
|
341 |
cs.setHost(getHost()); |
|
342 |
cs.setPort(getPort()); |
|
343 |
cs.setUser(getUser()); |
|
344 |
cs.setPassw(getPassword()); |
|
345 |
cs.setName(getSettingsName()); |
|
346 |
|
|
347 |
PluginServices ps = PluginServices.getPluginServices(this); |
|
348 |
XMLEntity xml = ps.getPersistentXML(); |
|
349 |
|
|
350 |
try { |
|
351 |
String[] connections = xml.getStringArrayProperty("jdbc-connections"); |
|
352 |
String[] newConnections = new String[connections.length + 1]; |
|
353 |
System.arraycopy(connections, 0, newConnections, 0, connections.length); |
|
354 |
newConnections[connections.length] = cs.toString(); |
|
355 |
xml.putProperty("jdbc-connections", newConnections); |
|
356 |
} catch (NotExistInXMLEntity e) { |
|
357 |
xml.putProperty("jdbc-connections", new String[] { cs.toString() }); |
|
358 |
} |
|
359 |
|
|
360 |
|
|
361 |
} |
|
362 |
|
|
363 |
/** |
|
364 |
* DOCUMENT ME! |
|
365 |
* |
|
366 |
* @return DOCUMENT ME! |
|
367 |
*/ |
|
368 |
public String getDriver() { |
|
369 |
return cmbDriver.getSelectedItem().toString(); |
|
370 |
} |
|
371 |
|
|
372 |
/** |
|
373 |
* DOCUMENT ME! |
|
374 |
* |
|
375 |
* @param cs DOCUMENT ME! |
|
376 |
*/ |
|
377 |
public void setSettings(HashMap cs) { |
|
378 |
this.cs = cs; |
|
379 |
((DefaultComboBoxModel) getCmbName().getModel()).removeAllElements(); |
|
380 |
|
|
381 |
Iterator i = cs.keySet().iterator(); |
|
382 |
|
|
383 |
while (i.hasNext()) { |
|
384 |
String item = (String) i.next(); |
|
385 |
((DefaultComboBoxModel) getCmbName().getModel()).addElement(item); |
|
386 |
} |
|
387 |
} |
|
388 |
|
|
389 |
/** |
|
390 |
* @see com.iver.utiles.swing.wizard.Step#init(com.iver.utiles.swing.wizard.WizardControl) |
|
391 |
*/ |
|
392 |
public void init(WizardControl w) { |
|
393 |
} |
|
394 |
|
|
395 |
/** |
|
396 |
* This method initializes cmbDriver |
|
397 |
* |
|
398 |
* @return com.iver.utiles.swing.JComboBox |
|
399 |
*/ |
|
400 |
private JComboBox getCmbDriver() { |
|
401 |
if (cmbDriver == null) { |
|
402 |
cmbDriver = new JComboBox(); |
|
403 |
cmbDriver.setPreferredSize(new java.awt.Dimension(170, 19)); |
|
404 |
cmbDriver.setName("cmbDriver"); |
|
405 |
cmbDriver.addActionListener(new ActionListener() { |
|
406 |
public void actionPerformed(ActionEvent e) { |
|
407 |
String driverName = cmbDriver.getSelectedItem().toString(); |
|
408 |
VectorialJDBCDriver driver; |
|
409 |
try { |
|
410 |
driver = (VectorialJDBCDriver) LayerFactory.getDM().getDriver(driverName); |
|
411 |
getTxtPort().setText(Integer.toString(driver.getDefaultPort())); |
|
412 |
} catch (DriverLoadException e1) { |
|
413 |
getTxtPort().setText(""); |
|
414 |
} |
|
415 |
} |
|
416 |
}); |
|
417 |
} |
|
418 |
|
|
419 |
return cmbDriver; |
|
420 |
} |
|
421 |
|
|
422 |
/** |
|
423 |
* DOCUMENT ME! |
|
424 |
* |
|
425 |
* @return |
|
426 |
*/ |
|
427 |
public boolean done() { |
|
428 |
return (getTxtBD().getText().length() > 0) && |
|
429 |
(getTxtHost().getText().length() > 0) && |
|
430 |
(getCmbName().getSelectedItem() != null) && |
|
431 |
(getCmbName().getSelectedItem().toString().length() > 0); |
|
432 |
} |
|
433 |
|
|
434 |
/** |
|
435 |
* This method initializes jLabel6 |
|
436 |
* |
|
437 |
* @return javax.swing.JLabel |
|
438 |
*/ |
|
439 |
private JLabel getJLabel6() { |
|
440 |
if (jLabel6 == null) { |
|
441 |
jLabel6 = new JLabel(); |
|
442 |
jLabel6.setText(PluginServices.getText(this, "connection_name")+":"); |
|
443 |
jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); |
|
444 |
jLabel6.setPreferredSize(new java.awt.Dimension(140,19)); |
|
445 |
} |
|
446 |
|
|
447 |
return jLabel6; |
|
448 |
} |
|
449 |
|
|
450 |
/** |
|
451 |
* This method initializes jComboBox |
|
452 |
* |
|
453 |
* @return com.iver.utiles.swing.JComboBox |
|
454 |
*/ |
|
455 |
private com.iver.utiles.swing.JComboBox getCmbName() { |
|
456 |
if (cmbName == null) { |
|
457 |
cmbName = new com.iver.utiles.swing.JComboBox(); |
|
458 |
cmbName.setEditable(true); |
|
459 |
cmbName.setPreferredSize(new java.awt.Dimension(170, 19)); |
|
460 |
cmbName.setModel(new DefaultComboBoxModel()); |
|
461 |
cmbName.addActionListener(new ActionListener() { |
|
462 |
public void actionPerformed(ActionEvent e) { |
|
463 |
Object item = cmbName.getSelectedItem(); |
|
464 |
|
|
465 |
if (item == null) { |
|
466 |
return; |
|
467 |
} |
|
468 |
|
|
469 |
ConnectionSettings c = (ConnectionSettings) cs.get(item.toString()); |
|
470 |
|
|
471 |
if (c != null) { |
|
472 |
getTxtHost().setText(c.getHost()); |
|
473 |
getTxtPort().setText(c.getPort()); |
|
474 |
getTxtBD().setText(c.getDb()); |
|
475 |
getTxtUser().setText(c.getUser()); |
|
476 |
if (c.getPassw() != null) |
|
477 |
getTxtPassword().setText(c.getPassw()); |
|
478 |
getCmbDriver().setSelectedItem(c.getDriver()); |
|
479 |
} |
|
480 |
} |
|
481 |
}); |
|
482 |
} |
|
483 |
|
|
484 |
return cmbName; |
|
485 |
} |
|
486 |
|
|
487 |
/** |
|
488 |
* This method initializes jPanel |
|
489 |
* |
|
490 |
* @return javax.swing.JPanel |
|
491 |
*/ |
|
492 |
private JPanel getJPanel() { |
|
493 |
if (jPanel == null) { |
|
494 |
jPanel = new JPanel(); |
|
495 |
jPanel.setLayout(new BorderLayout()); |
|
496 |
jPanel.setBounds(0, 0, 400, 240); |
|
497 |
jPanel.add(getJPanelLabels(), java.awt.BorderLayout.WEST); |
|
498 |
jPanel.add(getJPanelTexts(), java.awt.BorderLayout.EAST); |
|
499 |
} |
|
500 |
return jPanel; |
|
501 |
} |
|
502 |
} // @jve:decl-index=0:visual-constraint="7,3" |
|
0 | 503 |
branches/v10/extensions/extOracleSpatial/src/com/iver/cit/gvsig/jdbc_spatial/gui/jdbcwizard/ConnectionSettings.java | ||
---|---|---|
1 |
package com.iver.cit.gvsig.jdbc_spatial.gui.jdbcwizard; |
|
2 |
|
|
3 |
import com.hardcode.driverManager.DriverLoadException; |
|
4 |
import com.iver.cit.gvsig.fmap.drivers.DefaultDBDriver; |
|
5 |
import com.iver.cit.gvsig.fmap.drivers.VectorialJDBCDriver; |
|
6 |
import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
|
7 |
|
|
8 |
/** |
|
9 |
* |
|
10 |
* Utility class. Keeps connection parameters. |
|
11 |
* |
|
12 |
* @author Fernando Gonz?lez Cort?s |
|
13 |
*/ |
|
14 |
public class ConnectionSettings { |
|
15 |
private String host; |
|
16 |
private String port; |
|
17 |
private String db; |
|
18 |
private String driver; |
|
19 |
private String user; |
|
20 |
private String name; |
|
21 |
private String passw = null; |
|
22 |
|
|
23 |
public String getDb() { |
|
24 |
return db; |
|
25 |
} |
|
26 |
|
|
27 |
public void setDb(String db) { |
|
28 |
this.db = db; |
|
29 |
} |
|
30 |
|
|
31 |
public String getDriver() { |
|
32 |
return driver; |
|
33 |
} |
|
34 |
|
|
35 |
public void setDriver(String driver) { |
|
36 |
this.driver = driver; |
|
37 |
} |
|
38 |
|
|
39 |
public String getHost() { |
|
40 |
return host; |
|
41 |
} |
|
42 |
|
|
43 |
public void setHost(String host) { |
|
44 |
this.host = host; |
|
45 |
} |
|
46 |
|
|
47 |
public String getPort() { |
|
48 |
return port; |
|
49 |
} |
|
50 |
|
|
51 |
public void setPort(String port) { |
|
52 |
this.port = port; |
|
53 |
} |
|
54 |
|
|
55 |
public String getUser() { |
|
56 |
return user; |
|
57 |
} |
|
58 |
|
|
59 |
public void setUser(String user) { |
|
60 |
this.user = user; |
|
61 |
} |
|
62 |
|
|
63 |
public void setName(String name) { |
|
64 |
this.name = name; |
|
65 |
} |
|
66 |
|
|
67 |
public String getName() { |
|
68 |
return name; |
|
69 |
} |
|
70 |
|
|
71 |
public String toString() { |
|
72 |
return host + "," + port + "," + db + "," + driver + "," + user + "," + |
|
73 |
name; |
|
74 |
} |
|
75 |
|
|
76 |
public void setFromString(String _str) { |
|
77 |
String str = _str; |
|
78 |
if (str.endsWith(",")) str = str + " "; |
|
79 |
if (str.startsWith(",")) str = " " + str; |
|
80 |
|
|
81 |
String[] values = str.split(","); |
|
82 |
host = values[0]; |
|
83 |
port = values[1]; |
|
84 |
db = values[2]; |
|
85 |
driver = values[3]; |
|
86 |
user = values[4]; |
|
87 |
name = values[5]; |
|
88 |
|
|
89 |
if (values.length == 7) { |
|
90 |
passw = values[6]; |
|
91 |
} |
|
92 |
} |
|
93 |
|
|
94 |
public String getPassw() { |
|
95 |
return passw; |
|
96 |
} |
|
97 |
|
|
98 |
public void setPassw(String passw) { |
|
99 |
this.passw = passw; |
|
100 |
} |
|
101 |
|
|
102 |
public String getConnectionString() throws DriverLoadException { |
|
103 |
VectorialJDBCDriver vecDriver = (VectorialJDBCDriver) LayerFactory.getDM() |
|
104 |
.getDriver(getDriver()); |
|
105 |
|
|
106 |
if (vecDriver instanceof DefaultDBDriver) { |
|
107 |
return ((DefaultDBDriver) vecDriver).getConnectionString(getHost(), |
|
108 |
getPort(), getDb(), getUser(), getPassw()); |
|
109 |
} |
|
110 |
|
|
111 |
String connectionString = vecDriver.getConnectionStringBeginning() + |
|
112 |
"//" + getHost(); |
|
113 |
connectionString += (":" + getPort()); |
|
114 |
connectionString += ("/" + getDb()); |
|
115 |
|
|
116 |
return connectionString; |
|
117 |
} |
|
118 |
} |
|
0 | 119 |
branches/v10/extensions/extOracleSpatial/src/com/iver/cit/gvsig/jdbc_spatial/DlgConnection.java | ||
---|---|---|
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" |
|
0 | 210 |
Also available in: Unified diff