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