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 @ 44422
History | View | Annotate | Download (21.4 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 |
LabeledValue<JDBCServerExplorerParameters> params = this.getLabeledServerExplorerParameters();
|
333 |
params.getValue().validate(); |
334 |
return null; |
335 |
} catch (ValidateDataParametersException ex) {
|
336 |
return ex.getLocalizedMessageStack();
|
337 |
} |
338 |
} |
339 |
|
340 |
private String getUniqueEntryName(String name) { |
341 |
DataManager dataManager = DALLocator.getDataManager(); |
342 |
DataServerExplorerPool pool = dataManager.getDataServerExplorerPool(); |
343 |
String baseName = name;
|
344 |
for (int i = 0; i < 1000; i++) { |
345 |
if( !pool.contains(name) ) {
|
346 |
return name;
|
347 |
} |
348 |
name = baseName+"-"+i;
|
349 |
} |
350 |
return name + System.currentTimeMillis(); |
351 |
} |
352 |
|
353 |
protected void setConnectionName(String connectionName) { |
354 |
JTextField txtConnections = (JTextField) this.cboConnections.getEditor().getEditorComponent(); |
355 |
txtConnections.setText(connectionName); |
356 |
} |
357 |
|
358 |
@Override
|
359 |
public String getConnectionName() { |
360 |
String value = (String) this.cboConnections.getSelectedItem(); |
361 |
return StringUtils.defaultIfBlank(value, null); |
362 |
} |
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 |
|
380 |
protected JDBCServerExplorerParameters getConnector() {
|
381 |
LabeledValue<JDBCServerExplorerParameters> item = (LabeledValue<JDBCServerExplorerParameters>) this.cboConnectors.getSelectedItem();
|
382 |
if( item == null ) { |
383 |
return null; |
384 |
} |
385 |
return item.getValue();
|
386 |
} |
387 |
|
388 |
protected String getConnectorName() { |
389 |
JDBCServerExplorerParameters value = this.getConnector();
|
390 |
if ( value == null ) { |
391 |
return null; |
392 |
} |
393 |
return (String) StringUtils.defaultIfBlank(value.getExplorerName(), null); |
394 |
} |
395 |
|
396 |
protected String getServer() { |
397 |
return (String) StringUtils.defaultIfBlank(this.txtServer.getText(), null); |
398 |
} |
399 |
|
400 |
protected int getPort() { |
401 |
String svalue = (String) StringUtils.defaultIfBlank(this.txtPort.getText(), null); |
402 |
int ivalue;
|
403 |
try {
|
404 |
ivalue = Integer.parseInt(svalue);
|
405 |
} catch (Exception ex) { |
406 |
ivalue = -1;
|
407 |
} |
408 |
return ivalue;
|
409 |
} |
410 |
|
411 |
protected String getDataBaseName() { |
412 |
return (String) StringUtils.defaultIfBlank(this.txtDataBase.getText(), null); |
413 |
} |
414 |
|
415 |
protected String getUsername() { |
416 |
return (String) StringUtils.defaultIfBlank(this.txtUsername.getText(), null); |
417 |
} |
418 |
|
419 |
protected String getPassword() { |
420 |
return (String) StringUtils.defaultIfBlank(this.txtPassword.getText(), null); |
421 |
} |
422 |
|
423 |
private void onChangeConnector() { |
424 |
LabeledValue<JDBCServerExplorerParameters> item = (LabeledValue<JDBCServerExplorerParameters>) this.cboConnectors.getSelectedItem();
|
425 |
if( item==null ) { |
426 |
return;
|
427 |
} |
428 |
JDBCServerExplorerParameters connector = item.getValue(); |
429 |
|
430 |
if ( connector == null ) { |
431 |
return;
|
432 |
} |
433 |
this.setServerExplorerParameters(connector);
|
434 |
} |
435 |
|
436 |
private void onChangeConnection() { |
437 |
LabeledValue<JDBCServerExplorerParameters> item = (LabeledValue<JDBCServerExplorerParameters>) this.cboConnections.getSelectedItem();
|
438 |
if( item == null ) { |
439 |
return;
|
440 |
} |
441 |
JDBCServerExplorerParameters connection = item.getValue(); |
442 |
if ( connection == null ) { |
443 |
return;
|
444 |
} |
445 |
this.setServerExplorerParameters(connection);
|
446 |
} |
447 |
|
448 |
|
449 |
private int getIndexOfConnector(JDBCServerExplorerParameters explorerParameters) { |
450 |
String code = null; |
451 |
try {
|
452 |
code = explorerParameters.toString(); |
453 |
ComboBoxModel model = this.cboConnectors.getModel(); |
454 |
for ( int i = 0; i < model.getSize(); i++ ) { |
455 |
LabeledValue<JDBCServerExplorerParameters> x = (LabeledValue<JDBCServerExplorerParameters>) model.getElementAt(i); |
456 |
if ( x!=null && x.getValue()!=null && x.getValue().getExplorerName().equalsIgnoreCase(explorerParameters.getExplorerName()) ) { |
457 |
return i;
|
458 |
} |
459 |
} |
460 |
} catch (Exception ex) { |
461 |
LOGGER.warn("Can't get index of exporer parameter '" + code + "'.", ex); |
462 |
} |
463 |
return -1; |
464 |
} |
465 |
|
466 |
@Override
|
467 |
public void setConnectorFilter(ConnectorFilter connectorFilter) { |
468 |
this.connectorFilter = connectorFilter;
|
469 |
fillConnections(); |
470 |
fillConnectors(); |
471 |
} |
472 |
|
473 |
private void fillConnectors() { |
474 |
DataManager dataManager = DALLocator.getDataManager(); |
475 |
|
476 |
LabeledValue<JDBCServerExplorerParameters> last = null;
|
477 |
this.cboConnectors.removeAllItems();
|
478 |
this.cboConnectors.addItem(new LabeledValueImpl("",(JDBCServerExplorerParameters)null)); |
479 |
|
480 |
for (DataFactory factory : dataManager.getServerExplorerRegister() ) {
|
481 |
if( factory.isHidden() ) {
|
482 |
continue;
|
483 |
} |
484 |
DataServerExplorerParameters params = (DataServerExplorerParameters) factory.createParameters(); |
485 |
if ( params instanceof JDBCServerExplorerParameters ) { |
486 |
if( this.connectorFilter==null || this.connectorFilter.accept((JDBCServerExplorerParameters) params) ) { |
487 |
if( params.getClass() == JDBCServerExplorerParameters.class &&
|
488 |
last == null ) {
|
489 |
// Si es el proveedor generico de JDBC, lo guarda para
|
490 |
// a?adirlo al final del combo.
|
491 |
last = new LabeledValueImpl(
|
492 |
factory.getDescription(), |
493 |
(JDBCServerExplorerParameters) params |
494 |
); |
495 |
} else {
|
496 |
this.cboConnectors.addItem(
|
497 |
new LabeledValueImpl(
|
498 |
factory.getDescription(), |
499 |
(JDBCServerExplorerParameters) params |
500 |
) |
501 |
); |
502 |
} |
503 |
} |
504 |
} |
505 |
} |
506 |
if( last!=null ) { |
507 |
this.cboConnectors.addItem(last);
|
508 |
} |
509 |
} |
510 |
|
511 |
private void fillConnections() { |
512 |
DataManager dataManager = DALLocator.getDataManager(); |
513 |
DataServerExplorerPool pool = dataManager.getDataServerExplorerPool(); |
514 |
|
515 |
this.cboConnections.removeAllItems();
|
516 |
for (DataServerExplorerPoolEntry entry : pool) {
|
517 |
if ( entry.getExplorerParameters() instanceof JDBCServerExplorerParameters ) { |
518 |
if( this.connectorFilter==null || this.connectorFilter.accept((JDBCServerExplorerParameters) entry.getExplorerParameters()) ) { |
519 |
JDBCServerExplorerParameters dbParams = (JDBCServerExplorerParameters) entry.getExplorerParameters(); |
520 |
this.cboConnections.addItem(
|
521 |
new LabeledValueImpl<>(entry.getName(), dbParams)
|
522 |
); |
523 |
} |
524 |
} |
525 |
} |
526 |
this.cboConnections.setSelectedIndex(-1); |
527 |
} |
528 |
|
529 |
@Override
|
530 |
public void delete() { |
531 |
String name = this.getConnectionName(); |
532 |
DataManager dataManager = DALLocator.getDataManager(); |
533 |
DataServerExplorerPool pool = dataManager.getDataServerExplorerPool(); |
534 |
|
535 |
pool.remove(name); |
536 |
fillConnections(); |
537 |
} |
538 |
|
539 |
@Override
|
540 |
public void clear() { |
541 |
this.cboConnections.setSelectedIndex(-1); |
542 |
this.cboConnectors.setSelectedIndex(-1); |
543 |
this.txtServer.setText(""); |
544 |
this.txtPort.setText(""); |
545 |
this.txtDataBase.setText(""); |
546 |
this.txtUsername.setText(""); |
547 |
this.txtPassword.setText(""); |
548 |
this.txtFile.setText(""); |
549 |
} |
550 |
|
551 |
private void onBrowseDatabase() { |
552 |
if( this.forcedParameters==null ) { |
553 |
return;
|
554 |
} |
555 |
ThreadSafeDialogsManager dlgmanager = ToolsSwingLocator.getThreadSafeDialogsManager(); |
556 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
557 |
File[] files = dlgmanager.showOpenFileDialog( |
558 |
i18nManager.getTranslation("_Select_database"),
|
559 |
null
|
560 |
); |
561 |
if( ArrayUtils.isEmpty(files) ) {
|
562 |
return;
|
563 |
} |
564 |
((FilesystemStoreParameters)this.forcedParameters).setFile(files[0]); |
565 |
this.txtFile.setText(((FilesystemStoreParameters)(this.forcedParameters)).getFile().getAbsolutePath()); |
566 |
} |
567 |
} |