Statistics
| Revision:

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

History | View | Annotate | Download (7.33 KB)

1
/*
2
 * Created on 09-mar-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: AbstractGeoprocessPanel.java 5753 2006-06-08 18:22:02Z azabala $
47
* $Log$
48
* Revision 1.4  2006-06-08 18:22:02  azabala
49
* Arreglado pete cuando abr?amos un dialogo de geoprocessing habiendo agrupaciones en el TOC
50
*
51
* Revision 1.3  2006/06/02 18:21:28  azabala
52
* *** empty log message ***
53
*
54
* Revision 1.2  2006/05/25 08:21:14  jmvivo
55
* A?adido metodo de peticion de confirmacion para sobreescribir el fichero de salida
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.2  2006/05/08 15:36:33  azabala
61
* check and ask for spatial index creation
62
*
63
* Revision 1.1  2006/04/11 18:01:23  azabala
64
* primera version en cvs
65
*
66
* Revision 1.5  2006/04/07 19:00:58  azabala
67
* *** empty log message ***
68
*
69
* Revision 1.4  2006/03/23 21:02:37  azabala
70
* *** empty log message ***
71
*
72
* Revision 1.3  2006/03/21 19:26:08  azabala
73
* *** empty log message ***
74
*
75
* Revision 1.2  2006/03/14 19:32:22  azabala
76
* *** empty log message ***
77
*
78
* Revision 1.1  2006/03/09 17:03:59  azabala
79
* *** empty log message ***
80
*
81
*
82
*/
83
package com.iver.cit.gvsig.geoprocess.core.gui;
84

    
85
import java.io.File;
86
import java.util.ArrayList;
87
import java.util.Arrays;
88

    
89
import javax.swing.JComboBox;
90
import javax.swing.JOptionPane;
91
import javax.swing.JPanel;
92

    
93
import com.iver.andami.PluginServices;
94
import com.iver.cit.gvsig.fmap.DriverException;
95
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
96
import com.iver.cit.gvsig.fmap.layers.FLayer;
97
import com.iver.cit.gvsig.fmap.layers.FLayers;
98
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
99
import com.iver.cit.gvsig.gui.thememanager.CreateSpatialIndexMonitorableTask;
100
import com.iver.utiles.swing.threads.IMonitorableTask;
101

    
102
/**
103
 * Abstract base class with utility methods
104
 * commons to all GeoprocessXXXPanel
105
 * @author azabala
106
 *
107
 */
108
public abstract class AbstractGeoprocessPanel extends JPanel implements IGeoprocessPanel{
109
        protected FLayers layers = null;
110
        protected JComboBox layersComboBox = null;
111
        
112
        public FLyrVect getInputLayer() {
113
                FLyrVect solution = null;
114
                String selectedLayer = (String)layersComboBox.getSelectedItem();
115
        solution = (FLyrVect)layers.getLayer(selectedLayer);
116
        return solution;
117
        }
118
        
119
        public void setFLayers(FLayers layers){
120
                this.layers = layers;
121
        }
122
        
123
        public FLayers getFLayers(){
124
                return layers;
125
        }
126
        
127
        protected FLyrVect[] getVectorialLayers(FLayers layers){
128
                FLyrVect[] solution = null;
129
                ArrayList list = new ArrayList();
130
                int numLayers = layers.getLayersCount();
131
                for(int i = 0; i < numLayers; i++){
132
                        FLayer layer = layers.getLayer(i);
133
                        if(layer instanceof FLyrVect)
134
                                list.add(layer);
135
                        else if(layer instanceof FLayers)
136
                                list.addAll(Arrays.asList(getVectorialLayers((FLayers)layer)));
137
                }
138
                solution = new FLyrVect[list.size()];
139
                list.toArray(solution);
140
                return solution;
141
                
142
        }
143
        
144
        protected String[] getLayerNames() {
145
                String[] solution = null;
146
                int numLayers = layers.getLayersCount();
147
                if(layers != null &&  numLayers > 0){
148
                        ArrayList list = new ArrayList();
149
                        for(int i = 0; i < numLayers; i++){
150
                                FLayer layer = layers.getLayer(i);
151
                                if(layer instanceof FLyrVect)
152
                                        list.add(layer.getName());
153
                                if(layer instanceof FLayers){
154
                                        FLayers layers = (FLayers) layer;
155
                                        FLyrVect[] vectorials = getVectorialLayers(layers);
156
                                        for(int j = 0; j < vectorials.length; j++){
157
                                                list.add(vectorials[j].getName());
158
                                        }
159
                                }
160
                        }//for
161
                        solution = new String[list.size()];
162
                        list.toArray(solution);
163
                }
164
                return solution;
165
        }
166
        
167
        /**
168
         * Shows to the user a dialog error, whith the title and message body
169
         * specified as parameters.
170
         * 
171
         * @param message body of the error message
172
         * @param title title of the error message
173
         */
174
        public void error(String message, String title) {
175
                JOptionPane.showMessageDialog(this, message, title,
176
                                JOptionPane.ERROR_MESSAGE);
177
        }
178
        
179
        
180
        /**
181
         * Asks to the user for the creation of a spatial index for the
182
         * specified layer.
183
         * It will be of help for certain geoprocesses.
184
         * 
185
         * FLyrVect default spatial index is MapServer quadtree, that hasnt
186
         * the ability to do nearest neighbour searches.
187
         * 
188
         * For those geoprocesses that needs it (NN searches) overwrite this
189
         * method and use JSI RTree, or SIL RTree.
190
         * 
191
         * It returns an IMonitorableTask, a task to build the spatial
192
         * index in background.
193
         * 
194
         * @param layer
195
         * @return an ITask
196
         */
197
        public IMonitorableTask askForSpatialIndexCreation(FLyrVect layer){
198
                String title = PluginServices.getText(this, "Crear_Indice");
199
                String confirmDialogText = 
200
                        PluginServices.getText(this, "Crear_Indice_Pregunta_1")+
201
                                        " " +
202
                                        layer.getName()+
203
                                        " " +
204
                        PluginServices.getText(this, "Crear_Indice_Pregunta_2");
205
                int option = JOptionPane.showConfirmDialog(this, 
206
                                        confirmDialogText,
207
                                        title, 
208
                                        JOptionPane.YES_NO_OPTION, 
209
                                        JOptionPane.QUESTION_MESSAGE, null);
210
                if(option == JOptionPane.YES_OPTION){
211
                        //Usually we want task like spatial index creation dont block
212
                        //GUI responses. Now, we dont want to start geoprocess execution
213
                        //until spatial index creation would finish, to have advantage
214
                        //of the spatial index
215
                        try {
216
                                CreateSpatialIndexMonitorableTask task
217
                                        = new CreateSpatialIndexMonitorableTask(layer);
218
                                return task;
219
                        } catch (DriverIOException e) {
220
                                // TODO Auto-generated catch block
221
                                e.printStackTrace();
222
                                return null;
223
                        } catch (DriverException e) {
224
                                // TODO Auto-generated catch block
225
                                e.printStackTrace();
226
                                return null;
227
                        }
228
                }else
229
                        return null;
230
                                        
231
        }
232
        /**
233
         * Confirm overwrite the output file
234
         * if it allready exist.
235
         * 
236
         * 
237
         * @param outputFile
238
         * @return answer
239
         */
240
        public boolean askForOverwriteOutputFile(File outputFile){
241
                String title = PluginServices.getText(this, "Sobreescribir_fichero");
242
                String confirmDialogText = 
243
                        PluginServices.getText(this, "Sobreescribir_fichero_Pregunta_1")+
244
                                        "\n'" +
245
                                        outputFile.getAbsolutePath()+
246
                                        "'\n" +
247
                        PluginServices.getText(this, "Sobreescribir_fichero_Pregunta_2");
248
                int option = JOptionPane.showConfirmDialog(this, 
249
                                        confirmDialogText,
250
                                        title, 
251
                                        JOptionPane.YES_NO_OPTION, 
252
                                        JOptionPane.QUESTION_MESSAGE, null);
253
                if(option == JOptionPane.YES_OPTION){
254
                        return true;
255
                }
256
                return false;
257
        }
258

    
259
}
260

    
261

    
262