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