svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extGeoDB / src / org / gvsig / geodb / vectorialdb / wizard / VectorialDBConnectionParamsDialog.java @ 39398
History | View | Annotate | Download (21.8 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 org.gvsig.geodb.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.Iterator; |
51 |
import java.util.List; |
52 |
|
53 |
import javax.swing.JButton; |
54 |
import javax.swing.JCheckBox; |
55 |
import javax.swing.JComboBox; |
56 |
import javax.swing.JLabel; |
57 |
import javax.swing.JOptionPane; |
58 |
import javax.swing.JPanel; |
59 |
import javax.swing.JPasswordField; |
60 |
import javax.swing.JTextField; |
61 |
|
62 |
import org.slf4j.Logger; |
63 |
import org.slf4j.LoggerFactory; |
64 |
|
65 |
import org.gvsig.andami.PluginServices; |
66 |
import org.gvsig.andami.messages.NotificationManager; |
67 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
68 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
69 |
import org.gvsig.fmap.dal.DALLocator; |
70 |
import org.gvsig.fmap.dal.DataManager; |
71 |
import org.gvsig.fmap.dal.DataServerExplorerParameters; |
72 |
import org.gvsig.fmap.dal.exception.DataException; |
73 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
74 |
import org.gvsig.fmap.dal.serverexplorer.db.DBServerExplorerParameters; |
75 |
import org.gvsig.fmap.mapcontrol.swing.dynobject.DynObjectEditor; |
76 |
import org.gvsig.gui.beans.Messages; |
77 |
import org.gvsig.tools.service.ServiceException; |
78 |
|
79 |
|
80 |
|
81 |
/**
|
82 |
* Lets the user input the connection parameters.
|
83 |
*
|
84 |
* @author jldominguez
|
85 |
*
|
86 |
*/
|
87 |
public class VectorialDBConnectionParamsDialog extends JPanel implements IWindow, |
88 |
ActionListener, KeyListener { |
89 |
|
90 |
private static final long serialVersionUID = -5493563028200403559L; |
91 |
|
92 |
private static final Logger LOG = LoggerFactory |
93 |
.getLogger(VectorialDBConnectionParamsDialog.class); |
94 |
|
95 |
private WindowInfo winfo = new WindowInfo(8); // MODAL only |
96 |
private JButton cancelButton = null; |
97 |
private JButton okButton = null; |
98 |
private JButton advancedButton = null; |
99 |
private JPanel paramsPanel = null; |
100 |
private JComboBox driverComboBox = null; |
101 |
private JTextField portTextField = null; |
102 |
private JTextField dbTextField = null; |
103 |
private JTextField userTextField = null; |
104 |
private JPasswordField passwordField = null; |
105 |
private JLabel driverLabel = null; |
106 |
private JLabel portLabel = null; |
107 |
private JLabel dbLabel = null; |
108 |
private JLabel dbLabelWarning = null; |
109 |
private JLabel userLabel = null; |
110 |
private JLabel pwLabel = null; |
111 |
private boolean okPressed = false; |
112 |
private JTextField urlTextField = null; |
113 |
private JLabel urlLabel = null; |
114 |
private JCheckBox connectedCheckBox = null; |
115 |
private JLabel connectedLabel = null; |
116 |
private JLabel connNameLabel = null; |
117 |
private JTextField connNameTextField = null; |
118 |
|
119 |
private DBServerExplorerParameters params = null; |
120 |
|
121 |
/**
|
122 |
* This method initializes
|
123 |
*
|
124 |
*/
|
125 |
public VectorialDBConnectionParamsDialog() {
|
126 |
super();
|
127 |
initialize(); |
128 |
} |
129 |
|
130 |
public void showDialog() { |
131 |
PluginServices.getMDIManager().addWindow(this);
|
132 |
} |
133 |
|
134 |
/**
|
135 |
* This method initializes this
|
136 |
*
|
137 |
*/
|
138 |
private void initialize() { |
139 |
winfo.setWidth(370);
|
140 |
winfo.setHeight(317 - 25); |
141 |
winfo.setTitle(PluginServices.getText(this, "_Connection_parameters")); |
142 |
|
143 |
this.setSize(new java.awt.Dimension(360, 329)); |
144 |
this.setLayout(null); |
145 |
this.add(getCancelButton(), null); |
146 |
this.add(getOkButton(), null); |
147 |
this.add(getAdvancedButton(), null); |
148 |
this.add(getParamsPanel(), null); |
149 |
} |
150 |
|
151 |
public WindowInfo getWindowInfo() {
|
152 |
return winfo;
|
153 |
} |
154 |
|
155 |
/**
|
156 |
* This method initializes cancelButton
|
157 |
*
|
158 |
* @return javax.swing.JButton
|
159 |
*/
|
160 |
private JButton getCancelButton() { |
161 |
if (cancelButton == null) { |
162 |
cancelButton = new JButton(); |
163 |
cancelButton.setText(PluginServices.getText(this, "cancel")); |
164 |
cancelButton.addActionListener(this);
|
165 |
cancelButton.setBounds(new java.awt.Rectangle(124, 292, 90, 26)); |
166 |
} |
167 |
|
168 |
return cancelButton;
|
169 |
} |
170 |
|
171 |
/**
|
172 |
* This method initializes okButton
|
173 |
*
|
174 |
* @return javax.swing.JButton
|
175 |
*/
|
176 |
private JButton getOkButton() { |
177 |
if (okButton == null) { |
178 |
okButton = new JButton(); |
179 |
okButton.setText(PluginServices.getText(this, "ok")); |
180 |
okButton.addActionListener(this);
|
181 |
okButton.setBounds(new java.awt.Rectangle(30, 292, 90, 26)); |
182 |
} |
183 |
|
184 |
return okButton;
|
185 |
} |
186 |
|
187 |
/**
|
188 |
* This method initializes okButton
|
189 |
*
|
190 |
* @return javax.swing.JButton
|
191 |
*/
|
192 |
private JButton getAdvancedButton() { |
193 |
if (advancedButton == null) { |
194 |
advancedButton = new JButton(); |
195 |
advancedButton.setText(PluginServices.getText(this, "advanced")); |
196 |
advancedButton.addActionListener(this);
|
197 |
advancedButton.setBounds(new java.awt.Rectangle(218, 292, 90, 26)); |
198 |
} |
199 |
|
200 |
return advancedButton;
|
201 |
} |
202 |
|
203 |
/**
|
204 |
* This method initializes paramsPanel
|
205 |
*
|
206 |
* @return javax.swing.JPanel
|
207 |
*/
|
208 |
private JPanel getParamsPanel() { |
209 |
if (paramsPanel == null) { |
210 |
connNameLabel = new JLabel(); |
211 |
connNameLabel.setBounds(new java.awt.Rectangle(10, 30, 141, 21)); |
212 |
connNameLabel.setText(PluginServices.getText(this, "_Connection_name") + |
213 |
":");
|
214 |
connectedLabel = new JLabel(); |
215 |
connectedLabel.setBounds(new java.awt.Rectangle(10, 247, 141, 21)); |
216 |
connectedLabel.setText(PluginServices.getText(this, "_Connected") + |
217 |
":");
|
218 |
urlLabel = new JLabel(); |
219 |
urlLabel.setBounds(new java.awt.Rectangle(10, 80, 141, 21)); |
220 |
urlLabel.setText(PluginServices.getText(this, "_Host") + ":"); |
221 |
pwLabel = new JLabel(); |
222 |
pwLabel.setBounds(new java.awt.Rectangle(10, 222, 141, 21)); |
223 |
pwLabel.setText(PluginServices.getText(this, "_Password") + ":"); |
224 |
userLabel = new JLabel(); |
225 |
userLabel.setBounds(new java.awt.Rectangle(10, 197, 141, 21)); |
226 |
userLabel.setText(PluginServices.getText(this, "_User") + ":"); |
227 |
dbLabel = new JLabel(); |
228 |
dbLabel.setBounds(new java.awt.Rectangle(10, 130, 141, 21)); |
229 |
dbLabel.setText(PluginServices.getText(this, "_Database") + |
230 |
":");
|
231 |
dbLabelWarning = new JLabel(); |
232 |
dbLabelWarning.setBounds(new java.awt.Rectangle(10, 155, 310, 41)); |
233 |
dbLabelWarning.setText(PluginServices.getText(this, "warning_you_must_input_the_exact_name_this_difference_between_capital_letters_and_small_letters") |
234 |
); |
235 |
|
236 |
portLabel = new JLabel(); |
237 |
portLabel.setBounds(new java.awt.Rectangle(10, 105, 141, 21)); |
238 |
portLabel.setText(PluginServices.getText(this, "_Port") + ":"); |
239 |
driverLabel = new JLabel(); |
240 |
driverLabel.setBounds(new java.awt.Rectangle(10, 55, 141, 21)); |
241 |
driverLabel.setText(PluginServices.getText(this, "_Driver_type") + ":"); |
242 |
paramsPanel = new JPanel(); |
243 |
paramsPanel.setBounds(new java.awt.Rectangle(10, 10, 336, 273)); |
244 |
paramsPanel.setBorder(javax.swing.BorderFactory.createTitledBorder( |
245 |
null, PluginServices.getText(this, "_Connection_parameters"), |
246 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
247 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
248 |
paramsPanel.setLayout(null);
|
249 |
paramsPanel.add(getPortTextField(), null);
|
250 |
paramsPanel.add(getDriverComboBox(), null);
|
251 |
paramsPanel.add(getDbTextField(), null);
|
252 |
paramsPanel.add(getUserTextField(), null);
|
253 |
paramsPanel.add(getPasswordField(), null);
|
254 |
paramsPanel.add(driverLabel, null);
|
255 |
paramsPanel.add(portLabel, null);
|
256 |
paramsPanel.add(dbLabel, null);
|
257 |
paramsPanel.add(dbLabelWarning, null);
|
258 |
paramsPanel.add(userLabel, null);
|
259 |
paramsPanel.add(pwLabel, null);
|
260 |
paramsPanel.add(getUrlTextArea(), null);
|
261 |
paramsPanel.add(urlLabel, null);
|
262 |
paramsPanel.add(getConnectedCheckBox(), null);
|
263 |
paramsPanel.add(connectedLabel, null);
|
264 |
paramsPanel.add(connNameLabel, null);
|
265 |
paramsPanel.add(getConnNameTextField(), null);
|
266 |
} |
267 |
|
268 |
return paramsPanel;
|
269 |
} |
270 |
|
271 |
/**
|
272 |
* This method initializes driverComboBox
|
273 |
*
|
274 |
* @return javax.swing.JComboBox
|
275 |
*/
|
276 |
private JComboBox getDriverComboBox() { |
277 |
if (driverComboBox == null) { |
278 |
driverComboBox = new JComboBox(); |
279 |
driverComboBox.addActionListener(this);
|
280 |
DataManager dm = DALLocator.getDataManager(); |
281 |
List<String> explorers = dm.getExplorerProviders(); |
282 |
Iterator<String> iter = explorers.iterator(); |
283 |
String expName;
|
284 |
|
285 |
DataServerExplorerParameters params; |
286 |
while (iter.hasNext()) {
|
287 |
expName = iter.next(); |
288 |
try {
|
289 |
params = dm.createServerExplorerParameters(expName); |
290 |
} catch (DataException e) {
|
291 |
NotificationManager.addWarning(PluginServices.getText(null,
|
292 |
"DataExplorer_parameters_error")
|
293 |
+ ": " + expName, e);
|
294 |
continue;
|
295 |
} |
296 |
if (params instanceof DBServerExplorerParameters) { |
297 |
DBServerExplorerParameters dbParams = (DBServerExplorerParameters) params; |
298 |
driverComboBox.addItem(new DriverComboBoxItem(
|
299 |
dbParams)); |
300 |
} |
301 |
|
302 |
} |
303 |
|
304 |
driverComboBox.setBounds(new java.awt.Rectangle(155, 55, 166, 21)); |
305 |
|
306 |
} |
307 |
|
308 |
return driverComboBox;
|
309 |
} |
310 |
|
311 |
private class DriverComboBoxItem { |
312 |
private DBServerExplorerParameters params;
|
313 |
|
314 |
public DriverComboBoxItem(DBServerExplorerParameters dbParams) {
|
315 |
this.params = dbParams;
|
316 |
} |
317 |
|
318 |
public String toString() { |
319 |
// FIXME
|
320 |
return params.getExplorerName();
|
321 |
} |
322 |
} |
323 |
|
324 |
/**
|
325 |
* This method initializes portTextField
|
326 |
*
|
327 |
* @return javax.swing.JTextField
|
328 |
*/
|
329 |
private JTextField getPortTextField() { |
330 |
if (portTextField == null) { |
331 |
portTextField = new JTextField(); |
332 |
portTextField.addKeyListener(this);
|
333 |
portTextField.setBounds(new java.awt.Rectangle(155, 105, 166, 21)); |
334 |
} |
335 |
|
336 |
return portTextField;
|
337 |
} |
338 |
|
339 |
/**
|
340 |
* This method initializes dbTextField
|
341 |
*
|
342 |
* @return javax.swing.JTextField
|
343 |
*/
|
344 |
private JTextField getDbTextField() { |
345 |
if (dbTextField == null) { |
346 |
dbTextField = new JTextField(); |
347 |
dbTextField.addKeyListener(this);
|
348 |
dbTextField.setBounds(new java.awt.Rectangle(155, 130, 166, 21)); |
349 |
} |
350 |
|
351 |
return dbTextField;
|
352 |
} |
353 |
|
354 |
/**
|
355 |
* This method initializes userTextField
|
356 |
*
|
357 |
* @return javax.swing.JTextField
|
358 |
*/
|
359 |
private JTextField getUserTextField() { |
360 |
if (userTextField == null) { |
361 |
userTextField = new JTextField(); |
362 |
userTextField.addKeyListener(this);
|
363 |
userTextField.setBounds(new java.awt.Rectangle(155, 197, 166, 21)); |
364 |
} |
365 |
|
366 |
return userTextField;
|
367 |
} |
368 |
|
369 |
/**
|
370 |
* This method initializes passwordField
|
371 |
*
|
372 |
* @return javax.swing.JPasswordField
|
373 |
*/
|
374 |
private JPasswordField getPasswordField() { |
375 |
if (passwordField == null) { |
376 |
passwordField = new JPasswordField(); |
377 |
passwordField.addKeyListener(this);
|
378 |
passwordField.setBounds(new java.awt.Rectangle(155, 222, 166, 21)); |
379 |
} |
380 |
|
381 |
return passwordField;
|
382 |
} |
383 |
|
384 |
// private String[] getDriverNames() {
|
385 |
// Class[] classes = new Class[] { IVectorialDatabaseDriver.class };
|
386 |
//
|
387 |
// ArrayList ret = new ArrayList();
|
388 |
// String[] driverNames = LayerFactory.getDM().getDriverNames();
|
389 |
//
|
390 |
// for (int i = 0; i < driverNames.length; i++) {
|
391 |
// for (int j = 0; j < classes.length; j++) {
|
392 |
// if (LayerFactory.getDM().isA(driverNames[i], classes[j])) {
|
393 |
// ret.add(driverNames[i]);
|
394 |
// }
|
395 |
// }
|
396 |
// }
|
397 |
//
|
398 |
// return (String[]) ret.toArray(new String[0]);
|
399 |
// }
|
400 |
|
401 |
public void actionPerformed(ActionEvent arg0) { |
402 |
Object src = arg0.getSource();
|
403 |
|
404 |
if (src == connectedCheckBox) {
|
405 |
if (connectedCheckBox.isSelected()) {
|
406 |
passwordField.setEnabled(true);
|
407 |
passwordField.setBackground(Color.WHITE);
|
408 |
} |
409 |
else {
|
410 |
passwordField.setText("");
|
411 |
passwordField.setEnabled(false);
|
412 |
passwordField.setBackground(Color.LIGHT_GRAY);
|
413 |
} |
414 |
} |
415 |
|
416 |
if (src == okButton) {
|
417 |
DBServerExplorerParameters myParams = getParameters(); |
418 |
try {
|
419 |
myParams.validate(); |
420 |
|
421 |
okPressed = true;
|
422 |
PluginServices.getMDIManager().closeWindow(this);
|
423 |
} catch (Exception e) { |
424 |
// There are errors in the parameters, maybe more required ones.
|
425 |
// Warn the user and open the advanced parameters panel
|
426 |
JOptionPane
|
427 |
.showMessageDialog(this, Messages
|
428 |
.getText("more_provider_parameters_needed_message"),
|
429 |
Messages |
430 |
.getText("more_provider_parameters_needed_title"),
|
431 |
JOptionPane.WARNING_MESSAGE);
|
432 |
showAdvancedParametersPanel(); |
433 |
} |
434 |
|
435 |
return;
|
436 |
} |
437 |
|
438 |
if (src == cancelButton) {
|
439 |
okPressed = false;
|
440 |
PluginServices.getMDIManager().closeWindow(this);
|
441 |
|
442 |
return;
|
443 |
} |
444 |
|
445 |
if (src == advancedButton) {
|
446 |
showAdvancedParametersPanel(); |
447 |
|
448 |
return;
|
449 |
} |
450 |
|
451 |
if (src == driverComboBox) {
|
452 |
DBServerExplorerParameters params = ((DriverComboBoxItem) driverComboBox |
453 |
.getSelectedItem()).params; |
454 |
try {
|
455 |
params.validate(); |
456 |
} catch (ValidateDataParametersException e) {
|
457 |
} |
458 |
|
459 |
// try {
|
460 |
// DataManager dm=DataManager.getManager();
|
461 |
// featureStore = (FeatureStore) dm.createDataStore()LayerFactory.getDM()
|
462 |
// .getDriver(driverName);
|
463 |
if (params.getPort() != null) { |
464 |
portTextField.setText(params.getPort() + "");
|
465 |
} else {
|
466 |
portTextField.setText("");
|
467 |
} |
468 |
// }
|
469 |
// catch (DriverLoadException e1) {
|
470 |
// portTextField.setText("");
|
471 |
// }
|
472 |
|
473 |
return;
|
474 |
} |
475 |
} |
476 |
|
477 |
/**
|
478 |
* @param myParams
|
479 |
*/
|
480 |
private void showAdvancedParametersPanel() { |
481 |
DBServerExplorerParameters myParams = getParameters(); |
482 |
try {
|
483 |
myParams.validate(); |
484 |
} catch (Exception e) { |
485 |
// ignore... only for fill default values
|
486 |
} |
487 |
try {
|
488 |
DynObjectEditor editor = new DynObjectEditor(myParams);
|
489 |
editor.editObject(true);
|
490 |
refreshFormParameters(); |
491 |
} catch (ServiceException ex) {
|
492 |
LOG.error("Error creating a Swing component for the DynObject: "
|
493 |
+ myParams, ex); |
494 |
} |
495 |
} |
496 |
|
497 |
private void refreshFormParameters() { |
498 |
DBServerExplorerParameters myParams = internalGetParameters(); |
499 |
getDbTextField().setText(myParams.getDBName()); |
500 |
getPasswordField().setText(myParams.getPassword()); |
501 |
Integer port = myParams.getPort();
|
502 |
getPortTextField().setText(port == null ? "" : port.toString()); |
503 |
getUrlTextArea().setText(myParams.getHost()); |
504 |
getUserTextField().setText(myParams.getUser()); |
505 |
this.updateUI();
|
506 |
} |
507 |
|
508 |
public boolean isOkPressed() { |
509 |
return okPressed;
|
510 |
} |
511 |
|
512 |
public boolean hasToBeConnected() { |
513 |
return connectedCheckBox.isSelected();
|
514 |
} |
515 |
|
516 |
public String getConnectionDriverName() { |
517 |
return ((DriverComboBoxItem) driverComboBox.getSelectedItem()).params
|
518 |
.getExplorerName(); |
519 |
} |
520 |
|
521 |
public String getConnectionServerUrl() { |
522 |
return urlTextField.getText();
|
523 |
} |
524 |
|
525 |
public String getConnectionPort() { |
526 |
return portTextField.getText();
|
527 |
} |
528 |
|
529 |
public String getConnectionDBName() { |
530 |
return dbTextField.getText();
|
531 |
} |
532 |
|
533 |
public String getConnectionUser() { |
534 |
return userTextField.getText();
|
535 |
} |
536 |
|
537 |
public String getConnectionPassword() { |
538 |
String resp = new String(passwordField.getPassword()); |
539 |
|
540 |
return resp;
|
541 |
} |
542 |
|
543 |
private JTextField getUrlTextArea() { |
544 |
if (urlTextField == null) { |
545 |
urlTextField = new JTextField(); |
546 |
urlTextField.addKeyListener(this);
|
547 |
urlTextField.setBounds(new java.awt.Rectangle(155, 80, 166, 21)); |
548 |
} |
549 |
|
550 |
return urlTextField;
|
551 |
} |
552 |
|
553 |
/**
|
554 |
* This method initializes connectedCheckBox
|
555 |
*
|
556 |
* @return javax.swing.JCheckBox
|
557 |
*/
|
558 |
private JCheckBox getConnectedCheckBox() { |
559 |
if (connectedCheckBox == null) { |
560 |
connectedCheckBox = new JCheckBox(); |
561 |
connectedCheckBox.setSelected(true);
|
562 |
connectedCheckBox.addActionListener(this);
|
563 |
connectedCheckBox.setBounds(new java.awt.Rectangle(155, 247, 26, 21)); |
564 |
} |
565 |
|
566 |
return connectedCheckBox;
|
567 |
} |
568 |
|
569 |
public String getConnectionName() { |
570 |
return getConnNameTextField().getText();
|
571 |
} |
572 |
|
573 |
/**
|
574 |
* This method initializes connNameTextField
|
575 |
*
|
576 |
* @return javax.swing.JTextField
|
577 |
*/
|
578 |
private JTextField getConnNameTextField() { |
579 |
if (connNameTextField == null) { |
580 |
connNameTextField = new JTextField(); |
581 |
connNameTextField.addKeyListener(this);
|
582 |
connNameTextField.setBounds(new java.awt.Rectangle(155, 30, 166, 21)); |
583 |
} |
584 |
|
585 |
return connNameTextField;
|
586 |
} |
587 |
|
588 |
public void keyPressed(KeyEvent e) { |
589 |
} |
590 |
|
591 |
public void keyReleased(KeyEvent e) { |
592 |
if (e.getKeyChar() != '\n') { |
593 |
return;
|
594 |
} |
595 |
|
596 |
Object src = e.getSource();
|
597 |
|
598 |
if (src == passwordField) {
|
599 |
ActionEvent aevt = new ActionEvent(okButton, |
600 |
ActionEvent.ACTION_PERFORMED, ""); |
601 |
actionPerformed(aevt); |
602 |
} |
603 |
else {
|
604 |
if (src instanceof JTextField) { |
605 |
((JTextField) src).transferFocus();
|
606 |
} |
607 |
} |
608 |
} |
609 |
|
610 |
public void keyTyped(KeyEvent e) { |
611 |
} |
612 |
|
613 |
public void loadValues(DBServerExplorerParameters cwp) { |
614 |
if (cwp.getPort() != null){ |
615 |
getPortTextField().setText(cwp.getPort().toString()); |
616 |
} else{
|
617 |
getPortTextField().setText("");
|
618 |
} |
619 |
selectThisInDriverCombo(cwp.getExplorerName()); |
620 |
getDbTextField().setText(cwp.getDBName()); |
621 |
getUserTextField().setText(cwp.getUser()); |
622 |
|
623 |
if (cwp.getPassword() == null) { |
624 |
getPasswordField().setText("");
|
625 |
} |
626 |
else {
|
627 |
getPasswordField().setText(cwp.getPassword()); |
628 |
} |
629 |
|
630 |
getUrlTextArea().setText(cwp.getHost()); |
631 |
|
632 |
// boolean connected = false;
|
633 |
//
|
634 |
// try {
|
635 |
// connected = (cwp.getConnection() != null) &&
|
636 |
// (!cwp.getConnection().isClosed());
|
637 |
// }
|
638 |
// catch (DBException e) {
|
639 |
// LOG.error("While checking connection: " + e.getMessage());
|
640 |
// connected = false;
|
641 |
// }
|
642 |
|
643 |
// getConnectedCheckBox().setSelected(connected);
|
644 |
getConnNameTextField().setText(cwp.getExplorerName()); |
645 |
} |
646 |
|
647 |
private void selectThisInDriverCombo(String drvName) { |
648 |
int size = getDriverComboBox().getItemCount();
|
649 |
int curSel = getDriverComboBox().getSelectedIndex();
|
650 |
|
651 |
for (int i = 0; i < size; i++) { |
652 |
DriverComboBoxItem item = (DriverComboBoxItem) getDriverComboBox() |
653 |
.getItemAt(i); |
654 |
|
655 |
if (item.params.getExplorerName().compareToIgnoreCase(drvName) == 0) { |
656 |
getDriverComboBox().setSelectedIndex(i); |
657 |
if (curSel != i) {
|
658 |
this.params = null; |
659 |
} |
660 |
|
661 |
return;
|
662 |
} |
663 |
} |
664 |
} |
665 |
|
666 |
public Object getWindowProfile() { |
667 |
return WindowInfo.DIALOG_PROFILE;
|
668 |
} |
669 |
|
670 |
public DBServerExplorerParameters getParameters(){
|
671 |
|
672 |
DBServerExplorerParameters params = internalGetParameters(); |
673 |
|
674 |
String _host = getConnectionServerUrl();
|
675 |
String _port = getConnectionPort();
|
676 |
String _dbname = getConnectionDBName();
|
677 |
String _user = getConnectionUser();
|
678 |
String _pw = getConnectionPassword();
|
679 |
|
680 |
params.setHost(_host); |
681 |
if (_port.trim().length() != 0) { |
682 |
try {
|
683 |
params.setPort(Integer.parseInt(_port));
|
684 |
} catch (NumberFormatException e) { |
685 |
NotificationManager.addError("Invalid port", e);
|
686 |
} |
687 |
} |
688 |
params.setDBName(_dbname); |
689 |
params.setUser(_user); |
690 |
params.setPassword(_pw); |
691 |
|
692 |
return params;
|
693 |
} |
694 |
|
695 |
private DBServerExplorerParameters internalGetParameters() {
|
696 |
if (params == null) { |
697 |
DriverComboBoxItem item = |
698 |
(DriverComboBoxItem) getDriverComboBox().getItemAt( |
699 |
getDriverComboBox().getSelectedIndex()); |
700 |
params = (DBServerExplorerParameters) item.params.getCopy(); |
701 |
|
702 |
} |
703 |
|
704 |
return params;
|
705 |
} |
706 |
|
707 |
} // @jve:decl-index=0:visual-constraint="10,10"
|