Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / extensions / org.gvsig.geocoding.extension / src / org / gvsig / geocoding / tasks / IndexingTask.java @ 32526

History | View | Annotate | Download (3.69 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
 * MA  02110-1301, USA.
20
 * 
21
 */
22

    
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2008 Prodevelop S.L. main development
26
 */
27

    
28
package org.gvsig.geocoding.tasks;
29

    
30
import org.gvsig.andami.PluginServices;
31
import org.gvsig.fmap.dal.DataStore;
32
import org.gvsig.fmap.dal.feature.FeatureSet;
33
import org.gvsig.geocoding.Geocoder;
34
import org.gvsig.geocoding.GeocodingLocator;
35
import org.gvsig.geocoding.address.Literal;
36
import org.gvsig.geocoding.extension.GeocodingController;
37
import org.gvsig.geocoding.impl.LuceneGeocoderImpl;
38
import org.gvsig.geocoding.index.FeatureIndexedEvent;
39
import org.gvsig.geocoding.index.IndexListener;
40
import org.gvsig.geocoding.utils.GeocodingUtils;
41
import org.gvsig.utils.swing.threads.AbstractMonitorableTask;
42
import org.slf4j.Logger;
43
import org.slf4j.LoggerFactory;
44

    
45
/**
46
 * Geocoding task in background
47
 * 
48
 * @author <a href="mailto:jsanz@prodevelop.es"> Jorge Gaspar Sanz Salinas</a>
49
 * @author <a href="mailto:vsanjaime@prodevelop.es"> Vicent Sanjaime Calvet</a>
50
 */
51
public class IndexingTask extends AbstractMonitorableTask implements
52
                IndexListener {
53

    
54
        private static final Logger log = LoggerFactory
55
                        .getLogger(IndexingTask.class);
56
        private GeocodingController control;
57
        private long finalStep;
58
        private Geocoder geoco = null;
59
        private DataStore store = null;        
60
        private String textTask;
61

    
62
        /**
63
         * Constructor task
64
         * 
65
         * @param control
66
         */
67
        @SuppressWarnings("static-access")
68
        public IndexingTask(GeocodingController control) {
69

    
70
                this.control = control;
71
                // configure task
72
                setInitialStep(0);
73
                setStatusMessage(PluginServices.getText(this, "indexingrun"));
74
                setDeterminatedProcess(true);
75

    
76
                //
77
                GeocodingLocator loc = GeocodingLocator.getInstance();
78
                geoco = loc.getGeocoder();
79
                ((LuceneGeocoderImpl)geoco).registreIndexListener(this);
80

    
81
                try {
82
                        store = GeocodingUtils.searchLayerInCurrentView(control
83
                                        .getPattern());
84
                        FeatureSet fset = (FeatureSet) store.getDataSet();
85
                        finalStep = fset.getSize();
86
                        setFinalStep((int) finalStep);
87
                } catch (Exception e) {
88
                        log.debug("Error getting data store");
89
                }
90
                textTask = PluginServices.getText(this, "featuresindexed");
91
        }
92

    
93
        /**
94
         * run process
95
         */
96
        public void run() throws Exception {
97
                // desactivate search button in the main panel
98
                control.getGPanel().enableSearchButton(false);
99

    
100
                // index process
101
                log.debug("Indexing data store .....");
102

    
103
                Literal relLit = control.getPattern().getDataSource().getStyle()
104
                                .getRelationsLiteral();
105
                ((LuceneGeocoderImpl) this.geoco).indexer(store, relLit);
106

    
107
                // activate search button in the main panel
108
                control.getGPanel().enableSearchButton(true);
109
        }
110

    
111
        /**
112
         * 
113
         */
114
        public void featureIndexed(FeatureIndexedEvent e) {
115
                int posi = (int)e.getPositionFeature();
116
                setCurrentStep(posi+1);
117
                setNote(posi+1 + " " + textTask);
118
        }
119

    
120
}