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 @ 44423
History | View | Annotate | Download (21.6 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 |
} |
142 |
|
143 |
private void adjustPreferedHeight(JLabel label, int prefWidth) { |
144 |
JLabel resizer = new JLabel(); |
145 |
resizer.setText(label.getText()); |
146 |
View view = (View) resizer.getClientProperty(BasicHTML.propertyKey); |
147 |
view.setSize(prefWidth,15);
|
148 |
float w = view.getPreferredSpan(View.X_AXIS); |
149 |
float h = view.getPreferredSpan(View.Y_AXIS); |
150 |
Dimension dim = new Dimension( |
151 |
(int) Math.ceil(w), |
152 |
(int) Math.ceil(h) |
153 |
); |
154 |
label.setPreferredSize(dim); |
155 |
} |
156 |
|
157 |
private void translate() { |
158 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
159 |
|
160 |
this.lblFile.setText(i18nManager.getTranslation("_File")); |
161 |
this.lblConnectionName.setText(i18nManager.getTranslation("_Connection_name")); |
162 |
this.lblConnector.setText(i18nManager.getTranslation("_Driver_type")); |
163 |
this.lblServer.setText(i18nManager.getTranslation("_Host")); |
164 |
this.lblPort.setText(i18nManager.getTranslation("_Port")); |
165 |
this.lblDataBase.setText(i18nManager.getTranslation("_Database")); |
166 |
this.lblUsername.setText(i18nManager.getTranslation("_User")); |
167 |
this.lblPassword.setText(i18nManager.getTranslation("_Password")); |
168 |
this.lblFoother.setText("<html>"+i18nManager.getTranslation("_JDBCConecctionPanel_foother")+"</html>"); |
169 |
} |
170 |
|
171 |
@Override
|
172 |
public void setLabeledServerExplorerParameters(LabeledValue<JDBCServerExplorerParameters> parameters) { |
173 |
if( parameters == null ) { |
174 |
return;
|
175 |
} |
176 |
if( parameters.getValue()!=null ) { |
177 |
this.setServerExplorerParameters(parameters.getValue());
|
178 |
} |
179 |
if( !StringUtils.isBlank(parameters.getLabel()) ) {
|
180 |
this.cboConnections.setSelectedItem(parameters.getLabel());
|
181 |
} |
182 |
} |
183 |
|
184 |
@Override
|
185 |
public void setServerExplorerParameters(JDBCServerExplorerParameters parameters) { |
186 |
this.forcedParameters = (JDBCServerExplorerParameters) parameters.getCopy();
|
187 |
|
188 |
int indexConnector = this.getIndexOfConnector(parameters); |
189 |
if ( indexConnector >= 0 && this.cboConnectors.getSelectedIndex()!=indexConnector ) { |
190 |
this.cboConnectors.removeItemListener(this.onChangeConnectorItemListener); |
191 |
this.cboConnectors.setSelectedIndex(indexConnector);
|
192 |
this.cboConnectors.addItemListener(onChangeConnectorItemListener);
|
193 |
} |
194 |
|
195 |
this.txtServer.setText(parameters.getHost());
|
196 |
Integer port = parameters.getPort();
|
197 |
if ( port == null ) { |
198 |
this.txtPort.setText(""); |
199 |
} else {
|
200 |
this.txtPort.setText(String.valueOf(port)); |
201 |
} |
202 |
this.txtDataBase.setText(parameters.getDBName());
|
203 |
this.txtUsername.setText(parameters.getUser());
|
204 |
this.txtPassword.setText(parameters.getPassword());
|
205 |
|
206 |
DynClass definition = parameters.getDynClass(); |
207 |
|
208 |
DynField field = definition.getDynField(JDBCServerExplorerParameters.HOST_PARAMTER_NAME); |
209 |
this.txtServer.setEnabled( !( field.isReadOnly() || field.isHidden() ));
|
210 |
field = definition.getDynField(JDBCServerExplorerParameters.PORT_PARAMTER_NAME); |
211 |
this.txtPort.setEnabled( !( field.isReadOnly() || field.isHidden() ));
|
212 |
field = definition.getDynField(JDBCServerExplorerParameters.DBNAME_PARAMTER_NAME); |
213 |
this.txtDataBase.setEnabled( !( field.isReadOnly() || field.isHidden() ));
|
214 |
field = definition.getDynField(JDBCServerExplorerParameters.USER_PARAMTER_NAME); |
215 |
this.txtUsername.setEnabled( !( field.isReadOnly() || field.isHidden() ));
|
216 |
field = definition.getDynField(JDBCServerExplorerParameters.PASSWORD_PARAMTER_NAME); |
217 |
this.txtPassword.setEnabled( !( field.isReadOnly() || field.isHidden() ));
|
218 |
if( parameters instanceof FilesystemStoreParameters ) { |
219 |
File f = ((FilesystemStoreParameters) parameters).getFile();
|
220 |
if( f==null ) { |
221 |
this.txtFile.setText(""); |
222 |
} else {
|
223 |
this.txtFile.setText(f.getAbsolutePath());
|
224 |
} |
225 |
this.btnDataBaseBrowser.setVisible(true); |
226 |
this.txtFile.setVisible(true); |
227 |
this.lblFile.setVisible(true); |
228 |
} else {
|
229 |
this.btnDataBaseBrowser.setVisible(false); |
230 |
this.txtFile.setVisible(false); |
231 |
this.lblFile.setVisible(false); |
232 |
} |
233 |
} |
234 |
|
235 |
@Override
|
236 |
public JDBCServerExplorerParameters getServerExplorerParameters() {
|
237 |
LabeledValue<JDBCServerExplorerParameters> labeledConnection = this.getLabeledServerExplorerParameters();
|
238 |
if( labeledConnection==null ) { |
239 |
return null; |
240 |
} |
241 |
return labeledConnection.getValue();
|
242 |
} |
243 |
|
244 |
@Override
|
245 |
public LabeledValue<JDBCServerExplorerParameters> getLabeledServerExplorerParameters() {
|
246 |
JDBCServerExplorerParameters params; |
247 |
JDBCServerExplorerParameters connector = this.getConnector();
|
248 |
if( connector==null ) { |
249 |
return null; |
250 |
} |
251 |
if( this.forcedParameters==null ) { |
252 |
params = (JDBCServerExplorerParameters) connector.getCopy(); |
253 |
} else {
|
254 |
params = (JDBCServerExplorerParameters) this.forcedParameters.getCopy();
|
255 |
} |
256 |
String s = this.getServer(); |
257 |
if( s!=null ) { |
258 |
params.setHost(s); |
259 |
} |
260 |
int n = this.getPort(); |
261 |
if( n>0 ) { |
262 |
params.setPort(n); |
263 |
} |
264 |
s = this.getDataBaseName();
|
265 |
if( s!=null ) { |
266 |
params.setDBName(s); |
267 |
} |
268 |
s = this.getUsername();
|
269 |
if( s!=null ) { |
270 |
params.setUser(s); |
271 |
} |
272 |
s = this.getPassword();
|
273 |
if( s!=null ) { |
274 |
params.setPassword(s); |
275 |
} |
276 |
|
277 |
String name = this.getConnectionName(); |
278 |
if ( StringUtils.isBlank(name) ) {
|
279 |
if( params instanceof FilesystemStoreParameters ) { |
280 |
File f = ((FilesystemStoreParameters) params).getFile();
|
281 |
if( f!=null ) { |
282 |
name = FilenameUtils.getBaseName(f.getPath()); |
283 |
} |
284 |
} |
285 |
if( StringUtils.isBlank(name) ) {
|
286 |
StringBuilder builder = new StringBuilder(); |
287 |
builder.append(Objects.toString(params.getHost(),""));
|
288 |
if( builder.length()>0 && !builder.toString().endsWith("-")) { |
289 |
builder.append("-");
|
290 |
} |
291 |
builder.append(Objects.toString(params.getPort(),""));
|
292 |
if( builder.length()>0 && !builder.toString().endsWith("-")) { |
293 |
builder.append("-");
|
294 |
} |
295 |
builder.append(Objects.toString(params.getDBName(),""));
|
296 |
name = builder.toString(); |
297 |
} |
298 |
} |
299 |
|
300 |
if( StringUtils.isBlank(name) ) {
|
301 |
name = getUniqueEntryName("Connection");
|
302 |
} else if( this.isNewConnection() ) { |
303 |
name = getUniqueEntryName(name); |
304 |
} |
305 |
|
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 |
|
315 |
return new LabeledValueImpl<>(name,params); |
316 |
} |
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 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
333 |
LabeledValue<JDBCServerExplorerParameters> params = this.getLabeledServerExplorerParameters();
|
334 |
if( params == null ) { |
335 |
return i18n.getTranslation("You need to select a connector"); |
336 |
} |
337 |
params.getValue().validate(); |
338 |
return null; |
339 |
} catch (ValidateDataParametersException ex) {
|
340 |
return ex.getLocalizedMessageStack();
|
341 |
} |
342 |
} |
343 |
|
344 |
private String getUniqueEntryName(String name) { |
345 |
DataManager dataManager = DALLocator.getDataManager(); |
346 |
DataServerExplorerPool pool = dataManager.getDataServerExplorerPool(); |
347 |
String baseName = name;
|
348 |
for (int i = 0; i < 1000; i++) { |
349 |
if( !pool.contains(name) ) {
|
350 |
return name;
|
351 |
} |
352 |
name = baseName+"-"+i;
|
353 |
} |
354 |
return name + System.currentTimeMillis(); |
355 |
} |
356 |
|
357 |
protected void setConnectionName(String connectionName) { |
358 |
JTextField txtConnections = (JTextField) this.cboConnections.getEditor().getEditorComponent(); |
359 |
txtConnections.setText(connectionName); |
360 |
} |
361 |
|
362 |
@Override
|
363 |
public String getConnectionName() { |
364 |
String value = (String) this.cboConnections.getSelectedItem(); |
365 |
return StringUtils.defaultIfBlank(value, null); |
366 |
} |
367 |
|
368 |
@Override
|
369 |
public boolean isNewConnection() { |
370 |
String name = this.getConnectionName(); |
371 |
if( name == null ) { |
372 |
return true; |
373 |
} |
374 |
ComboBoxModel<LabeledValue<JDBCServerExplorerParameters>> model = this.cboConnections.getModel(); |
375 |
for (int i = 0; i < model.getSize(); i++) { |
376 |
LabeledValue<JDBCServerExplorerParameters> conn = model.getElementAt(i); |
377 |
if( StringUtils.equalsIgnoreCase(name, conn.getLabel()) ) {
|
378 |
return false; |
379 |
} |
380 |
} |
381 |
return true; |
382 |
} |
383 |
|
384 |
protected JDBCServerExplorerParameters getConnector() {
|
385 |
LabeledValue<JDBCServerExplorerParameters> item = (LabeledValue<JDBCServerExplorerParameters>) this.cboConnectors.getSelectedItem();
|
386 |
if( item == null ) { |
387 |
return null; |
388 |
} |
389 |
return item.getValue();
|
390 |
} |
391 |
|
392 |
protected String getConnectorName() { |
393 |
JDBCServerExplorerParameters value = this.getConnector();
|
394 |
if ( value == null ) { |
395 |
return null; |
396 |
} |
397 |
return (String) StringUtils.defaultIfBlank(value.getExplorerName(), null); |
398 |
} |
399 |
|
400 |
protected String getServer() { |
401 |
return (String) StringUtils.defaultIfBlank(this.txtServer.getText(), null); |
402 |
} |
403 |
|
404 |
protected int getPort() { |
405 |
String svalue = (String) StringUtils.defaultIfBlank(this.txtPort.getText(), null); |
406 |
int ivalue;
|
407 |
try {
|
408 |
ivalue = Integer.parseInt(svalue);
|
409 |
} catch (Exception ex) { |
410 |
ivalue = -1;
|
411 |
} |
412 |
return ivalue;
|
413 |
} |
414 |
|
415 |
protected String getDataBaseName() { |
416 |
return (String) StringUtils.defaultIfBlank(this.txtDataBase.getText(), null); |
417 |
} |
418 |
|
419 |
protected String getUsername() { |
420 |
return (String) StringUtils.defaultIfBlank(this.txtUsername.getText(), null); |
421 |
} |
422 |
|
423 |
protected String getPassword() { |
424 |
return (String) StringUtils.defaultIfBlank(this.txtPassword.getText(), null); |
425 |
} |
426 |
|
427 |
private void onChangeConnector() { |
428 |
LabeledValue<JDBCServerExplorerParameters> item = (LabeledValue<JDBCServerExplorerParameters>) this.cboConnectors.getSelectedItem();
|
429 |
if( item==null ) { |
430 |
return;
|
431 |
} |
432 |
JDBCServerExplorerParameters connector = item.getValue(); |
433 |
|
434 |
if ( connector == null ) { |
435 |
return;
|
436 |
} |
437 |
this.setServerExplorerParameters(connector);
|
438 |
} |
439 |
|
440 |
private void onChangeConnection() { |
441 |
LabeledValue<JDBCServerExplorerParameters> item = (LabeledValue<JDBCServerExplorerParameters>) this.cboConnections.getSelectedItem();
|
442 |
if( item == null ) { |
443 |
return;
|
444 |
} |
445 |
JDBCServerExplorerParameters connection = item.getValue(); |
446 |
if ( connection == null ) { |
447 |
return;
|
448 |
} |
449 |
this.setServerExplorerParameters(connection);
|
450 |
} |
451 |
|
452 |
|
453 |
private int getIndexOfConnector(JDBCServerExplorerParameters explorerParameters) { |
454 |
String code = null; |
455 |
try {
|
456 |
code = explorerParameters.toString(); |
457 |
ComboBoxModel model = this.cboConnectors.getModel(); |
458 |
for ( int i = 0; i < model.getSize(); i++ ) { |
459 |
LabeledValue<JDBCServerExplorerParameters> x = (LabeledValue<JDBCServerExplorerParameters>) model.getElementAt(i); |
460 |
if ( x!=null && x.getValue()!=null && x.getValue().getExplorerName().equalsIgnoreCase(explorerParameters.getExplorerName()) ) { |
461 |
return i;
|
462 |
} |
463 |
} |
464 |
} catch (Exception ex) { |
465 |
LOGGER.warn("Can't get index of exporer parameter '" + code + "'.", ex); |
466 |
} |
467 |
return -1; |
468 |
} |
469 |
|
470 |
@Override
|
471 |
public void setConnectorFilter(ConnectorFilter connectorFilter) { |
472 |
this.connectorFilter = connectorFilter;
|
473 |
fillConnections(); |
474 |
fillConnectors(); |
475 |
} |
476 |
|
477 |
private void fillConnectors() { |
478 |
DataManager dataManager = DALLocator.getDataManager(); |
479 |
|
480 |
LabeledValue<JDBCServerExplorerParameters> last = null;
|
481 |
this.cboConnectors.removeAllItems();
|
482 |
this.cboConnectors.addItem(new LabeledValueImpl("",(JDBCServerExplorerParameters)null)); |
483 |
|
484 |
for (DataFactory factory : dataManager.getServerExplorerRegister() ) {
|
485 |
if( factory.isHidden() ) {
|
486 |
continue;
|
487 |
} |
488 |
DataServerExplorerParameters params = (DataServerExplorerParameters) factory.createParameters(); |
489 |
if ( params instanceof JDBCServerExplorerParameters ) { |
490 |
if( this.connectorFilter==null || this.connectorFilter.accept((JDBCServerExplorerParameters) params) ) { |
491 |
if( params.getClass() == JDBCServerExplorerParameters.class &&
|
492 |
last == null ) {
|
493 |
// Si es el proveedor generico de JDBC, lo guarda para
|
494 |
// a?adirlo al final del combo.
|
495 |
last = new LabeledValueImpl(
|
496 |
factory.getDescription(), |
497 |
(JDBCServerExplorerParameters) params |
498 |
); |
499 |
} else {
|
500 |
this.cboConnectors.addItem(
|
501 |
new LabeledValueImpl(
|
502 |
factory.getDescription(), |
503 |
(JDBCServerExplorerParameters) params |
504 |
) |
505 |
); |
506 |
} |
507 |
} |
508 |
} |
509 |
} |
510 |
if( last!=null ) { |
511 |
this.cboConnectors.addItem(last);
|
512 |
} |
513 |
} |
514 |
|
515 |
private void fillConnections() { |
516 |
DataManager dataManager = DALLocator.getDataManager(); |
517 |
DataServerExplorerPool pool = dataManager.getDataServerExplorerPool(); |
518 |
|
519 |
this.cboConnections.removeAllItems();
|
520 |
for (DataServerExplorerPoolEntry entry : pool) {
|
521 |
if ( entry.getExplorerParameters() instanceof JDBCServerExplorerParameters ) { |
522 |
if( this.connectorFilter==null || this.connectorFilter.accept((JDBCServerExplorerParameters) entry.getExplorerParameters()) ) { |
523 |
JDBCServerExplorerParameters dbParams = (JDBCServerExplorerParameters) entry.getExplorerParameters(); |
524 |
this.cboConnections.addItem(
|
525 |
new LabeledValueImpl<>(entry.getName(), dbParams)
|
526 |
); |
527 |
} |
528 |
} |
529 |
} |
530 |
this.cboConnections.setSelectedIndex(-1); |
531 |
} |
532 |
|
533 |
@Override
|
534 |
public void delete() { |
535 |
String name = this.getConnectionName(); |
536 |
DataManager dataManager = DALLocator.getDataManager(); |
537 |
DataServerExplorerPool pool = dataManager.getDataServerExplorerPool(); |
538 |
|
539 |
pool.remove(name); |
540 |
fillConnections(); |
541 |
} |
542 |
|
543 |
@Override
|
544 |
public void clear() { |
545 |
this.cboConnections.setSelectedIndex(-1); |
546 |
this.cboConnectors.setSelectedIndex(-1); |
547 |
this.txtServer.setText(""); |
548 |
this.txtPort.setText(""); |
549 |
this.txtDataBase.setText(""); |
550 |
this.txtUsername.setText(""); |
551 |
this.txtPassword.setText(""); |
552 |
this.txtFile.setText(""); |
553 |
} |
554 |
|
555 |
private void onBrowseDatabase() { |
556 |
if( this.forcedParameters==null ) { |
557 |
return;
|
558 |
} |
559 |
ThreadSafeDialogsManager dlgmanager = ToolsSwingLocator.getThreadSafeDialogsManager(); |
560 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
561 |
File[] files = dlgmanager.showOpenFileDialog( |
562 |
i18nManager.getTranslation("_Select_database"),
|
563 |
null
|
564 |
); |
565 |
if( ArrayUtils.isEmpty(files) ) {
|
566 |
return;
|
567 |
} |
568 |
((FilesystemStoreParameters)this.forcedParameters).setFile(files[0]); |
569 |
this.txtFile.setText(((FilesystemStoreParameters)(this.forcedParameters)).getFile().getAbsolutePath()); |
570 |
} |
571 |
} |