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