Revision 34114 branches/v2_0_0_prep/extensions/extGeoDB/src/org/gvsig/geodb/vectorialdb/wizard/WizardDB.java
WizardDB.java | ||
---|---|---|
34 | 34 |
import java.util.ArrayList; |
35 | 35 |
import java.util.Iterator; |
36 | 36 |
import java.util.List; |
37 |
import java.util.Map; |
|
38 |
import java.util.Map.Entry; |
|
37 | 39 |
|
38 | 40 |
import javax.swing.DefaultListModel; |
39 | 41 |
import javax.swing.ImageIcon; |
... | ... | |
45 | 47 |
import javax.swing.event.ListSelectionEvent; |
46 | 48 |
import javax.swing.event.ListSelectionListener; |
47 | 49 |
|
50 |
import org.apache.commons.collections.map.HashedMap; |
|
48 | 51 |
import org.gvsig.andami.PluginServices; |
52 |
import org.gvsig.andami.PluginsLocator; |
|
53 |
import org.gvsig.andami.PluginsManager; |
|
49 | 54 |
import org.gvsig.andami.messages.NotificationManager; |
50 | 55 |
import org.gvsig.app.ApplicationLocator; |
51 | 56 |
import org.gvsig.app.ApplicationManager; |
... | ... | |
67 | 72 |
import org.gvsig.fmap.dal.store.db.DBStoreParameters; |
68 | 73 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
69 | 74 |
import org.gvsig.fmap.mapcontrol.MapControl; |
70 |
import org.gvsig.geodb.SingleVectorialDBConnectionExtension;
|
|
75 |
import org.gvsig.geodb.ExtDB_Spatial;
|
|
71 | 76 |
import org.gvsig.gui.beans.swing.JButton; |
77 |
import org.gvsig.tools.dynobject.DynObject; |
|
72 | 78 |
import org.slf4j.Logger; |
73 | 79 |
import org.slf4j.LoggerFactory; |
74 | 80 |
|
... | ... | |
76 | 82 |
public class WizardDB extends WizardPanel implements ActionListener, |
77 | 83 |
ListSelectionListener { |
78 | 84 |
|
79 |
private static final String WIZARD_TAB_NAME = "DB"; |
|
85 |
/** |
|
86 |
* |
|
87 |
*/ |
|
88 |
private static final long serialVersionUID = -7045762275505941695L; |
|
89 |
private static final String WIZARD_TAB_NAME = "DB"; |
|
80 | 90 |
private static Logger logger = LoggerFactory.getLogger(WizardDB.class |
81 | 91 |
.getName()); |
82 | 92 |
|
... | ... | |
121 | 131 |
} |
122 | 132 |
|
123 | 133 |
|
134 |
@SuppressWarnings("rawtypes") |
|
124 | 135 |
private void loadVectorialDBDatasourcesCombo(MyExplorer sel) { |
125 |
getDatasourceComboBox().removeAllItems(); |
|
126 |
DataManager dm = DALLocator.getDataManager(); |
|
127 |
List names = dm.getStoreProviders(); |
|
128 |
if (sel != null) { |
|
129 |
getDatasourceComboBox().addItem(sel); |
|
130 |
} |
|
131 |
|
|
132 |
if (names == null) { |
|
133 |
return; |
|
134 |
} |
|
135 |
|
|
136 |
|
|
137 |
PluginsManager manager = PluginsLocator.getManager(); |
|
138 |
DynObject values = manager.getPlugin(ExtDB_Spatial.class).getPluginProperties(); |
|
139 |
Map connections = (Map) values.getDynValue("db_connections"); |
|
140 |
if (connections != null){ |
|
141 |
Iterator it = connections.entrySet().iterator(); |
|
142 |
getDatasourceComboBox().removeAllItems(); |
|
143 |
while (it.hasNext()){ |
|
144 |
Map.Entry entry = (Entry) it.next(); |
|
145 |
MyExplorer myExplorer = new MyExplorer(); |
|
146 |
myExplorer.setDbExplorerParameters((DBServerExplorerParameters) entry.getValue()); |
|
147 |
myExplorer.setName((String) entry.getKey()); |
|
148 |
getDatasourceComboBox().addItem(myExplorer); |
|
149 |
if(sel!=null && sel.getName().equalsIgnoreCase(myExplorer.getName())){ |
|
150 |
getDatasourceComboBox().setSelectedItem(myExplorer); |
|
151 |
} |
|
152 |
} |
|
153 |
} else { |
|
154 |
connections = new HashedMap(); |
|
155 |
values.setDynValue("db_connections", connections); |
|
156 |
} |
|
136 | 157 |
} |
137 | 158 |
|
138 | 159 |
public void initWizard() { |
139 | 160 |
} |
140 | 161 |
|
141 | 162 |
public void execute() { |
142 |
SingleVectorialDBConnectionExtension.saveAllToPersistence(); |
|
143 |
|
|
144 | 163 |
TablesListItem[] tables = getSelectedTables(); |
145 | 164 |
|
146 | 165 |
DataManager man = DALLocator.getDataManager(); |
147 |
FeatureStore store, storeToAdd;
|
|
148 |
|
|
166 |
FeatureStore store; |
|
167 |
|
|
149 | 168 |
String docName; |
150 | 169 |
TableDocument document; |
151 |
// Project project = ((ProjectExtension) PluginServices |
|
152 |
// .getExtension(ProjectExtension.class)).getProject(); |
|
153 | 170 |
Project project = ProjectManager.getInstance().getCurrentProject(); |
154 | 171 |
|
155 | 172 |
ApplicationManager appGvSIGMan = ApplicationLocator.getManager(); |
... | ... | |
171 | 188 |
|
172 | 189 |
docName = userTableSettingsPanel.getUserLayerName(); |
173 | 190 |
try { |
174 |
store = (FeatureStore) man.createStore(storeParams);
|
|
191 |
store = (FeatureStore) man.openStore(storeParams.getDataStoreName(), storeParams);
|
|
175 | 192 |
} catch (Exception e) { |
176 | 193 |
NotificationManager.addError(e); |
177 | 194 |
return; |
178 | 195 |
} |
179 | 196 |
|
180 | 197 |
try { |
181 |
storeToAdd = (FeatureStore) appGvSIGMan.pepareOpenDataSource(
|
|
198 |
appGvSIGMan.pepareOpenDataSource( |
|
182 | 199 |
store, context); |
183 | 200 |
} catch (Exception e) { |
184 | 201 |
NotificationManager.addError(e); |
... | ... | |
186 | 203 |
return; |
187 | 204 |
} |
188 | 205 |
|
189 |
|
|
190 |
// document = ProjectFactory.createTable(docName, store); |
|
191 |
|
|
192 | 206 |
document = (TableDocument) ProjectManager.getInstance().createDocument(TableManager.TYPENAME, docName); |
193 | 207 |
document.setStore(store); |
194 | 208 |
project.add(document); |
... | ... | |
228 | 242 |
|
229 | 243 |
} |
230 | 244 |
|
231 |
protected TablesListItem[] getSelectedTables() { |
|
245 |
@SuppressWarnings({ "rawtypes", "unchecked" }) |
|
246 |
protected TablesListItem[] getSelectedTables() { |
|
232 | 247 |
int count = tablesList.getModel().getSize(); |
233 | 248 |
ArrayList resp = new ArrayList(); |
234 | 249 |
|
... | ... | |
352 | 367 |
Object src = arg0.getSource(); |
353 | 368 |
|
354 | 369 |
if (src == datasourceComboBox) { |
355 |
Object sel_obj = datasourceComboBox.getSelectedItem();
|
|
370 |
MyExplorer sel_obj = (MyExplorer)datasourceComboBox.getSelectedItem();
|
|
356 | 371 |
|
357 | 372 |
if (sel_obj == null) { |
358 | 373 |
return; |
359 | 374 |
} |
360 | 375 |
getDatasourceComboBox().repaint(); |
361 |
return; |
|
362 |
} |
|
376 |
dbExplorerParameters = sel_obj.getDbSeverExplorerParameters(); |
|
363 | 377 |
|
364 |
if (src == dbButton) { |
|
378 |
} else if (src == dbButton) {
|
|
365 | 379 |
MyExplorer sel = addNewConnection(); |
366 | 380 |
|
367 | 381 |
if (sel != null) { |
... | ... | |
370 | 384 |
getDatasourceComboBox().setSelectedItem(sel); |
371 | 385 |
|
372 | 386 |
} |
373 |
updateTableList(dbExplorerParameters); |
|
374 | 387 |
} |
388 |
|
|
389 |
updateTableList(dbExplorerParameters); |
|
375 | 390 |
} |
376 | 391 |
|
377 |
private MyExplorer addNewConnection() { |
|
392 |
@SuppressWarnings({ "unchecked", "rawtypes" }) |
|
393 |
private MyExplorer addNewConnection() { |
|
378 | 394 |
MyExplorer myExplorer = new MyExplorer(); |
379 | 395 |
DBServerExplorerParameters resp = null; |
380 | 396 |
|
... | ... | |
388 | 404 |
showConnectionErrorMessage(e.getMessage()); |
389 | 405 |
return null; |
390 | 406 |
} |
391 |
SingleVectorialDBConnectionExtension.saveAllToPersistence(); |
|
407 |
PluginsManager manager = PluginsLocator.getManager(); |
|
408 |
DynObject values = manager.getPlugin(ExtDB_Spatial.class).getPluginProperties(); |
|
409 |
Map connections = (Map) values.getDynValue("db_connections"); |
|
410 |
if(connections == null){ |
|
411 |
connections = new HashedMap(); |
|
412 |
values.setDynValue("db_connections", connections); |
|
413 |
} |
|
414 |
connections.put(newco.getConnectionName(), resp); |
|
415 |
|
|
416 |
// SingleVectorialDBConnectionExtension.saveAllToPersistence(); |
|
392 | 417 |
myExplorer.setDbExplorerParameters(resp); |
393 | 418 |
myExplorer.setName(newco.getConnectionName()); |
394 | 419 |
return myExplorer; |
... | ... | |
402 | 427 |
return new TablesListItem(dbExplorer, param, this); |
403 | 428 |
} |
404 | 429 |
|
405 |
private void updateTableList( |
|
430 |
@SuppressWarnings("rawtypes") |
|
431 |
private void updateTableList( |
|
406 | 432 |
DBServerExplorerParameters dbSeverExplorerParameters2) { |
407 | 433 |
if (dbSeverExplorerParameters2 == null) { |
408 | 434 |
return; |
... | ... | |
410 | 436 |
DataManager dm = DALLocator.getDataManager(); |
411 | 437 |
DBServerExplorer dbExplorer; |
412 | 438 |
try { |
413 |
dbExplorer = (DBServerExplorer) dm |
|
414 |
.createServerExplorer(dbSeverExplorerParameters2); |
|
439 |
dbExplorer = (DBServerExplorer) dm.openServerExplorer(dbSeverExplorerParameters2.getExplorerName(), dbSeverExplorerParameters2); |
|
415 | 440 |
|
416 | 441 |
// TODO: use the mode to filter tables with geometries when opening |
417 | 442 |
// a view document |
... | ... | |
421 | 446 |
|
422 | 447 |
Iterator iter = parameters.iterator(); |
423 | 448 |
DBStoreParameters param; |
449 |
int count = 0; |
|
424 | 450 |
while (iter.hasNext()) { |
425 | 451 |
param = (DBStoreParameters) iter.next(); |
426 | 452 |
lmodel.addElement(createTabeListItem(dbExplorer, param)); |
453 |
count++; |
|
427 | 454 |
} |
428 | 455 |
|
429 | 456 |
getTablesList().setModel(lmodel); |
Also available in: Unified diff