svn-gvsig-desktop / tags / v1_0_2_Build_916 / extensions / extWMS / src / com / iver / cit / gvsig / wmc / ExportWebMapContextExtension.java @ 12327
History | View | Annotate | Download (8.94 KB)
1 | 5023 | jaume | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
|
||
4 | *
|
||
5 | * This program is free software; you can redistribute it and/or
|
||
6 | * modify it under the terms of the GNU General Public License
|
||
7 | * as published by the Free Software Foundation; either version 2
|
||
8 | * of the License, or (at your option) any later version.
|
||
9 | *
|
||
10 | * This program is distributed in the hope that it will be useful,
|
||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
13 | * GNU General Public License for more details.
|
||
14 | *
|
||
15 | * You should have received a copy of the GNU General Public License
|
||
16 | * along with this program; if not, write to the Free Software
|
||
17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
18 | *
|
||
19 | * For more information, contact:
|
||
20 | *
|
||
21 | * Generalitat Valenciana
|
||
22 | * Conselleria d'Infraestructures i Transport
|
||
23 | * Av. Blasco Ib??ez, 50
|
||
24 | * 46010 VALENCIA
|
||
25 | * SPAIN
|
||
26 | *
|
||
27 | * +34 963862235
|
||
28 | * gvsig@gva.es
|
||
29 | * www.gvsig.gva.es
|
||
30 | *
|
||
31 | * or
|
||
32 | *
|
||
33 | * IVER T.I. S.A
|
||
34 | * Salamanca 50
|
||
35 | * 46005 Valencia
|
||
36 | * Spain
|
||
37 | *
|
||
38 | * +34 963163400
|
||
39 | * dac@iver.es
|
||
40 | */
|
||
41 | |||
42 | /* CVS MESSAGES:
|
||
43 | *
|
||
44 | * $Id$
|
||
45 | * $Log$
|
||
46 | 10887 | jcampos | * Revision 1.8.2.4 2007-03-26 10:03:12 jcampos
|
47 | * Update to use 3D extension
|
||
48 | *
|
||
49 | * Revision 1.8.2.3 2007/01/04 10:08:41 jcampos
|
||
50 | 9536 | jcampos | * Upgrade new version
|
51 | *
|
||
52 | * Revision 1.8.2.2 2006/11/15 00:08:21 jjdelcerro
|
||
53 | 7390 | jaume | * *** empty log message ***
|
54 | *
|
||
55 | 8765 | jjdelcerro | * Revision 1.13 2006/09/27 13:28:38 jaume
|
56 | * *** empty log message ***
|
||
57 | *
|
||
58 | * Revision 1.12 2006/09/20 10:38:43 jaume
|
||
59 | * *** empty log message ***
|
||
60 | *
|
||
61 | * Revision 1.11 2006/09/20 07:45:21 caballero
|
||
62 | * constante registerName
|
||
63 | *
|
||
64 | * Revision 1.10 2006/09/18 08:28:44 caballero
|
||
65 | * cambio de nombre
|
||
66 | *
|
||
67 | * Revision 1.9 2006/09/15 10:44:24 caballero
|
||
68 | * extensibilidad de documentos
|
||
69 | *
|
||
70 | 7390 | jaume | * Revision 1.8 2006/08/29 07:56:15 cesar
|
71 | 6880 | cesar | * Rename the *View* family of classes to *Window* (ie: SingletonView to SingletonWindow, ViewInfo to WindowInfo, etc)
|
72 | *
|
||
73 | * Revision 1.7 2006/08/29 07:13:43 cesar
|
||
74 | 6877 | cesar | * Rename class com.iver.andami.ui.mdiManager.View to com.iver.andami.ui.mdiManager.IWindow
|
75 | *
|
||
76 | * Revision 1.6 2006/07/21 10:31:05 jaume
|
||
77 | 6495 | jaume | * *** empty log message ***
|
78 | *
|
||
79 | * Revision 1.5 2006/06/19 11:20:26 jorpiell
|
||
80 | 5900 | jorpiell | * Cambiadas las comprobaciones de una clase con == por instanceof.
|
81 | *
|
||
82 | * Revision 1.4 2006/05/30 08:56:57 jaume
|
||
83 | 5530 | jaume | * fixed bug http://www.gvsig.org/phpcollab/tasks/viewtask.php?id=279&msg=addAssignment&PHPSESSID=3fea791a62107ef5325283641039b311#etDAnchor
|
84 | *
|
||
85 | * Revision 1.3 2006/05/12 07:47:39 jaume
|
||
86 | 5158 | jaume | * removed unnecessary imports
|
87 | *
|
||
88 | * Revision 1.2 2006/05/03 11:10:54 jaume
|
||
89 | 5023 | jaume | * *** empty log message ***
|
90 | *
|
||
91 | 5034 | jaume | * Revision 1.1 2006/05/03 07:51:21 jaume
|
92 | * *** empty log message ***
|
||
93 | *
|
||
94 | 5023 | jaume | * Revision 1.7 2006/05/02 16:12:12 jorpiell
|
95 | * Se ha cambiado la interfaz Extension por dos clases: una interfaz (IExtension) y una clase abstract(Extension). A partir de ahora todas las extensiones deben heredar de Extension
|
||
96 | *
|
||
97 | * Revision 1.6 2006/05/02 15:57:44 jaume
|
||
98 | * Few better javadoc
|
||
99 | *
|
||
100 | * Revision 1.5 2006/04/25 11:40:56 jaume
|
||
101 | * *** empty log message ***
|
||
102 | *
|
||
103 | * Revision 1.4 2006/04/21 10:27:32 jaume
|
||
104 | * exporting now supported
|
||
105 | *
|
||
106 | * Revision 1.3 2006/04/20 17:11:54 jaume
|
||
107 | * Attempting to export
|
||
108 | *
|
||
109 | * Revision 1.2 2006/04/19 16:34:29 jaume
|
||
110 | * *** empty log message ***
|
||
111 | *
|
||
112 | * Revision 1.1 2006/04/19 07:57:29 jaume
|
||
113 | * *** empty log message ***
|
||
114 | *
|
||
115 | * Revision 1.3 2006/04/12 17:10:53 jaume
|
||
116 | * *** empty log message ***
|
||
117 | *
|
||
118 | * Revision 1.2 2006/04/07 12:10:37 jaume
|
||
119 | * *** empty log message ***
|
||
120 | *
|
||
121 | * Revision 1.1 2006/04/04 14:22:22 jaume
|
||
122 | * Now exports MapContext (not yet tested)
|
||
123 | *
|
||
124 | *
|
||
125 | */
|
||
126 | package com.iver.cit.gvsig.wmc; |
||
127 | |||
128 | import java.io.BufferedWriter; |
||
129 | import java.io.File; |
||
130 | import java.io.FileWriter; |
||
131 | import java.io.IOException; |
||
132 | import java.util.ArrayList; |
||
133 | |||
134 | import com.iver.andami.PluginServices; |
||
135 | import com.iver.andami.messages.NotificationManager; |
||
136 | import com.iver.andami.plugins.Extension; |
||
137 | import com.iver.andami.plugins.IExtension; |
||
138 | 8765 | jjdelcerro | import com.iver.andami.ui.mdiManager.IWindow; |
139 | 5023 | jaume | import com.iver.cit.gvsig.ProjectExtension; |
140 | import com.iver.cit.gvsig.fmap.layers.FLayer; |
||
141 | import com.iver.cit.gvsig.fmap.layers.FLayers; |
||
142 | import com.iver.cit.gvsig.fmap.layers.FLyrWMS; |
||
143 | import com.iver.cit.gvsig.gui.panels.WebMapContextSettingsPanel; |
||
144 | import com.iver.cit.gvsig.project.Project; |
||
145 | 8765 | jjdelcerro | import com.iver.cit.gvsig.project.documents.view.ProjectView; |
146 | import com.iver.cit.gvsig.project.documents.view.ProjectViewFactory; |
||
147 | 9536 | jcampos | import com.iver.cit.gvsig.project.documents.view.gui.BaseView; |
148 | 8765 | jjdelcerro | import com.iver.cit.gvsig.project.documents.view.gui.View; |
149 | 5023 | jaume | |
150 | /**
|
||
151 | * Extension to export a view with WMS layers to a OGC's Web Map Context XML
|
||
152 | * file
|
||
153 | 6495 | jaume | *
|
154 | 5023 | jaume | * @author jaume dom?nguez faus - jaume.dominguez@iver.es
|
155 | * @author laura d?az s?nchez - laura.diaz@iver.es
|
||
156 | */
|
||
157 | public class ExportWebMapContextExtension extends Extension { |
||
158 | private static ArrayList supportedVersions; |
||
159 | 9536 | jcampos | private BaseView viewToExport;
|
160 | 5023 | jaume | private WebMapContextSettingsPanel mc;
|
161 | private static IExtension thisExtension; |
||
162 | |||
163 | { |
||
164 | supportedVersions = new ArrayList(); |
||
165 | supportedVersions.add("1.1.0");
|
||
166 | } |
||
167 | |||
168 | public void initialize() { |
||
169 | thisExtension = PluginServices |
||
170 | .getExtension(ExportWebMapContextExtension.class); |
||
171 | } |
||
172 | |||
173 | public void execute(String actionCommand) { |
||
174 | if (actionCommand.equals("EXPORT")) { |
||
175 | 5158 | jaume | // Here we collect the info
|
176 | 5023 | jaume | ProjectView[] views = getExportableViews();
|
177 | 7390 | jaume | if (views.length <= 0) |
178 | return;
|
||
179 | 5023 | jaume | mc = new WebMapContextSettingsPanel(views);
|
180 | 6880 | cesar | PluginServices.getMDIManager().addWindow(mc); |
181 | 5023 | jaume | |
182 | } else if (actionCommand.equals("DO_EXPORT")) { |
||
183 | // Here the target file is produced (called from the WebMapContextSettingsPanel)
|
||
184 | String xml = mc.getXML();
|
||
185 | File f = mc.getTargetFile();
|
||
186 | if (xml != null) { |
||
187 | createFile(f, xml); |
||
188 | } |
||
189 | 6495 | jaume | |
190 | 5023 | jaume | } |
191 | } |
||
192 | |||
193 | /**
|
||
194 | * Takes a File object and its XML contents and stores it as a regular
|
||
195 | * file in the file system.
|
||
196 | * @param f
|
||
197 | * @param xml
|
||
198 | */
|
||
199 | public static void createFile(File f, String xml) { |
||
200 | if (xml != null) { |
||
201 | try {
|
||
202 | if (!f.exists()) {
|
||
203 | f.createNewFile(); |
||
204 | } |
||
205 | BufferedWriter bw = new BufferedWriter(new FileWriter(f)); |
||
206 | bw.write(xml); |
||
207 | bw.close(); |
||
208 | bw = null;
|
||
209 | } catch (IOException e) { |
||
210 | NotificationManager.addError(PluginServices.getText( |
||
211 | thisExtension, "error_writting_file"), e);
|
||
212 | } |
||
213 | } |
||
214 | } |
||
215 | |||
216 | public boolean isEnabled() { |
||
217 | return true; |
||
218 | } |
||
219 | |||
220 | public boolean isVisible() { |
||
221 | // Will be visible if the current project has, at least, one FLyrWMS.
|
||
222 | Project project = ((ProjectExtension) PluginServices |
||
223 | .getExtension(ProjectExtension.class)).getProject(); |
||
224 | 5530 | jaume | if (project == null) |
225 | return false; |
||
226 | 8765 | jjdelcerro | IWindow f = PluginServices.getMDIManager().getActiveWindow(); |
227 | 10887 | jcampos | if (f instanceof View) { |
228 | View v = (View) f; |
||
229 | if (v != null && v instanceof View) { |
||
230 | 5023 | jaume | // Check if the active contains WMS layers. If so, this view
|
231 | // will be the one to be exported.
|
||
232 | FLayers lyrs = v.getMapControl().getMapContext().getLayers(); |
||
233 | for (int i = 0; i < lyrs.getLayersCount(); i++) { |
||
234 | FLayer lyr = lyrs.getLayer(i); |
||
235 | 6495 | jaume | if (WebMapContext.containsExportableLayers(lyr)) {
|
236 | 5023 | jaume | viewToExport = v; |
237 | return true; |
||
238 | } |
||
239 | } |
||
240 | } |
||
241 | } |
||
242 | |||
243 | // Since the active view does not contain WMS layers then will
|
||
244 | // see what about the others. In this case, no view set to be
|
||
245 | // the exported one.
|
||
246 | viewToExport = null;
|
||
247 | 8765 | jjdelcerro | ArrayList views = project.getDocumentsByType(ProjectViewFactory.registerName);
|
248 | 5023 | jaume | for (int i = 0; i < views.size(); i++) { |
249 | ProjectView v = ((ProjectView) views.get(i)); |
||
250 | if (v != null) { |
||
251 | FLayers lyrs = v.getMapContext().getLayers(); |
||
252 | for (int j = 0; j < lyrs.getLayersCount(); j++) { |
||
253 | FLayer lyr = lyrs.getLayer(j); |
||
254 | 6495 | jaume | if (WebMapContext.containsExportableLayers(lyr))
|
255 | 5023 | jaume | return true; |
256 | } |
||
257 | } |
||
258 | } |
||
259 | return false; |
||
260 | } |
||
261 | 6495 | jaume | |
262 | 5023 | jaume | /**
|
263 | * <p>
|
||
264 | * Searches the views in the current project that can be exported to a
|
||
265 | 6495 | jaume | * WebMapContext file (with ".cml" extension) and return them in a
|
266 | 5023 | jaume | * ProjectView array.<br>
|
267 | * </p>
|
||
268 | * <p>
|
||
269 | * A view is exportable to WebMapContext if it contains at least one FLyrWMS
|
||
270 | * and in a near future, any other OGC layer such as WCS, WFS, and so on. Only
|
||
271 | * these layers will be exported. Other kind of layers are ignored since they
|
||
272 | 5158 | jaume | * are out of the OGC premises.
|
273 | 5023 | jaume | * </p>
|
274 | * @return
|
||
275 | */
|
||
276 | private ProjectView[] getExportableViews() { |
||
277 | Project project = ((ProjectExtension) PluginServices |
||
278 | .getExtension(ProjectExtension.class)).getProject(); |
||
279 | 6495 | jaume | |
280 | 8765 | jjdelcerro | ArrayList views = project.getDocumentsByType(ProjectViewFactory.registerName);
|
281 | 5023 | jaume | ArrayList exportableViews = new ArrayList(); |
282 | if (viewToExport!=null) |
||
283 | exportableViews.add(viewToExport.getModel()); |
||
284 | 6495 | jaume | |
285 | 5023 | jaume | for (int i = 0; i < views.size(); i++) { |
286 | ProjectView v = ((ProjectView) views.get(i)); |
||
287 | if (v != null) { |
||
288 | FLayers lyrs = v.getMapContext().getLayers(); |
||
289 | for (int j = 0; j < lyrs.getLayersCount(); j++) { |
||
290 | FLayer lyr = lyrs.getLayer(j); |
||
291 | if (lyr instanceof FLyrWMS && !exportableViews.contains(v)) { |
||
292 | exportableViews.add(v); |
||
293 | break;
|
||
294 | } |
||
295 | } |
||
296 | } |
||
297 | } |
||
298 | return (ProjectView[]) exportableViews.toArray(new ProjectView[0]); |
||
299 | } |
||
300 | |||
301 | } |