Statistics
| Revision:

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

History | View | Annotate | Download (4.23 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
 * 2009 Prodevelop S.L  vsanjaime   programador
26
 */
27

    
28
package org.gvsig.geocoding.utils;
29

    
30
import java.io.File;
31

    
32
import javax.swing.JOptionPane;
33

    
34
import org.gvsig.andami.PluginServices;
35
import org.gvsig.fmap.dal.DataStore;
36
import org.gvsig.geocoding.pattern.GeocodingPattern;
37
import org.gvsig.geocoding.pattern.impl.DefaultGeocodingPattern;
38
import org.slf4j.Logger;
39
import org.slf4j.LoggerFactory;
40

    
41
/**
42
 * This internal class loads the pattern
43
 * 
44
 * @author Jorge Gaspar Sanz Salinas (jsanz@prodevelop.es)
45
 * @author Vicent Sanjaime Calvet (vsanjaime@prodevelop.es)
46
 * 
47
 */
48

    
49
public class PatternLoaderThread extends Thread {
50

    
51
        private static final Logger log = LoggerFactory
52
                        .getLogger(PatternLoaderThread.class);
53
        private File file = null;
54
        private boolean ok = true;
55
        private GeocodingPattern pattern = null;
56

    
57
        /**
58
         * Constructor
59
         */
60
        public PatternLoaderThread() {
61
                super();
62
        }
63

    
64
        /**
65
         * Constructor with file
66
         * 
67
         * @param file
68
         */
69
        public PatternLoaderThread(File file) {
70
                this();
71
                this.file = file;
72
        }
73

    
74
        /**
75
         * run
76
         */
77
        public void run() {
78
                pattern = new DefaultGeocodingPattern();
79
                if (this.file != null) {
80
                        try {
81
                                pattern.loadFromXML(this.file);
82
                        } catch (Exception e) {
83
                                this.ok = false;
84
                                String mes = PluginServices.getText(this,
85
                                                "geocoerrorreadingfile");
86
                                String tit = PluginServices.getText(this, "geocoding");
87
                                JOptionPane.showMessageDialog(null, mes, tit,
88
                                                JOptionPane.ERROR_MESSAGE);
89
                                log.error("Error parsing the XML Pattern", e);
90
                                file.delete();
91
                        }
92
                        if (ok) {
93
                                DataStore store = null;
94
                                try {
95
                                         store = GeocodingUtils.searchLayerInCurrentView(pattern);
96
                                } catch (GeocodingNoDataStoreException e) {                                        
97
                                        log.info("The layer isn't loaded in the current view");
98
                                        String title = PluginServices.getPluginServices(this).getText("nolayertitle");
99
                                        String message = PluginServices.getPluginServices(this).getText("nolayer1");
100
                                        String message2 = PluginServices.getPluginServices(this).getText("nolayer2");
101
                                        message = message + pattern.getDataSource().getLayerName();
102
                                        message = message + " [" + pattern.getDataSource().getLayerProvider() + "] ";
103
                                        message = message + message2;
104
                                        JOptionPane.showMessageDialog(null,
105
                                                    message,
106
                                                    title,
107
                                                    JOptionPane.WARNING_MESSAGE);
108
                                        ok = false;
109
                                }
110
                                if(store == null){
111
                                        ok = false;
112
                                }
113
                                // search the layer in the view
114
                                // try {
115
                                // // DataStore store =
116
                                // GeocodingUtils.searchLayerInCurrentView(pattern);
117
                                // // pattern.getSource().setStore(store);
118
                                //
119
                                // } catch (GeocodingNoDataStoreException e) {
120
                                // String message = PluginServices.getText(null, "loadlayer");
121
                                // String title = PluginServices.getText(null, "geocoding");
122
                                // log.warn("There is not the pattern's datastore ", e);
123
                                // JOptionPane.showMessageDialog(null, message, title,
124
                                // JOptionPane.ERROR_MESSAGE);
125
                                // pattern = null;
126
                                // file = null;
127
                                // ok = false;
128
                                // }
129
                        }
130
                }
131
        }
132

    
133
        /**
134
         * @return the apto
135
         */
136
        public boolean isOk() {
137
                return ok;
138
        }
139

    
140
        /**
141
         * @return the file
142
         */
143
        public File getFile() {
144
                return file;
145
        }
146

    
147
        /**
148
         * @return the pattern
149
         */
150
        public GeocodingPattern getPattern() {
151
                return pattern;
152
        }
153

    
154
        
155

    
156
        
157
}