svn-gvsig-desktop / branches / v10 / applications / appgvSIG / src / com / prodevelop / cit / gvsig / vectorialdb / wizard / WizardVectorialDB.java @ 11952
History | View | Annotate | Download (22.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 com.prodevelop.cit.gvsig.vectorialdb.wizard; |
44 |
|
45 |
import com.hardcode.driverManager.DriverLoadException; |
46 |
|
47 |
import com.iver.andami.PluginServices; |
48 |
import com.iver.andami.messages.NotificationManager; |
49 |
import com.iver.andami.ui.mdiManager.IWindow; |
50 |
|
51 |
import com.iver.cit.gvsig.fmap.MapContext; |
52 |
import com.iver.cit.gvsig.fmap.core.ICanReproject; |
53 |
import com.iver.cit.gvsig.fmap.crs.CRSFactory; |
54 |
import com.iver.cit.gvsig.fmap.drivers.DBException; |
55 |
import com.iver.cit.gvsig.fmap.drivers.DBLayerDefinition; |
56 |
import com.iver.cit.gvsig.fmap.drivers.IConnection; |
57 |
import com.iver.cit.gvsig.fmap.drivers.IVectorialDatabaseDriver; |
58 |
import com.iver.cit.gvsig.fmap.drivers.db.utils.ConnectionWithParams; |
59 |
import com.iver.cit.gvsig.fmap.drivers.db.utils.SingleVectorialDBConnectionManager; |
60 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
61 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
62 |
import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
63 |
import com.iver.cit.gvsig.gui.WizardPanel; |
64 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
65 |
|
66 |
import com.iver.utiles.swing.JPasswordDlg; |
67 |
|
68 |
import org.apache.log4j.Logger; |
69 |
|
70 |
import org.cresques.cts.IProjection; |
71 |
|
72 |
import org.gvsig.gui.beans.swing.JButton; |
73 |
|
74 |
import java.awt.BorderLayout; |
75 |
import java.awt.event.ActionEvent; |
76 |
import java.awt.event.ActionListener; |
77 |
import java.awt.geom.Rectangle2D; |
78 |
|
79 |
import java.util.ArrayList; |
80 |
|
81 |
import javax.swing.DefaultListModel; |
82 |
import javax.swing.ImageIcon; |
83 |
import javax.swing.JComboBox; |
84 |
import javax.swing.JOptionPane; |
85 |
import javax.swing.JPanel; |
86 |
import javax.swing.JScrollPane; |
87 |
import javax.swing.ListSelectionModel; |
88 |
import javax.swing.event.ListSelectionEvent; |
89 |
import javax.swing.event.ListSelectionListener; |
90 |
|
91 |
|
92 |
/**
|
93 |
* Driver-independent GeoBD wizard. Queries the drivers to fill GUI controls.
|
94 |
* Multi-table selection available.
|
95 |
*
|
96 |
* @author jldominguez
|
97 |
*
|
98 |
*/
|
99 |
public class WizardVectorialDB extends WizardPanel implements ActionListener, |
100 |
ListSelectionListener {
|
101 |
private static Logger logger = Logger.getLogger(WizardVectorialDB.class.getName()); |
102 |
|
103 |
// private DefaultDBDriver driver;
|
104 |
private IConnection conex = null; |
105 |
private ConnectionWithParams selectedDataSource = null; |
106 |
private JPanel namePanel = null; |
107 |
private JPanel tablesPanel = null; |
108 |
private JScrollPane tablesScrollPane = null; |
109 |
private AvailableTablesCheckBoxList tablesList = null; |
110 |
private JComboBox datasourceComboBox = null; |
111 |
private UserTableSettingsPanel settingsPanel = null; |
112 |
private UserSelectedFieldsPanel fieldsPanel = null; |
113 |
private UserTableSettingsPanel emptySettingsPanel = null; |
114 |
private UserSelectedFieldsPanel emptyFieldsPanel = null; |
115 |
private JButton dbButton = null; |
116 |
private View view = null; |
117 |
|
118 |
public WizardVectorialDB() {
|
119 |
super();
|
120 |
initialize(); |
121 |
} |
122 |
|
123 |
/**
|
124 |
* This method initializes this
|
125 |
*
|
126 |
* @return void
|
127 |
*/
|
128 |
private void initialize() { |
129 |
setTabName("GeoBD");
|
130 |
setLayout(null);
|
131 |
setSize(512, 478); |
132 |
|
133 |
IWindow iw = PluginServices.getMDIManager().getActiveWindow(); |
134 |
|
135 |
if (iw == null) { |
136 |
return;
|
137 |
} |
138 |
|
139 |
if (!(iw instanceof View)) { |
140 |
return;
|
141 |
} |
142 |
|
143 |
view = (View) iw;
|
144 |
setMapCtrl(view.getMapControl()); |
145 |
|
146 |
emptySettingsPanel = new UserTableSettingsPanel(null, null, "", |
147 |
getMapCtrl(), true, this); |
148 |
emptyFieldsPanel = new UserSelectedFieldsPanel(null, null, true, this); |
149 |
|
150 |
add(getNamePanel(), null);
|
151 |
loadVectorialDBDatasourcesCombo(); |
152 |
|
153 |
add(getTablesPanel(), null);
|
154 |
} |
155 |
|
156 |
private void loadVectorialDBDatasourcesCombo() { |
157 |
getDatasourceComboBox().removeAllItems(); |
158 |
|
159 |
getDatasourceComboBox().addItem(new ConnectionWithParams());
|
160 |
|
161 |
ConnectionWithParams[] conn = SingleVectorialDBConnectionManager.instance()
|
162 |
.getAllConnections(); |
163 |
|
164 |
if (conn == null) { |
165 |
return;
|
166 |
} |
167 |
|
168 |
for (int i = 0; i < conn.length; i++) { |
169 |
getDatasourceComboBox().addItem(conn[i]); |
170 |
} |
171 |
} |
172 |
|
173 |
private String[] getDriverNames() { |
174 |
Class[] classes = new Class[] { IVectorialDatabaseDriver.class }; |
175 |
|
176 |
ArrayList ret = new ArrayList(); |
177 |
String[] driverNames = LayerFactory.getDM().getDriverNames(); |
178 |
|
179 |
for (int i = 0; i < driverNames.length; i++) { |
180 |
boolean is = false; |
181 |
|
182 |
for (int j = 0; j < classes.length; j++) { |
183 |
if (LayerFactory.getDM().isA(driverNames[i], classes[j])) {
|
184 |
ret.add(driverNames[i]); |
185 |
} |
186 |
} |
187 |
} |
188 |
|
189 |
return (String[]) ret.toArray(new String[0]); |
190 |
} |
191 |
|
192 |
/**
|
193 |
* Utility method to instantiate a IVectorialDataBaseDriver from its name.
|
194 |
*
|
195 |
* @param drvname driver's name
|
196 |
* @return a IVectorialDataBaseDriver
|
197 |
*
|
198 |
* @throws DriverLoadException
|
199 |
*/
|
200 |
public IVectorialDatabaseDriver getDriverFromName(String drvname) |
201 |
throws DriverLoadException {
|
202 |
IVectorialDatabaseDriver resp = |
203 |
(IVectorialDatabaseDriver) LayerFactory.getDM().getDriver(drvname); |
204 |
return resp;
|
205 |
} |
206 |
|
207 |
public void initWizard() { |
208 |
} |
209 |
|
210 |
public void execute() { |
211 |
} |
212 |
|
213 |
/**
|
214 |
* Return FLayers if user performs multi selection.
|
215 |
*/
|
216 |
public FLayer getLayer() {
|
217 |
try {
|
218 |
IProjection proj = null;
|
219 |
TablesListItem[] selected = getSelectedTables();
|
220 |
int count = selected.length;
|
221 |
String groupName = selectedDataSource.getDb() + " (" + |
222 |
conex.getNameServer() + ")";
|
223 |
|
224 |
FLayer[] all_layers = new FLayer[count]; |
225 |
String strEPSG = getMapCtrl().getViewPort().getProjection()
|
226 |
.getAbrev().substring(5);
|
227 |
|
228 |
for (int i = 0; i < count; i++) { |
229 |
TablesListItem item = selected[i]; |
230 |
|
231 |
IVectorialDatabaseDriver driver = null;
|
232 |
driver = (IVectorialDatabaseDriver) getDriverFromName(selectedDataSource.getDrvName()); |
233 |
|
234 |
Rectangle2D _wa = item.getUserTableSettingsPanel()
|
235 |
.getWorkingArea(); |
236 |
|
237 |
if (_wa != null) { |
238 |
driver.setWorkingArea(_wa); |
239 |
} |
240 |
|
241 |
String layerName = item.getUserTableSettingsPanel()
|
242 |
.getUserLayerName(); |
243 |
|
244 |
// Change: we parse tableName to extract schema (or owner in Oracle)
|
245 |
String[] tokens = item.getTableName().split("\\u002E", 2); |
246 |
String tableName;
|
247 |
String schema = null; |
248 |
if (tokens.length > 1) |
249 |
{ |
250 |
schema = tokens[0];
|
251 |
tableName = tokens[1];
|
252 |
} |
253 |
else
|
254 |
{ |
255 |
tableName = tokens[1];
|
256 |
} |
257 |
|
258 |
String fidField = item.getUserTableSettingsPanel()
|
259 |
.getIdFieldName(); |
260 |
String geomField = item.getUserTableSettingsPanel()
|
261 |
.getGeoFieldName(); |
262 |
String[] fields = item.getUserSelectedFieldsPanel() |
263 |
.getUserSelectedFields(fidField, geomField); |
264 |
|
265 |
// fields = driver.manageGeometryField(fields, geomField);
|
266 |
|
267 |
// driver.manageGeometryField(geomField);
|
268 |
DBLayerDefinition lyrDef = new DBLayerDefinition();
|
269 |
lyrDef.setName(layerName); |
270 |
lyrDef.setSchema(schema); |
271 |
lyrDef.setTableName(tableName); |
272 |
|
273 |
if (item.getUserTableSettingsPanel().isSqlActive()) {
|
274 |
String whereClause = item.getUserTableSettingsPanel()
|
275 |
.getWhereClause(); |
276 |
lyrDef.setWhereClause(whereClause); |
277 |
} |
278 |
else {
|
279 |
lyrDef.setWhereClause("");
|
280 |
} |
281 |
|
282 |
lyrDef.setFieldGeometry(geomField); |
283 |
lyrDef.setFieldNames(fields); |
284 |
|
285 |
lyrDef.setFieldID(fidField); |
286 |
|
287 |
if (_wa != null) { |
288 |
lyrDef.setWorkingArea(_wa); |
289 |
} |
290 |
|
291 |
lyrDef.setSRID_EPSG(strEPSG); |
292 |
|
293 |
if (driver instanceof ICanReproject) { |
294 |
((ICanReproject) driver).setDestProjection(strEPSG); |
295 |
} |
296 |
lyrDef.setHost(selectedDataSource.getHost()); |
297 |
lyrDef.setPort(Integer.parseInt(selectedDataSource.getPort()));
|
298 |
lyrDef.setDataBase(selectedDataSource.getDb()); |
299 |
lyrDef.setUser(selectedDataSource.getUser()); |
300 |
lyrDef.setPassword(selectedDataSource.getPw()); |
301 |
|
302 |
driver.setData(conex, lyrDef); |
303 |
|
304 |
if (driver instanceof ICanReproject) { |
305 |
proj = CRSFactory.getCRS("EPSG:" +
|
306 |
((ICanReproject) driver).getSourceProjection()); |
307 |
} |
308 |
|
309 |
all_layers[i] = LayerFactory.createDBLayer(driver, layerName, |
310 |
proj); |
311 |
} |
312 |
|
313 |
return layerArrayToGroup(all_layers, groupName);
|
314 |
} |
315 |
catch (Exception e) { |
316 |
logger.error("While creating jdbc layer: " + e.getMessage(), e);
|
317 |
NotificationManager.addError("Error al cargar la capa: " +
|
318 |
e.getMessage(), e); |
319 |
} |
320 |
|
321 |
return null; |
322 |
} |
323 |
|
324 |
private FLayer layerArrayToGroup(FLayer[] all_layers, String name) { |
325 |
if (all_layers.length == 1) { |
326 |
return all_layers[0]; |
327 |
} |
328 |
|
329 |
MapContext mc = view.getMapControl().getMapContext(); |
330 |
FLayers root = view.getMapControl().getMapContext().getLayers(); |
331 |
|
332 |
FLayers group = new FLayers(mc, root);
|
333 |
group.setName(name); |
334 |
|
335 |
for (int i = 0; i < all_layers.length; i++) { |
336 |
group.addLayer(all_layers[i]); |
337 |
} |
338 |
|
339 |
return group;
|
340 |
} |
341 |
|
342 |
private TablesListItem[] getSelectedTables() { |
343 |
int count = tablesList.getModel().getSize();
|
344 |
ArrayList resp = new ArrayList(); |
345 |
|
346 |
for (int i = 0; i < count; i++) { |
347 |
TablesListItem item = (TablesListItem) tablesList.getModel() |
348 |
.getElementAt(i); |
349 |
|
350 |
if (item.isSelected()) {
|
351 |
resp.add(item); |
352 |
} |
353 |
} |
354 |
|
355 |
return (TablesListItem[]) resp.toArray(new TablesListItem[0]); |
356 |
} |
357 |
|
358 |
/**
|
359 |
* This method initializes namePanel
|
360 |
*
|
361 |
* @return javax.swing.JPanel
|
362 |
*/
|
363 |
private JPanel getNamePanel() { |
364 |
if (namePanel == null) { |
365 |
namePanel = new JPanel(); |
366 |
namePanel.setLayout(null);
|
367 |
namePanel.setBounds(new java.awt.Rectangle(5, 5, 501, 51)); |
368 |
namePanel.setBorder(javax.swing.BorderFactory.createTitledBorder( |
369 |
null, PluginServices.getText(this, "choose_connection"), |
370 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
371 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
372 |
namePanel.add(getDatasourceComboBox(), null);
|
373 |
namePanel.add(getJdbcButton(), null);
|
374 |
} |
375 |
|
376 |
return namePanel;
|
377 |
} |
378 |
|
379 |
/**
|
380 |
* This method initializes tablesPanel
|
381 |
*
|
382 |
* @return javax.swing.JPanel
|
383 |
*/
|
384 |
private JPanel getTablesPanel() { |
385 |
if (tablesPanel == null) { |
386 |
tablesPanel = new JPanel(); |
387 |
tablesPanel.setLayout(new BorderLayout()); |
388 |
tablesPanel.setBorder(javax.swing.BorderFactory.createTitledBorder( |
389 |
null, PluginServices.getText(this, "choose_table"), |
390 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
391 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
392 |
tablesPanel.setBounds(new java.awt.Rectangle(5, 55, 246, 191)); |
393 |
tablesPanel.add(getTablesScrollPane(), java.awt.BorderLayout.CENTER); |
394 |
} |
395 |
|
396 |
return tablesPanel;
|
397 |
} |
398 |
|
399 |
/**
|
400 |
* This method initializes settingsPanel
|
401 |
*
|
402 |
* @return javax.swing.JPanel
|
403 |
*/
|
404 |
|
405 |
/**
|
406 |
* This method initializes tablesScrollPane
|
407 |
*
|
408 |
* @return javax.swing.JScrollPane
|
409 |
*/
|
410 |
private JScrollPane getTablesScrollPane() { |
411 |
if (tablesScrollPane == null) { |
412 |
tablesScrollPane = new JScrollPane(); |
413 |
tablesScrollPane.setViewportView(getTablesList()); |
414 |
} |
415 |
|
416 |
return tablesScrollPane;
|
417 |
} |
418 |
|
419 |
/**
|
420 |
* This method initializes tablesList
|
421 |
*
|
422 |
* @return javax.swing.JList
|
423 |
*/
|
424 |
private AvailableTablesCheckBoxList getTablesList() {
|
425 |
if (tablesList == null) { |
426 |
tablesList = new AvailableTablesCheckBoxList(this); |
427 |
tablesList.addListSelectionListener(this);
|
428 |
tablesList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
429 |
} |
430 |
|
431 |
return tablesList;
|
432 |
} |
433 |
|
434 |
/**
|
435 |
* This method initializes layerNameTextField
|
436 |
*
|
437 |
* @return javax.swing.JTextField
|
438 |
*/
|
439 |
|
440 |
/**
|
441 |
* This method initializes jComboBox
|
442 |
*
|
443 |
* @return javax.swing.JComboBox
|
444 |
*/
|
445 |
private JComboBox getDatasourceComboBox() { |
446 |
if (datasourceComboBox == null) { |
447 |
datasourceComboBox = new JComboBox(); |
448 |
datasourceComboBox.setBounds(new java.awt.Rectangle(10, 20, 446, 21)); |
449 |
datasourceComboBox.addActionListener(this);
|
450 |
} |
451 |
|
452 |
return datasourceComboBox;
|
453 |
} |
454 |
|
455 |
public void actionPerformed(ActionEvent arg0) { |
456 |
Object src = arg0.getSource();
|
457 |
|
458 |
if (src == datasourceComboBox) {
|
459 |
Object sel_obj = datasourceComboBox.getSelectedItem();
|
460 |
|
461 |
if (sel_obj == null) { |
462 |
return;
|
463 |
} |
464 |
|
465 |
if (!(sel_obj instanceof ConnectionWithParams)) { |
466 |
return;
|
467 |
} |
468 |
|
469 |
selectedDataSource = (ConnectionWithParams) sel_obj; |
470 |
|
471 |
if (selectedDataSource.isNull()) {
|
472 |
updateTableList(selectedDataSource); |
473 |
setEmptyPanels(); |
474 |
|
475 |
return;
|
476 |
} |
477 |
|
478 |
if (!selectedDataSource.isConnected()) {
|
479 |
if (!tryToConnect(selectedDataSource)) {
|
480 |
datasourceComboBox.setSelectedIndex(0);
|
481 |
|
482 |
return;
|
483 |
} |
484 |
} |
485 |
|
486 |
getDatasourceComboBox().repaint(); |
487 |
updateTableList(selectedDataSource); |
488 |
|
489 |
// setEmptyPanels();
|
490 |
return;
|
491 |
} |
492 |
|
493 |
if (src == dbButton) {
|
494 |
ConnectionWithParams sel = addNewConnection(); |
495 |
|
496 |
if (sel != null) { |
497 |
loadVectorialDBDatasourcesCombo(); |
498 |
getDatasourceComboBox().setSelectedItem(sel); |
499 |
} |
500 |
} |
501 |
} |
502 |
|
503 |
private boolean tryToConnect(ConnectionWithParams _cwp) { |
504 |
JPasswordDlg dlg = new JPasswordDlg();
|
505 |
String strMessage = PluginServices.getText(this, "conectar_jdbc"); |
506 |
String strPassword = PluginServices.getText(this, "password"); |
507 |
dlg.setMessage(strMessage + " [" + _cwp.getDrvName() + ", " + |
508 |
_cwp.getHost() + ", " + _cwp.getPort() + ", " + _cwp.getDb() + |
509 |
", " + _cwp.getUser() + "]. " + strPassword + "?"); |
510 |
|
511 |
dlg.show(); |
512 |
|
513 |
String clave = dlg.getPassword();
|
514 |
|
515 |
if (clave == null) { |
516 |
return false; |
517 |
} |
518 |
|
519 |
try {
|
520 |
_cwp.connect(clave); |
521 |
} |
522 |
catch (DBException e) {
|
523 |
showConnectionErrorMessage(e.getMessage()); |
524 |
|
525 |
return false; |
526 |
} |
527 |
|
528 |
return true; |
529 |
} |
530 |
|
531 |
private void updateTableList(ConnectionWithParams src) { |
532 |
if (src.isNull()) {
|
533 |
getTablesList().setModel(new DefaultListModel()); |
534 |
getTablesScrollPane().setViewportView(tablesList); |
535 |
tablesScrollPane.updateUI(); |
536 |
|
537 |
return;
|
538 |
} |
539 |
|
540 |
conex = src.getConnection(); |
541 |
|
542 |
String drvName = src.getDrvName();
|
543 |
String dbName = ""; |
544 |
|
545 |
IVectorialDatabaseDriver drv = null;
|
546 |
|
547 |
try {
|
548 |
dbName = src.getConnection().getCatalogName(); |
549 |
drv = (IVectorialDatabaseDriver) LayerFactory.getDM().getDriver(drvName); |
550 |
} |
551 |
catch (Exception e) { |
552 |
logger.error("While getting driver instance: " + e.getMessage(), e);
|
553 |
} |
554 |
|
555 |
if (!(drv instanceof IVectorialDatabaseDriver)) { |
556 |
logger.error( |
557 |
"Unexpected driver type (not a DefaultDBDriver driver)");
|
558 |
|
559 |
return;
|
560 |
} |
561 |
|
562 |
String[] tablnames = null; |
563 |
|
564 |
try {
|
565 |
tablnames = drv.getTableNames(conex, dbName); |
566 |
} |
567 |
catch (DBException e) {
|
568 |
logger.error("While getting table names: " + e.getMessage(), e);
|
569 |
|
570 |
return;
|
571 |
} |
572 |
|
573 |
DefaultListModel lmodel = new DefaultListModel(); |
574 |
|
575 |
for (int i = 0; i < tablnames.length; i++) { |
576 |
lmodel.addElement(new TablesListItem(tablnames[i], drv, conex,
|
577 |
getMapCtrl(), this));
|
578 |
} |
579 |
|
580 |
getTablesList().setModel(lmodel); |
581 |
getTablesScrollPane().setViewportView(tablesList); |
582 |
tablesScrollPane.updateUI(); |
583 |
} |
584 |
|
585 |
public void valueChanged(ListSelectionEvent arg0) { |
586 |
Object src = arg0.getSource();
|
587 |
|
588 |
if (src == tablesList) {
|
589 |
TablesListItem selected = (TablesListItem) tablesList.getSelectedValue(); |
590 |
|
591 |
try {
|
592 |
setSettingsPanels(selected); |
593 |
} |
594 |
catch (DBException e) {
|
595 |
showConnectionErrorMessage(e.getMessage()); |
596 |
tablesList.clearSelection(); |
597 |
setEmptyPanels(); |
598 |
} |
599 |
|
600 |
checkFinishable(); |
601 |
} |
602 |
} |
603 |
|
604 |
private boolean validFormSettings() { |
605 |
int count = tablesList.getModel().getSize();
|
606 |
|
607 |
boolean at_least_one = false; |
608 |
boolean resp = true; |
609 |
|
610 |
for (int i = 0; i < count; i++) { |
611 |
TablesListItem item = (TablesListItem) tablesList.getModel() |
612 |
.getElementAt(i); |
613 |
|
614 |
if (item.isSelected()) {
|
615 |
at_least_one = true;
|
616 |
} |
617 |
|
618 |
if (item.disturbsWizardValidity()) {
|
619 |
resp = false;
|
620 |
} |
621 |
} |
622 |
|
623 |
return (at_least_one && resp);
|
624 |
} |
625 |
|
626 |
public void checkFinishable() { |
627 |
boolean finishable = validFormSettings();
|
628 |
callStateChanged(finishable); |
629 |
} |
630 |
|
631 |
/**
|
632 |
* This method initializes jdbcButton
|
633 |
*
|
634 |
* @return javax.swing.JButton
|
635 |
*/
|
636 |
private JButton getJdbcButton() { |
637 |
if (dbButton == null) { |
638 |
dbButton = new JButton(); |
639 |
dbButton.addActionListener(this);
|
640 |
dbButton.setToolTipText(PluginServices.getText(this,
|
641 |
"add_connection"));
|
642 |
dbButton.setBounds(new java.awt.Rectangle(465, 20, 26, 21)); |
643 |
|
644 |
String _file = createResourceUrl("images/jdbc.png").getFile(); |
645 |
dbButton.setIcon(new ImageIcon(_file)); |
646 |
} |
647 |
|
648 |
return dbButton;
|
649 |
} |
650 |
|
651 |
private ConnectionWithParams addNewConnection() {
|
652 |
ConnectionWithParams resp = null;
|
653 |
|
654 |
VectorialDBConnectionParamsDialog newco = new VectorialDBConnectionParamsDialog();
|
655 |
newco.showDialog(); |
656 |
|
657 |
if (newco.isOkPressed()) {
|
658 |
String _drvname = newco.getConnectionDriverName();
|
659 |
String _host = newco.getConnectionServerUrl();
|
660 |
String _port = newco.getConnectionPort();
|
661 |
String _dbname = newco.getConnectionDBName();
|
662 |
String _user = newco.getConnectionUser();
|
663 |
String _pw = newco.getConnectionPassword();
|
664 |
String _conn_usr_name = newco.getConnectionName();
|
665 |
|
666 |
boolean hasToBeCon = newco.hasToBeConnected();
|
667 |
|
668 |
try {
|
669 |
resp = SingleVectorialDBConnectionManager.instance() |
670 |
.getConnection(_drvname, |
671 |
_user, _pw, _conn_usr_name, _host, _port, _dbname, |
672 |
hasToBeCon); |
673 |
} |
674 |
catch (DBException e) {
|
675 |
showConnectionErrorMessage(e.getMessage()); |
676 |
|
677 |
return null; |
678 |
} |
679 |
|
680 |
return resp;
|
681 |
} |
682 |
else {
|
683 |
return null; |
684 |
} |
685 |
} |
686 |
|
687 |
private void showConnectionErrorMessage(String _msg) { |
688 |
String msg;
|
689 |
if (_msg == null){ |
690 |
_msg = PluginServices.getText(this, "connection_error"); |
691 |
} |
692 |
msg = (_msg.length() > 300) ? "" : (": " + _msg); |
693 |
String title = PluginServices.getText(this, "connection_error"); |
694 |
JOptionPane.showMessageDialog(this, title + msg, title, |
695 |
JOptionPane.ERROR_MESSAGE);
|
696 |
} |
697 |
|
698 |
private java.net.URL createResourceUrl(String path) { |
699 |
return getClass().getClassLoader().getResource(path);
|
700 |
} |
701 |
|
702 |
public void setSettingsPanels(TablesListItem actTable) |
703 |
throws DBException {
|
704 |
if (actTable == null) { |
705 |
setEmptyPanels(); |
706 |
|
707 |
return;
|
708 |
} |
709 |
|
710 |
settingsPanel = actTable.getUserTableSettingsPanel(); |
711 |
fieldsPanel = actTable.getUserSelectedFieldsPanel(); |
712 |
|
713 |
removeFieldPanels(); |
714 |
add(fieldsPanel); |
715 |
fieldsPanel.repaint(); |
716 |
|
717 |
removeSettingsPanels(); |
718 |
add(settingsPanel); |
719 |
settingsPanel.repaint(); |
720 |
|
721 |
repaint(); |
722 |
} |
723 |
|
724 |
private void setEmptyPanels() { |
725 |
removeFieldPanels(); |
726 |
add(emptyFieldsPanel); |
727 |
removeSettingsPanels(); |
728 |
add(emptySettingsPanel); |
729 |
|
730 |
settingsPanel = emptySettingsPanel; |
731 |
fieldsPanel = emptyFieldsPanel; |
732 |
|
733 |
repaint(); |
734 |
} |
735 |
|
736 |
private void removeFieldPanels() { |
737 |
for (int i = 0; i < getComponentCount(); i++) { |
738 |
if (getComponent(i) instanceof UserSelectedFieldsPanel) { |
739 |
remove(i); |
740 |
} |
741 |
} |
742 |
} |
743 |
|
744 |
private void removeSettingsPanels() { |
745 |
for (int i = 0; i < getComponentCount(); i++) { |
746 |
if (getComponent(i) instanceof UserTableSettingsPanel) { |
747 |
remove(i); |
748 |
} |
749 |
} |
750 |
} |
751 |
} // @jve:decl-index=0:visual-constraint="10,10"
|