root / trunk / extensions / extGeoProcessing / src / com / iver / cit / gvsig / geoprocess / core / gui / AddResultLayerTask.java @ 8213
History | View | Annotate | Download (5.58 KB)
1 |
/*
|
---|---|
2 |
* Created on 10-abr-2006
|
3 |
*
|
4 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
5 |
*
|
6 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
7 |
*
|
8 |
* This program is free software; you can redistribute it and/or
|
9 |
* modify it under the terms of the GNU General Public License
|
10 |
* as published by the Free Software Foundation; either version 2
|
11 |
* of the License, or (at your option) any later version.
|
12 |
*
|
13 |
* This program is distributed in the hope that it will be useful,
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
* GNU General Public License for more details.
|
17 |
*
|
18 |
* You should have received a copy of the GNU General Public License
|
19 |
* along with this program; if not, write to the Free Software
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
21 |
*
|
22 |
* For more information, contact:
|
23 |
*
|
24 |
* Generalitat Valenciana
|
25 |
* Conselleria d'Infraestructures i Transport
|
26 |
* Av. Blasco Ib??ez, 50
|
27 |
* 46010 VALENCIA
|
28 |
* SPAIN
|
29 |
*
|
30 |
* +34 963862235
|
31 |
* gvsig@gva.es
|
32 |
* www.gvsig.gva.es
|
33 |
*
|
34 |
* or
|
35 |
*
|
36 |
* IVER T.I. S.A
|
37 |
* Salamanca 50
|
38 |
* 46005 Valencia
|
39 |
* Spain
|
40 |
*
|
41 |
* +34 963163400
|
42 |
* dac@iver.es
|
43 |
*/
|
44 |
/* CVS MESSAGES:
|
45 |
*
|
46 |
* $Id: AddResultLayerTask.java 8213 2006-10-20 14:29:07Z azabala $
|
47 |
* $Log$
|
48 |
* Revision 1.5 2006-10-20 14:29:07 azabala
|
49 |
* temporal bug fixed (problems when we add FLayers to another FLayers)
|
50 |
*
|
51 |
* Revision 1.4 2006/08/29 07:56:30 cesar
|
52 |
* Rename the *View* family of classes to *Window* (ie: SingletonView to SingletonWindow, ViewInfo to WindowInfo, etc)
|
53 |
*
|
54 |
* Revision 1.3 2006/06/12 19:16:17 azabala
|
55 |
* a?adida comprobaci?n de que la capa resultado tiene elementos antes de a?adirla
|
56 |
*
|
57 |
* Revision 1.2 2006/06/08 18:22:31 azabala
|
58 |
* Se a?ade chequeo de capas vac?as antes de a?adir result al TOC
|
59 |
*
|
60 |
* Revision 1.1 2006/05/24 21:13:09 azabala
|
61 |
* primera version en cvs despues de refactoring orientado a crear un framework extensible de geoprocessing
|
62 |
*
|
63 |
* Revision 1.1 2006/04/11 17:55:51 azabala
|
64 |
* primera version en cvs
|
65 |
*
|
66 |
*
|
67 |
*/
|
68 |
package com.iver.cit.gvsig.geoprocess.core.gui; |
69 |
|
70 |
import javax.swing.JComponent; |
71 |
import javax.swing.JOptionPane; |
72 |
|
73 |
import com.iver.andami.PluginServices; |
74 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
75 |
import com.iver.cit.gvsig.fmap.layers.CancelationException; |
76 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
77 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
78 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
79 |
import com.iver.cit.gvsig.geoprocess.core.fmap.GeoprocessException; |
80 |
import com.iver.cit.gvsig.geoprocess.core.fmap.IGeoprocess; |
81 |
import com.iver.utiles.swing.threads.IMonitorableTask; |
82 |
|
83 |
/**
|
84 |
* Implementation of IMonitorableTask that add result layer
|
85 |
* of a geoprocess to the TOC in a background thread
|
86 |
* @author azabala
|
87 |
*
|
88 |
*/
|
89 |
public class AddResultLayerTask implements IMonitorableTask { |
90 |
/**
|
91 |
* Layers of a view's TOC.
|
92 |
*/
|
93 |
FLayers layers; |
94 |
/**
|
95 |
* These are fictitial steps of adding layer to TOC task,
|
96 |
* to get satisfactory visual results.
|
97 |
*/
|
98 |
int initialStep = 1; |
99 |
int currentStep = 5; |
100 |
int lastStep = 10; |
101 |
/**
|
102 |
* Finalization flag of the task
|
103 |
*/
|
104 |
boolean finished = false; |
105 |
/**
|
106 |
* Geoprocess whose result layer we want to add to TOC
|
107 |
*/
|
108 |
IGeoprocess geoprocess; |
109 |
/**
|
110 |
* Constructor
|
111 |
* @param geoprocess
|
112 |
*/
|
113 |
public AddResultLayerTask(IGeoprocess geoprocess) {
|
114 |
this.geoprocess = geoprocess;
|
115 |
} |
116 |
/**
|
117 |
* Sets FLayers instance, to add new layer to it
|
118 |
* @param layers
|
119 |
*/
|
120 |
public void setLayers(FLayers layers){ |
121 |
this.layers = layers;
|
122 |
} |
123 |
|
124 |
public int getInitialStep() { |
125 |
return initialStep;
|
126 |
} |
127 |
|
128 |
public int getFinishStep() { |
129 |
return lastStep;
|
130 |
} |
131 |
|
132 |
public int getCurrentStep() { |
133 |
if (!finished)
|
134 |
return 5; |
135 |
else
|
136 |
return lastStep;
|
137 |
} |
138 |
|
139 |
public String getStatusMessage() { |
140 |
return "Loading layer..."; |
141 |
} |
142 |
|
143 |
public String getNote() { |
144 |
return ""; |
145 |
} |
146 |
|
147 |
public boolean isDefined() { |
148 |
return true; |
149 |
} |
150 |
|
151 |
public void cancel() { |
152 |
finished = true;
|
153 |
} |
154 |
|
155 |
private boolean checkToAdd(FLayer layer) throws GeoprocessException{ |
156 |
try {
|
157 |
if(layer instanceof FLyrVect){ |
158 |
FLyrVect result = (FLyrVect) layer; |
159 |
if(result.getSource().getShapeCount() > 0){ |
160 |
return true; |
161 |
}else
|
162 |
return false; |
163 |
}else if (layer instanceof FLayers){ |
164 |
FLayers result = (FLayers) layer; |
165 |
int numLayers = result.getLayersCount();
|
166 |
if( numLayers == 0) |
167 |
return false; |
168 |
for(int i = 0; i < numLayers; i++){ |
169 |
FLayer lyrI = result.getLayer(i); |
170 |
if(lyrI instanceof FLyrVect){ |
171 |
if(((FLyrVect)lyrI).getSource().getShapeCount() != 0) |
172 |
return true; |
173 |
}//if
|
174 |
}//for
|
175 |
return false; |
176 |
}else//TODO Verificar esto si queremos meter en geoprocessing capas raster |
177 |
return false; |
178 |
} catch (DriverIOException e) {
|
179 |
throw new GeoprocessException("Error al chequear la capa resultado antes de pasarla al TOC"); |
180 |
} |
181 |
} |
182 |
|
183 |
public void run() throws GeoprocessException { |
184 |
try {
|
185 |
FLayer result = geoprocess.getResult(); |
186 |
if(checkToAdd(result)){
|
187 |
if(result instanceof FLayers){//TODO PRUEBA |
188 |
FLayers resultLayers = (FLayers)result; |
189 |
for(int i = 0; i < resultLayers.getLayersCount(); i++) |
190 |
layers.addLayer(resultLayers.getLayer(i)); |
191 |
}else
|
192 |
layers.addLayer(result); |
193 |
} |
194 |
else{
|
195 |
JOptionPane.showMessageDialog(
|
196 |
(JComponent) PluginServices.
|
197 |
getMDIManager(). |
198 |
getActiveWindow(), |
199 |
PluginServices. |
200 |
getText(this, "Error_capa_vacia"), |
201 |
"Error",
|
202 |
JOptionPane.ERROR_MESSAGE);
|
203 |
} |
204 |
|
205 |
} catch (CancelationException e) {
|
206 |
throw new GeoprocessException( |
207 |
"Error al a?adir el resultado de un geoproceso a flayers");
|
208 |
} finally {
|
209 |
finished = true;
|
210 |
} |
211 |
} |
212 |
|
213 |
public boolean isCanceled() { |
214 |
return false; |
215 |
} |
216 |
|
217 |
public boolean isFinished() { |
218 |
return finished;
|
219 |
} |
220 |
} |
221 |
|