Revision 44422 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.impl/src/main/java/org/gvsig/fmap/dal/swing/impl/jdbc/DefaultJDBCConnectionPanel.java
DefaultJDBCConnectionPanel.java | ||
---|---|---|
23 | 23 |
import org.gvsig.fmap.dal.DataServerExplorerParameters; |
24 | 24 |
import org.gvsig.fmap.dal.DataServerExplorerPool; |
25 | 25 |
import org.gvsig.fmap.dal.DataServerExplorerPoolEntry; |
26 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
|
26 | 27 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters; |
27 | 28 |
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters; |
28 | 29 |
import org.gvsig.fmap.dal.swing.jdbc.JDBCConnectionPanel; |
... | ... | |
272 | 273 |
if( s!=null ) { |
273 | 274 |
params.setPassword(s); |
274 | 275 |
} |
275 |
|
|
276 |
|
|
276 | 277 |
String name = this.getConnectionName(); |
277 | 278 |
if ( StringUtils.isBlank(name) ) { |
278 | 279 |
if( params instanceof FilesystemStoreParameters ) { |
... | ... | |
295 | 296 |
name = builder.toString(); |
296 | 297 |
} |
297 | 298 |
} |
299 |
|
|
298 | 300 |
if( StringUtils.isBlank(name) ) { |
299 | 301 |
name = getUniqueEntryName("Connection"); |
300 |
} else { |
|
302 |
} else if( this.isNewConnection() ) {
|
|
301 | 303 |
name = getUniqueEntryName(name); |
302 | 304 |
} |
303 | 305 |
|
304 |
DataManager dataManager = DALLocator.getDataManager(); |
|
305 |
DataServerExplorerPool pool = dataManager.getDataServerExplorerPool(); |
|
306 |
pool.add(name, params); |
|
306 |
try { |
|
307 |
params.validate(); |
|
308 |
DataManager dataManager = DALLocator.getDataManager(); |
|
309 |
DataServerExplorerPool pool = dataManager.getDataServerExplorerPool(); |
|
310 |
pool.add(name, params); |
|
311 |
} catch (ValidateDataParametersException ex) { |
|
312 |
|
|
313 |
} |
|
314 |
|
|
307 | 315 |
return new LabeledValueImpl<>(name,params); |
308 | 316 |
} |
309 | 317 |
|
318 |
@Override |
|
319 |
public boolean areTheParametersValid() { |
|
320 |
try { |
|
321 |
LabeledValue<JDBCServerExplorerParameters> params = this.getLabeledServerExplorerParameters(); |
|
322 |
params.getValue().validate(); |
|
323 |
return true; |
|
324 |
} catch (ValidateDataParametersException ex) { |
|
325 |
return false; |
|
326 |
} |
|
327 |
} |
|
328 |
|
|
329 |
@Override |
|
330 |
public String getParametersProblems() { |
|
331 |
try { |
|
332 |
LabeledValue<JDBCServerExplorerParameters> params = this.getLabeledServerExplorerParameters(); |
|
333 |
params.getValue().validate(); |
|
334 |
return null; |
|
335 |
} catch (ValidateDataParametersException ex) { |
|
336 |
return ex.getLocalizedMessageStack(); |
|
337 |
} |
|
338 |
} |
|
339 |
|
|
310 | 340 |
private String getUniqueEntryName(String name) { |
311 | 341 |
DataManager dataManager = DALLocator.getDataManager(); |
312 | 342 |
DataServerExplorerPool pool = dataManager.getDataServerExplorerPool(); |
... | ... | |
327 | 357 |
|
328 | 358 |
@Override |
329 | 359 |
public String getConnectionName() { |
330 |
JTextField txtConnections = (JTextField) this.cboConnections.getEditor().getEditorComponent(); |
|
331 |
String value = txtConnections.getText(); |
|
332 |
return (String) StringUtils.defaultIfBlank(value, null); |
|
360 |
String value = (String) this.cboConnections.getSelectedItem(); |
|
361 |
return StringUtils.defaultIfBlank(value, null); |
|
333 | 362 |
} |
334 | 363 |
|
364 |
@Override |
|
365 |
public boolean isNewConnection() { |
|
366 |
String name = this.getConnectionName(); |
|
367 |
if( name == null ) { |
|
368 |
return true; |
|
369 |
} |
|
370 |
ComboBoxModel<LabeledValue<JDBCServerExplorerParameters>> model = this.cboConnections.getModel(); |
|
371 |
for (int i = 0; i < model.getSize(); i++) { |
|
372 |
LabeledValue<JDBCServerExplorerParameters> conn = model.getElementAt(i); |
|
373 |
if( StringUtils.equalsIgnoreCase(name, conn.getLabel()) ) { |
|
374 |
return false; |
|
375 |
} |
|
376 |
} |
|
377 |
return true; |
|
378 |
} |
|
379 |
|
|
335 | 380 |
protected JDBCServerExplorerParameters getConnector() { |
336 | 381 |
LabeledValue<JDBCServerExplorerParameters> item = (LabeledValue<JDBCServerExplorerParameters>) this.cboConnectors.getSelectedItem(); |
337 | 382 |
if( item == null ) { |
Also available in: Unified diff