Statistics
| Revision:

svn-gvsig-desktop / tags / v1_0_2_Build_901 / extensions / extGeoProcessing / src / com / iver / cit / gvsig / geoprocess / impl / merge / MergeGeoprocessController.java @ 10571

History | View | Annotate | Download (7.16 KB)

1
/*
2
 * Created on 11-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: MergeGeoprocessController.java 10571 2007-03-01 11:52:43Z  $
47
* $Log$
48
* Revision 1.6.2.2  2006-11-29 12:51:36  jmvivo
49
* Se ha a?adido mas informaci?n al mensaje de error para los GeoprocessException: e.getMessage()
50
*
51
* Revision 1.6.2.1  2006/11/15 00:08:17  jjdelcerro
52
* *** empty log message ***
53
*
54
* Revision 1.7  2006/10/23 10:29:18  caballero
55
* ancho y alto del panel
56
*
57
* Revision 1.6  2006/08/11 16:30:38  azabala
58
* *** empty log message ***
59
*
60
* Revision 1.5  2006/07/26 17:21:55  azabala
61
* added capability of saving result layer in multiple SHP when input layers are DXF
62
*
63
* Revision 1.4  2006/07/21 09:56:25  azabala
64
* fixed bug 667: exception when user dont select any layer to merge
65
*
66
* Revision 1.3  2006/07/21 09:10:34  azabala
67
* fixed bug 608: user doesnt enter any result file to the geoprocess panel
68
*
69
* Revision 1.2  2006/06/29 07:33:57  fjp
70
* Cambios ISchemaManager y IFieldManager por terminar
71
*
72
* Revision 1.1  2006/06/20 18:20:45  azabala
73
* first version in cvs
74
*
75
* Revision 1.2  2006/05/25 08:21:48  jmvivo
76
* A?adida peticion de confirmacion para sobreescribir el fichero de salida, si este ya existiera
77
*
78
* Revision 1.1  2006/05/24 21:10:15  azabala
79
* primera version en cvs despues de refactoring orientado a crear un framework extensible de geoprocessing
80
*
81
* Revision 1.2  2006/05/08 15:35:32  azabala
82
* *** empty log message ***
83
*
84
* Revision 1.1  2006/04/11 17:55:51  azabala
85
* primera version en cvs
86
*
87
*
88
*/
89
package com.iver.cit.gvsig.geoprocess.impl.merge;
90

    
91
import java.io.File;
92
import java.io.FileNotFoundException;
93

    
94
import com.iver.andami.PluginServices;
95
import com.iver.cit.gvsig.fmap.drivers.SHPLayerDefinition;
96
import com.iver.cit.gvsig.fmap.edition.IWriter;
97
import com.iver.cit.gvsig.fmap.edition.ShpSchemaManager;
98
import com.iver.cit.gvsig.fmap.layers.FLayers;
99
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
100
import com.iver.cit.gvsig.geoprocess.core.fmap.AbstractGeoprocessController;
101
import com.iver.cit.gvsig.geoprocess.core.fmap.GeoprocessException;
102
import com.iver.cit.gvsig.geoprocess.core.fmap.IGeoprocess;
103
import com.iver.cit.gvsig.geoprocess.core.gui.AddResultLayerTask;
104
import com.iver.cit.gvsig.geoprocess.core.gui.IGeoprocessPanel;
105
import com.iver.cit.gvsig.geoprocess.impl.merge.fmap.MergeGeoprocess;
106
import com.iver.cit.gvsig.geoprocess.impl.merge.gui.MergePanelIF;
107
import com.iver.utiles.swing.threads.IMonitorableTask;
108
import com.iver.utiles.swing.threads.MonitorableDecoratorMainFirst;
109

    
110
public class MergeGeoprocessController extends AbstractGeoprocessController {
111
        private MergePanelIF geoProcessingMergePanel;
112
        private MergeGeoprocess merge;
113

    
114
        public void setView(IGeoprocessPanel viewPanel) {
115
                this.geoProcessingMergePanel =
116
                        (MergePanelIF) viewPanel;
117
        }
118

    
119
        public IGeoprocess getGeoprocess() {
120
                return merge;
121
        }
122

    
123
        public boolean launchGeoprocess() {
124
                FLyrVect[] inputLayers = geoProcessingMergePanel.getSelectedLayers();
125
                if(inputLayers == null || inputLayers.length == 0){
126
                        String error = PluginServices.getText(this, "Error_entrada_datos");
127
                        String errorDescription = PluginServices.getText(this, "Error_seleccionar_capas_merge");
128
                        geoProcessingMergePanel.error(errorDescription, error);
129
                        return false;
130
                }
131
                //a reference to layers' FLayers allow us to add result layer to
132
                //active view's TOC.
133
                FLayers layers = geoProcessingMergePanel.getFLayers();
134
                FLyrVect schemaToPreserve = geoProcessingMergePanel.getSelectedSchema();
135
                if(schemaToPreserve == null){
136
                        String error = PluginServices.
137
                                getText(this, "Error_entrada_datos");
138
                        String errorDescription = PluginServices.
139
                                getText(this, "Error_seleccionar_esquema_merge");
140
                        geoProcessingMergePanel.error(errorDescription, error);
141
                        return false;
142
                }
143
                File outputFile = null;
144
                try {
145
                        outputFile = geoProcessingMergePanel.getOutputFile();
146
                } catch (FileNotFoundException e3) {
147
                        String error = PluginServices.getText(this, "Error_entrada_datos");
148
                        String errorDescription = PluginServices.getText(this, "Error_seleccionar_resultado");
149
                        geoProcessingMergePanel.error(errorDescription, error);
150
                        return false;
151
                }
152
                if (outputFile == null || (outputFile.getAbsolutePath().length() == 0)) {
153
                        String error = PluginServices.getText(this, "Error_entrada_datos");
154
                        String errorDescription = PluginServices.getText(this, "Error_seleccionar_resultado");
155
                        geoProcessingMergePanel.error(errorDescription, error);
156
                        return false;
157
                }
158
                if (outputFile.exists()) {
159
                        if (!geoProcessingMergePanel.askForOverwriteOutputFile(outputFile)) {
160
                                return false;
161
                        }
162
                }
163
                MergeGeoprocess merge = new MergeGeoprocess();
164
                merge.setInputLayers(inputLayers);
165
                merge.setOutputSchemaLayer(schemaToPreserve);
166

    
167
                SHPLayerDefinition definition = (SHPLayerDefinition) merge
168
                                                                                .createLayerDefinition();
169
                definition.setFile(outputFile);
170
                ShpSchemaManager schemaManager = new ShpSchemaManager(outputFile.getAbsolutePath());
171
                IWriter writer = null;
172
                try {
173
                        writer = getShpWriter(definition);
174
                } catch (Exception e1) {
175
                        String error = PluginServices.getText(this, "Error_escritura_resultados");
176
                        String errorDescription = PluginServices.getText(this, "Error_preparar_escritura_resultados");
177
                        geoProcessingMergePanel.error(errorDescription, error);
178
                        return false;
179
                }
180
                merge.setResultLayerProperties(writer, schemaManager);
181
                try {
182
                        merge.checkPreconditions();
183
                } catch (GeoprocessException e) {
184
                        String error = PluginServices.getText(this, "Error_chequeando_precondiciones");
185
                        String errorDescription = PluginServices.getText(this, "Error_chequeo_tipo_geometria");
186
                        errorDescription = "<html>" + errorDescription + ":<br>" + e.getMessage()+ "</html>";
187
                        geoProcessingMergePanel.error(errorDescription, error);
188
                        return false;
189
                }
190
                IMonitorableTask task1 = merge.createTask();
191
                AddResultLayerTask task2 = new AddResultLayerTask(merge);
192
                task2.setLayers(layers);
193
                MonitorableDecoratorMainFirst globalTask = new MonitorableDecoratorMainFirst(task1,
194
                                task2);
195
                if (globalTask.preprocess())
196
                        PluginServices.cancelableBackgroundExecution(globalTask);
197
                return true;
198
        }
199
        public int getWidth() {
200
                return 700;
201
        }
202

    
203
        public int getHeight() {
204
                return 500;
205
        }
206
}
207