svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extGeocoding / src / org / gvsig / geocoding / utils / PatternLoaderThread.java @ 31267
History | View | Annotate | Download (4.03 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 |
PluginServices ps = PluginServices.getPluginServices(this);
|
99 |
String title = PluginServices.getPluginServices(this).getText("nolayertitle"); |
100 |
String message = PluginServices.getPluginServices(this).getText("nolayer");; |
101 |
JOptionPane.showMessageDialog(null, |
102 |
message, |
103 |
title, |
104 |
JOptionPane.WARNING_MESSAGE);
|
105 |
ok = false;
|
106 |
} |
107 |
if(store == null){ |
108 |
ok = false;
|
109 |
} |
110 |
// search the layer in the view
|
111 |
// try {
|
112 |
// // DataStore store =
|
113 |
// GeocodingUtils.searchLayerInCurrentView(pattern);
|
114 |
// // pattern.getSource().setStore(store);
|
115 |
//
|
116 |
// } catch (GeocodingNoDataStoreException e) {
|
117 |
// String message = PluginServices.getText(null, "loadlayer");
|
118 |
// String title = PluginServices.getText(null, "geocoding");
|
119 |
// log.warn("There is not the pattern's datastore ", e);
|
120 |
// JOptionPane.showMessageDialog(null, message, title,
|
121 |
// JOptionPane.ERROR_MESSAGE);
|
122 |
// pattern = null;
|
123 |
// file = null;
|
124 |
// ok = false;
|
125 |
// }
|
126 |
} |
127 |
} |
128 |
} |
129 |
|
130 |
/**
|
131 |
* @return the apto
|
132 |
*/
|
133 |
public boolean isOk() { |
134 |
return ok;
|
135 |
} |
136 |
|
137 |
/**
|
138 |
* @return the file
|
139 |
*/
|
140 |
public File getFile() { |
141 |
return file;
|
142 |
} |
143 |
|
144 |
/**
|
145 |
* @return the pattern
|
146 |
*/
|
147 |
public GeocodingPattern getPattern() {
|
148 |
return pattern;
|
149 |
} |
150 |
|
151 |
|
152 |
|
153 |
|
154 |
} |