Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extTopology / src / com / iver / cit / gvsig / geoprocess / impl / fliplines / FlipLinesGeoprocessController.java @ 21293

History | View | Annotate | Download (5.51 KB)

1
/*
2
 * Created on 10-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: 
47
* $Log: 
48
*/
49
package com.iver.cit.gvsig.geoprocess.impl.fliplines;
50

    
51
import java.io.File;
52
import java.io.FileNotFoundException;
53
import java.util.HashMap;
54

    
55
import com.iver.andami.PluginServices;
56
import com.iver.cit.gvsig.fmap.drivers.SHPLayerDefinition;
57
import com.iver.cit.gvsig.fmap.edition.IWriter;
58
import com.iver.cit.gvsig.fmap.edition.ShpSchemaManager;
59
import com.iver.cit.gvsig.fmap.layers.FLayers;
60
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
61
import com.iver.cit.gvsig.geoprocess.core.fmap.AbstractGeoprocessController;
62
import com.iver.cit.gvsig.geoprocess.core.fmap.GeoprocessException;
63
import com.iver.cit.gvsig.geoprocess.core.fmap.IGeoprocess;
64
import com.iver.cit.gvsig.geoprocess.core.gui.AddResultLayerTask;
65
import com.iver.cit.gvsig.geoprocess.core.gui.IGeoprocessUserEntries;
66
import com.iver.cit.gvsig.geoprocess.impl.fliplines.fmap.FlipLinesGeoprocess;
67
import com.iver.utiles.swing.threads.IMonitorableTask;
68
import com.iver.utiles.swing.threads.MonitorableDecoratorMainFirst;
69

    
70
public class FlipLinesGeoprocessController extends AbstractGeoprocessController {
71

    
72
        private IFlipLinesGeoprocessUserEntries userEntries;
73
        private FlipLinesGeoprocess geoprocess;
74

    
75
        public void setView(IGeoprocessUserEntries viewPanel) {
76
                this.userEntries =  (IFlipLinesGeoprocessUserEntries) viewPanel;
77
        }
78

    
79
        public IGeoprocess getGeoprocess() {
80
                return geoprocess;
81
        }
82

    
83
        public boolean launchGeoprocess() {
84
/*MOVER A CLASE ABSTRACTA*/                
85
                final FLyrVect inputLayer = userEntries.getInputLayer();
86
                FLayers layers = userEntries.getFLayers();
87
                File outputFile = null;
88
                try {
89
                        outputFile = userEntries.getOutputFile();
90
                } catch (FileNotFoundException e3) {
91
                        String error = PluginServices.getText(this, "Error_entrada_datos");
92
                        String errorDescription = PluginServices.getText(this,
93
                                        "Error_seleccionar_resultado");
94
                        userEntries.error(errorDescription, error);
95
                        return false;
96
                }
97
                if (outputFile == null || (outputFile.getAbsolutePath().length() == 0)) {
98
                        String error = PluginServices.getText(this, "Error_entrada_datos");
99
                        String errorDescription = PluginServices.getText(this,
100
                                        "Error_seleccionar_resultado");
101
                        userEntries.error(errorDescription, error);
102
                        return false;
103
                }
104
                if (outputFile.exists()) {
105
                        if (!userEntries.askForOverwriteOutputFile(outputFile)) {
106
                                return false;
107
                        }
108
                }
109
/*MOVER A CLASE ABSTRACTA*/                
110
                
111
                geoprocess = new FlipLinesGeoprocess(inputLayer);
112

    
113
/*MOVER A CLASE ABSTRACTA*/                
114
                SHPLayerDefinition definition = (SHPLayerDefinition) geoprocess
115
                                .createLayerDefinition();
116
                definition.setFile(outputFile);
117
                ShpSchemaManager schemaManager = new ShpSchemaManager(outputFile
118
                                .getAbsolutePath());
119
                IWriter writer = null;
120
                try {
121
                        writer = getShpWriter(definition);
122
                } catch (Exception e1) {
123
                        String error = PluginServices.getText(this,
124
                                        "Error_escritura_resultados");
125
                        String errorDescription = PluginServices.getText(this,
126
                                        "Error_preparar_escritura_resultados");
127
                        userEntries.error(errorDescription, error);
128
                        return false;
129
                }
130
                geoprocess.setResultLayerProperties(writer, schemaManager);
131

    
132
/*MOVER A CLASE ABSTRACTA*/        
133
                
134
                HashMap params = new HashMap();
135
                
136
                boolean onlySelection = userEntries.onlyFirstLayerSelected();
137
                params.put("layer_selection", new Boolean(onlySelection));
138
                
139
/*
140
 * MOVER A CLASE ABSTRACTA 
141
 * */                
142
                try {
143
                        geoprocess.setParameters(params);
144
                        geoprocess.checkPreconditions();
145
                        IMonitorableTask task1 = geoprocess.createTask();
146
                        if (task1 == null) {
147
                                return false;
148

    
149
                        }
150
                        AddResultLayerTask task2 = new AddResultLayerTask(geoprocess);
151
                        task2.setLayers(layers);
152
                        MonitorableDecoratorMainFirst globalTask = new MonitorableDecoratorMainFirst(
153
                                        task1, task2);
154
                        if (globalTask.preprocess())
155
                                PluginServices.cancelableBackgroundExecution(globalTask);
156

    
157
                } catch (GeoprocessException e) {
158
                        String error = PluginServices.getText(this, "Error_ejecucion");
159
                        String errorDescription = PluginServices.getText(this,
160
                                        "Error_fallo_geoproceso");
161
                        userEntries.error(errorDescription, error);
162
                        return false;
163
                }
164
                return true;
165
                /*
166
                 * MOVER A CLASE ABSTRACTA 
167
                 * */                
168
        }
169

    
170
        public int getWidth() {
171
                return 700;
172
        }
173

    
174
        public int getHeight() {
175
                return 600;
176
        }
177

    
178
}