Statistics
| Revision:

root / tags / v10_RC2c / extensions / extGeoProcessing / src / com / iver / cit / gvsig / geoprocess / core / gui / AddResultLayerTask.java @ 8745

History | View | Annotate | Download (5.25 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 6880 2006-08-29 07:56:34Z cesar $
47
* $Log$
48
* Revision 1.4  2006-08-29 07:56:30  cesar
49
* Rename the *View* family of classes to *Window* (ie: SingletonView to SingletonWindow, ViewInfo to WindowInfo, etc)
50
*
51
* Revision 1.3  2006/06/12 19:16:17  azabala
52
* a?adida comprobaci?n de que la capa resultado tiene elementos antes de a?adirla
53
*
54
* Revision 1.2  2006/06/08 18:22:31  azabala
55
* Se a?ade chequeo de capas vac?as antes de a?adir result al TOC
56
*
57
* Revision 1.1  2006/05/24 21:13:09  azabala
58
* primera version en cvs despues de refactoring orientado a crear un framework extensible de geoprocessing
59
*
60
* Revision 1.1  2006/04/11 17:55:51  azabala
61
* primera version en cvs
62
*
63
*
64
*/
65
package com.iver.cit.gvsig.geoprocess.core.gui;
66

    
67
import javax.swing.JComponent;
68
import javax.swing.JOptionPane;
69

    
70
import com.iver.andami.PluginServices;
71
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
72
import com.iver.cit.gvsig.fmap.layers.CancelationException;
73
import com.iver.cit.gvsig.fmap.layers.FLayer;
74
import com.iver.cit.gvsig.fmap.layers.FLayers;
75
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
76
import com.iver.cit.gvsig.geoprocess.core.fmap.GeoprocessException;
77
import com.iver.cit.gvsig.geoprocess.core.fmap.IGeoprocess;
78
import com.iver.utiles.swing.threads.IMonitorableTask;
79

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

    
121
        public int getInitialStep() {
122
                return initialStep;
123
        }
124

    
125
        public int getFinishStep() {
126
                return lastStep;
127
        }
128

    
129
        public int getCurrentStep() {
130
                if (!finished)
131
                        return 5;
132
                else
133
                        return lastStep;
134
        }
135

    
136
        public String getStatusMessage() {
137
                return "Loading layer...";
138
        }
139

    
140
        public String getNote() {
141
                return "";
142
        }
143

    
144
        public boolean isDefined() {
145
                return true;
146
        }
147

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

    
180
        public void run() throws GeoprocessException {
181
                try {
182
                        FLayer result = geoprocess.getResult();
183
                        if(checkToAdd(result))
184
                                layers.addLayer(result);
185
                        else{
186
                                JOptionPane.showMessageDialog(
187
                                                (JComponent) PluginServices.
188
                                                        getMDIManager().
189
                                                        getActiveWindow(), 
190
                                                PluginServices.
191
                                                        getText(this, "Error_capa_vacia"), 
192
                                                        "Error",
193
                                                JOptionPane.ERROR_MESSAGE);
194
                        }
195
                                
196
                } catch (CancelationException e) {
197
                        throw new GeoprocessException(
198
                                        "Error al a?adir el resultado de un geoproceso a flayers");
199
                } finally {
200
                        finished = true;
201
                }
202
        }
203

    
204
        public boolean isCanceled() {
205
                return false;
206
        }
207

    
208
        public boolean isFinished() {
209
                return finished;
210
        }
211
}
212