Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extGeoProcessing / src / com / iver / cit / gvsig / geoprocess / impl / merge / MergeGeoprocessController.java @ 8235

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

    
85
import java.io.File;
86
import java.io.FileNotFoundException;
87

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

    
104
public class MergeGeoprocessController extends AbstractGeoprocessController {
105
        private MergePanelIF geoProcessingMergePanel;
106
        private MergeGeoprocess merge;
107

    
108
        public void setView(IGeoprocessPanel viewPanel) {
109
                this.geoProcessingMergePanel =
110
                        (MergePanelIF) viewPanel;
111
        }
112

    
113
        public IGeoprocess getGeoprocess() {
114
                return merge;
115
        }
116

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

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

    
196
        public int getHeight() {
197
                return 500;
198
        }
199
}
200