Statistics
| Revision:

root / trunk / extensions / extGeoProcessing / src / com / iver / cit / gvsig / geoprocess / impl / merge / MergeGeoprocessController.java @ 21232

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

    
88
import java.io.File;
89
import java.io.FileNotFoundException;
90

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

    
107
public class MergeGeoprocessController extends AbstractGeoprocessController {
108
        private MergePanelIF geoProcessingMergePanel;
109
        private MergeGeoprocess merge;
110

    
111
        public void setView(IGeoprocessUserEntries viewPanel) {
112
                this.geoProcessingMergePanel =
113
                        (MergePanelIF) viewPanel;
114
        }
115

    
116
        public IGeoprocess getGeoprocess() {
117
                return merge;
118
        }
119

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

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

    
200
        public int getHeight() {
201
                return 500;
202
        }
203
}
204