svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app.document.table.app / org.gvsig.app.document.table.app.mainplugin / src / main / java / org / gvsig / fmap / dal / serverexplorer / filesystem / swing / FilesystemExplorerTableWizardPanel.java @ 43534
History | View | Annotate | Download (6.79 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.fmap.dal.serverexplorer.filesystem.swing; |
26 |
|
27 |
import java.awt.Window; |
28 |
import java.util.ArrayList; |
29 |
import java.util.HashSet; |
30 |
import java.util.List; |
31 |
import java.util.Set; |
32 |
|
33 |
import javax.swing.JOptionPane; |
34 |
|
35 |
import org.cresques.cts.IProjection; |
36 |
import org.slf4j.Logger; |
37 |
import org.slf4j.LoggerFactory; |
38 |
|
39 |
import org.gvsig.andami.PluginServices; |
40 |
import org.gvsig.andami.messages.NotificationManager; |
41 |
import org.gvsig.app.ApplicationLocator; |
42 |
import org.gvsig.app.ApplicationManager; |
43 |
import org.gvsig.app.prepareAction.PrepareContext; |
44 |
import org.gvsig.app.project.Project; |
45 |
import org.gvsig.app.project.ProjectManager; |
46 |
import org.gvsig.app.project.documents.table.TableDocument; |
47 |
import org.gvsig.app.project.documents.table.TableManager; |
48 |
import org.gvsig.fmap.dal.DALLocator; |
49 |
import org.gvsig.fmap.dal.DataManager; |
50 |
import org.gvsig.fmap.dal.DataStoreParameters; |
51 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
52 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
53 |
import org.gvsig.fmap.dal.swing.DALSwingLocator; |
54 |
import org.gvsig.fmap.dal.swing.dataStoreParameters.DataStoreParametersPanel; |
55 |
import org.gvsig.fmap.dal.swing.dataStoreParameters.DataStoreParametersPanelManager; |
56 |
import org.gvsig.i18n.Messages; |
57 |
import org.gvsig.tools.dynobject.DynObject; |
58 |
import org.gvsig.tools.dynobject.exception.DynFieldRequiredValueException; |
59 |
import org.gvsig.tools.dynobject.exception.DynObjectValidateException; |
60 |
|
61 |
public class FilesystemExplorerTableWizardPanel extends |
62 |
FilesystemExplorerWizardPanel { |
63 |
|
64 |
private static final long serialVersionUID = 8469934188826417698L; |
65 |
private static final Logger LOG = LoggerFactory.getLogger( |
66 |
FilesystemExplorerTableWizardPanel.class); |
67 |
|
68 |
private PrepareContext prepareDSContext = null; |
69 |
|
70 |
public FilesystemExplorerTableWizardPanel() {
|
71 |
super(true); |
72 |
} |
73 |
|
74 |
@Override
|
75 |
public void execute() { |
76 |
executeWizard(); |
77 |
} |
78 |
|
79 |
@Override
|
80 |
public Object executeWizard() { |
81 |
FeatureStore store; |
82 |
TableDocument table; |
83 |
|
84 |
ApplicationManager manager = ApplicationLocator.getManager(); |
85 |
Project project = manager.getCurrentProject(); |
86 |
|
87 |
PrepareContext context = this.getPrepareDataStoreContext();
|
88 |
DataStoreParameters[] parameters = this.getParameters(); |
89 |
List<TableDocument> tabledocs =
|
90 |
new ArrayList<>(parameters.length); |
91 |
|
92 |
Set<String> not_valid = new HashSet<>(); |
93 |
|
94 |
for (DataStoreParameters params : parameters) {
|
95 |
store = null;
|
96 |
|
97 |
/*
|
98 |
* Try to validate.
|
99 |
*/
|
100 |
try {
|
101 |
params.validate(); |
102 |
} catch (ValidateDataParametersException ecx) {
|
103 |
StringBuffer buffer = new StringBuffer(); |
104 |
if( ecx.getCause() instanceof DynObjectValidateException ) { |
105 |
DynObjectValidateException exceptions = (DynObjectValidateException) ecx.getCause(); |
106 |
for( int i=0; i<exceptions.size(); i++ ) { |
107 |
if( exceptions.get(i) instanceof DynFieldRequiredValueException ) { |
108 |
DynFieldRequiredValueException exx = (DynFieldRequiredValueException) exceptions.get(i); |
109 |
if( buffer.length()>0 ) { |
110 |
buffer.append(", ");
|
111 |
} |
112 |
buffer.append(exx.getMessage()); |
113 |
} |
114 |
|
115 |
} |
116 |
} |
117 |
String msg = params.getDataStoreName();
|
118 |
if( buffer.length()>0 ) { |
119 |
msg = msg + ": "+buffer.toString();
|
120 |
} |
121 |
LOG.info("Unable to validate params: " + msg);
|
122 |
not_valid.add(msg); |
123 |
continue;
|
124 |
} |
125 |
|
126 |
try {
|
127 |
|
128 |
DataManager dataManager = DALLocator.getDataManager(); |
129 |
store = |
130 |
(FeatureStore) dataManager.openStore( |
131 |
params.getDataStoreName(), params); |
132 |
manager.pepareOpenDataSource(store, context); |
133 |
|
134 |
table = |
135 |
(TableDocument) ProjectManager.getInstance() |
136 |
.createDocument(TableManager.TYPENAME); |
137 |
table.setName(store.getName()); |
138 |
table.setStore(store); |
139 |
|
140 |
// project.add(table);
|
141 |
tabledocs.add(table); |
142 |
} catch (Exception e) { |
143 |
if (store != null) { |
144 |
store.dispose(); |
145 |
} |
146 |
NotificationManager.addError(e); |
147 |
} |
148 |
|
149 |
} |
150 |
|
151 |
if (not_valid.size() > 0) { |
152 |
String not_str = not_valid.toString();
|
153 |
JOptionPane.showMessageDialog(
|
154 |
this,
|
155 |
Messages.getText("_These_sources_were_not_loaded")
|
156 |
+ ": " + not_str, // not_valid, |
157 |
Messages.getText("_Load_error"),
|
158 |
JOptionPane.WARNING_MESSAGE);
|
159 |
} |
160 |
return tabledocs;
|
161 |
} |
162 |
|
163 |
@Override
|
164 |
protected PrepareContext getPrepareDataStoreContext() {
|
165 |
if (this.prepareDSContext == null) { |
166 |
this.prepareDSContext = new PrepareContext() { |
167 |
|
168 |
@Override
|
169 |
public Window getOwnerWindow() { |
170 |
return null; |
171 |
} |
172 |
|
173 |
@Override
|
174 |
public IProjection getViewProjection() {
|
175 |
return null; |
176 |
} |
177 |
|
178 |
}; |
179 |
} |
180 |
return this.prepareDSContext; |
181 |
} |
182 |
|
183 |
@Override
|
184 |
public String getTabName() { |
185 |
return PluginServices.getText(this, "File"); |
186 |
} |
187 |
|
188 |
|
189 |
@Override
|
190 |
protected void showPropertiesDialog(final DynObject parameters) { |
191 |
DataStoreParametersPanelManager manager = DALSwingLocator.getDataStoreParametersPanelManager(); |
192 |
DataStoreParametersPanel panel = manager.createDataStoreParametersPanel(parameters); |
193 |
panel.setExcludeGeometryOptions(true);
|
194 |
manager.showPropertiesDialog(parameters, panel); |
195 |
} |
196 |
|
197 |
|
198 |
} |