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