Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / legend / CreateSpatialIndexMonitorableTask.java @ 28460

History | View | Annotate | Download (4.64 KB)

1
/*
2
 * Created on 03-may-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: CreateSpatialIndexMonitorableTask.java 12826 2007-07-30 12:56:04Z jaume $
47
* $Log$
48
* Revision 1.4  2007-07-30 12:56:04  jaume
49
* organize imports, java 5 code downgraded to 1.4 and added PictureFillSymbol
50
*
51
* Revision 1.3  2007/05/15 07:22:56  cesar
52
* Add the finished method for execution from Event Dispatch Thread
53
*
54
* Revision 1.2  2007/03/06 16:37:08  caballero
55
* Exceptions
56
*
57
* Revision 1.1  2006/09/15 10:41:30  caballero
58
* extensibilidad de documentos
59
*
60
* Revision 1.2  2006/05/22 10:35:41  fjp
61
* Monitorable tasks easy
62
*
63
* Revision 1.1  2006/05/08 15:41:06  azabala
64
* added rtree spatial indexing capabilities
65
*
66
*
67
*/
68
package com.iver.cit.gvsig.project.documents.view.legend;
69

    
70
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
71
import com.hardcode.gdbms.engine.data.driver.DriverException;
72
import com.iver.andami.PluginServices;
73
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
74
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
75
import com.iver.utiles.swing.threads.CancellableMonitorable;
76
import com.iver.utiles.swing.threads.DefaultCancellableMonitorable;
77
import com.iver.utiles.swing.threads.IMonitorableTask;
78

    
79
public class CreateSpatialIndexMonitorableTask implements IMonitorableTask{
80

    
81
        String MAIN_MESSAGE;
82
        String HULL_MESSAGE = PluginServices.getText(this, "Indexando");
83
        String OF = "de";
84

    
85
        FLyrVect layer;
86
        /**
87
         * It monitors advance of indexing process
88
         */
89
        private CancellableMonitorable cancelMonitor = null;
90
        /**
91
         * flag to tell if the process is finished
92
         */
93
        private boolean finished = false;
94

    
95
        /**
96
         * Default constructor
97
         * @throws DriverIOException
98
         * @throws DriverException
99
         */
100
        public CreateSpatialIndexMonitorableTask(FLyrVect layer) throws ReadDriverException{
101
                this.layer = layer;
102
                MAIN_MESSAGE = PluginServices.getText(this, "Indexando_espacialmente") +
103
                                                                layer.getName();
104
                cancelMonitor = createCancelMonitor();
105
        }
106

    
107
        /**
108
         * Creates a CancellableMonitorable instance to monitor
109
         * progress and to cancel the process.
110
         * @return
111
         * @throws DriverIOException
112
         * @throws DriverException
113
         */
114
        private CancellableMonitorable createCancelMonitor()
115
                                throws ReadDriverException {
116
                DefaultCancellableMonitorable monitor =
117
                        new DefaultCancellableMonitorable();
118
                monitor.setInitialStep(0);
119
                monitor.setDeterminatedProcess(true);
120
                int numSteps = ((FLyrVect)layer).getSource().getShapeCount();
121
                monitor.setFinalStep(numSteps);
122
                return monitor;
123
        }
124

    
125
        public void run() throws Exception {
126
                ((FLyrVect)layer).createSpatialIndex(cancelMonitor);
127
                finished = true;
128
        }
129

    
130
        public int getInitialStep() {
131
                return cancelMonitor.getInitialStep();
132
        }
133

    
134
        public int getFinishStep() {
135
                return cancelMonitor.getFinalStep();
136
        }
137

    
138
        public int getCurrentStep() {
139
                return cancelMonitor.getCurrentStep();
140
        }
141

    
142
        public String getStatusMessage() {
143
                return MAIN_MESSAGE;
144
        }
145

    
146
        public String getNote() {
147
                return HULL_MESSAGE + " " +
148
                getCurrentStep()+ " " +
149
                OF  + " "+
150
                getFinishStep();
151
        }
152
        //FIXME Borrar los ficheros de indice en caso de cancelacion
153
        public void cancel() {
154
                ((DefaultCancellableMonitorable) cancelMonitor).setCanceled(true);
155
        }
156
        /**
157
         * Tells if it is a defined process (we know its number of steps)
158
         */
159
        public boolean isDefined() {
160
                return true;
161
        }
162
        public boolean isCanceled() {
163
                return cancelMonitor.isCanceled();
164
        }
165

    
166
        public boolean isFinished() {
167
                return finished;
168
        }
169

    
170
        /* (non-Javadoc)
171
         * @see com.iver.utiles.swing.threads.IMonitorableTask#finished()
172
         */
173
        public void finished() {
174
                // TODO Auto-generated method stub
175
                
176
        }
177
}//CreateSpatialIndexMonitorableTask
178

    
179