svn-gvsig-desktop / trunk / extensions / extGeoProcessing / src / com / iver / cit / gvsig / geoprocess / core / gui / AddResultLayerTask.java @ 5796
History | View | Annotate | Download (5.09 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 5796 2006-06-12 19:16:17Z azabala $
|
47 |
* $Log$
|
48 |
* Revision 1.3 2006-06-12 19:16:17 azabala
|
49 |
* a?adida comprobaci?n de que la capa resultado tiene elementos antes de a?adirla
|
50 |
*
|
51 |
* Revision 1.2 2006/06/08 18:22:31 azabala
|
52 |
* Se a?ade chequeo de capas vac?as antes de a?adir result al TOC
|
53 |
*
|
54 |
* Revision 1.1 2006/05/24 21:13:09 azabala
|
55 |
* primera version en cvs despues de refactoring orientado a crear un framework extensible de geoprocessing
|
56 |
*
|
57 |
* Revision 1.1 2006/04/11 17:55:51 azabala
|
58 |
* primera version en cvs
|
59 |
*
|
60 |
*
|
61 |
*/
|
62 |
package com.iver.cit.gvsig.geoprocess.core.gui; |
63 |
|
64 |
import javax.swing.JComponent; |
65 |
import javax.swing.JOptionPane; |
66 |
|
67 |
import com.iver.andami.PluginServices; |
68 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
69 |
import com.iver.cit.gvsig.fmap.layers.CancelationException; |
70 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
71 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
72 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
73 |
import com.iver.cit.gvsig.geoprocess.core.fmap.GeoprocessException; |
74 |
import com.iver.cit.gvsig.geoprocess.core.fmap.IGeoprocess; |
75 |
import com.iver.utiles.swing.threads.IMonitorableTask; |
76 |
|
77 |
/**
|
78 |
* Implementation of IMonitorableTask that add result layer
|
79 |
* of a geoprocess to the TOC in a background thread
|
80 |
* @author azabala
|
81 |
*
|
82 |
*/
|
83 |
public class AddResultLayerTask implements IMonitorableTask { |
84 |
/**
|
85 |
* Layers of a view's TOC.
|
86 |
*/
|
87 |
FLayers layers; |
88 |
/**
|
89 |
* These are fictitial steps of adding layer to TOC task,
|
90 |
* to get satisfactory visual results.
|
91 |
*/
|
92 |
int initialStep = 1; |
93 |
int currentStep = 5; |
94 |
int lastStep = 10; |
95 |
/**
|
96 |
* Finalization flag of the task
|
97 |
*/
|
98 |
boolean finished = false; |
99 |
/**
|
100 |
* Geoprocess whose result layer we want to add to TOC
|
101 |
*/
|
102 |
IGeoprocess geoprocess; |
103 |
/**
|
104 |
* Constructor
|
105 |
* @param geoprocess
|
106 |
*/
|
107 |
public AddResultLayerTask(IGeoprocess geoprocess) {
|
108 |
this.geoprocess = geoprocess;
|
109 |
} |
110 |
/**
|
111 |
* Sets FLayers instance, to add new layer to it
|
112 |
* @param layers
|
113 |
*/
|
114 |
public void setLayers(FLayers layers){ |
115 |
this.layers = layers;
|
116 |
} |
117 |
|
118 |
public int getInitialStep() { |
119 |
return initialStep;
|
120 |
} |
121 |
|
122 |
public int getFinishStep() { |
123 |
return lastStep;
|
124 |
} |
125 |
|
126 |
public int getCurrentStep() { |
127 |
if (!finished)
|
128 |
return 5; |
129 |
else
|
130 |
return lastStep;
|
131 |
} |
132 |
|
133 |
public String getStatusMessage() { |
134 |
return "Loading layer..."; |
135 |
} |
136 |
|
137 |
public String getNote() { |
138 |
return ""; |
139 |
} |
140 |
|
141 |
public boolean isDefined() { |
142 |
return true; |
143 |
} |
144 |
|
145 |
public void cancel() { |
146 |
finished = true;
|
147 |
} |
148 |
|
149 |
private boolean checkToAdd(FLayer layer) throws GeoprocessException{ |
150 |
try {
|
151 |
if(layer instanceof FLyrVect){ |
152 |
FLyrVect result = (FLyrVect) layer; |
153 |
if(result.getSource().getShapeCount() > 0){ |
154 |
return true; |
155 |
}else
|
156 |
return false; |
157 |
}else if (layer instanceof FLayers){ |
158 |
FLayers result = (FLayers) layer; |
159 |
int numLayers = result.getLayersCount();
|
160 |
if( numLayers == 0) |
161 |
return false; |
162 |
for(int i = 0; i < numLayers; i++){ |
163 |
FLayer lyrI = result.getLayer(i); |
164 |
if(lyrI instanceof FLyrVect){ |
165 |
if(((FLyrVect)lyrI).getSource().getShapeCount() != 0) |
166 |
return true; |
167 |
}//if
|
168 |
}//for
|
169 |
return false; |
170 |
}else//TODO Verificar esto si queremos meter en geoprocessing capas raster |
171 |
return false; |
172 |
} catch (DriverIOException e) {
|
173 |
throw new GeoprocessException("Error al chequear la capa resultado antes de pasarla al TOC"); |
174 |
} |
175 |
} |
176 |
|
177 |
public void run() throws GeoprocessException { |
178 |
try {
|
179 |
FLayer result = geoprocess.getResult(); |
180 |
if(checkToAdd(result))
|
181 |
layers.addLayer(result); |
182 |
else{
|
183 |
JOptionPane.showMessageDialog(
|
184 |
(JComponent) PluginServices.
|
185 |
getMDIManager(). |
186 |
getActiveView(), |
187 |
PluginServices. |
188 |
getText(this, "Error_capa_vacia"), |
189 |
"Error",
|
190 |
JOptionPane.ERROR_MESSAGE);
|
191 |
} |
192 |
|
193 |
} catch (CancelationException e) {
|
194 |
throw new GeoprocessException( |
195 |
"Error al a?adir el resultado de un geoproceso a flayers");
|
196 |
} finally {
|
197 |
finished = true;
|
198 |
} |
199 |
} |
200 |
|
201 |
public boolean isCanceled() { |
202 |
return false; |
203 |
} |
204 |
|
205 |
public boolean isFinished() { |
206 |
return finished;
|
207 |
} |
208 |
} |
209 |
|