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 @ 34981
History | View | Annotate | Download (8.28 KB)
1 | 34981 | jpiera | /* 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 = |
||
65 | LoggerFactory.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 = |
||
71 | ExporttoLocator.getManager(); |
||
72 | |||
73 | private DataServerExplorerPanel dataServerExplorerPanel = null; |
||
74 | private DataServerExplorerParamsPanel dataServerExplorerParamsPanel = null; |
||
75 | private DataStorePanel dataStorePanel = null; |
||
76 | private DataStoreParamsPanel dataStoreParamsPanel = null; |
||
77 | |||
78 | |||
79 | private FeatureStore featureStore;
|
||
80 | private IProjection projection;
|
||
81 | private DataServerExplorer dataServerExplorer = null; |
||
82 | |||
83 | /**
|
||
84 | * Constructor.
|
||
85 | *
|
||
86 | * @param providerServices
|
||
87 | * the services for the provider
|
||
88 | * @param file
|
||
89 | * to get the Exporto from
|
||
90 | */
|
||
91 | public ExporttoGenericProvider(ProviderServices providerServices, 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) throws ExporttoPanelValidationException { |
||
121 | DataServerExplorerParameters dataServerExplorerParameters; |
||
122 | try {
|
||
123 | dataServerExplorerParameters = DATA_MANAGER.createServerExplorerParameters(explorerName); |
||
124 | JDynObjectComponent dynObjectComponent = DYN_OBJECT_SWING_MANAGER.createJDynObjectComponent(dataServerExplorerParameters, true);
|
||
125 | this.dataServerExplorerParamsPanel.setDynObjectComponent(dynObjectComponent);
|
||
126 | } catch (InitializeException e1) {
|
||
127 | throw new ExporttoPanelValidationException("Error creating the explorer params panel", e1); |
||
128 | } catch (ProviderNotRegisteredException e1) {
|
||
129 | throw new ExporttoPanelValidationException("Error creating the explorer params panel", e1); |
||
130 | } catch (ServiceException e1) {
|
||
131 | throw new ExporttoPanelValidationException("Error creating the explorer params panel", e1); |
||
132 | } |
||
133 | } |
||
134 | |||
135 | public void setDataServerExplorerParameters(DataServerExplorerParameters dataServerExplorerParameters) throws ExporttoPanelValidationException { |
||
136 | String explorerName = this.dataServerExplorerPanel.getSelectedProvider(); |
||
137 | if (explorerName != null){ |
||
138 | if (dataServerExplorerParameters != null){ |
||
139 | try {
|
||
140 | dataServerExplorer = DATA_MANAGER.openServerExplorer(explorerName, dataServerExplorerParameters); |
||
141 | this.dataStorePanel.setDataServerExplorer(dataServerExplorer);
|
||
142 | } catch (ValidateDataParametersException e) {
|
||
143 | throw new ExporttoPanelValidationException("error creating the explorer", e); |
||
144 | } catch (InitializeException e) {
|
||
145 | throw new ExporttoPanelValidationException("error creating the explorer", e); |
||
146 | } catch (ProviderNotRegisteredException e) {
|
||
147 | throw new ExporttoPanelValidationException("error creating the explorer", e); |
||
148 | } |
||
149 | } |
||
150 | } |
||
151 | } |
||
152 | |||
153 | public DataServerExplorer getDataServerExplorer() {
|
||
154 | return dataServerExplorer;
|
||
155 | } |
||
156 | |||
157 | public void setDataStoreSelected(String storeName) throws ExporttoPanelValidationException { |
||
158 | try{
|
||
159 | NewDataStoreParameters newDataStoreParameters = dataServerExplorer.getAddParameters(storeName); |
||
160 | |||
161 | try{
|
||
162 | newDataStoreParameters.setDynValue("CRS", projection);
|
||
163 | } |
||
164 | catch(DynFieldNotFoundException e)
|
||
165 | { |
||
166 | LOG.info("The provider {} doesn't support the CRS parameter", storeName);
|
||
167 | } |
||
168 | try{
|
||
169 | newDataStoreParameters.setDynValue("featureType", featureStore.getDefaultFeatureType().getEditable());
|
||
170 | } |
||
171 | catch(DynFieldNotFoundException e)
|
||
172 | { |
||
173 | LOG.info("The provider {} doesn't support the featureType parameter", storeName);
|
||
174 | } |
||
175 | |||
176 | JDynObjectComponent dynObjectComponent = DYN_OBJECT_SWING_MANAGER.createJDynObjectComponent(newDataStoreParameters, true);
|
||
177 | this.dataStoreParamsPanel.setDynObjectComponent(dynObjectComponent);
|
||
178 | } catch (Exception e1) { |
||
179 | throw new ExporttoPanelValidationException("Error creating the store params panel", e1); |
||
180 | } |
||
181 | } |
||
182 | |||
183 | |||
184 | private NewDataStoreParameters getNewDataStoreParameters()
|
||
185 | { |
||
186 | return dataStoreParamsPanel.getNewDataStoreParameters();
|
||
187 | } |
||
188 | |||
189 | public ExporttoService createExporttoService() {
|
||
190 | return EXPORTTO_MANAGER.getExporttoService(dataServerExplorer, getNewDataStoreParameters());
|
||
191 | |||
192 | } |
||
193 | } |