svn-gvsig-desktop / branches / v2_0_0_prep / libraries / org.gvsig.exportto / org.gvsig.exportto.swing / org.gvsig.exportto.swing.prov / org.gvsig.exportto.swing.prov.generic / src / main / java / org / gvsig / exportto / swing / prov / generic / ExporttoGenericProvider.java @ 37780
History | View | Annotate | Download (8.55 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
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 2
|
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 |
*/
|
22 |
package org.gvsig.exportto.swing.prov.generic; |
23 |
|
24 |
import org.cresques.cts.IProjection; |
25 |
import org.slf4j.Logger; |
26 |
import org.slf4j.LoggerFactory; |
27 |
|
28 |
import org.gvsig.exportto.ExporttoLocator; |
29 |
import org.gvsig.exportto.ExporttoManager; |
30 |
import org.gvsig.exportto.ExporttoService; |
31 |
import org.gvsig.exportto.swing.prov.generic.panel.DataServerExplorerPanel; |
32 |
import org.gvsig.exportto.swing.prov.generic.panel.DataServerExplorerParamsPanel; |
33 |
import org.gvsig.exportto.swing.prov.generic.panel.DataStorePanel; |
34 |
import org.gvsig.exportto.swing.prov.generic.panel.DataStoreParamsPanel; |
35 |
import org.gvsig.exportto.swing.spi.ExporttoPanelValidationException; |
36 |
import org.gvsig.exportto.swing.spi.ExporttoSwingProvider; |
37 |
import org.gvsig.exportto.swing.spi.ExporttoSwingProviderPanel; |
38 |
import org.gvsig.fmap.dal.DALLocator; |
39 |
import org.gvsig.fmap.dal.DataManager; |
40 |
import org.gvsig.fmap.dal.DataServerExplorer; |
41 |
import org.gvsig.fmap.dal.DataServerExplorerParameters; |
42 |
import org.gvsig.fmap.dal.NewDataStoreParameters; |
43 |
import org.gvsig.fmap.dal.exception.InitializeException; |
44 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
45 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
46 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
47 |
import org.gvsig.tools.dynobject.exception.DynFieldNotFoundException; |
48 |
import org.gvsig.tools.service.ServiceException; |
49 |
import org.gvsig.tools.service.spi.AbstractProvider; |
50 |
import org.gvsig.tools.service.spi.ProviderServices; |
51 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
52 |
import org.gvsig.tools.swing.api.dynobject.DynObjectSwingManager; |
53 |
import org.gvsig.tools.swing.api.dynobject.JDynObjectComponent; |
54 |
|
55 |
/**
|
56 |
* Exporto provider which gets Exporto from a file.
|
57 |
*
|
58 |
* @author gvSIG Team
|
59 |
* @version $Id$
|
60 |
*/
|
61 |
public class ExporttoGenericProvider extends AbstractProvider implements |
62 |
ExporttoSwingProvider { |
63 |
|
64 |
private static final Logger LOG = LoggerFactory |
65 |
.getLogger(ExporttoGenericProvider.class); |
66 |
|
67 |
private static final DataManager DATA_MANAGER = DALLocator.getDataManager(); |
68 |
private static final DynObjectSwingManager DYN_OBJECT_SWING_MANAGER = |
69 |
ToolsSwingLocator.getDynObjectSwingManager(); |
70 |
private static final ExporttoManager EXPORTTO_MANAGER = ExporttoLocator |
71 |
.getManager(); |
72 |
|
73 |
private DataServerExplorerPanel dataServerExplorerPanel = null; |
74 |
private DataServerExplorerParamsPanel dataServerExplorerParamsPanel = null; |
75 |
private DataStorePanel dataStorePanel = null; |
76 |
private DataStoreParamsPanel dataStoreParamsPanel = null; |
77 |
|
78 |
private FeatureStore featureStore;
|
79 |
private IProjection projection;
|
80 |
private DataServerExplorer dataServerExplorer = null; |
81 |
|
82 |
/**
|
83 |
* Constructor.
|
84 |
*
|
85 |
* @param providerServices
|
86 |
* the services for the provider
|
87 |
* @param file
|
88 |
* to get the Exporto from
|
89 |
*/
|
90 |
public ExporttoGenericProvider(ProviderServices providerServices,
|
91 |
FeatureStore featureStore, IProjection projection) { |
92 |
super(providerServices);
|
93 |
this.featureStore = featureStore;
|
94 |
this.projection = projection;
|
95 |
|
96 |
dataServerExplorerPanel = new DataServerExplorerPanel(this); |
97 |
dataServerExplorerParamsPanel = new DataServerExplorerParamsPanel(this); |
98 |
dataStorePanel = new DataStorePanel(this); |
99 |
dataStoreParamsPanel = new DataStoreParamsPanel(this); |
100 |
} |
101 |
|
102 |
public int getPanelCount() { |
103 |
return 4; |
104 |
} |
105 |
|
106 |
public ExporttoSwingProviderPanel getPanelAt(int index) { |
107 |
switch (index) {
|
108 |
case 0: |
109 |
return dataServerExplorerPanel;
|
110 |
case 1: |
111 |
return dataServerExplorerParamsPanel;
|
112 |
case 2: |
113 |
return dataStorePanel;
|
114 |
case 3: |
115 |
return dataStoreParamsPanel;
|
116 |
} |
117 |
return null; |
118 |
} |
119 |
|
120 |
public void setDataServerExplorerSelected(String explorerName) |
121 |
throws ExporttoPanelValidationException {
|
122 |
DataServerExplorerParameters dataServerExplorerParameters; |
123 |
try {
|
124 |
dataServerExplorerParameters = |
125 |
DATA_MANAGER.createServerExplorerParameters(explorerName); |
126 |
JDynObjectComponent dynObjectComponent = |
127 |
DYN_OBJECT_SWING_MANAGER.createJDynObjectComponent( |
128 |
dataServerExplorerParameters, true);
|
129 |
this.dataServerExplorerParamsPanel
|
130 |
.setDynObjectComponent(dynObjectComponent); |
131 |
} catch (InitializeException e1) {
|
132 |
throw new ExporttoPanelValidationException( |
133 |
"Error creating the explorer params panel", e1);
|
134 |
} catch (ProviderNotRegisteredException e1) {
|
135 |
throw new ExporttoPanelValidationException( |
136 |
"Error creating the explorer params panel", e1);
|
137 |
} catch (ServiceException e1) {
|
138 |
throw new ExporttoPanelValidationException( |
139 |
"Error creating the explorer params panel", e1);
|
140 |
} |
141 |
} |
142 |
|
143 |
public void setDataServerExplorerParameters( |
144 |
DataServerExplorerParameters dataServerExplorerParameters) |
145 |
throws ExporttoPanelValidationException {
|
146 |
String explorerName =
|
147 |
this.dataServerExplorerPanel.getSelectedProvider();
|
148 |
if (explorerName != null) { |
149 |
if (dataServerExplorerParameters != null) { |
150 |
try {
|
151 |
dataServerExplorer = |
152 |
DATA_MANAGER.openServerExplorer(explorerName, |
153 |
dataServerExplorerParameters); |
154 |
this.dataStorePanel
|
155 |
.setDataServerExplorer(dataServerExplorer); |
156 |
} catch (ValidateDataParametersException e) {
|
157 |
throw new ExporttoPanelValidationException( |
158 |
"error creating the explorer", e);
|
159 |
} catch (InitializeException e) {
|
160 |
throw new ExporttoPanelValidationException( |
161 |
"error creating the explorer", e);
|
162 |
} catch (ProviderNotRegisteredException e) {
|
163 |
throw new ExporttoPanelValidationException( |
164 |
"error creating the explorer", e);
|
165 |
} |
166 |
} |
167 |
} |
168 |
} |
169 |
|
170 |
public DataServerExplorer getDataServerExplorer() {
|
171 |
return dataServerExplorer;
|
172 |
} |
173 |
|
174 |
public void setDataStoreSelected(String storeName) |
175 |
throws ExporttoPanelValidationException {
|
176 |
try {
|
177 |
NewDataStoreParameters newDataStoreParameters = |
178 |
dataServerExplorer.getAddParameters(storeName); |
179 |
|
180 |
try {
|
181 |
newDataStoreParameters.setDynValue("CRS", projection);
|
182 |
} catch (DynFieldNotFoundException e) {
|
183 |
LOG.info("The provider {} doesn't support the CRS parameter",
|
184 |
storeName); |
185 |
} |
186 |
try {
|
187 |
newDataStoreParameters.setDynValue("featureType", featureStore
|
188 |
.getDefaultFeatureType().getEditable()); |
189 |
} catch (DynFieldNotFoundException e) {
|
190 |
LOG.info( |
191 |
"The provider {} doesn't support the featureType parameter",
|
192 |
storeName); |
193 |
} |
194 |
|
195 |
JDynObjectComponent dynObjectComponent = |
196 |
DYN_OBJECT_SWING_MANAGER.createJDynObjectComponent( |
197 |
newDataStoreParameters, true);
|
198 |
this.dataStoreParamsPanel.setDynObjectComponent(dynObjectComponent);
|
199 |
} catch (Exception e1) { |
200 |
throw new ExporttoPanelValidationException( |
201 |
"Error creating the store params panel", e1);
|
202 |
} |
203 |
} |
204 |
|
205 |
private NewDataStoreParameters getNewDataStoreParameters() {
|
206 |
return dataStoreParamsPanel.getNewDataStoreParameters();
|
207 |
} |
208 |
|
209 |
public ExporttoService createExporttoService() {
|
210 |
return EXPORTTO_MANAGER.getExporttoService(dataServerExplorer,
|
211 |
getNewDataStoreParameters()); |
212 |
|
213 |
} |
214 |
} |