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