Revision 46336 trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.geodb.app/org.gvsig.geodb.app.mainplugin/src/main/java/org/gvsig/geodb/databaseworkspace/WorkspaceConfigurationPanel.java
WorkspaceConfigurationPanel.java | ||
---|---|---|
1 | 1 |
package org.gvsig.geodb.databaseworkspace; |
2 | 2 |
|
3 |
import java.awt.BorderLayout; |
|
3 | 4 |
import org.gvsig.fmap.dal.DatabaseWorkspaceManager; |
4 | 5 |
import java.awt.event.ActionEvent; |
5 | 6 |
import java.awt.event.ActionListener; |
6 | 7 |
import javax.swing.JButton; |
7 | 8 |
import javax.swing.JComponent; |
9 |
import javax.swing.JOptionPane; |
|
8 | 10 |
import javax.swing.event.ChangeEvent; |
9 |
import javax.swing.event.ChangeListener; |
|
10 | 11 |
import org.apache.commons.lang.StringUtils; |
11 | 12 |
import org.gvsig.featureform.swing.JFeaturesForm; |
12 | 13 |
import org.gvsig.fmap.dal.DALLocator; |
13 | 14 |
import org.gvsig.fmap.dal.DataManager; |
14 | 15 |
import org.gvsig.fmap.dal.DataStoreParameters; |
15 | 16 |
import org.gvsig.fmap.dal.StoresRepository; |
16 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
17 | 17 |
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters; |
18 | 18 |
import org.gvsig.fmap.dal.swing.DALSwingLocator; |
19 | 19 |
import org.gvsig.fmap.dal.swing.DataSwingManager; |
20 | 20 |
import org.gvsig.fmap.dal.swing.searchpanel.FeatureStoreSearchPanel; |
21 | 21 |
import static org.gvsig.fmap.dal.DatabaseWorkspaceManager.CONFIG_NAME_STORESREPOSITORYID; |
22 | 22 |
import static org.gvsig.fmap.dal.DatabaseWorkspaceManager.CONFIG_NAME_STORESREPOSITORYLABEL; |
23 |
import org.gvsig.fmap.dal.feature.Feature; |
|
24 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
25 |
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters; |
|
26 |
import org.gvsig.fmap.dal.swing.dataStoreParameters.DataStoreParametersPanel; |
|
27 |
import org.gvsig.fmap.dal.swing.dataStoreParameters.DataStoreParametersPanelManager; |
|
28 |
import org.gvsig.tools.ToolsLocator; |
|
29 |
import org.gvsig.tools.i18n.I18nManager; |
|
23 | 30 |
import org.gvsig.tools.swing.api.Component; |
24 | 31 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
32 |
import org.gvsig.tools.swing.api.ToolsSwingUtils; |
|
25 | 33 |
import org.gvsig.tools.swing.api.pickercontroller.PickerController; |
26 | 34 |
import org.gvsig.tools.swing.api.windowmanager.Dialog; |
27 | 35 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
28 | 36 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager_v2; |
37 |
import org.gvsig.tools.util.LabeledValue; |
|
29 | 38 |
import org.slf4j.Logger; |
30 | 39 |
import org.slf4j.LoggerFactory; |
31 | 40 |
|
... | ... | |
36 | 45 |
@SuppressWarnings("UseSpecificCatch") |
37 | 46 |
public class WorkspaceConfigurationPanel |
38 | 47 |
extends WorkspaceConfigurationPanelView |
39 |
implements Component |
|
40 |
{ |
|
48 |
implements Component { |
|
41 | 49 |
|
42 | 50 |
private static final Logger LOGGER = LoggerFactory.getLogger(WorkspaceConfigurationPanel.class); |
51 |
private FeatureStoreSearchPanel configurationSearch; |
|
52 |
private FeatureStoreSearchPanel repositorySearch; |
|
53 |
private FeatureStoreSearchPanel resourcesSearch; |
|
43 | 54 |
|
44 | 55 |
private class TableController { |
45 | 56 |
|
46 | 57 |
private final JButton btnCreate; |
47 | 58 |
private final JButton btnDrop; |
48 |
private final JButton btnSearch; |
|
59 |
// private final JButton btnSearch;
|
|
49 | 60 |
private final JButton btnShowForm; |
50 | 61 |
private final int tableid; |
51 | 62 |
|
52 | 63 |
public TableController( |
53 | 64 |
int tableid, |
54 | 65 |
JButton btnCreate, |
55 |
JButton btnDrop,
|
|
56 |
JButton btnSearch,
|
|
57 |
JButton btnShowForm |
|
66 |
JButton btnDrop // , JButton btnSearch
|
|
67 |
, |
|
68 |
JButton btnShowForm
|
|
58 | 69 |
) { |
59 | 70 |
this.tableid = tableid; |
60 | 71 |
this.btnCreate = btnCreate; |
61 | 72 |
this.btnDrop = btnDrop; |
62 |
this.btnSearch = btnSearch; |
|
73 |
// this.btnSearch = btnSearch;
|
|
63 | 74 |
this.btnShowForm = btnShowForm; |
64 | 75 |
this.btnCreate.addActionListener(new ActionListener() { |
65 | 76 |
@Override |
... | ... | |
79 | 90 |
doShowForm(); |
80 | 91 |
} |
81 | 92 |
}); |
82 |
this.btnSearch.addActionListener(new ActionListener() { |
|
83 |
@Override |
|
84 |
public void actionPerformed(ActionEvent e) { |
|
85 |
doSearch(); |
|
86 |
} |
|
87 |
}); |
|
93 |
// this.btnSearch.addActionListener(new ActionListener() {
|
|
94 |
// @Override
|
|
95 |
// public void actionPerformed(ActionEvent e) {
|
|
96 |
// doSearch();
|
|
97 |
// }
|
|
98 |
// });
|
|
88 | 99 |
} |
89 | 100 |
|
90 | 101 |
private void doCreate() { |
... | ... | |
126 | 137 |
workspace.dropTable(this.tableid); |
127 | 138 |
} |
128 | 139 |
|
129 |
private void doSearch() { |
|
130 |
try { |
|
131 |
DataManager dataManager = DALLocator.getDataManager(); |
|
132 |
DatabaseWorkspaceManager workspace = dataManager.createDatabaseWorkspaceManager(getConnection()); |
|
133 |
if (!workspace.existsTable(this.tableid)) { |
|
134 |
return; |
|
135 |
} |
|
136 |
FeatureStore store = workspace.getTable(this.tableid); |
|
137 |
DataSwingManager dalSwingManager = DALSwingLocator.getSwingManager(); |
|
138 |
FeatureStoreSearchPanel search = dalSwingManager.createFeatureStoreSearchPanel(store); |
|
139 |
WindowManager winManager = ToolsSwingLocator.getWindowManager(); |
|
140 |
winManager.showWindow( |
|
141 |
search.asJComponent(), |
|
142 |
"Resources", |
|
143 |
WindowManager.MODE.WINDOW |
|
144 |
); |
|
145 |
} catch (Exception ex) { |
|
146 |
LOGGER.warn("Can't show search panel for resources table.", ex); |
|
147 |
} |
|
148 |
} |
|
149 |
|
|
140 |
// private void doSearch() { |
|
141 |
// try { |
|
142 |
// DataManager dataManager = DALLocator.getDataManager(); |
|
143 |
// DatabaseWorkspaceManager workspace = dataManager.createDatabaseWorkspaceManager(getConnection()); |
|
144 |
// if (!workspace.existsTable(this.tableid)) { |
|
145 |
// return; |
|
146 |
// } |
|
147 |
// FeatureStore store = workspace.getTable(this.tableid); |
|
148 |
// DataSwingManager dalSwingManager = DALSwingLocator.getSwingManager(); |
|
149 |
// FeatureStoreSearchPanel search = dalSwingManager.createFeatureStoreSearchPanel(store); |
|
150 |
// WindowManager winManager = ToolsSwingLocator.getWindowManager(); |
|
151 |
// winManager.showWindow( |
|
152 |
// search.asJComponent(), |
|
153 |
// "Resources", |
|
154 |
// WindowManager.MODE.WINDOW |
|
155 |
// ); |
|
156 |
// } catch (Exception ex) { |
|
157 |
// LOGGER.warn("Can't show search panel for resources table.", ex); |
|
158 |
// } |
|
159 |
// } |
|
150 | 160 |
public void setEnabled(boolean enabled) { |
151 | 161 |
this.btnCreate.setEnabled(enabled); |
152 | 162 |
this.btnDrop.setEnabled(enabled); |
153 |
this.btnSearch.setEnabled(enabled); |
|
163 |
// this.btnSearch.setEnabled(enabled);
|
|
154 | 164 |
this.btnShowForm.setEnabled(enabled); |
155 | 165 |
} |
156 | 166 |
} |
... | ... | |
169 | 179 |
this.cboConnections, |
170 | 180 |
this.btnAddConnection |
171 | 181 |
); |
172 |
this.connectionPicker.addChangeListener(new ChangeListener() { |
|
173 |
@Override |
|
174 |
public void stateChanged(ChangeEvent e) { |
|
175 |
doUpdateEnableComponents(); |
|
176 |
doUpdateStoresRepositoryInfo(); |
|
177 |
} |
|
182 |
this.connectionPicker.addChangeListener((ChangeEvent e) -> { |
|
183 |
doUpdateEnableComponents(); |
|
184 |
doUpdateStoresRepositoryInfo(); |
|
178 | 185 |
}); |
179 | 186 |
this.resourcesTableController = new TableController( |
180 |
DatabaseWorkspaceManager.TABLE_RESOURCES, |
|
181 |
btnCreateResourceTable, |
|
182 |
btnDropResourceTable, |
|
183 |
btnSearchResourceTable, |
|
187 |
DatabaseWorkspaceManager.TABLE_RESOURCES, |
|
188 |
btnCreateResourceTable, |
|
189 |
btnDropResourceTable, |
|
184 | 190 |
btnShowResourceTable |
185 | 191 |
); |
186 | 192 |
this.repositoryTableController = new TableController( |
187 |
DatabaseWorkspaceManager.TABLE_REPOSITORY, |
|
188 |
btnCreateRepositoryTable, |
|
189 |
btnDropRepositoryTable, |
|
190 |
btnSearchRepositoryTable, |
|
193 |
DatabaseWorkspaceManager.TABLE_REPOSITORY, |
|
194 |
btnCreateRepositoryTable, |
|
195 |
btnDropRepositoryTable, |
|
191 | 196 |
btnShowRepositoryTable |
192 | 197 |
); |
193 | 198 |
this.configurationTableController = new TableController( |
194 |
DatabaseWorkspaceManager.TABLE_CONFIGURATION, |
|
195 |
btnCreateConfigurationTable, |
|
196 |
btnDropConfigurationTable, |
|
197 |
btnSearchConfigurationTable, |
|
199 |
DatabaseWorkspaceManager.TABLE_CONFIGURATION, |
|
200 |
btnCreateConfigurationTable, |
|
201 |
btnDropConfigurationTable, |
|
198 | 202 |
btnShowConfigurationTable |
199 | 203 |
); |
200 | 204 |
|
201 |
this.btnRepositoryAddTable.addActionListener(new ActionListener() { |
|
202 |
@Override |
|
203 |
public void actionPerformed(ActionEvent e) { |
|
204 |
doAddTableToRepository(); |
|
205 |
} |
|
205 |
this.btnRepositoryAddTable.addActionListener((ActionEvent e) -> { |
|
206 |
doAddTableToRepository(); |
|
206 | 207 |
}); |
207 |
|
|
208 |
this.btnConnectToRepository.addActionListener(new ActionListener() { |
|
209 |
@Override |
|
210 |
public void actionPerformed(ActionEvent e) { |
|
211 |
doConnectToRepository(); |
|
212 |
} |
|
208 |
|
|
209 |
this.btnConnectToRepository.addActionListener((ActionEvent e) -> { |
|
210 |
doConnectToRepository(); |
|
213 | 211 |
}); |
212 |
this.btnShowRepositoryTableParameters.addActionListener((ActionEvent e) -> { |
|
213 |
doShowParametersOfRepositoryTable(); |
|
214 |
}); |
|
215 |
this.btnFixRepositoryEntries.addActionListener((ActionEvent e) -> { |
|
216 |
doFixRepositoryEntriesToSelectedConnection(); |
|
217 |
}); |
|
218 |
this.pnlConfiguration.setLayout(new BorderLayout()); |
|
219 |
this.pnlRepository.setLayout(new BorderLayout()); |
|
220 |
this.pnlResorces.setLayout(new BorderLayout()); |
|
214 | 221 |
|
222 |
|
|
223 |
ToolsSwingUtils.ensureRowsCols(this, 20, 150, 25, 200); |
|
215 | 224 |
doUpdateEnableComponents(); |
216 | 225 |
} |
217 | 226 |
|
... | ... | |
233 | 242 |
this.btnRepositoryAddTable.setEnabled(theEnabled); |
234 | 243 |
this.btnConnectToRepository.setEnabled(theEnabled); |
235 | 244 |
} |
236 |
|
|
245 |
|
|
237 | 246 |
private void doAddTableToRepository() { |
238 | 247 |
final RepositoryAddTablePanel panel = new RepositoryAddTablePanel(); |
239 | 248 |
WindowManager_v2 winManager = (WindowManager_v2) ToolsSwingLocator.getWindowManager(); |
240 | 249 |
final Dialog dialog = winManager.createDialog( |
241 | 250 |
panel, |
242 | 251 |
"Add table to repository", |
243 |
null,
|
|
252 |
null, |
|
244 | 253 |
WindowManager_v2.BUTTONS_OK_CANCEL |
245 | 254 |
); |
246 | 255 |
dialog.addActionListener(new ActionListener() { |
247 | 256 |
@Override |
248 | 257 |
public void actionPerformed(ActionEvent e) { |
249 |
if( dialog.getAction()==WindowManager_v2.BUTTON_OK ) {
|
|
258 |
if (dialog.getAction() == WindowManager_v2.BUTTON_OK) {
|
|
250 | 259 |
DataManager dataManager = DALLocator.getDataManager(); |
251 | 260 |
DatabaseWorkspaceManager workspace = dataManager.createDatabaseWorkspaceManager(getConnection()); |
252 |
String tableName = panel.getTableName(); |
|
253 |
DataStoreParameters parameters = panel.getDataStoreParameters(); |
|
254 |
if( !workspace.writeStoresRepositoryEntry(tableName, parameters) ) { |
|
255 |
// TODO: mensaje al usuario,no se ha podido crear |
|
261 |
for (LabeledValue<DataStoreParameters> p : panel.getDataStoreParameters()) { |
|
262 |
if (p == null) { |
|
263 |
continue; |
|
264 |
} |
|
265 |
if (!workspace.writeStoresRepositoryEntry(p.getLabel(), p.getValue())) { |
|
266 |
LOGGER.warn("Can't add table '" + p.getLabel() + "' to repository"); |
|
267 |
// TODO: mensaje al usuario,no se ha podido crear |
|
268 |
} |
|
256 | 269 |
} |
257 | 270 |
} |
258 | 271 |
} |
259 | 272 |
}); |
260 |
dialog.show(WindowManager.MODE.WINDOW);
|
|
273 |
dialog.show(WindowManager.MODE.DIALOG);
|
|
261 | 274 |
} |
262 | 275 |
|
263 | 276 |
private void doUpdateStoresRepositoryInfo() { |
264 | 277 |
DataManager dataManager = DALLocator.getDataManager(); |
278 |
DataSwingManager dataSwingManager = DALSwingLocator.getDataSwingManager(); |
|
279 |
|
|
265 | 280 |
DatabaseWorkspaceManager workspace = dataManager.createDatabaseWorkspaceManager(getConnection()); |
266 | 281 |
String id = workspace.get(CONFIG_NAME_STORESREPOSITORYID); |
267 | 282 |
String label = workspace.get(CONFIG_NAME_STORESREPOSITORYLABEL); |
268 | 283 |
this.txtStoresRepositoryId.setText(StringUtils.defaultIfBlank(id, "")); |
269 | 284 |
this.txtStoresRepositoryLabel.setText(StringUtils.defaultIfBlank(label, "")); |
270 |
|
|
285 |
|
|
271 | 286 |
this.btnConnectToRepository.setEnabled(!StringUtils.isBlank(id)); |
287 |
|
|
288 |
try { |
|
289 |
this.pnlConfiguration.removeAll(); |
|
290 |
this.configurationSearch = dataSwingManager.createFeatureStoreSearchPanel( |
|
291 |
workspace.getTable(DatabaseWorkspaceManager.TABLE_CONFIGURATION) |
|
292 |
); |
|
293 |
this.pnlConfiguration.add(this.configurationSearch.asJComponent(), BorderLayout.CENTER); |
|
294 |
this.configurationSearch.setFilterOnlyMode(true); |
|
295 |
this.configurationSearch.setShowActions(false); |
|
296 |
// this.configurationSearch.setAllowCollapseSearchCondition(true); |
|
297 |
// this.configurationSearch.setCollapseSearchCondition(true); |
|
298 |
} catch (Exception ex) { |
|
299 |
|
|
300 |
} |
|
301 |
try { |
|
302 |
this.pnlRepository.removeAll(); |
|
303 |
this.repositorySearch = dataSwingManager.createFeatureStoreSearchPanel( |
|
304 |
workspace.getTable(DatabaseWorkspaceManager.TABLE_REPOSITORY) |
|
305 |
); |
|
306 |
this.pnlRepository.add(this.repositorySearch.asJComponent(), BorderLayout.CENTER); |
|
307 |
this.repositorySearch.setFilterOnlyMode(true); |
|
308 |
this.repositorySearch.setShowActions(false); |
|
309 |
// this.repositorySearch.setAllowCollapseSearchCondition(true); |
|
310 |
// this.repositorySearch.setCollapseSearchCondition(true); |
|
311 |
} catch (Exception ex) { |
|
312 |
|
|
313 |
} |
|
314 |
try { |
|
315 |
this.pnlResorces.removeAll(); |
|
316 |
this.resourcesSearch = dataSwingManager.createFeatureStoreSearchPanel( |
|
317 |
workspace.getTable(DatabaseWorkspaceManager.TABLE_RESOURCES) |
|
318 |
); |
|
319 |
this.resourcesSearch.setFilterOnlyMode(true); |
|
320 |
this.resourcesSearch.setShowActions(false); |
|
321 |
// this.resourcesSearch.setAllowCollapseSearchCondition(true); |
|
322 |
// this.resourcesSearch.setCollapseSearchCondition(true); |
|
323 |
this.pnlResorces.add(this.resourcesSearch.asJComponent(), BorderLayout.CENTER); |
|
324 |
} catch (Exception ex) { |
|
325 |
|
|
326 |
} |
|
327 |
|
|
328 |
this.invalidate(); |
|
272 | 329 |
} |
273 |
|
|
330 |
|
|
274 | 331 |
private void doConnectToRepository() { |
275 | 332 |
DataManager dataManager = DALLocator.getDataManager(); |
276 | 333 |
DatabaseWorkspaceManager workspace = dataManager.createDatabaseWorkspaceManager(getConnection()); |
277 | 334 |
StoresRepository repo = workspace.getStoresRepository(); |
278 | 335 |
dataManager.getStoresRepository().addRepository(repo); |
279 | 336 |
} |
337 |
|
|
338 |
private void doShowParametersOfRepositoryTable() { |
|
339 |
try { |
|
340 |
DataManager dataManager = DALLocator.getDataManager(); |
|
341 |
DataStoreParametersPanelManager manager = DALSwingLocator.getDataStoreParametersPanelManager(); |
|
342 |
FeatureStore store = this.repositorySearch.getStore(); |
|
343 |
Feature f = store.findFirst(this.repositorySearch.getFilterForSelectedFeature()); |
|
344 |
if (f == null) { |
|
345 |
return; |
|
346 |
} |
|
347 |
String name = f.getString(DatabaseWorkspaceManager.FIELD_REPOSITORY_NAME); |
|
348 |
DatabaseWorkspaceManager workspace = dataManager.createDatabaseWorkspaceManager(getConnection()); |
|
349 |
StoresRepository repository = workspace.getStoresRepository(); |
|
350 |
DataStoreParameters parameters = repository.get(name); |
|
351 |
DataStoreParametersPanel panel = manager.createDataStoreParametersPanel(parameters); |
|
352 |
Dialog dialog = manager.createPropertiesDialog(parameters, panel); |
|
353 |
dialog.addActionListener((ActionEvent ae) -> { |
|
354 |
switch(ae.getID() ) { |
|
355 |
case WindowManager_v2.BUTTON_APPLY: |
|
356 |
manager.showAdvancedPropertiesDialog(parameters); |
|
357 |
break; |
|
358 |
case WindowManager_v2.BUTTON_OK: |
|
359 |
panel.fetchParameters(parameters); |
|
360 |
workspace.writeStoresRepositoryEntry(name, parameters); |
|
361 |
break; |
|
362 |
case WindowManager_v2.BUTTON_CANCEL: |
|
363 |
break; |
|
364 |
} |
|
365 |
}); |
|
366 |
dialog.show(WindowManager.MODE.WINDOW); |
|
367 |
} catch (Exception ex) { |
|
368 |
LOGGER.warn("Can't show parameters of repository table", ex); |
|
369 |
} |
|
370 |
} |
|
371 |
|
|
372 |
private void doFixRepositoryEntriesToSelectedConnection() { |
|
373 |
DataManager dataManager = DALLocator.getDataManager(); |
|
374 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
|
375 |
|
|
376 |
JDBCServerExplorerParameters conn = getConnection(); |
|
377 |
DatabaseWorkspaceManager workspace = dataManager.createDatabaseWorkspaceManager(conn); |
|
378 |
StoresRepository repository = workspace.getStoresRepository(); |
|
379 |
|
|
380 |
int n = 0; |
|
381 |
for (String name : repository.keySet()) { |
|
382 |
DataStoreParameters params = repository.get(name); |
|
383 |
if( params instanceof JDBCStoreParameters ) { |
|
384 |
((JDBCStoreParameters) params).setUrl(conn.getUrl()); |
|
385 |
((JDBCStoreParameters) params).setUser(conn.getUser()); |
|
386 |
((JDBCStoreParameters) params).setPassword(conn.getPassword()); |
|
387 |
workspace.writeStoresRepositoryEntry(name, params); |
|
388 |
n++; |
|
389 |
} |
|
390 |
} |
|
391 |
ToolsSwingLocator.getThreadSafeDialogsManager().messageDialog( |
|
392 |
"Total updateds entries "+n, |
|
393 |
i18n.getTranslation("_Manage_Dabatase_workspace"), |
|
394 |
JOptionPane.INFORMATION_MESSAGE |
|
395 |
); |
|
396 |
|
|
397 |
} |
|
280 | 398 |
} |
Also available in: Unified diff