Revision 41627 trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.geodb.app/org.gvsig.geodb.app.mainplugin/src/main/java/org/gvsig/geodb/vectorialdb/wizard/VectorialDBConnectionParamsDialog.java
VectorialDBConnectionParamsDialog.java | ||
---|---|---|
3 | 3 |
* |
4 | 4 |
* Copyright (C) 2007-2013 gvSIG Association. |
5 | 5 |
* |
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License
|
|
8 |
* as published by the Free Software Foundation; either version 3
|
|
9 |
* of the License, or (at your option) any later version.
|
|
6 |
* This program is free software; you can redistribute it and/or modify it under
|
|
7 |
* the terms of the GNU General Public License as published by the Free Software
|
|
8 |
* Foundation; either version 3 of the License, or (at your option) any later
|
|
9 |
* version. |
|
10 | 10 |
* |
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 |
* GNU General Public License for more details.
|
|
11 |
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
13 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
14 |
* details. |
|
15 | 15 |
* |
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
16 |
* You should have received a copy of the GNU General Public License along with |
|
17 |
* this program; if not, write to the Free Software Foundation, Inc., 51 |
|
18 |
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
20 | 19 |
* |
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
|
20 |
* For any additional information, do not hesitate to contact us at info AT
|
|
21 |
* gvsig.com, or visit our website www.gvsig.com. |
|
23 | 22 |
*/ |
24 | 23 |
package org.gvsig.geodb.vectorialdb.wizard; |
25 | 24 |
|
... | ... | |
28 | 27 |
import java.awt.event.ActionListener; |
29 | 28 |
import java.awt.event.KeyEvent; |
30 | 29 |
import java.awt.event.KeyListener; |
30 |
import java.util.ArrayList; |
|
31 | 31 |
import java.util.Iterator; |
32 | 32 |
import java.util.List; |
33 | 33 |
|
... | ... | |
53 | 53 |
import org.gvsig.fmap.dal.exception.DataException; |
54 | 54 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
55 | 55 |
import org.gvsig.fmap.dal.serverexplorer.db.DBServerExplorerParameters; |
56 |
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters; |
|
56 | 57 |
import org.gvsig.fmap.mapcontrol.swing.dynobject.DynObjectEditor; |
57 | 58 |
import org.gvsig.gui.beans.Messages; |
58 | 59 |
import org.gvsig.tools.service.ServiceException; |
59 | 60 |
|
60 |
|
|
61 |
|
|
62 | 61 |
/** |
63 | 62 |
* Lets the user input the connection parameters. |
64 | 63 |
* |
... | ... | |
66 | 65 |
* |
67 | 66 |
*/ |
68 | 67 |
public class VectorialDBConnectionParamsDialog extends JPanel implements IWindow, |
69 |
ActionListener, KeyListener { |
|
68 |
ActionListener, KeyListener {
|
|
70 | 69 |
|
71 | 70 |
private static final long serialVersionUID = -5493563028200403559L; |
72 | 71 |
|
73 | 72 |
private static final Logger LOG = LoggerFactory |
74 |
.getLogger(VectorialDBConnectionParamsDialog.class); |
|
73 |
.getLogger(VectorialDBConnectionParamsDialog.class);
|
|
75 | 74 |
|
76 | 75 |
private WindowInfo winfo = new WindowInfo(8); // MODAL only |
77 | 76 |
private JButton cancelButton = null; |
... | ... | |
165 | 164 |
return okButton; |
166 | 165 |
} |
167 | 166 |
|
168 |
/**
|
|
169 |
* This method initializes okButton
|
|
170 |
*
|
|
171 |
* @return javax.swing.JButton
|
|
172 |
*/
|
|
173 |
private JButton getAdvancedButton() {
|
|
174 |
if (advancedButton == null) {
|
|
175 |
advancedButton = new JButton();
|
|
176 |
advancedButton.setText(PluginServices.getText(this, "advanced"));
|
|
177 |
advancedButton.addActionListener(this);
|
|
178 |
advancedButton.setBounds(new java.awt.Rectangle(218, 292, 90, 26));
|
|
179 |
}
|
|
167 |
/**
|
|
168 |
* This method initializes okButton
|
|
169 |
*
|
|
170 |
* @return javax.swing.JButton
|
|
171 |
*/
|
|
172 |
private JButton getAdvancedButton() {
|
|
173 |
if (advancedButton == null) {
|
|
174 |
advancedButton = new JButton();
|
|
175 |
advancedButton.setText(PluginServices.getText(this, "advanced"));
|
|
176 |
advancedButton.addActionListener(this);
|
|
177 |
advancedButton.setBounds(new java.awt.Rectangle(218, 292, 90, 26));
|
|
178 |
}
|
|
180 | 179 |
|
181 |
return advancedButton;
|
|
182 |
}
|
|
180 |
return advancedButton;
|
|
181 |
}
|
|
183 | 182 |
|
184 |
/**
|
|
185 |
* This method initializes paramsPanel
|
|
186 |
*
|
|
187 |
* @return javax.swing.JPanel
|
|
188 |
*/
|
|
183 |
/**
|
|
184 |
* This method initializes paramsPanel
|
|
185 |
*
|
|
186 |
* @return javax.swing.JPanel
|
|
187 |
*/
|
|
189 | 188 |
private JPanel getParamsPanel() { |
190 | 189 |
if (paramsPanel == null) { |
191 | 190 |
connNameLabel = new JLabel(); |
192 | 191 |
connNameLabel.setBounds(new java.awt.Rectangle(10, 30, 141, 21)); |
193 |
connNameLabel.setText(PluginServices.getText(this, "_Connection_name") +
|
|
194 |
":"); |
|
192 |
connNameLabel.setText(PluginServices.getText(this, "_Connection_name") |
|
193 |
+ ":");
|
|
195 | 194 |
connectedLabel = new JLabel(); |
196 | 195 |
connectedLabel.setBounds(new java.awt.Rectangle(10, 247, 141, 21)); |
197 |
connectedLabel.setText(PluginServices.getText(this, "_Connected") +
|
|
198 |
":"); |
|
196 |
connectedLabel.setText(PluginServices.getText(this, "_Connected") |
|
197 |
+ ":");
|
|
199 | 198 |
urlLabel = new JLabel(); |
200 | 199 |
urlLabel.setBounds(new java.awt.Rectangle(10, 80, 141, 21)); |
201 | 200 |
urlLabel.setText(PluginServices.getText(this, "_Host") + ":"); |
... | ... | |
207 | 206 |
userLabel.setText(PluginServices.getText(this, "_User") + ":"); |
208 | 207 |
dbLabel = new JLabel(); |
209 | 208 |
dbLabel.setBounds(new java.awt.Rectangle(10, 130, 141, 21)); |
210 |
dbLabel.setText(PluginServices.getText(this, "_Database") +
|
|
211 |
":"); |
|
209 |
dbLabel.setText(PluginServices.getText(this, "_Database") |
|
210 |
+ ":");
|
|
212 | 211 |
dbLabelWarning = new JLabel(); |
213 | 212 |
dbLabelWarning.setBounds(new java.awt.Rectangle(10, 155, 310, 41)); |
214 | 213 |
dbLabelWarning.setText(PluginServices.getText(this, "warning_you_must_input_the_exact_name_this_difference_between_capital_letters_and_small_letters") |
215 |
);
|
|
214 |
); |
|
216 | 215 |
|
217 | 216 |
portLabel = new JLabel(); |
218 | 217 |
portLabel.setBounds(new java.awt.Rectangle(10, 105, 141, 21)); |
... | ... | |
258 | 257 |
if (driverComboBox == null) { |
259 | 258 |
driverComboBox = new JComboBox(); |
260 | 259 |
driverComboBox.addActionListener(this); |
260 |
|
|
261 | 261 |
DataManager dm = DALLocator.getDataManager(); |
262 | 262 |
List<String> explorers = dm.getExplorerProviders(); |
263 | 263 |
Iterator<String> iter = explorers.iterator(); |
264 | 264 |
String expName; |
265 | 265 |
|
266 |
List<DBServerExplorerParameters> dbServerExplorerParameters = new ArrayList<DBServerExplorerParameters>(); |
|
266 | 267 |
DataServerExplorerParameters params; |
267 | 268 |
while (iter.hasNext()) { |
268 |
expName = iter.next(); |
|
269 |
try { |
|
270 |
params = dm.createServerExplorerParameters(expName); |
|
271 |
} catch (DataException e) { |
|
272 |
NotificationManager.addWarning(PluginServices.getText(null, |
|
273 |
"DataExplorer_parameters_error") |
|
274 |
+ ": " + expName, e); |
|
275 |
continue; |
|
276 |
} |
|
277 |
if (params instanceof DBServerExplorerParameters) { |
|
278 |
DBServerExplorerParameters dbParams = (DBServerExplorerParameters) params; |
|
279 |
driverComboBox.addItem(new DriverComboBoxItem( |
|
280 |
dbParams)); |
|
281 |
} |
|
269 |
expName = iter.next(); |
|
270 |
try { |
|
271 |
params = dm.createServerExplorerParameters(expName); |
|
272 |
} catch (DataException e) { |
|
273 |
NotificationManager.addWarning(PluginServices.getText(null, |
|
274 |
"DataExplorer_parameters_error") |
|
275 |
+ ": " + expName, e); |
|
276 |
continue; |
|
277 |
} |
|
278 |
if (params instanceof DBServerExplorerParameters) { |
|
279 |
DBServerExplorerParameters dbParams = (DBServerExplorerParameters) params; |
|
280 |
if( JDBCServerExplorerParameters.class.getName().equals(dbParams.getClass().getName()) ) { |
|
281 |
// JDBC is always the last option in the combo. |
|
282 |
dbServerExplorerParameters.add(dbParams); |
|
283 |
} else { |
|
284 |
dbServerExplorerParameters.add(0, dbParams); |
|
285 |
} |
|
286 |
} |
|
282 | 287 |
|
283 | 288 |
} |
284 |
|
|
289 |
for( int i=0; i<dbServerExplorerParameters.size(); i++ ) { |
|
290 |
driverComboBox.addItem(new DriverComboBoxItem( |
|
291 |
dbServerExplorerParameters.get(i))); |
|
292 |
} |
|
285 | 293 |
driverComboBox.setBounds(new java.awt.Rectangle(155, 55, 166, 21)); |
286 | 294 |
|
287 | 295 |
} |
... | ... | |
290 | 298 |
} |
291 | 299 |
|
292 | 300 |
private class DriverComboBoxItem { |
293 |
private DBServerExplorerParameters params; |
|
294 | 301 |
|
295 |
public DriverComboBoxItem(DBServerExplorerParameters dbParams) { |
|
296 |
this.params = dbParams; |
|
297 |
} |
|
302 |
private DBServerExplorerParameters params; |
|
298 | 303 |
|
299 |
public String toString() { |
|
300 |
// FIXME |
|
301 |
return params.getExplorerName(); |
|
302 |
} |
|
304 |
public DriverComboBoxItem(DBServerExplorerParameters dbParams) { |
|
305 |
this.params = dbParams; |
|
306 |
} |
|
307 |
|
|
308 |
public String toString() { |
|
309 |
return params.getExplorerName(); |
|
310 |
} |
|
303 | 311 |
} |
304 | 312 |
|
305 | 313 |
/** |
... | ... | |
378 | 386 |
// |
379 | 387 |
// return (String[]) ret.toArray(new String[0]); |
380 | 388 |
// } |
381 |
|
|
382 | 389 |
public void actionPerformed(ActionEvent arg0) { |
383 | 390 |
Object src = arg0.getSource(); |
384 | 391 |
|
... | ... | |
386 | 393 |
if (connectedCheckBox.isSelected()) { |
387 | 394 |
passwordField.setEnabled(true); |
388 | 395 |
passwordField.setBackground(Color.WHITE); |
389 |
} |
|
390 |
else { |
|
396 |
} else { |
|
391 | 397 |
passwordField.setText(""); |
392 | 398 |
passwordField.setEnabled(false); |
393 | 399 |
passwordField.setBackground(Color.LIGHT_GRAY); |
... | ... | |
405 | 411 |
// There are errors in the parameters, maybe more required ones. |
406 | 412 |
// Warn the user and open the advanced parameters panel |
407 | 413 |
JOptionPane |
408 |
.showMessageDialog(this, Messages |
|
409 |
.getText("more_provider_parameters_needed_message"), |
|
410 |
Messages |
|
411 |
.getText("more_provider_parameters_needed_title"), |
|
412 |
JOptionPane.WARNING_MESSAGE); |
|
414 |
.showMessageDialog(this, Messages
|
|
415 |
.getText("more_provider_parameters_needed_message"),
|
|
416 |
Messages
|
|
417 |
.getText("more_provider_parameters_needed_title"),
|
|
418 |
JOptionPane.WARNING_MESSAGE);
|
|
413 | 419 |
showAdvancedParametersPanel(); |
414 | 420 |
} |
415 | 421 |
|
... | ... | |
426 | 432 |
if (src == advancedButton) { |
427 | 433 |
showAdvancedParametersPanel(); |
428 | 434 |
|
429 |
return;
|
|
430 |
}
|
|
435 |
return;
|
|
436 |
}
|
|
431 | 437 |
|
432 | 438 |
if (src == driverComboBox) { |
433 |
DBServerExplorerParameters params = ((DriverComboBoxItem) driverComboBox
|
|
434 |
.getSelectedItem()).params;
|
|
435 |
try {
|
|
436 |
params.validate();
|
|
437 |
} catch (ValidateDataParametersException e) {
|
|
438 |
}
|
|
439 |
DBServerExplorerParameters params = ((DriverComboBoxItem) driverComboBox
|
|
440 |
.getSelectedItem()).params;
|
|
441 |
try {
|
|
442 |
params.validate();
|
|
443 |
} catch (ValidateDataParametersException e) {
|
|
444 |
}
|
|
439 | 445 |
|
440 | 446 |
// try { |
441 | 447 |
// DataManager dm=DataManager.getManager(); |
442 | 448 |
// featureStore = (FeatureStore) dm.createDataStore()LayerFactory.getDM() |
443 | 449 |
// .getDriver(driverName); |
444 |
if (params.getPort() != null) {
|
|
445 |
portTextField.setText(params.getPort() + "");
|
|
446 |
} else {
|
|
447 |
portTextField.setText("");
|
|
448 |
}
|
|
450 |
if (params.getPort() != null) {
|
|
451 |
portTextField.setText(params.getPort() + "");
|
|
452 |
} else {
|
|
453 |
portTextField.setText("");
|
|
454 |
}
|
|
449 | 455 |
// } |
450 | 456 |
// catch (DriverLoadException e1) { |
451 | 457 |
// portTextField.setText(""); |
... | ... | |
471 | 477 |
refreshFormParameters(); |
472 | 478 |
} catch (ServiceException ex) { |
473 | 479 |
LOG.error("Error creating a Swing component for the DynObject: " |
474 |
+ myParams, ex); |
|
480 |
+ myParams, ex);
|
|
475 | 481 |
} |
476 | 482 |
} |
477 | 483 |
|
... | ... | |
496 | 502 |
|
497 | 503 |
public String getConnectionDriverName() { |
498 | 504 |
return ((DriverComboBoxItem) driverComboBox.getSelectedItem()).params |
499 |
.getExplorerName();
|
|
505 |
.getExplorerName();
|
|
500 | 506 |
} |
501 | 507 |
|
502 | 508 |
public String getConnectionServerUrl() { |
... | ... | |
580 | 586 |
ActionEvent aevt = new ActionEvent(okButton, |
581 | 587 |
ActionEvent.ACTION_PERFORMED, ""); |
582 | 588 |
actionPerformed(aevt); |
583 |
} |
|
584 |
else { |
|
589 |
} else { |
|
585 | 590 |
if (src instanceof JTextField) { |
586 | 591 |
((JTextField) src).transferFocus(); |
587 | 592 |
} |
... | ... | |
589 | 594 |
} |
590 | 595 |
|
591 | 596 |
public void keyTyped(KeyEvent e) { |
592 |
}
|
|
597 |
}
|
|
593 | 598 |
|
594 | 599 |
public void loadValues(DBServerExplorerParameters cwp) { |
595 |
if (cwp.getPort() != null){
|
|
596 |
getPortTextField().setText(cwp.getPort().toString());
|
|
597 |
} else{
|
|
598 |
getPortTextField().setText("");
|
|
599 |
}
|
|
600 |
if (cwp.getPort() != null) {
|
|
601 |
getPortTextField().setText(cwp.getPort().toString());
|
|
602 |
} else {
|
|
603 |
getPortTextField().setText("");
|
|
604 |
}
|
|
600 | 605 |
selectThisInDriverCombo(cwp.getExplorerName()); |
601 | 606 |
getDbTextField().setText(cwp.getDBName()); |
602 | 607 |
getUserTextField().setText(cwp.getUser()); |
603 | 608 |
|
604 | 609 |
if (cwp.getPassword() == null) { |
605 | 610 |
getPasswordField().setText(""); |
606 |
} |
|
607 |
else { |
|
611 |
} else { |
|
608 | 612 |
getPasswordField().setText(cwp.getPassword()); |
609 | 613 |
} |
610 | 614 |
|
... | ... | |
620 | 624 |
// LOG.error("While checking connection: " + e.getMessage()); |
621 | 625 |
// connected = false; |
622 | 626 |
// } |
623 |
|
|
624 | 627 |
// getConnectedCheckBox().setSelected(connected); |
625 |
getConnNameTextField().setText(cwp.getExplorerName());
|
|
628 |
getConnNameTextField().setText(cwp.getExplorerName());
|
|
626 | 629 |
} |
627 | 630 |
|
628 | 631 |
private void selectThisInDriverCombo(String drvName) { |
... | ... | |
631 | 634 |
|
632 | 635 |
for (int i = 0; i < size; i++) { |
633 | 636 |
DriverComboBoxItem item = (DriverComboBoxItem) getDriverComboBox() |
634 |
.getItemAt(i);
|
|
637 |
.getItemAt(i);
|
|
635 | 638 |
|
636 | 639 |
if (item.params.getExplorerName().compareToIgnoreCase(drvName) == 0) { |
637 | 640 |
getDriverComboBox().setSelectedIndex(i); |
638 | 641 |
if (curSel != i) { |
639 |
this.params = null;
|
|
640 |
}
|
|
642 |
this.params = null;
|
|
643 |
}
|
|
641 | 644 |
|
642 | 645 |
return; |
643 | 646 |
} |
644 | 647 |
} |
645 | 648 |
} |
646 | 649 |
|
647 |
public Object getWindowProfile() {
|
|
648 |
return WindowInfo.DIALOG_PROFILE;
|
|
649 |
}
|
|
650 |
public Object getWindowProfile() {
|
|
651 |
return WindowInfo.DIALOG_PROFILE;
|
|
652 |
}
|
|
650 | 653 |
|
651 |
public DBServerExplorerParameters getParameters(){
|
|
654 |
public DBServerExplorerParameters getParameters() {
|
|
652 | 655 |
|
653 | 656 |
DBServerExplorerParameters params = internalGetParameters(); |
654 | 657 |
|
655 |
String _host = getConnectionServerUrl();
|
|
656 |
String _port = getConnectionPort();
|
|
657 |
String _dbname = getConnectionDBName();
|
|
658 |
String _user = getConnectionUser();
|
|
659 |
String _pw = getConnectionPassword();
|
|
658 |
String _host = getConnectionServerUrl();
|
|
659 |
String _port = getConnectionPort();
|
|
660 |
String _dbname = getConnectionDBName();
|
|
661 |
String _user = getConnectionUser();
|
|
662 |
String _pw = getConnectionPassword();
|
|
660 | 663 |
|
661 |
params.setHost(_host);
|
|
662 |
if (_port.trim().length() != 0) {
|
|
663 |
try {
|
|
664 |
params.setPort(Integer.parseInt(_port));
|
|
665 |
} catch (NumberFormatException e) {
|
|
666 |
NotificationManager.addError("Invalid port", e);
|
|
667 |
}
|
|
668 |
}
|
|
669 |
params.setDBName(_dbname);
|
|
670 |
params.setUser(_user);
|
|
671 |
params.setPassword(_pw);
|
|
664 |
params.setHost(_host);
|
|
665 |
if (_port.trim().length() != 0) {
|
|
666 |
try {
|
|
667 |
params.setPort(Integer.parseInt(_port));
|
|
668 |
} catch (NumberFormatException e) {
|
|
669 |
NotificationManager.addError("Invalid port", e);
|
|
670 |
}
|
|
671 |
}
|
|
672 |
params.setDBName(_dbname);
|
|
673 |
params.setUser(_user);
|
|
674 |
params.setPassword(_pw);
|
|
672 | 675 |
|
673 |
return params;
|
|
674 |
}
|
|
676 |
return params;
|
|
677 |
}
|
|
675 | 678 |
|
676 | 679 |
private DBServerExplorerParameters internalGetParameters() { |
677 | 680 |
if (params == null) { |
678 |
DriverComboBoxItem item =
|
|
679 |
(DriverComboBoxItem) getDriverComboBox().getItemAt( |
|
680 |
getDriverComboBox().getSelectedIndex()); |
|
681 |
DriverComboBoxItem item |
|
682 |
= (DriverComboBoxItem) getDriverComboBox().getItemAt(
|
|
683 |
getDriverComboBox().getSelectedIndex());
|
|
681 | 684 |
params = (DBServerExplorerParameters) item.params.getCopy(); |
682 | 685 |
|
683 | 686 |
} |
Also available in: Unified diff