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