Statistics
| Revision:

root / trunk / extensions / extGeoProcessing / src / com / iver / cit / gvsig / geoprocess / core / gui / AddResultLayerTask.java @ 5754

History | View | Annotate | Download (4.22 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 5754 2006-06-08 18:22:31Z azabala $
47
* $Log$
48
* Revision 1.2  2006-06-08 18:22:31  azabala
49
* Se a?ade chequeo de capas vac?as antes de a?adir result al TOC
50
*
51
* Revision 1.1  2006/05/24 21:13:09  azabala
52
* primera version en cvs despues de refactoring orientado a crear un framework extensible de geoprocessing
53
*
54
* Revision 1.1  2006/04/11 17:55:51  azabala
55
* primera version en cvs
56
*
57
*
58
*/
59
package com.iver.cit.gvsig.geoprocess.core.gui;
60

    
61
import javax.swing.JComponent;
62
import javax.swing.JOptionPane;
63

    
64
import com.iver.andami.PluginServices;
65
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
66
import com.iver.cit.gvsig.fmap.layers.CancelationException;
67
import com.iver.cit.gvsig.fmap.layers.FLayers;
68
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
69
import com.iver.cit.gvsig.geoprocess.core.fmap.GeoprocessException;
70
import com.iver.cit.gvsig.geoprocess.core.fmap.IGeoprocess;
71
import com.iver.utiles.swing.threads.IMonitorableTask;
72

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

    
114
        public int getInitialStep() {
115
                return initialStep;
116
        }
117

    
118
        public int getFinishStep() {
119
                return lastStep;
120
        }
121

    
122
        public int getCurrentStep() {
123
                if (!finished)
124
                        return 5;
125
                else
126
                        return lastStep;
127
        }
128

    
129
        public String getStatusMessage() {
130
                return "Loading layer...";
131
        }
132

    
133
        public String getNote() {
134
                return "";
135
        }
136

    
137
        public boolean isDefined() {
138
                return true;
139
        }
140

    
141
        public void cancel() {
142
                finished = true;
143
        }
144

    
145
        public void run() throws GeoprocessException {
146
                try {
147
                        FLyrVect result = geoprocess.getResult();
148
                        if(result.getSource().getShapeCount() > 0)
149
                                layers.addLayer(result);
150
                        else{
151
                                JOptionPane.showMessageDialog(
152
                                                (JComponent) PluginServices.
153
                                                        getMDIManager().
154
                                                        getActiveView(), 
155
                                                PluginServices.
156
                                                        getText(this, "Error_capa_vacia"), 
157
                                                        "Error",
158
                                                JOptionPane.ERROR_MESSAGE);
159
                        }
160
                                
161
                } catch (CancelationException e) {
162
                        throw new GeoprocessException(
163
                                        "Error al a?adir el resultado de un geoproceso a flayers");
164
                } catch (DriverIOException e) {
165
                        throw new GeoprocessException(
166
                        "Error al comprobar si el resultado de un geoproceso tiene registros");
167
                }  finally {
168
                        finished = true;
169
                }
170
        }
171

    
172
        public boolean isCanceled() {
173
                return false;
174
        }
175

    
176
        public boolean isFinished() {
177
                return finished;
178
        }
179
}
180