Statistics
| Revision:

svn-gvsig-desktop / tags / v1_1_Build_1000 / extensions / extGeoProcessing / src / com / iver / cit / gvsig / geoprocess / core / gui / AddResultLayerTask.java @ 11885

History | View | Annotate | Download (5.66 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 11885 2007-05-30 06:44:47Z  $
47
* $Log$
48
* Revision 1.4.2.1  2006-11-15 00:08:17  jjdelcerro
49
* *** empty log message ***
50
*
51
* Revision 1.5  2006/10/20 14:29:07  azabala
52
* temporal bug fixed (problems when we add FLayers to another FLayers)
53
*
54
* Revision 1.4  2006/08/29 07:56:30  cesar
55
* Rename the *View* family of classes to *Window* (ie: SingletonView to SingletonWindow, ViewInfo to WindowInfo, etc)
56
*
57
* Revision 1.3  2006/06/12 19:16:17  azabala
58
* a?adida comprobaci?n de que la capa resultado tiene elementos antes de a?adirla
59
*
60
* Revision 1.2  2006/06/08 18:22:31  azabala
61
* Se a?ade chequeo de capas vac?as antes de a?adir result al TOC
62
*
63
* Revision 1.1  2006/05/24 21:13:09  azabala
64
* primera version en cvs despues de refactoring orientado a crear un framework extensible de geoprocessing
65
*
66
* Revision 1.1  2006/04/11 17:55:51  azabala
67
* primera version en cvs
68
*
69
*
70
*/
71
package com.iver.cit.gvsig.geoprocess.core.gui;
72

    
73
import javax.swing.JComponent;
74
import javax.swing.JOptionPane;
75

    
76
import com.iver.andami.PluginServices;
77
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
78
import com.iver.cit.gvsig.fmap.layers.CancelationException;
79
import com.iver.cit.gvsig.fmap.layers.FLayer;
80
import com.iver.cit.gvsig.fmap.layers.FLayers;
81
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
82
import com.iver.cit.gvsig.geoprocess.core.fmap.GeoprocessException;
83
import com.iver.cit.gvsig.geoprocess.core.fmap.IGeoprocess;
84
import com.iver.utiles.swing.threads.IMonitorableTask;
85

    
86
/**
87
 * Implementation of IMonitorableTask that add result layer
88
 * of a geoprocess to the TOC in a background thread
89
 * @author azabala
90
 *
91
 */
92
public class AddResultLayerTask implements IMonitorableTask {
93
        /**
94
         * Layers of a view's TOC.
95
         */
96
        FLayers layers;
97
        /**
98
         * These are fictitial steps of adding layer to TOC task,
99
         * to get satisfactory visual results.
100
         */
101
        int initialStep = 1;
102
        int currentStep = 5;
103
        int lastStep = 10;
104
        /**
105
         * Finalization flag of the task
106
         */
107
        boolean finished = false;
108
        /**
109
         * Geoprocess whose result layer we want to add to TOC
110
         */
111
        IGeoprocess geoprocess;
112
        /**
113
         * Constructor
114
         * @param geoprocess
115
         */
116
        public AddResultLayerTask(IGeoprocess geoprocess) {
117
                this.geoprocess = geoprocess;
118
        }
119
        /**
120
         * Sets FLayers instance, to add new layer to it
121
         * @param layers
122
         */
123
        public void setLayers(FLayers layers){
124
                this.layers = layers;
125
        }
126

    
127
        public int getInitialStep() {
128
                return initialStep;
129
        }
130

    
131
        public int getFinishStep() {
132
                return lastStep;
133
        }
134

    
135
        public int getCurrentStep() {
136
                if (!finished)
137
                        return 5;
138
                else
139
                        return lastStep;
140
        }
141

    
142
        public String getStatusMessage() {
143
                return "Loading layer...";
144
        }
145

    
146
        public String getNote() {
147
                return "";
148
        }
149

    
150
        public boolean isDefined() {
151
                return true;
152
        }
153

    
154
        public void cancel() {
155
                finished = true;
156
        }
157
        
158
        private boolean checkToAdd(FLayer layer) throws GeoprocessException{
159
                try {
160
                        if(layer instanceof FLyrVect){
161
                                FLyrVect result = (FLyrVect) layer;
162
                                if(result.getSource().getShapeCount() > 0){
163
                                        return true;
164
                                }else
165
                                        return false;
166
                        }else if (layer instanceof FLayers){
167
                                FLayers result = (FLayers) layer;
168
                                int numLayers = result.getLayersCount();
169
                                if( numLayers == 0)
170
                                        return false;
171
                                for(int i = 0; i < numLayers; i++){
172
                                        FLayer lyrI = result.getLayer(i);
173
                                        if(lyrI instanceof FLyrVect){
174
                                                if(((FLyrVect)lyrI).getSource().getShapeCount() != 0)
175
                                                        return true;
176
                                        }//if
177
                                }//for
178
                                return false;
179
                        }else//TODO Verificar esto si queremos meter en geoprocessing capas raster
180
                                return false;
181
                } catch (DriverIOException e) {
182
                        throw new GeoprocessException("Error al chequear la capa resultado antes de pasarla al TOC");
183
                }
184
        }
185

    
186
        public void run() throws GeoprocessException {
187
                try {
188
                        FLayer result = geoprocess.getResult();
189
                        if(checkToAdd(result)){
190
                                if(result instanceof FLayers){//TODO PRUEBA
191
                                        FLayers resultLayers = (FLayers)result;
192
                                        for(int i = 0; i < resultLayers.getLayersCount(); i++)
193
                                                layers.addLayer(resultLayers.getLayer(i));
194
                                }else
195
                                        layers.addLayer(result);
196
                        }
197
                        else{
198
                                JOptionPane.showMessageDialog(
199
                                                (JComponent) PluginServices.
200
                                                        getMDIManager().
201
                                                        getActiveWindow(), 
202
                                                PluginServices.
203
                                                        getText(this, "Error_capa_vacia"), 
204
                                                        "Error",
205
                                                JOptionPane.ERROR_MESSAGE);
206
                        }
207
                                
208
                } catch (CancelationException e) {
209
                        throw new GeoprocessException(
210
                                        "Error al a?adir el resultado de un geoproceso a flayers");
211
                } finally {
212
                        finished = true;
213
                }
214
        }
215

    
216
        public boolean isCanceled() {
217
                return false;
218
        }
219

    
220
        public boolean isFinished() {
221
                return finished;
222
        }
223
}
224