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