svn-gvsig-desktop / 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 @ 44591
History | View | Annotate | Download (21.7 KB)
1 |
package org.gvsig.fmap.dal.swing.impl.jdbc; |
---|---|
2 |
|
3 |
import java.awt.Dimension; |
4 |
import java.awt.event.ActionEvent; |
5 |
import java.awt.event.ActionListener; |
6 |
import java.awt.event.ItemEvent; |
7 |
import java.awt.event.ItemListener; |
8 |
import java.io.File; |
9 |
import java.util.Objects; |
10 |
import javax.swing.ComboBoxModel; |
11 |
import javax.swing.JComponent; |
12 |
import javax.swing.JLabel; |
13 |
import javax.swing.JTextField; |
14 |
import javax.swing.SwingUtilities; |
15 |
import javax.swing.plaf.basic.BasicHTML; |
16 |
import javax.swing.text.View; |
17 |
import org.apache.commons.io.FilenameUtils; |
18 |
import org.apache.commons.lang3.ArrayUtils; |
19 |
import org.apache.commons.lang3.StringUtils; |
20 |
import org.gvsig.fmap.dal.DALLocator; |
21 |
import org.gvsig.fmap.dal.DataFactory; |
22 |
import org.gvsig.fmap.dal.DataManager; |
23 |
import org.gvsig.fmap.dal.DataServerExplorerParameters; |
24 |
import org.gvsig.fmap.dal.DataServerExplorerPool; |
25 |
import org.gvsig.fmap.dal.DataServerExplorerPoolEntry; |
26 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
27 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters; |
28 |
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters; |
29 |
import org.gvsig.fmap.dal.swing.jdbc.JDBCConnectionPanel; |
30 |
import org.gvsig.tools.ToolsLocator; |
31 |
import org.gvsig.tools.dynobject.DynClass; |
32 |
import org.gvsig.tools.dynobject.DynField; |
33 |
import org.gvsig.tools.i18n.I18nManager; |
34 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
35 |
import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager; |
36 |
import org.gvsig.tools.util.LabeledValue; |
37 |
import org.gvsig.tools.util.LabeledValueImpl; |
38 |
import org.slf4j.Logger; |
39 |
import org.slf4j.LoggerFactory; |
40 |
|
41 |
// org.gvsig.fmap.mapcontrol.dal.jdbc.JDBCConnectionPanel
|
42 |
@SuppressWarnings("UseSpecificCatch") |
43 |
public class DefaultJDBCConnectionPanel extends DefaultJDBCConnectionPanelView implements JDBCConnectionPanel{ |
44 |
|
45 |
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultJDBCConnectionPanel.class); |
46 |
private static final long serialVersionUID = -6119489353793596382L; |
47 |
private JDBCServerExplorerParameters forcedParameters;
|
48 |
private ItemListener onChangeConnectorItemListener; |
49 |
private ConnectorFilter connectorFilter=null; |
50 |
|
51 |
@Override
|
52 |
public JComponent asJComponent() { |
53 |
return this; |
54 |
} |
55 |
|
56 |
// private static class ServerExplorerParametersComboItem {
|
57 |
//
|
58 |
// private JDBCServerExplorerParameters params;
|
59 |
// private String label;
|
60 |
//
|
61 |
// public ServerExplorerParametersComboItem(String label, JDBCServerExplorerParameters params) {
|
62 |
// this.params = params;
|
63 |
// this.label = label;
|
64 |
// }
|
65 |
//
|
66 |
// public ServerExplorerParametersComboItem(JDBCServerExplorerParameters params) {
|
67 |
// this(params.getExplorerName(), params);
|
68 |
// }
|
69 |
//
|
70 |
// @Override
|
71 |
// public String toString() {
|
72 |
// return this.label;
|
73 |
// }
|
74 |
//
|
75 |
// public JDBCServerExplorerParameters getParams() {
|
76 |
// return this.params;
|
77 |
// }
|
78 |
//
|
79 |
// public String getLabel() {
|
80 |
// return this.label;
|
81 |
// }
|
82 |
// }
|
83 |
|
84 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
85 |
public DefaultJDBCConnectionPanel() {
|
86 |
initComponents(); |
87 |
} |
88 |
|
89 |
protected void initComponents() { |
90 |
this.cboConnections.setEditable(true); |
91 |
this.cboConnections.addItemListener(new ItemListener() { |
92 |
@Override
|
93 |
public void itemStateChanged(ItemEvent e) { |
94 |
if(e.getStateChange() != ItemEvent.SELECTED) { |
95 |
return;
|
96 |
} // Lo hago asi para evitar cuelgues durante la depuracion
|
97 |
// al poner puntos de ruptura en un evento de un combo.
|
98 |
SwingUtilities.invokeLater(new Runnable() { |
99 |
|
100 |
@Override
|
101 |
public void run() { |
102 |
onChangeConnection(); |
103 |
} |
104 |
}); |
105 |
} |
106 |
}); |
107 |
this.onChangeConnectorItemListener = new ItemListener() { |
108 |
@Override
|
109 |
public void itemStateChanged(ItemEvent e) { |
110 |
if(e.getStateChange() != ItemEvent.SELECTED) { |
111 |
return;
|
112 |
} |
113 |
// Lo hago asi para evitar cuelgues durante la depuracion
|
114 |
// al poner puntos de ruptura en un evento de un combo.
|
115 |
SwingUtilities.invokeLater(new Runnable() { |
116 |
|
117 |
@Override
|
118 |
public void run() { |
119 |
onChangeConnector(); |
120 |
} |
121 |
}); |
122 |
} |
123 |
}; |
124 |
this.cboConnectors.addItemListener(onChangeConnectorItemListener);
|
125 |
try {
|
126 |
fillConnections(); |
127 |
fillConnectors(); |
128 |
} catch(Throwable th) { |
129 |
// Ignore it to allow use in GUI builders
|
130 |
LOGGER.warn("Can't fill combos",th);
|
131 |
} |
132 |
this.translate();
|
133 |
this.btnDataBaseBrowser.addActionListener(new ActionListener() { |
134 |
|
135 |
@Override
|
136 |
public void actionPerformed(ActionEvent e) { |
137 |
onBrowseDatabase(); |
138 |
} |
139 |
}); |
140 |
adjustPreferedHeight(this.lblFoother,300); |
141 |
Dimension sz = this.getPreferredSize(); |
142 |
if( sz.width<400 ) { |
143 |
sz.width = 400;
|
144 |
this.setPreferredSize(sz);
|
145 |
} |
146 |
} |
147 |
|
148 |
private void adjustPreferedHeight(JLabel label, int prefWidth) { |
149 |
JLabel resizer = new JLabel(); |
150 |
resizer.setText(label.getText()); |
151 |
View view = (View) resizer.getClientProperty(BasicHTML.propertyKey); |
152 |
view.setSize(prefWidth,15);
|
153 |
float w = view.getPreferredSpan(View.X_AXIS); |
154 |
float h = view.getPreferredSpan(View.Y_AXIS); |
155 |
Dimension dim = new Dimension( |
156 |
(int) Math.ceil(w), |
157 |
(int) Math.ceil(h) |
158 |
); |
159 |
label.setPreferredSize(dim); |
160 |
} |
161 |
|
162 |
private void translate() { |
163 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
164 |
|
165 |
this.lblFile.setText(i18nManager.getTranslation("_File")); |
166 |
this.lblConnectionName.setText(i18nManager.getTranslation("_Connection_name")); |
167 |
this.lblConnector.setText(i18nManager.getTranslation("_Driver_type")); |
168 |
this.lblServer.setText(i18nManager.getTranslation("_Host")); |
169 |
this.lblPort.setText(i18nManager.getTranslation("_Port")); |
170 |
this.lblDataBase.setText(i18nManager.getTranslation("_Database")); |
171 |
this.lblUsername.setText(i18nManager.getTranslation("_User")); |
172 |
this.lblPassword.setText(i18nManager.getTranslation("_Password")); |
173 |
this.lblFoother.setText("<html>"+i18nManager.getTranslation("_JDBCConecctionPanel_foother")+"</html>"); |
174 |
} |
175 |
|
176 |
@Override
|
177 |
public void setLabeledServerExplorerParameters(LabeledValue<JDBCServerExplorerParameters> parameters) { |
178 |
if( parameters == null ) { |
179 |
return;
|
180 |
} |
181 |
if( parameters.getValue()!=null ) { |
182 |
this.setServerExplorerParameters(parameters.getValue());
|
183 |
} |
184 |
if( !StringUtils.isBlank(parameters.getLabel()) ) {
|
185 |
this.cboConnections.setSelectedItem(parameters.getLabel());
|
186 |
} |
187 |
} |
188 |
|
189 |
@Override
|
190 |
public void setServerExplorerParameters(JDBCServerExplorerParameters parameters) { |
191 |
this.forcedParameters = (JDBCServerExplorerParameters) parameters.getCopy();
|
192 |
|
193 |
int indexConnector = this.getIndexOfConnector(parameters); |
194 |
if ( indexConnector >= 0 && this.cboConnectors.getSelectedIndex()!=indexConnector ) { |
195 |
this.cboConnectors.removeItemListener(this.onChangeConnectorItemListener); |
196 |
this.cboConnectors.setSelectedIndex(indexConnector);
|
197 |
this.cboConnectors.addItemListener(onChangeConnectorItemListener);
|
198 |
} |
199 |
|
200 |
this.txtServer.setText(parameters.getHost());
|
201 |
Integer port = parameters.getPort();
|
202 |
if ( port == null ) { |
203 |
this.txtPort.setText(""); |
204 |
} else {
|
205 |
this.txtPort.setText(String.valueOf(port)); |
206 |
} |
207 |
this.txtDataBase.setText(parameters.getDBName());
|
208 |
this.txtUsername.setText(parameters.getUser());
|
209 |
this.txtPassword.setText(parameters.getPassword());
|
210 |
|
211 |
DynClass definition = parameters.getDynClass(); |
212 |
|
213 |
DynField field = definition.getDynField(JDBCServerExplorerParameters.HOST_PARAMTER_NAME); |
214 |
this.txtServer.setEnabled( !( field.isReadOnly() || field.isHidden() ));
|
215 |
field = definition.getDynField(JDBCServerExplorerParameters.PORT_PARAMTER_NAME); |
216 |
this.txtPort.setEnabled( !( field.isReadOnly() || field.isHidden() ));
|
217 |
field = definition.getDynField(JDBCServerExplorerParameters.DBNAME_PARAMTER_NAME); |
218 |
this.txtDataBase.setEnabled( !( field.isReadOnly() || field.isHidden() ));
|
219 |
field = definition.getDynField(JDBCServerExplorerParameters.USER_PARAMTER_NAME); |
220 |
this.txtUsername.setEnabled( !( field.isReadOnly() || field.isHidden() ));
|
221 |
field = definition.getDynField(JDBCServerExplorerParameters.PASSWORD_PARAMTER_NAME); |
222 |
this.txtPassword.setEnabled( !( field.isReadOnly() || field.isHidden() ));
|
223 |
if( parameters instanceof FilesystemStoreParameters ) { |
224 |
File f = ((FilesystemStoreParameters) parameters).getFile();
|
225 |
if( f==null ) { |
226 |
this.txtFile.setText(""); |
227 |
} else {
|
228 |
this.txtFile.setText(f.getAbsolutePath());
|
229 |
} |
230 |
this.btnDataBaseBrowser.setVisible(true); |
231 |
this.txtFile.setVisible(true); |
232 |
this.lblFile.setVisible(true); |
233 |
} else {
|
234 |
this.btnDataBaseBrowser.setVisible(false); |
235 |
this.txtFile.setVisible(false); |
236 |
this.lblFile.setVisible(false); |
237 |
} |
238 |
} |
239 |
|
240 |
@Override
|
241 |
public JDBCServerExplorerParameters getServerExplorerParameters() {
|
242 |
JDBCServerExplorerParameters params; |
243 |
JDBCServerExplorerParameters connector = this.getConnector();
|
244 |
if( connector==null ) { |
245 |
return null; |
246 |
} |
247 |
if( this.forcedParameters==null ) { |
248 |
params = (JDBCServerExplorerParameters) connector.getCopy(); |
249 |
} else {
|
250 |
params = (JDBCServerExplorerParameters) this.forcedParameters.getCopy();
|
251 |
} |
252 |
String s = this.getServer(); |
253 |
if( s!=null ) { |
254 |
params.setHost(s); |
255 |
} |
256 |
int n = this.getPort(); |
257 |
if( n>0 ) { |
258 |
params.setPort(n); |
259 |
} |
260 |
s = this.getDataBaseName();
|
261 |
if( s!=null ) { |
262 |
params.setDBName(s); |
263 |
} |
264 |
s = this.getUsername();
|
265 |
if( s!=null ) { |
266 |
params.setUser(s); |
267 |
} |
268 |
s = this.getPassword();
|
269 |
if( s!=null ) { |
270 |
params.setPassword(s); |
271 |
} |
272 |
return params;
|
273 |
} |
274 |
|
275 |
@Override
|
276 |
public LabeledValue<JDBCServerExplorerParameters> getLabeledServerExplorerParameters() {
|
277 |
JDBCServerExplorerParameters params = this.getServerExplorerParameters();
|
278 |
if( params == null ) { |
279 |
return null; |
280 |
} |
281 |
String name = this.getConnectionName(); |
282 |
if ( StringUtils.isBlank(name) ) {
|
283 |
if( params instanceof FilesystemStoreParameters ) { |
284 |
File f = ((FilesystemStoreParameters) params).getFile();
|
285 |
if( f!=null ) { |
286 |
name = FilenameUtils.getBaseName(f.getPath()); |
287 |
} |
288 |
} |
289 |
if( StringUtils.isBlank(name) ) {
|
290 |
StringBuilder builder = new StringBuilder(); |
291 |
builder.append(Objects.toString(params.getHost(),""));
|
292 |
if( builder.length()>0 && !builder.toString().endsWith("-")) { |
293 |
builder.append("-");
|
294 |
} |
295 |
builder.append(Objects.toString(params.getPort(),""));
|
296 |
if( builder.length()>0 && !builder.toString().endsWith("-")) { |
297 |
builder.append("-");
|
298 |
} |
299 |
builder.append(Objects.toString(params.getDBName(),""));
|
300 |
name = builder.toString(); |
301 |
} |
302 |
} |
303 |
|
304 |
if( StringUtils.isBlank(name) ) {
|
305 |
name = getUniqueEntryName("Connection");
|
306 |
} else if( this.isNewConnection() ) { |
307 |
name = getUniqueEntryName(name); |
308 |
} |
309 |
return new LabeledValueImpl<>(name,params); |
310 |
} |
311 |
|
312 |
@Override
|
313 |
public boolean areTheParametersValid() { |
314 |
try {
|
315 |
LabeledValue<JDBCServerExplorerParameters> params = this.getLabeledServerExplorerParameters();
|
316 |
params.getValue().validate(); |
317 |
return true; |
318 |
} catch (ValidateDataParametersException ex) {
|
319 |
return false; |
320 |
} |
321 |
} |
322 |
|
323 |
@Override
|
324 |
public String getParametersProblems() { |
325 |
try {
|
326 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
327 |
JDBCServerExplorerParameters params = this.getServerExplorerParameters();
|
328 |
if( params == null ) { |
329 |
return i18n.getTranslation("You need to select a connector"); |
330 |
} |
331 |
params.validate(); |
332 |
return null; |
333 |
} catch (ValidateDataParametersException ex) {
|
334 |
return ex.getLocalizedMessageStack();
|
335 |
} |
336 |
} |
337 |
|
338 |
private String getUniqueEntryName(String name) { |
339 |
DataManager dataManager = DALLocator.getDataManager(); |
340 |
DataServerExplorerPool pool = dataManager.getDataServerExplorerPool(); |
341 |
String baseName = name;
|
342 |
for (int i = 0; i < 1000; i++) { |
343 |
if( !pool.contains(name) ) {
|
344 |
return name;
|
345 |
} |
346 |
name = baseName+"-"+i;
|
347 |
} |
348 |
return name + System.currentTimeMillis(); |
349 |
} |
350 |
|
351 |
protected void setConnectionName(String connectionName) { |
352 |
JTextField txtConnections = (JTextField) this.cboConnections.getEditor().getEditorComponent(); |
353 |
txtConnections.setText(connectionName); |
354 |
} |
355 |
|
356 |
@Override
|
357 |
public String getConnectionName() { |
358 |
Object value = this.cboConnections.getSelectedItem(); |
359 |
String name = StringUtils.defaultIfBlank(Objects.toString(value, null), null); |
360 |
if( StringUtils.isBlank(name) ) {
|
361 |
name = getUniqueEntryName("Connection");
|
362 |
} else if( this.isNewConnection() ) { |
363 |
name = getUniqueEntryName(name); |
364 |
} |
365 |
return name;
|
366 |
|
367 |
} |
368 |
|
369 |
@Override
|
370 |
public boolean isNewConnection() { |
371 |
Object value = this.cboConnections.getSelectedItem(); |
372 |
String name = StringUtils.defaultIfBlank(Objects.toString(value, null), null); |
373 |
if( name == null ) { |
374 |
return true; |
375 |
} |
376 |
ComboBoxModel<LabeledValue<JDBCServerExplorerParameters>> model = this.cboConnections.getModel(); |
377 |
for (int i = 0; i < model.getSize(); i++) { |
378 |
LabeledValue<JDBCServerExplorerParameters> conn = model.getElementAt(i); |
379 |
if( StringUtils.equalsIgnoreCase(name, conn.getLabel()) ) {
|
380 |
return false; |
381 |
} |
382 |
} |
383 |
return true; |
384 |
} |
385 |
|
386 |
protected JDBCServerExplorerParameters getConnector() {
|
387 |
LabeledValue<JDBCServerExplorerParameters> item = (LabeledValue<JDBCServerExplorerParameters>) this.cboConnectors.getSelectedItem();
|
388 |
if( item == null ) { |
389 |
return null; |
390 |
} |
391 |
return item.getValue();
|
392 |
} |
393 |
|
394 |
protected String getConnectorName() { |
395 |
JDBCServerExplorerParameters value = this.getConnector();
|
396 |
if ( value == null ) { |
397 |
return null; |
398 |
} |
399 |
return (String) StringUtils.defaultIfBlank(value.getExplorerName(), null); |
400 |
} |
401 |
|
402 |
protected String getServer() { |
403 |
return (String) StringUtils.defaultIfBlank(this.txtServer.getText(), null); |
404 |
} |
405 |
|
406 |
protected int getPort() { |
407 |
String svalue = (String) StringUtils.defaultIfBlank(this.txtPort.getText(), null); |
408 |
int ivalue;
|
409 |
try {
|
410 |
ivalue = Integer.parseInt(svalue);
|
411 |
} catch (Exception ex) { |
412 |
ivalue = -1;
|
413 |
} |
414 |
return ivalue;
|
415 |
} |
416 |
|
417 |
protected String getDataBaseName() { |
418 |
return (String) StringUtils.defaultIfBlank(this.txtDataBase.getText(), null); |
419 |
} |
420 |
|
421 |
protected String getUsername() { |
422 |
return (String) StringUtils.defaultIfBlank(this.txtUsername.getText(), null); |
423 |
} |
424 |
|
425 |
protected String getPassword() { |
426 |
return (String) StringUtils.defaultIfBlank(this.txtPassword.getText(), null); |
427 |
} |
428 |
|
429 |
private void onChangeConnector() { |
430 |
LabeledValue<JDBCServerExplorerParameters> item = (LabeledValue<JDBCServerExplorerParameters>) this.cboConnectors.getSelectedItem();
|
431 |
if( item==null ) { |
432 |
return;
|
433 |
} |
434 |
JDBCServerExplorerParameters connector = item.getValue(); |
435 |
|
436 |
if ( connector == null ) { |
437 |
return;
|
438 |
} |
439 |
this.setServerExplorerParameters(connector);
|
440 |
} |
441 |
|
442 |
private void onChangeConnection() { |
443 |
Object value = this.cboConnections.getSelectedItem(); |
444 |
if( value instanceof LabeledValue ) { |
445 |
LabeledValue<JDBCServerExplorerParameters> item = (LabeledValue<JDBCServerExplorerParameters>) value; |
446 |
JDBCServerExplorerParameters connection = item.getValue(); |
447 |
if ( connection == null ) { |
448 |
return;
|
449 |
} |
450 |
this.setServerExplorerParameters(connection);
|
451 |
} |
452 |
} |
453 |
|
454 |
|
455 |
private int getIndexOfConnector(JDBCServerExplorerParameters explorerParameters) { |
456 |
String code = null; |
457 |
try {
|
458 |
code = explorerParameters.toString(); |
459 |
ComboBoxModel model = this.cboConnectors.getModel(); |
460 |
for ( int i = 0; i < model.getSize(); i++ ) { |
461 |
LabeledValue<JDBCServerExplorerParameters> x = (LabeledValue<JDBCServerExplorerParameters>) model.getElementAt(i); |
462 |
if ( x!=null && x.getValue()!=null && x.getValue().getExplorerName().equalsIgnoreCase(explorerParameters.getExplorerName()) ) { |
463 |
return i;
|
464 |
} |
465 |
} |
466 |
} catch (Exception ex) { |
467 |
LOGGER.warn("Can't get index of exporer parameter '" + code + "'.", ex); |
468 |
} |
469 |
return -1; |
470 |
} |
471 |
|
472 |
@Override
|
473 |
public void setConnectorFilter(ConnectorFilter connectorFilter) { |
474 |
this.connectorFilter = connectorFilter;
|
475 |
fillConnections(); |
476 |
fillConnectors(); |
477 |
} |
478 |
|
479 |
private void fillConnectors() { |
480 |
DataManager dataManager = DALLocator.getDataManager(); |
481 |
|
482 |
LabeledValue<JDBCServerExplorerParameters> last = null;
|
483 |
this.cboConnectors.removeAllItems();
|
484 |
this.cboConnectors.addItem(new LabeledValueImpl("",(JDBCServerExplorerParameters)null)); |
485 |
|
486 |
for (DataFactory factory : dataManager.getServerExplorerRegister() ) {
|
487 |
if( factory.isHidden() ) {
|
488 |
continue;
|
489 |
} |
490 |
DataServerExplorerParameters params = (DataServerExplorerParameters) factory.createParameters(); |
491 |
if ( params instanceof JDBCServerExplorerParameters ) { |
492 |
if( this.connectorFilter==null || this.connectorFilter.accept((JDBCServerExplorerParameters) params) ) { |
493 |
if( params.getClass() == JDBCServerExplorerParameters.class &&
|
494 |
last == null ) {
|
495 |
// Si es el proveedor generico de JDBC, lo guarda para
|
496 |
// a?adirlo al final del combo.
|
497 |
last = new LabeledValueImpl(
|
498 |
factory.getDescription(), |
499 |
(JDBCServerExplorerParameters) params |
500 |
); |
501 |
} else {
|
502 |
this.cboConnectors.addItem(
|
503 |
new LabeledValueImpl(
|
504 |
factory.getDescription(), |
505 |
(JDBCServerExplorerParameters) params |
506 |
) |
507 |
); |
508 |
} |
509 |
} |
510 |
} |
511 |
} |
512 |
if( last!=null ) { |
513 |
this.cboConnectors.addItem(last);
|
514 |
} |
515 |
} |
516 |
|
517 |
private void fillConnections() { |
518 |
DataManager dataManager = DALLocator.getDataManager(); |
519 |
DataServerExplorerPool pool = dataManager.getDataServerExplorerPool(); |
520 |
|
521 |
this.cboConnections.removeAllItems();
|
522 |
for (DataServerExplorerPoolEntry entry : pool) {
|
523 |
if ( entry.getExplorerParameters() instanceof JDBCServerExplorerParameters ) { |
524 |
if( this.connectorFilter==null || this.connectorFilter.accept((JDBCServerExplorerParameters) entry.getExplorerParameters()) ) { |
525 |
JDBCServerExplorerParameters dbParams = (JDBCServerExplorerParameters) entry.getExplorerParameters(); |
526 |
this.cboConnections.addItem(
|
527 |
new LabeledValueImpl<>(entry.getName(), dbParams)
|
528 |
); |
529 |
} |
530 |
} |
531 |
} |
532 |
this.cboConnections.setSelectedIndex(-1); |
533 |
} |
534 |
|
535 |
@Override
|
536 |
public void delete() { |
537 |
String name = this.getConnectionName(); |
538 |
DataManager dataManager = DALLocator.getDataManager(); |
539 |
DataServerExplorerPool pool = dataManager.getDataServerExplorerPool(); |
540 |
|
541 |
pool.remove(name); |
542 |
fillConnections(); |
543 |
} |
544 |
|
545 |
@Override
|
546 |
public void clear() { |
547 |
this.cboConnections.setSelectedIndex(-1); |
548 |
this.cboConnectors.setSelectedIndex(-1); |
549 |
this.txtServer.setText(""); |
550 |
this.txtPort.setText(""); |
551 |
this.txtDataBase.setText(""); |
552 |
this.txtUsername.setText(""); |
553 |
this.txtPassword.setText(""); |
554 |
this.txtFile.setText(""); |
555 |
} |
556 |
|
557 |
private void onBrowseDatabase() { |
558 |
if( this.forcedParameters==null ) { |
559 |
return;
|
560 |
} |
561 |
ThreadSafeDialogsManager dlgmanager = ToolsSwingLocator.getThreadSafeDialogsManager(); |
562 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
563 |
File[] files = dlgmanager.showOpenFileDialog( |
564 |
i18nManager.getTranslation("_Select_database"),
|
565 |
null
|
566 |
); |
567 |
if( ArrayUtils.isEmpty(files) ) {
|
568 |
return;
|
569 |
} |
570 |
((FilesystemStoreParameters)this.forcedParameters).setFile(files[0]); |
571 |
this.txtFile.setText(((FilesystemStoreParameters)(this.forcedParameters)).getFile().getAbsolutePath()); |
572 |
} |
573 |
} |