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