svn-gvsig-desktop / branches / org.gvsig.desktop-2018a / org.gvsig.desktop.plugin / org.gvsig.geodb.app / org.gvsig.geodb.app.mainplugin / src / main / java / org / gvsig / geodb / vectorialdb / wizard / WizardDB.java @ 43891
History | View | Annotate | Download (23.8 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.geodb.vectorialdb.wizard; |
25 |
|
26 |
import java.awt.BorderLayout; |
27 |
import java.awt.Window; |
28 |
import java.awt.event.ActionEvent; |
29 |
import java.awt.event.ActionListener; |
30 |
import java.util.ArrayList; |
31 |
import java.util.Comparator; |
32 |
import java.util.Iterator; |
33 |
import java.util.List; |
34 |
import java.util.Map; |
35 |
import java.util.Map.Entry; |
36 |
|
37 |
import javax.swing.JComboBox; |
38 |
import javax.swing.JOptionPane; |
39 |
import javax.swing.JPanel; |
40 |
import javax.swing.JScrollPane; |
41 |
import javax.swing.ListSelectionModel; |
42 |
import javax.swing.SwingUtilities; |
43 |
import javax.swing.event.AncestorEvent; |
44 |
import javax.swing.event.AncestorListener; |
45 |
import javax.swing.event.ListSelectionEvent; |
46 |
import javax.swing.event.ListSelectionListener; |
47 |
|
48 |
import org.apache.commons.lang3.text.WordUtils; |
49 |
import org.cresques.cts.IProjection; |
50 |
import org.slf4j.Logger; |
51 |
import org.slf4j.LoggerFactory; |
52 |
|
53 |
import org.gvsig.andami.IconThemeHelper; |
54 |
import org.gvsig.andami.PluginServices; |
55 |
import org.gvsig.andami.PluginsLocator; |
56 |
import org.gvsig.andami.PluginsManager; |
57 |
import org.gvsig.andami.messages.NotificationManager; |
58 |
import org.gvsig.app.ApplicationLocator; |
59 |
import org.gvsig.app.ApplicationManager; |
60 |
import org.gvsig.app.gui.WizardPanel; |
61 |
import org.gvsig.app.prepareAction.PrepareContext; |
62 |
import org.gvsig.app.project.Project; |
63 |
import org.gvsig.app.project.ProjectManager; |
64 |
import org.gvsig.app.project.documents.table.TableDocument; |
65 |
import org.gvsig.app.project.documents.table.TableManager; |
66 |
import org.gvsig.fmap.dal.DALLocator; |
67 |
import org.gvsig.fmap.dal.DataManager; |
68 |
import org.gvsig.fmap.dal.DataServerExplorerPool; |
69 |
import org.gvsig.fmap.dal.DataServerExplorerPoolEntry; |
70 |
import org.gvsig.fmap.dal.DataStoreParameters; |
71 |
import org.gvsig.fmap.dal.DataTypes; |
72 |
import org.gvsig.fmap.dal.exception.DataException; |
73 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
74 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
75 |
import org.gvsig.fmap.dal.serverexplorer.db.DBServerExplorer; |
76 |
import org.gvsig.fmap.dal.serverexplorer.db.DBServerExplorerParameters; |
77 |
import org.gvsig.fmap.dal.store.db.DBStoreParameters; |
78 |
import org.gvsig.fmap.geom.Geometry; |
79 |
import org.gvsig.fmap.mapcontext.BaseCreateLayerParameters; |
80 |
import org.gvsig.fmap.mapcontext.MapContextManager.CreateLayerParameters; |
81 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
82 |
import org.gvsig.fmap.mapcontrol.MapControl; |
83 |
import org.gvsig.geodb.ExtDB_Spatial; |
84 |
import org.gvsig.gui.beans.swing.JButton; |
85 |
import org.gvsig.i18n.Messages; |
86 |
import org.gvsig.tools.dynobject.DynObject; |
87 |
|
88 |
public class WizardDB extends WizardPanel implements ActionListener, |
89 |
ListSelectionListener {
|
90 |
|
91 |
/**
|
92 |
*
|
93 |
*/
|
94 |
private static final long serialVersionUID = -7045762275505941695L; |
95 |
private static final String WIZARD_TAB_NAME = "DB"; |
96 |
private static Logger logger = LoggerFactory.getLogger(WizardDB.class |
97 |
.getName()); |
98 |
|
99 |
private JPanel namePanel = null; |
100 |
private JPanel tablesPanel = null; |
101 |
private JScrollPane tablesScrollPane = null; |
102 |
private AvailableTablesCheckBoxList tablesList = null; |
103 |
private JComboBox datasourceComboBox = null; |
104 |
private UserSelectedFieldsPanel fieldsPanel = null; |
105 |
private UserSelectedFieldsPanel emptyFieldsPanel = null; |
106 |
private JButton dbButton = null; |
107 |
private DBServerExplorerParameters dbExplorerParameters;
|
108 |
private DBServerExplorer dbExplorer = null; |
109 |
|
110 |
private UserTableSettingsPanel settingsPanel = null; |
111 |
protected UserTableSettingsPanel emptySettingsPanel = null; |
112 |
private PrepareContext prepareDSContext;
|
113 |
|
114 |
public WizardDB() {
|
115 |
super();
|
116 |
initialize(); |
117 |
this.addAncestorListener(new AncestorListener() { |
118 |
public void ancestorAdded(AncestorEvent ae) { |
119 |
} |
120 |
|
121 |
public void ancestorRemoved(AncestorEvent ae) { |
122 |
if ( dbExplorer != null ) { |
123 |
dbExplorer.dispose(); |
124 |
dbExplorer = null;
|
125 |
} |
126 |
} |
127 |
|
128 |
public void ancestorMoved(AncestorEvent ae) { |
129 |
} |
130 |
}); |
131 |
} |
132 |
|
133 |
public DBServerExplorer getServerExplorer() {
|
134 |
return this.dbExplorer; |
135 |
} |
136 |
|
137 |
protected void initialize() { |
138 |
setTabName(WIZARD_TAB_NAME); |
139 |
setLayout(null);
|
140 |
setSize(512, 478); |
141 |
|
142 |
emptyFieldsPanel = new UserSelectedFieldsPanel(null, true, this); |
143 |
add(emptyFieldsPanel); |
144 |
|
145 |
add(getNamePanel(), null);
|
146 |
loadVectorialDBDatasourcesCombo(null);
|
147 |
|
148 |
add(getTablesPanel(), null);
|
149 |
|
150 |
emptySettingsPanel = createSettingsPanel(null);
|
151 |
add(emptySettingsPanel); |
152 |
|
153 |
} |
154 |
|
155 |
@SuppressWarnings("rawtypes") |
156 |
private void loadVectorialDBDatasourcesCombo(MyExplorer sel) { |
157 |
DataManager dataManager = DALLocator.getDataManager(); |
158 |
DataServerExplorerPool explorersPool = dataManager.getDataServerExplorerPool(); |
159 |
Iterator it = explorersPool.iterator();
|
160 |
getDatasourceComboBox().removeAllItems(); |
161 |
getDatasourceComboBox().addItem("");
|
162 |
while ( it.hasNext() ) {
|
163 |
DataServerExplorerPoolEntry entry = (DataServerExplorerPoolEntry) it.next(); |
164 |
if( entry.getExplorerParameters() instanceof DBServerExplorerParameters ) { |
165 |
MyExplorer myExplorer = new MyExplorer();
|
166 |
myExplorer.setDbExplorerParameters((DBServerExplorerParameters) entry.getExplorerParameters()); |
167 |
myExplorer.setName(entry.getName()); |
168 |
getDatasourceComboBox().addItem(myExplorer); |
169 |
if ( sel != null && sel.getName().equalsIgnoreCase(myExplorer.getName()) ) { |
170 |
getDatasourceComboBox().setSelectedItem(myExplorer); |
171 |
} |
172 |
} |
173 |
} |
174 |
|
175 |
} |
176 |
|
177 |
public void initWizard() { |
178 |
} |
179 |
|
180 |
@Override
|
181 |
public void execute() { |
182 |
executeWizard(); |
183 |
} |
184 |
|
185 |
@Override
|
186 |
public Object executeWizard() { |
187 |
TablesListItem[] tables = getSelectedTables();
|
188 |
|
189 |
DataManager man = DALLocator.getDataManager(); |
190 |
FeatureStore store; |
191 |
|
192 |
String docName;
|
193 |
TableDocument document; |
194 |
Project project = ProjectManager.getInstance().getCurrentProject(); |
195 |
|
196 |
ApplicationManager appGvSIGMan = ApplicationLocator.getManager(); |
197 |
PrepareContext context = this.getPrepareDataStoreContext();
|
198 |
DBStoreParameters storeParams; |
199 |
List<TableDocument> tabledocs
|
200 |
= new ArrayList<>(tables.length); |
201 |
for ( TablesListItem table : tables ) {
|
202 |
CreateLayerParameters layerParams = getParameterForTable(table); |
203 |
storeParams = (DBStoreParameters) layerParams.getDataParameters(); |
204 |
|
205 |
UserTableSettingsPanel userTableSettingsPanel = table |
206 |
.getUserTableSettingsPanel(); |
207 |
|
208 |
docName = userTableSettingsPanel.getUserLayerName(); |
209 |
try {
|
210 |
store = (FeatureStore) man.openStore(storeParams.getDataStoreName(), storeParams); |
211 |
} catch (Exception e) { |
212 |
NotificationManager.addError(e); |
213 |
return null; |
214 |
} |
215 |
|
216 |
try {
|
217 |
appGvSIGMan.pepareOpenDataSource( |
218 |
store, context); |
219 |
} catch (Exception e) { |
220 |
NotificationManager.addError(e); |
221 |
store.dispose(); |
222 |
return null; |
223 |
} |
224 |
|
225 |
document = (TableDocument) ProjectManager.getInstance().createDocument(TableManager.TYPENAME, docName); |
226 |
document.setStore(store); |
227 |
tabledocs.add(document); |
228 |
} |
229 |
return tabledocs;
|
230 |
} |
231 |
|
232 |
protected CreateLayerParameters getParameterForTable(TablesListItem table) {
|
233 |
DBStoreParameters parameters = table.getParameters(); |
234 |
|
235 |
UserTableSettingsPanel userTableSettingsPanel = table.getUserTableSettingsPanel(); |
236 |
|
237 |
String fidField = userTableSettingsPanel.getIdFieldName();
|
238 |
//IF is a multiple PK, remove the {} symbols
|
239 |
if ( fidField.startsWith("{") && fidField.endsWith("}") ) { |
240 |
fidField = fidField.substring(1, fidField.length() - 1); |
241 |
} |
242 |
String[] pkFields = fidField.split(","); |
243 |
|
244 |
String[] fields = table.getUserSelectedFieldsPanel() |
245 |
.getUserSelectedFields(pkFields, null);
|
246 |
|
247 |
if ( userTableSettingsPanel.isSqlActive() ) {
|
248 |
String whereClause = userTableSettingsPanel.getWhereClause();
|
249 |
parameters.setBaseFilter(whereClause); |
250 |
} else {
|
251 |
parameters.setBaseFilter("");
|
252 |
} |
253 |
|
254 |
parameters.setFields(fields); |
255 |
|
256 |
BaseCreateLayerParameters layerParameters = new BaseCreateLayerParameters(
|
257 |
parameters, |
258 |
false,
|
259 |
null
|
260 |
); |
261 |
|
262 |
return layerParameters;
|
263 |
|
264 |
} |
265 |
|
266 |
@SuppressWarnings({"rawtypes", "unchecked"}) |
267 |
protected TablesListItem[] getSelectedTables() { |
268 |
int count = tablesList.getModel().getSize();
|
269 |
ArrayList resp = new ArrayList(); |
270 |
|
271 |
for ( int i = 0; i < count; i++ ) { |
272 |
TablesListItem item = (TablesListItem) tablesList.getModel() |
273 |
.getElementAt(i); |
274 |
|
275 |
if ( item.isSelected() ) {
|
276 |
resp.add(item); |
277 |
} |
278 |
} |
279 |
|
280 |
return (TablesListItem[]) resp.toArray(new TablesListItem[0]); |
281 |
} |
282 |
|
283 |
/**
|
284 |
* This method initializes namePanel
|
285 |
*
|
286 |
* @return javax.swing.JPanel
|
287 |
*/
|
288 |
private JPanel getNamePanel() { |
289 |
if ( namePanel == null ) { |
290 |
namePanel = new JPanel(); |
291 |
namePanel.setLayout(null);
|
292 |
namePanel.setBounds(new java.awt.Rectangle(5, 5, 501, 51)); |
293 |
namePanel.setBorder(javax.swing.BorderFactory.createTitledBorder( |
294 |
null, PluginServices.getText(this, "choose_connection"), |
295 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
296 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null,
|
297 |
null));
|
298 |
namePanel.add(getDatasourceComboBox(), null);
|
299 |
namePanel.add(getJdbcButton(), null);
|
300 |
} |
301 |
|
302 |
return namePanel;
|
303 |
} |
304 |
|
305 |
/**
|
306 |
* This method initializes tablesPanel
|
307 |
*
|
308 |
* @return javax.swing.JPanel
|
309 |
*/
|
310 |
private JPanel getTablesPanel() { |
311 |
if ( tablesPanel == null ) { |
312 |
tablesPanel = new JPanel(); |
313 |
tablesPanel.setLayout(new BorderLayout()); |
314 |
tablesPanel.setBorder(javax.swing.BorderFactory.createTitledBorder( |
315 |
null, PluginServices.getText(this, "choose_table"), |
316 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
317 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null,
|
318 |
null));
|
319 |
tablesPanel.setBounds(new java.awt.Rectangle(5, 55, 246, 166)); |
320 |
tablesPanel |
321 |
.add(getTablesScrollPane(), java.awt.BorderLayout.CENTER); |
322 |
} |
323 |
|
324 |
return tablesPanel;
|
325 |
} |
326 |
|
327 |
/**
|
328 |
* This method initializes settingsPanel
|
329 |
*
|
330 |
* @return javax.swing.JPanel
|
331 |
*/
|
332 |
/**
|
333 |
* This method initializes tablesScrollPane
|
334 |
*
|
335 |
* @return javax.swing.JScrollPane
|
336 |
*/
|
337 |
private JScrollPane getTablesScrollPane() { |
338 |
if ( tablesScrollPane == null ) { |
339 |
tablesScrollPane = new JScrollPane(); |
340 |
tablesScrollPane.setViewportView(getTablesList()); |
341 |
} |
342 |
|
343 |
return tablesScrollPane;
|
344 |
} |
345 |
|
346 |
/**
|
347 |
* This method initializes tablesList
|
348 |
*
|
349 |
* @return javax.swing.JList
|
350 |
*/
|
351 |
protected AvailableTablesCheckBoxList getTablesList() {
|
352 |
if ( tablesList == null ) { |
353 |
tablesList = new AvailableTablesCheckBoxList(this); |
354 |
tablesList.addListSelectionListener(this);
|
355 |
tablesList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
356 |
} |
357 |
|
358 |
return tablesList;
|
359 |
} |
360 |
|
361 |
/**
|
362 |
* This method initializes layerNameTextField
|
363 |
*
|
364 |
* @return javax.swing.JTextField
|
365 |
*/
|
366 |
/**
|
367 |
* This method initializes jComboBox
|
368 |
*
|
369 |
* @return javax.swing.JComboBox
|
370 |
*/
|
371 |
private JComboBox getDatasourceComboBox() { |
372 |
if ( datasourceComboBox == null ) { |
373 |
datasourceComboBox = new JComboBox(); |
374 |
datasourceComboBox |
375 |
.setBounds(new java.awt.Rectangle(10, 20, 446, 21)); |
376 |
datasourceComboBox.addActionListener(this);
|
377 |
} |
378 |
|
379 |
return datasourceComboBox;
|
380 |
} |
381 |
|
382 |
public void actionPerformed(ActionEvent arg0) { |
383 |
if ( datasourceComboBox.getItemCount() == 0 ) { |
384 |
setEmptyPanels(); |
385 |
} |
386 |
Object src = arg0.getSource();
|
387 |
|
388 |
if ( src == datasourceComboBox ) {
|
389 |
final Object selected = datasourceComboBox.getSelectedItem(); |
390 |
if ( selected instanceof MyExplorer ) { |
391 |
// Lo lanzamos asi para evitar cuelgues depurando, ya que estamos
|
392 |
// en el evento de un combo y ahi no se puede depurar sin mas.
|
393 |
SwingUtilities.invokeLater(new Runnable() { |
394 |
|
395 |
@Override
|
396 |
public void run() { |
397 |
MyExplorer sel_obj = (MyExplorer) selected; |
398 |
|
399 |
getDatasourceComboBox().repaint(); |
400 |
dbExplorerParameters = sel_obj.getDbSeverExplorerParameters(); |
401 |
updateTableList(dbExplorerParameters); |
402 |
} |
403 |
}); |
404 |
} |
405 |
|
406 |
} else if ( src == dbButton ) { |
407 |
MyExplorer sel = addNewConnection(); |
408 |
if ( sel == null ) { |
409 |
loadVectorialDBDatasourcesCombo(null);
|
410 |
} else {
|
411 |
dbExplorerParameters = sel.getDbSeverExplorerParameters(); |
412 |
loadVectorialDBDatasourcesCombo(sel); |
413 |
getDatasourceComboBox().setSelectedItem(sel); |
414 |
} |
415 |
} |
416 |
|
417 |
} |
418 |
|
419 |
@SuppressWarnings({"unchecked", "rawtypes"}) |
420 |
private MyExplorer addNewConnection() {
|
421 |
VectorialDBConnectionParamsDialog newco = new VectorialDBConnectionParamsDialog();
|
422 |
newco.showDialog(); |
423 |
if ( newco.isCanceled()) {
|
424 |
return null; |
425 |
} |
426 |
MyExplorer myExplorer = new MyExplorer();
|
427 |
myExplorer.setDbExplorerParameters(newco.getServerExplorerParameters()); |
428 |
myExplorer.setName(newco.getConnectionName()); |
429 |
loadVectorialDBDatasourcesCombo(myExplorer); |
430 |
return myExplorer;
|
431 |
} |
432 |
|
433 |
protected TablesListItem createTabeListItem(DBStoreParameters param) {
|
434 |
return new TablesListItem(param, this); |
435 |
} |
436 |
|
437 |
/**
|
438 |
* Subclasses of this wizard will return a filtered list
|
439 |
* if necessary
|
440 |
*
|
441 |
* @param explorer
|
442 |
* @return
|
443 |
* @throws DataException
|
444 |
*/
|
445 |
protected List<DBStoreParameters> getTableList(DBServerExplorer explorer) throws DataException { |
446 |
List<DBStoreParameters> l = new ArrayList<>(); |
447 |
l.addAll(explorer.list()); |
448 |
l.sort(new Comparator<DBStoreParameters>() { |
449 |
@Override
|
450 |
public int compare(DBStoreParameters o1, DBStoreParameters o2) { |
451 |
try {
|
452 |
return o1.getTable().compareToIgnoreCase(o2.getTable());
|
453 |
} catch(Exception ex) { |
454 |
return 0; |
455 |
} |
456 |
} |
457 |
}); |
458 |
return l;
|
459 |
} |
460 |
|
461 |
@SuppressWarnings("rawtypes") |
462 |
protected void updateTableList( |
463 |
DBServerExplorerParameters dbSeverExplorerParameters2) { |
464 |
if ( dbSeverExplorerParameters2 == null ) { |
465 |
return;
|
466 |
} |
467 |
DataManager dm = DALLocator.getDataManager(); |
468 |
String err_msg = Messages.getText("connection_error"); |
469 |
try {
|
470 |
dbExplorer = (DBServerExplorer) dm.openServerExplorer(dbSeverExplorerParameters2.getExplorerName(), dbSeverExplorerParameters2); |
471 |
|
472 |
List parameters = getTableList(dbExplorer);
|
473 |
List<TablesListItem> tableListItems = new ArrayList<>(); |
474 |
Iterator<DBStoreParameters> iter = parameters.iterator();
|
475 |
while ( iter.hasNext() ) {
|
476 |
DBStoreParameters param = iter.next(); |
477 |
tableListItems.add(createTabeListItem(param)); |
478 |
} |
479 |
tableListItems.sort(null);
|
480 |
getTablesList().setListData(tableListItems.toArray(new TablesListItem[0])); |
481 |
getTablesScrollPane().setViewportView(tablesList); |
482 |
tablesScrollPane.updateUI(); |
483 |
} catch (Exception e) { |
484 |
logger.info("Error while getting table names: " + e.getMessage(),e);
|
485 |
|
486 |
String remove_question = Messages.getText(
|
487 |
"_Remove_connection_parameters_from_list_question");
|
488 |
|
489 |
int opt = JOptionPane.showConfirmDialog( |
490 |
ApplicationLocator.getManager().getRootComponent(), |
491 |
WordUtils.wrap(err_msg + ": " + getLastMessage(e) + "\n" + remove_question, 80), |
492 |
err_msg, |
493 |
JOptionPane.YES_NO_OPTION);
|
494 |
|
495 |
if ( opt == JOptionPane.YES_OPTION ) { |
496 |
removeDBPArameters(dbSeverExplorerParameters2); |
497 |
// dbExplorer.
|
498 |
loadVectorialDBDatasourcesCombo(null);
|
499 |
} |
500 |
} |
501 |
|
502 |
} |
503 |
|
504 |
/**
|
505 |
* Removes DB parameters from list of pre-configured DB parameters
|
506 |
*
|
507 |
* @param dbSeverExplorerParameters2
|
508 |
*/
|
509 |
private void removeDBPArameters( |
510 |
DBServerExplorerParameters dbparams) { |
511 |
|
512 |
PluginsManager manager = PluginsLocator.getManager(); |
513 |
DynObject values = manager.getPlugin(ExtDB_Spatial.class).getPluginProperties(); |
514 |
Map connections = (Map) values.getDynValue("db_connections"); |
515 |
if ( connections == null ) { |
516 |
return;
|
517 |
} |
518 |
|
519 |
DBServerExplorerParameters item = null;
|
520 |
Iterator it = connections.entrySet().iterator();
|
521 |
List<String> toremove = new ArrayList(); |
522 |
|
523 |
while ( it.hasNext() ) {
|
524 |
Map.Entry entry = (Entry) it.next();
|
525 |
item = (DBServerExplorerParameters) entry.getValue(); |
526 |
if ( dbparams.equals(item) ) {
|
527 |
toremove.add((String) entry.getKey());
|
528 |
} |
529 |
} |
530 |
|
531 |
if ( toremove.size() == 0 ) { |
532 |
return;
|
533 |
} |
534 |
|
535 |
for ( int i = 0; i < toremove.size(); i++ ) { |
536 |
connections.remove(toremove.get(i)); |
537 |
} |
538 |
values.setDynValue("db_connections", connections);
|
539 |
|
540 |
} |
541 |
|
542 |
public void valueChanged(ListSelectionEvent arg0) { |
543 |
Object src = arg0.getSource();
|
544 |
|
545 |
if ( src == tablesList ) {
|
546 |
TablesListItem selected = (TablesListItem) tablesList |
547 |
.getSelectedValue(); |
548 |
|
549 |
setSettingsPanels(selected); |
550 |
checkFinishable(); |
551 |
} |
552 |
} |
553 |
|
554 |
public boolean areSettingsValid() { |
555 |
int count = tablesList.getModel().getSize();
|
556 |
|
557 |
boolean at_least_one = false; |
558 |
boolean resp = true; |
559 |
|
560 |
for ( int i = 0; i < count; i++ ) { |
561 |
TablesListItem item = (TablesListItem) tablesList.getModel() |
562 |
.getElementAt(i); |
563 |
|
564 |
if ( item.isSelected() ) {
|
565 |
at_least_one = true;
|
566 |
} |
567 |
|
568 |
if ( item.disturbsWizardValidity() ) {
|
569 |
resp = false;
|
570 |
} |
571 |
} |
572 |
|
573 |
return (at_least_one && resp);
|
574 |
} |
575 |
|
576 |
public void checkFinishable() { |
577 |
boolean finishable = areSettingsValid();
|
578 |
callStateChanged(finishable); |
579 |
} |
580 |
|
581 |
/**
|
582 |
* This method initializes jdbcButton
|
583 |
*
|
584 |
* @return javax.swing.JButton
|
585 |
*/
|
586 |
private JButton getJdbcButton() { |
587 |
if ( dbButton == null ) { |
588 |
dbButton = new JButton(); |
589 |
dbButton.addActionListener(this);
|
590 |
dbButton.setToolTipText(PluginServices.getText(this,
|
591 |
"add_connection"));
|
592 |
dbButton.setBounds(new java.awt.Rectangle(465, 20, 26, 21)); |
593 |
|
594 |
dbButton.setIcon(IconThemeHelper.getImageIcon("geodb-connection-add"));
|
595 |
} |
596 |
|
597 |
return dbButton;
|
598 |
} |
599 |
|
600 |
private void showConnectionErrorMessage(String _msg) { |
601 |
String msg = (_msg.length() > 300) ? "" : (": " + _msg); |
602 |
String title = PluginServices.getText(this, "connection_error"); |
603 |
JOptionPane.showMessageDialog(this, title + msg, title, |
604 |
JOptionPane.ERROR_MESSAGE);
|
605 |
} |
606 |
|
607 |
private java.net.URL createResourceUrl(String path) { |
608 |
return getClass().getClassLoader().getResource(path);
|
609 |
} |
610 |
|
611 |
public void setSettingsPanels(TablesListItem actTable) { |
612 |
if ( actTable == null ) { |
613 |
setEmptyPanels(); |
614 |
|
615 |
return;
|
616 |
} |
617 |
fieldsPanel = actTable.getUserSelectedFieldsPanel(); |
618 |
|
619 |
removeFieldPanels(); |
620 |
add(fieldsPanel); |
621 |
fieldsPanel.repaint(); |
622 |
removeSettingsPanels(); |
623 |
add(emptySettingsPanel); |
624 |
|
625 |
settingsPanel = createSettingsPanel(actTable); |
626 |
|
627 |
removeSettingsPanels(); |
628 |
add(settingsPanel); |
629 |
settingsPanel.repaint(); |
630 |
|
631 |
repaint(); |
632 |
} |
633 |
|
634 |
protected UserTableSettingsPanel createSettingsPanel(TablesListItem actTable) {
|
635 |
if ( actTable == null ) { |
636 |
return new UserTableSettingsPanel(null, "", true, this, null); |
637 |
} |
638 |
|
639 |
return actTable.getUserTableSettingsPanel();
|
640 |
} |
641 |
|
642 |
protected void setEmptyPanels() { |
643 |
removeFieldPanels(); |
644 |
add(emptyFieldsPanel); |
645 |
fieldsPanel = emptyFieldsPanel; |
646 |
|
647 |
repaint(); |
648 |
} |
649 |
|
650 |
private void removeFieldPanels() { |
651 |
for ( int i = 0; i < getComponentCount(); i++ ) { |
652 |
if ( getComponent(i) instanceof UserSelectedFieldsPanel ) { |
653 |
remove(i); |
654 |
} |
655 |
} |
656 |
} |
657 |
|
658 |
public DataStoreParameters[] getParameters() { |
659 |
try {
|
660 |
TablesListItem[] selected = getSelectedTables();
|
661 |
int count = selected.length;
|
662 |
DBStoreParameters[] dbParameters = new DBStoreParameters[count]; |
663 |
|
664 |
for ( int i = 0; i < count; i++ ) { |
665 |
TablesListItem item = selected[i]; |
666 |
|
667 |
dbParameters[i] = (DBStoreParameters) getParameterForTable(item).getDataParameters(); |
668 |
} |
669 |
|
670 |
return dbParameters;// layerArrayToGroup(all_layers, groupName); |
671 |
} catch (Exception e) { |
672 |
logger.info("Error while creating jdbc layer: " + e.getMessage(), e);
|
673 |
NotificationManager.addError("Error while loading layer: "
|
674 |
+ e.getMessage(), e); |
675 |
} |
676 |
|
677 |
return null; |
678 |
} |
679 |
|
680 |
/**
|
681 |
* This method process the errors found in a layer
|
682 |
*
|
683 |
* @param lyr
|
684 |
* @param mapControl
|
685 |
*/
|
686 |
protected void processErrorsOfLayer(FLayer lyr, MapControl mapControl) { |
687 |
this.getMapContext().callNewErrorEvent(null); |
688 |
} |
689 |
|
690 |
private void removeSettingsPanels() { |
691 |
for ( int i = 0; i < getComponentCount(); i++ ) { |
692 |
if ( getComponent(i) instanceof UserTableSettingsPanel ) { |
693 |
remove(i); |
694 |
} |
695 |
} |
696 |
} |
697 |
|
698 |
protected PrepareContext getPrepareDataStoreContext() {
|
699 |
if ( this.prepareDSContext == null ) { |
700 |
this.prepareDSContext = new PrepareContext() { |
701 |
public Window getOwnerWindow() { |
702 |
return null; |
703 |
} |
704 |
|
705 |
public IProjection getViewProjection() {
|
706 |
return WizardDB.this.getMapContext().getProjection();
|
707 |
} |
708 |
|
709 |
}; |
710 |
} |
711 |
return this.prepareDSContext; |
712 |
} |
713 |
|
714 |
@Override
|
715 |
public void close() { |
716 |
|
717 |
} |
718 |
|
719 |
protected String getLastMessage(Throwable ex) { |
720 |
|
721 |
Throwable p = ex;
|
722 |
while ( p.getCause() != null && p.getCause() != p ) { |
723 |
p = p.getCause(); |
724 |
} |
725 |
return p.getMessage();
|
726 |
} |
727 |
|
728 |
} |