Statistics
| Revision:

root / trunk / extensions / extTopology / src / com / iver / cit / gvsig / geoprocess / impl / lineclean / LineCleanGeoprocessController.java @ 32785

History | View | Annotate | Download (5.76 KB)

1
/*
2
 * Created on 10-oct-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: LineCleanGeoprocessController.java 21235 2008-06-05 14:08:38Z azabala $
47
* $Log$
48
* Revision 1.1  2006-12-21 17:23:27  azabala
49
* *** empty log message ***
50
*
51
* Revision 1.1  2006/12/04 19:42:23  azabala
52
* *** empty log message ***
53
*
54
* Revision 1.3  2006/10/23 16:52:39  azabala
55
* *** empty log message ***
56
*
57
* Revision 1.2  2006/10/17 18:25:53  azabala
58
* *** empty log message ***
59
*
60
* Revision 1.1  2006/10/10 18:50:17  azabala
61
* First version in CVS
62
*
63
*
64
*/
65
package com.iver.cit.gvsig.geoprocess.impl.lineclean;
66

    
67
import java.io.File;
68
import java.io.FileNotFoundException;
69
import java.util.HashMap;
70

    
71
import com.iver.andami.PluginServices;
72
import com.iver.cit.gvsig.fmap.drivers.SHPLayerDefinition;
73
import com.iver.cit.gvsig.fmap.edition.IWriter;
74
import com.iver.cit.gvsig.fmap.edition.ShpSchemaManager;
75
import com.iver.cit.gvsig.fmap.layers.FLayers;
76
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
77
import com.iver.cit.gvsig.geoprocess.core.fmap.AbstractGeoprocessController;
78
import com.iver.cit.gvsig.geoprocess.core.fmap.GeoprocessException;
79
import com.iver.cit.gvsig.geoprocess.core.fmap.IGeoprocess;
80
import com.iver.cit.gvsig.geoprocess.core.gui.AddResultLayerTask;
81
import com.iver.cit.gvsig.geoprocess.core.gui.IGeoprocessUserEntries;
82
import com.iver.cit.gvsig.geoprocess.impl.lineclean.fmap.LineCleanGeoprocess;
83
import com.iver.utiles.swing.threads.IMonitorableTask;
84
import com.iver.utiles.swing.threads.MonitorableDecoratorMainFirst;
85

    
86
public class LineCleanGeoprocessController extends AbstractGeoprocessController {
87

    
88
        private ILineCleanGeoprocessUserEntries userEntries;
89
        private LineCleanGeoprocess geoprocess;
90
        
91
        public void setView(IGeoprocessUserEntries viewPanel) {
92
                this.userEntries =  
93
                        (ILineCleanGeoprocessUserEntries) viewPanel;
94
        }
95
        public IGeoprocess getGeoprocess() {
96
                return geoprocess;
97
        }
98

    
99
        public boolean launchGeoprocess() {
100
                /*
101
                 * TODO
102
                 * METER TODO ESTO EN LA CLASE ABSTRACTA
103
                 * */
104
                FLyrVect inputLayer = userEntries.getInputLayer();
105
                FLayers layers = userEntries.getFLayers();
106
                File outputFile = null;
107
                try {
108
                        outputFile = userEntries.getOutputFile();
109
                } catch (FileNotFoundException e3) {
110
                        String error = PluginServices.getText(this, "Error_entrada_datos");
111
                        String errorDescription = PluginServices.getText(this, "Error_seleccionar_resultado");
112
                        userEntries.error(errorDescription, error);
113
                        return false;
114
                }
115
                if (outputFile == null || (outputFile.getAbsolutePath().length() == 0)) {
116
                        String error = PluginServices.getText(this, "Error_entrada_datos");
117
                        String errorDescription = PluginServices.getText(this, "Error_seleccionar_resultado");
118
                        userEntries.error(errorDescription, error);
119
                        return false;
120
                }
121
                if (outputFile.exists()) {
122
                        if (!userEntries.askForOverwriteOutputFile(outputFile)) {
123
                                return false;
124
                        }
125
                }
126
                
127
                
128
                
129
                
130
                geoprocess = new LineCleanGeoprocess(inputLayer);
131

    
132
                SHPLayerDefinition definition = (SHPLayerDefinition) geoprocess
133
                                .createLayerDefinition();
134
                definition.setFile(outputFile);
135
                ShpSchemaManager schemaManager = new ShpSchemaManager(outputFile.getAbsolutePath());
136
                IWriter writer = null;
137
                try {
138
                        writer = getShpWriter(definition);
139
                } catch (Exception e1) {
140
                        String error = PluginServices.getText(this, "Error_escritura_resultados");
141
                        String errorDescription = PluginServices.getText(this, "Error_preparar_escritura_resultados");
142
                        userEntries.error(errorDescription, error);
143
                        return false;
144
                } 
145
                geoprocess.setResultLayerProperties(writer, schemaManager);
146
                HashMap params = new HashMap();
147
                boolean onlySelected = userEntries.cleanOnlySelection();
148
                params.put("layer_selection", new Boolean(onlySelected));
149
                
150
                boolean createLayerWithError = userEntries.createLyrsWithErrorGeometries();
151
                params.put("createlayerswitherrors", new Boolean(createLayerWithError));
152
                
153
                try {
154
                        geoprocess.setParameters(params);
155
                        geoprocess.checkPreconditions();
156
                        IMonitorableTask task1 = geoprocess.createTask();
157
                        if(task1 == null){
158
                                return false;
159
                                
160
                        }
161
                        AddResultLayerTask task2 = new AddResultLayerTask(geoprocess);
162
                        task2.setLayers(layers);
163
                        MonitorableDecoratorMainFirst globalTask = new MonitorableDecoratorMainFirst(task1,
164
                                        task2);
165
                        if (globalTask.preprocess())
166
                                PluginServices.cancelableBackgroundExecution(globalTask);
167
                        
168
                } catch (GeoprocessException e) {
169
                        String error = PluginServices.getText(this, "Error_ejecucion");
170
                        String errorDescription = PluginServices.getText(this, "Error_fallo_geoproceso");
171
                        userEntries.error(errorDescription, error);
172
                        return false;
173
                }
174
                return true;
175
        }
176
        public int getWidth() {
177
                return 700;
178
        }
179
        public int getHeight() {
180
                return 600;
181
        }
182

    
183

    
184
}
185