root / branches / v2_0_0_prep / applications / appgvSIG / src / com / prodevelop / cit / gvsig / vectorialdb / wizard / VectorialDBConnectionParamsDialog.java @ 24759
History | View | Annotate | Download (18.1 KB)
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 com.prodevelop.cit.gvsig.vectorialdb.wizard; |
44 |
|
45 |
import java.awt.Color; |
46 |
import java.awt.event.ActionEvent; |
47 |
import java.awt.event.ActionListener; |
48 |
import java.awt.event.KeyEvent; |
49 |
import java.awt.event.KeyListener; |
50 |
import java.util.List; |
51 |
|
52 |
import javax.swing.JButton; |
53 |
import javax.swing.JCheckBox; |
54 |
import javax.swing.JComboBox; |
55 |
import javax.swing.JLabel; |
56 |
import javax.swing.JPanel; |
57 |
import javax.swing.JPasswordField; |
58 |
import javax.swing.JTextField; |
59 |
|
60 |
import org.apache.log4j.Logger; |
61 |
import org.gvsig.fmap.dal.DALLocator; |
62 |
import org.gvsig.fmap.dal.DataExplorerParameters; |
63 |
import org.gvsig.fmap.dal.DataManager; |
64 |
import org.gvsig.fmap.dal.exception.InitializeException; |
65 |
import org.gvsig.fmap.data.feature.db.DBExplorerParameters; |
66 |
|
67 |
import com.iver.andami.PluginServices; |
68 |
import com.iver.andami.messages.NotificationManager; |
69 |
import com.iver.andami.ui.mdiManager.IWindow; |
70 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
71 |
|
72 |
|
73 |
/**
|
74 |
* Lets the user input the connection parameters.
|
75 |
*
|
76 |
* @author jldominguez
|
77 |
*
|
78 |
*/
|
79 |
public class VectorialDBConnectionParamsDialog extends JPanel implements IWindow, |
80 |
ActionListener, KeyListener { |
81 |
private static Logger logger = Logger.getLogger(VectorialDBConnectionParamsDialog.class.getName()); |
82 |
private WindowInfo winfo = new WindowInfo(8); // MODAL only |
83 |
private JButton cancelButton = null; |
84 |
private JButton okButton = null; |
85 |
private JPanel paramsPanel = null; |
86 |
private JComboBox driverComboBox = null; |
87 |
private JTextField portTextField = null; |
88 |
private JTextField dbTextField = null; |
89 |
private JTextField userTextField = null; |
90 |
private JPasswordField passwordField = null; |
91 |
private JLabel driverLabel = null; |
92 |
private JLabel portLabel = null; |
93 |
private JLabel dbLabel = null; |
94 |
private JLabel dbLabelWarning = null; |
95 |
private JLabel userLabel = null; |
96 |
private JLabel pwLabel = null; |
97 |
private boolean okPressed = false; |
98 |
private JTextField urlTextField = null; |
99 |
private JLabel urlLabel = null; |
100 |
private JCheckBox connectedCheckBox = null; |
101 |
private JLabel connectedLabel = null; |
102 |
private JLabel connNameLabel = null; |
103 |
private JTextField connNameTextField = null; |
104 |
|
105 |
/**
|
106 |
* This method initializes
|
107 |
*
|
108 |
*/
|
109 |
public VectorialDBConnectionParamsDialog() {
|
110 |
super();
|
111 |
initialize(); |
112 |
} |
113 |
|
114 |
public void showDialog() { |
115 |
PluginServices.getMDIManager().addWindow(this);
|
116 |
} |
117 |
|
118 |
/**
|
119 |
* This method initializes this
|
120 |
*
|
121 |
*/
|
122 |
private void initialize() { |
123 |
winfo.setWidth(370);
|
124 |
winfo.setHeight(317 - 25); |
125 |
winfo.setTitle(PluginServices.getText(this, "connection_parameters")); |
126 |
|
127 |
this.setSize(new java.awt.Dimension(360, 329)); |
128 |
this.setLayout(null); |
129 |
this.add(getCancelButton(), null); |
130 |
this.add(getOkButton(), null); |
131 |
this.add(getParamsPanel(), null); |
132 |
} |
133 |
|
134 |
public WindowInfo getWindowInfo() {
|
135 |
return winfo;
|
136 |
} |
137 |
|
138 |
/**
|
139 |
* This method initializes cancelButton
|
140 |
*
|
141 |
* @return javax.swing.JButton
|
142 |
*/
|
143 |
private JButton getCancelButton() { |
144 |
if (cancelButton == null) { |
145 |
cancelButton = new JButton(); |
146 |
cancelButton.setText(PluginServices.getText(this, "cancel")); |
147 |
cancelButton.addActionListener(this);
|
148 |
cancelButton.setBounds(new java.awt.Rectangle(185, 292, 106, 26)); |
149 |
} |
150 |
|
151 |
return cancelButton;
|
152 |
} |
153 |
|
154 |
/**
|
155 |
* This method initializes okButton
|
156 |
*
|
157 |
* @return javax.swing.JButton
|
158 |
*/
|
159 |
private JButton getOkButton() { |
160 |
if (okButton == null) { |
161 |
okButton = new JButton(); |
162 |
okButton.setText(PluginServices.getText(this, "ok")); |
163 |
okButton.addActionListener(this);
|
164 |
okButton.setBounds(new java.awt.Rectangle(70, 292, 106, 26)); |
165 |
} |
166 |
|
167 |
return okButton;
|
168 |
} |
169 |
|
170 |
/**
|
171 |
* This method initializes paramsPanel
|
172 |
*
|
173 |
* @return javax.swing.JPanel
|
174 |
*/
|
175 |
private JPanel getParamsPanel() { |
176 |
if (paramsPanel == null) { |
177 |
connNameLabel = new JLabel(); |
178 |
connNameLabel.setBounds(new java.awt.Rectangle(10, 30, 141, 21)); |
179 |
connNameLabel.setText(PluginServices.getText(this, "connection_name") + |
180 |
":");
|
181 |
connectedLabel = new JLabel(); |
182 |
connectedLabel.setBounds(new java.awt.Rectangle(10, 247, 141, 21)); |
183 |
connectedLabel.setText(PluginServices.getText(this, "connected") + |
184 |
":");
|
185 |
urlLabel = new JLabel(); |
186 |
urlLabel.setBounds(new java.awt.Rectangle(10, 80, 141, 21)); |
187 |
urlLabel.setText(PluginServices.getText(this, "server_url") + ":"); |
188 |
pwLabel = new JLabel(); |
189 |
pwLabel.setBounds(new java.awt.Rectangle(10, 222, 141, 21)); |
190 |
pwLabel.setText(PluginServices.getText(this, "password") + ":"); |
191 |
userLabel = new JLabel(); |
192 |
userLabel.setBounds(new java.awt.Rectangle(10, 197, 141, 21)); |
193 |
userLabel.setText(PluginServices.getText(this, "user") + ":"); |
194 |
dbLabel = new JLabel(); |
195 |
dbLabel.setBounds(new java.awt.Rectangle(10, 130, 141, 21)); |
196 |
dbLabel.setText(PluginServices.getText(this, "database_name") + |
197 |
":");
|
198 |
dbLabelWarning = new JLabel(); |
199 |
dbLabelWarning.setBounds(new java.awt.Rectangle(10, 155, 310, 41)); |
200 |
dbLabelWarning.setText(PluginServices.getText(this, "warning_you_must_input_the_exact_name_this_difference_between_capital_letters_and_small_letters") |
201 |
); |
202 |
|
203 |
portLabel = new JLabel(); |
204 |
portLabel.setBounds(new java.awt.Rectangle(10, 105, 141, 21)); |
205 |
portLabel.setText(PluginServices.getText(this, "port") + ":"); |
206 |
driverLabel = new JLabel(); |
207 |
driverLabel.setBounds(new java.awt.Rectangle(10, 55, 141, 21)); |
208 |
driverLabel.setText(PluginServices.getText(this, "driver") + ":"); |
209 |
paramsPanel = new JPanel(); |
210 |
paramsPanel.setBounds(new java.awt.Rectangle(10, 10, 336, 273)); |
211 |
paramsPanel.setBorder(javax.swing.BorderFactory.createTitledBorder( |
212 |
null, PluginServices.getText(this, "connection_params"), |
213 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
214 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
215 |
paramsPanel.setLayout(null);
|
216 |
paramsPanel.add(getPortTextField(), null);
|
217 |
paramsPanel.add(getDriverComboBox(), null);
|
218 |
paramsPanel.add(getDbTextField(), null);
|
219 |
paramsPanel.add(getUserTextField(), null);
|
220 |
paramsPanel.add(getPasswordField(), null);
|
221 |
paramsPanel.add(driverLabel, null);
|
222 |
paramsPanel.add(portLabel, null);
|
223 |
paramsPanel.add(dbLabel, null);
|
224 |
paramsPanel.add(dbLabelWarning, null);
|
225 |
paramsPanel.add(userLabel, null);
|
226 |
paramsPanel.add(pwLabel, null);
|
227 |
paramsPanel.add(getUrlTextArea(), null);
|
228 |
paramsPanel.add(urlLabel, null);
|
229 |
paramsPanel.add(getConnectedCheckBox(), null);
|
230 |
paramsPanel.add(connectedLabel, null);
|
231 |
paramsPanel.add(connNameLabel, null);
|
232 |
paramsPanel.add(getConnNameTextField(), null);
|
233 |
} |
234 |
|
235 |
return paramsPanel;
|
236 |
} |
237 |
|
238 |
/**
|
239 |
* This method initializes driverComboBox
|
240 |
*
|
241 |
* @return javax.swing.JComboBox
|
242 |
*/
|
243 |
private JComboBox getDriverComboBox() { |
244 |
if (driverComboBox == null) { |
245 |
driverComboBox = new JComboBox(); |
246 |
driverComboBox.addActionListener(this);
|
247 |
DataManager dm = DALLocator.getDataManager(); |
248 |
List drvName = dm.getExplorerProviders();
|
249 |
DataExplorerParameters params; |
250 |
for (int i = 0; i < drvName.length; i++){ |
251 |
try {
|
252 |
params = dm.createDataExplorerParameters(drvName[i]); |
253 |
} catch (InitializeException e) {
|
254 |
NotificationManager.addWarning(PluginServices.getText(null,
|
255 |
"DataExplorer_parameters_error")
|
256 |
+ ": " + drvName[i], e);
|
257 |
continue;
|
258 |
} |
259 |
if (params instanceof DBExplorerParameters) { |
260 |
DBExplorerParameters dbParams = (DBExplorerParameters) params; |
261 |
driverComboBox.addItem(new DriverComboBoxItem(dbParams));
|
262 |
} |
263 |
|
264 |
|
265 |
} |
266 |
|
267 |
|
268 |
driverComboBox.setBounds(new java.awt.Rectangle(155, 55, 166, 21)); |
269 |
|
270 |
} |
271 |
|
272 |
return driverComboBox;
|
273 |
} |
274 |
|
275 |
private class DriverComboBoxItem { |
276 |
private DBExplorerParameters params;
|
277 |
|
278 |
public DriverComboBoxItem(DBExplorerParameters dbParams) {
|
279 |
this.params = dbParams;
|
280 |
} |
281 |
|
282 |
public String toString() { |
283 |
return params.getDescription();
|
284 |
} |
285 |
} |
286 |
|
287 |
/**
|
288 |
* This method initializes portTextField
|
289 |
*
|
290 |
* @return javax.swing.JTextField
|
291 |
*/
|
292 |
private JTextField getPortTextField() { |
293 |
if (portTextField == null) { |
294 |
portTextField = new JTextField(); |
295 |
portTextField.addKeyListener(this);
|
296 |
portTextField.setBounds(new java.awt.Rectangle(155, 105, 166, 21)); |
297 |
} |
298 |
|
299 |
return portTextField;
|
300 |
} |
301 |
|
302 |
/**
|
303 |
* This method initializes dbTextField
|
304 |
*
|
305 |
* @return javax.swing.JTextField
|
306 |
*/
|
307 |
private JTextField getDbTextField() { |
308 |
if (dbTextField == null) { |
309 |
dbTextField = new JTextField(); |
310 |
dbTextField.addKeyListener(this);
|
311 |
dbTextField.setBounds(new java.awt.Rectangle(155, 130, 166, 21)); |
312 |
} |
313 |
|
314 |
return dbTextField;
|
315 |
} |
316 |
|
317 |
/**
|
318 |
* This method initializes userTextField
|
319 |
*
|
320 |
* @return javax.swing.JTextField
|
321 |
*/
|
322 |
private JTextField getUserTextField() { |
323 |
if (userTextField == null) { |
324 |
userTextField = new JTextField(); |
325 |
userTextField.addKeyListener(this);
|
326 |
userTextField.setBounds(new java.awt.Rectangle(155, 197, 166, 21)); |
327 |
} |
328 |
|
329 |
return userTextField;
|
330 |
} |
331 |
|
332 |
/**
|
333 |
* This method initializes passwordField
|
334 |
*
|
335 |
* @return javax.swing.JPasswordField
|
336 |
*/
|
337 |
private JPasswordField getPasswordField() { |
338 |
if (passwordField == null) { |
339 |
passwordField = new JPasswordField(); |
340 |
passwordField.addKeyListener(this);
|
341 |
passwordField.setBounds(new java.awt.Rectangle(155, 222, 166, 21)); |
342 |
} |
343 |
|
344 |
return passwordField;
|
345 |
} |
346 |
|
347 |
// private String[] getDriverNames() {
|
348 |
// Class[] classes = new Class[] { IVectorialDatabaseDriver.class };
|
349 |
//
|
350 |
// ArrayList ret = new ArrayList();
|
351 |
// String[] driverNames = LayerFactory.getDM().getDriverNames();
|
352 |
//
|
353 |
// for (int i = 0; i < driverNames.length; i++) {
|
354 |
// for (int j = 0; j < classes.length; j++) {
|
355 |
// if (LayerFactory.getDM().isA(driverNames[i], classes[j])) {
|
356 |
// ret.add(driverNames[i]);
|
357 |
// }
|
358 |
// }
|
359 |
// }
|
360 |
//
|
361 |
// return (String[]) ret.toArray(new String[0]);
|
362 |
// }
|
363 |
|
364 |
public void actionPerformed(ActionEvent arg0) { |
365 |
Object src = arg0.getSource();
|
366 |
|
367 |
if (src == connectedCheckBox) {
|
368 |
if (connectedCheckBox.isSelected()) {
|
369 |
passwordField.setEnabled(true);
|
370 |
passwordField.setBackground(Color.WHITE);
|
371 |
} |
372 |
else {
|
373 |
passwordField.setText("");
|
374 |
passwordField.setEnabled(false);
|
375 |
passwordField.setBackground(Color.LIGHT_GRAY);
|
376 |
} |
377 |
} |
378 |
|
379 |
if (src == okButton) {
|
380 |
okPressed = true;
|
381 |
PluginServices.getMDIManager().closeWindow(this);
|
382 |
|
383 |
return;
|
384 |
} |
385 |
|
386 |
if (src == cancelButton) {
|
387 |
okPressed = false;
|
388 |
PluginServices.getMDIManager().closeWindow(this);
|
389 |
|
390 |
return;
|
391 |
} |
392 |
|
393 |
if (src == driverComboBox) {
|
394 |
DBExplorerParameters params = ((DriverComboBoxItem) driverComboBox |
395 |
.getSelectedItem()).params; |
396 |
|
397 |
// try {
|
398 |
// DataManager dm=DataManager.getManager();
|
399 |
// featureStore = (FeatureStore) dm.createDataStore()LayerFactory.getDM()
|
400 |
// .getDriver(driverName);
|
401 |
portTextField.setText(params.getPort()); |
402 |
// }
|
403 |
// catch (DriverLoadException e1) {
|
404 |
// portTextField.setText("");
|
405 |
// }
|
406 |
|
407 |
return;
|
408 |
} |
409 |
} |
410 |
|
411 |
public boolean isOkPressed() { |
412 |
return okPressed;
|
413 |
} |
414 |
|
415 |
public boolean hasToBeConnected() { |
416 |
return connectedCheckBox.isSelected();
|
417 |
} |
418 |
|
419 |
public String getConnectionDriverName() { |
420 |
return ((DriverComboBoxItem) driverComboBox.getSelectedItem()).params
|
421 |
.getDataExplorerName(); |
422 |
} |
423 |
|
424 |
public String getConnectionServerUrl() { |
425 |
return urlTextField.getText();
|
426 |
} |
427 |
|
428 |
public String getConnectionPort() { |
429 |
return portTextField.getText();
|
430 |
} |
431 |
|
432 |
public String getConnectionDBName() { |
433 |
return dbTextField.getText();
|
434 |
} |
435 |
|
436 |
public String getConnectionUser() { |
437 |
return userTextField.getText();
|
438 |
} |
439 |
|
440 |
public String getConnectionPassword() { |
441 |
String resp = new String(passwordField.getPassword()); |
442 |
|
443 |
return resp;
|
444 |
} |
445 |
|
446 |
public DBExplorerParameters getParameters() throws InitializeException{ |
447 |
String _drvname = getConnectionDriverName();
|
448 |
String _host = getConnectionServerUrl();
|
449 |
String _port = getConnectionPort();
|
450 |
String _dbname = getConnectionDBName();
|
451 |
String _user = getConnectionUser();
|
452 |
String _pw = getConnectionPassword();
|
453 |
// String _conn_usr_name = getConnectionName();
|
454 |
DataManager dm=DataManager.getManager(); |
455 |
DBExplorerParameters params=(DBExplorerParameters)dm.createDataExplorerParameters(_drvname); |
456 |
params.setHost(_host); |
457 |
params.setPort(_port); |
458 |
params.setDb(_dbname); |
459 |
params.setUser(_user); |
460 |
params.setPassw(_pw); |
461 |
// params.setCatalog("public");
|
462 |
return params;
|
463 |
} |
464 |
|
465 |
private JTextField getUrlTextArea() { |
466 |
if (urlTextField == null) { |
467 |
urlTextField = new JTextField(); |
468 |
urlTextField.addKeyListener(this);
|
469 |
urlTextField.setBounds(new java.awt.Rectangle(155, 80, 166, 21)); |
470 |
} |
471 |
|
472 |
return urlTextField;
|
473 |
} |
474 |
|
475 |
/**
|
476 |
* This method initializes connectedCheckBox
|
477 |
*
|
478 |
* @return javax.swing.JCheckBox
|
479 |
*/
|
480 |
private JCheckBox getConnectedCheckBox() { |
481 |
if (connectedCheckBox == null) { |
482 |
connectedCheckBox = new JCheckBox(); |
483 |
connectedCheckBox.setSelected(true);
|
484 |
connectedCheckBox.addActionListener(this);
|
485 |
connectedCheckBox.setBounds(new java.awt.Rectangle(155, 247, 26, 21)); |
486 |
} |
487 |
|
488 |
return connectedCheckBox;
|
489 |
} |
490 |
|
491 |
public String getConnectionName() { |
492 |
return getConnNameTextField().getText();
|
493 |
} |
494 |
|
495 |
/**
|
496 |
* This method initializes connNameTextField
|
497 |
*
|
498 |
* @return javax.swing.JTextField
|
499 |
*/
|
500 |
private JTextField getConnNameTextField() { |
501 |
if (connNameTextField == null) { |
502 |
connNameTextField = new JTextField(); |
503 |
connNameTextField.addKeyListener(this);
|
504 |
connNameTextField.setBounds(new java.awt.Rectangle(155, 30, 166, 21)); |
505 |
} |
506 |
|
507 |
return connNameTextField;
|
508 |
} |
509 |
|
510 |
public void keyPressed(KeyEvent e) { |
511 |
} |
512 |
|
513 |
public void keyReleased(KeyEvent e) { |
514 |
if (e.getKeyChar() != '\n') { |
515 |
return;
|
516 |
} |
517 |
|
518 |
Object src = e.getSource();
|
519 |
|
520 |
if (src == passwordField) {
|
521 |
ActionEvent aevt = new ActionEvent(okButton, |
522 |
ActionEvent.ACTION_PERFORMED, ""); |
523 |
actionPerformed(aevt); |
524 |
} |
525 |
else {
|
526 |
if (src instanceof JTextField) { |
527 |
((JTextField) src).transferFocus();
|
528 |
} |
529 |
} |
530 |
} |
531 |
|
532 |
public void keyTyped(KeyEvent e) { |
533 |
} |
534 |
|
535 |
public void loadValues(DBExplorerParameters cwp) { |
536 |
getPortTextField().setText(cwp.getPort()); |
537 |
selectThisInDriverCombo(cwp.getDataExplorerName()); |
538 |
getDbTextField().setText(cwp.getDb()); |
539 |
getUserTextField().setText(cwp.getUser()); |
540 |
|
541 |
if (cwp.getPassw() == null) { |
542 |
getPasswordField().setText("");
|
543 |
} |
544 |
else {
|
545 |
getPasswordField().setText(cwp.getPassw()); |
546 |
} |
547 |
|
548 |
getUrlTextArea().setText(cwp.getHost()); |
549 |
|
550 |
boolean connected = false; |
551 |
|
552 |
// try {
|
553 |
// connected = (cwp.getConnection() != null) &&
|
554 |
// (!cwp.getConnection().isClosed());
|
555 |
// }
|
556 |
// catch (DBException e) {
|
557 |
// logger.error("While checking connection: " + e.getMessage());
|
558 |
// connected = false;
|
559 |
// }
|
560 |
|
561 |
// getConnectedCheckBox().setSelected(connected);
|
562 |
getConnNameTextField().setText(cwp.getDataExplorerName()); |
563 |
} |
564 |
|
565 |
private void selectThisInDriverCombo(String drvName) { |
566 |
int size = getDriverComboBox().getItemCount();
|
567 |
|
568 |
for (int i = 0; i < size; i++) { |
569 |
DriverComboBoxItem item = (DriverComboBoxItem) getDriverComboBox() |
570 |
.getItemAt(i); |
571 |
|
572 |
if (item.params.getDataExplorerName().compareToIgnoreCase(drvName) == 0) { |
573 |
getDriverComboBox().setSelectedIndex(i); |
574 |
|
575 |
return;
|
576 |
} |
577 |
} |
578 |
} |
579 |
} // @jve:decl-index=0:visual-constraint="10,10"
|