gvsig-projects-pool / org.gvsig.online / trunk / org.gvsig.online / org.gvsig.online.app / org.gvsig.online.app.mainplugin / src / main / java / org / gvsig / online / app / mainplugin / addlayer / WizardOnlineTabular.java @ 9518
History | View | Annotate | Download (4.73 KB)
1 |
package org.gvsig.online.app.mainplugin.addlayer; |
---|---|
2 |
|
3 |
import java.util.ArrayList; |
4 |
import java.util.List; |
5 |
import javax.swing.JOptionPane; |
6 |
import org.gvsig.app.ApplicationLocator; |
7 |
import org.gvsig.app.ApplicationManager; |
8 |
import org.gvsig.app.project.documents.table.TableDocument; |
9 |
import org.gvsig.app.project.documents.table.TableManager; |
10 |
import org.gvsig.fmap.dal.DALLocator; |
11 |
import org.gvsig.fmap.dal.DataManager; |
12 |
import org.gvsig.fmap.dal.StoresRepository; |
13 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
14 |
import org.gvsig.fmap.dal.store.db.DBStoreParameters; |
15 |
import org.gvsig.geodb.TableInfo; |
16 |
import org.gvsig.online.lib.api.workingcopy.OnlineEntity; |
17 |
import org.gvsig.online.lib.api.workingcopy.OnlineWorkingcopy; |
18 |
import org.gvsig.tools.ToolsLocator; |
19 |
import org.gvsig.tools.dispose.DisposeUtils; |
20 |
import org.gvsig.tools.i18n.I18nManager; |
21 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
22 |
import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager; |
23 |
|
24 |
/**
|
25 |
*
|
26 |
* @author jjdelcerro
|
27 |
*/
|
28 |
public class WizardOnlineTabular extends AbstractWizardOnline { |
29 |
|
30 |
public WizardOnlineTabular() {
|
31 |
super();
|
32 |
} |
33 |
|
34 |
@Override
|
35 |
protected boolean requireGeometry() { |
36 |
return false; |
37 |
} |
38 |
|
39 |
@Override
|
40 |
public Object executeWizard() { |
41 |
DataManager man = DALLocator.getDataManager(); |
42 |
ApplicationManager application = ApplicationLocator.getManager(); |
43 |
OnlineWorkingcopy workspace = this.getWorkspace();
|
44 |
|
45 |
for (TableInfo tableInfo : getTablesInformation()) {
|
46 |
if (!tableInfo.isSelected()) {
|
47 |
continue;
|
48 |
} |
49 |
if( ((OnlineTableInfo)tableInfo).needConnectToModel() ) {
|
50 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
51 |
ThreadSafeDialogsManager dialogs = ToolsSwingLocator.getThreadSafeDialogsManager(); |
52 |
int n = dialogs.confirmDialog(
|
53 |
i18n.getTranslation("_Some_of_the_selected_tables_require_connection_to_a_data_model") +
|
54 |
"\n" +
|
55 |
i18n.getTranslation("_It_is_recommended_that_you_connect_to_the_data_model_before_loading_the_tables") +
|
56 |
"\n" +
|
57 |
i18n.getTranslation("_Do_you_want_to_add_the_selected_tables_anyway"),
|
58 |
i18n.getTranslation("_AddTable"),
|
59 |
JOptionPane.YES_NO_OPTION,
|
60 |
JOptionPane.QUESTION_MESSAGE,
|
61 |
"_Some_of_the_selected_tables_require_connection_to_a_data_model"
|
62 |
); |
63 |
if( n != JOptionPane.YES_OPTION ) { |
64 |
return null; |
65 |
} |
66 |
} |
67 |
} |
68 |
|
69 |
List<TableDocument> tabledocs = new ArrayList<>(); |
70 |
|
71 |
List<OnlineTableInfo> tablesInformation = new ArrayList<>(); |
72 |
for (TableInfo tableInfo : getTablesInformation()) {
|
73 |
if (!tableInfo.isSelected()) {
|
74 |
continue;
|
75 |
} |
76 |
tablesInformation.add((OnlineTableInfo) tableInfo); |
77 |
} |
78 |
|
79 |
List<String> dataModels = new ArrayList<>(); |
80 |
for (OnlineTableInfo tableInfo : tablesInformation) {
|
81 |
OnlineEntity entity = tableInfo.getEntity(); |
82 |
List<String> entityModels = entity.getDataModelsAsList(); |
83 |
if( entityModels!=null ) { |
84 |
for (String entityModel : entityModels) { |
85 |
dataModels.add(entityModel); |
86 |
} |
87 |
} |
88 |
} |
89 |
if( !dataModels.isEmpty() ) {
|
90 |
for (StoresRepository storesRepository : man.getStoresRepository().getSubrepositories() ) {
|
91 |
dataModels.remove(storesRepository.getID()); |
92 |
} |
93 |
for (String dataModel : dataModels) { |
94 |
registerDataModelRepository(workspace, dataModel); |
95 |
} |
96 |
} |
97 |
|
98 |
for (OnlineTableInfo tableInfo : tablesInformation) {
|
99 |
DBStoreParameters storeParams = tableInfo.getParameters(); |
100 |
FeatureStore store = null;
|
101 |
try {
|
102 |
try {
|
103 |
store = (FeatureStore) man.openStore( |
104 |
storeParams.getDataStoreName(), |
105 |
storeParams |
106 |
); |
107 |
} catch (Exception e) { |
108 |
LOGGER.warn("Can't open store ", e);
|
109 |
return null; |
110 |
} |
111 |
TableDocument document = (TableDocument) application.getProjectManager().createDocument( |
112 |
TableManager.TYPENAME, |
113 |
tableInfo.getDocumentName() |
114 |
); |
115 |
document.setStore(store); |
116 |
tabledocs.add(document); |
117 |
} finally {
|
118 |
DisposeUtils.disposeQuietly(store); |
119 |
} |
120 |
} |
121 |
return tabledocs;
|
122 |
} |
123 |
|
124 |
} |