svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / ProjectTable.java @ 1774
History | View | Annotate | Download (8.84 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.cit.gvsig.project; |
42 |
|
43 |
import java.text.DateFormat; |
44 |
import java.util.Date; |
45 |
|
46 |
import com.hardcode.driverManager.DriverLoadException; |
47 |
import com.hardcode.gdbms.engine.data.DataSource; |
48 |
import com.hardcode.gdbms.engine.data.DataSourceFactory; |
49 |
import com.hardcode.gdbms.engine.data.NoSuchTableException; |
50 |
import com.hardcode.gdbms.engine.data.ReadDriver; |
51 |
import com.hardcode.gdbms.parser.ParseException; |
52 |
import com.iver.andami.PluginServices; |
53 |
import com.iver.cit.gvsig.fmap.DriverException; |
54 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
55 |
import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
56 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
57 |
import com.iver.cit.gvsig.fmap.layers.XMLException; |
58 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
59 |
import com.iver.utiles.XMLEntity; |
60 |
|
61 |
|
62 |
/**
|
63 |
* Tabla del proyecto
|
64 |
*
|
65 |
* @author Fernando Gonz?lez Cort?s
|
66 |
*/
|
67 |
public class ProjectTable extends ProjectElement { |
68 |
private static int numTables = 0; |
69 |
private SelectableDataSource modelo;
|
70 |
|
71 |
/* No es necesaria para operar, s?lo para guardar el proyecto */
|
72 |
private AlphanumericData associatedTable;
|
73 |
|
74 |
/**
|
75 |
* Establece a true el bit index-?simo del bitmap de campos visibles. Los
|
76 |
* campos cuyos bits est?n a true se considerar?n visibles y viceversa
|
77 |
*
|
78 |
* @param index indice del bit que se quiere establecer a true
|
79 |
*/
|
80 |
public void set(int index) { |
81 |
//TODO implementar bien
|
82 |
// modelo.set(index);
|
83 |
change.firePropertyChange("visibles", true, true); |
84 |
} |
85 |
|
86 |
/**
|
87 |
* Obtiene el valor del bit index-?simo del bitmap de campos visibles
|
88 |
*
|
89 |
* @param index indice del bit que se quiere obtener
|
90 |
*
|
91 |
* @return devuelve true si el campo index-?simo es visible y false en caso
|
92 |
* contrario
|
93 |
*/
|
94 |
public boolean get(int index) { |
95 |
//TODO implementar bien
|
96 |
// return modelo.get(index);
|
97 |
return false; |
98 |
} |
99 |
|
100 |
/**
|
101 |
* Obtiene el modelo de la Tabla. Es decir, una clase con capacidad para
|
102 |
* leer la informaci?n de la tabla
|
103 |
*
|
104 |
* @return
|
105 |
*/
|
106 |
public SelectableDataSource getModelo() {
|
107 |
return modelo;
|
108 |
} |
109 |
|
110 |
/**
|
111 |
* Establece el valor del bit index-?simo al valor 'value'
|
112 |
*
|
113 |
* @param bitIndex indice del bit que se quiere tocar
|
114 |
* @param value valor que se quiere establecer en el bit indicado
|
115 |
*/
|
116 |
public void set(int bitIndex, boolean value) { |
117 |
//TODO implementar bien
|
118 |
// modelo.set(bitIndex, value);
|
119 |
change.firePropertyChange("visibles", value, value);
|
120 |
} |
121 |
|
122 |
/**
|
123 |
* DOCUMENT ME!
|
124 |
*
|
125 |
* @param sds DOCUMENT ME!
|
126 |
*
|
127 |
* @return
|
128 |
*/
|
129 |
public static ProjectTable createTable(String name, SelectableDataSource sds) { |
130 |
ProjectTable t = new ProjectTable();
|
131 |
t.modelo = sds; |
132 |
|
133 |
if (name == null){ |
134 |
t.setName(PluginServices.getText(t, "Tabla") + numTables);
|
135 |
}else{
|
136 |
t.setName(name); |
137 |
} |
138 |
t.setCreationDate(DateFormat.getInstance().format(new Date())); |
139 |
numTables++; |
140 |
|
141 |
return t;
|
142 |
} |
143 |
|
144 |
/**
|
145 |
* DOCUMENT ME!
|
146 |
*
|
147 |
* @param sds DOCUMENT ME!
|
148 |
*/
|
149 |
public void setDataSource(SelectableDataSource sds) { |
150 |
modelo = sds; |
151 |
|
152 |
setName(sds.getName()); |
153 |
setCreationDate(DateFormat.getInstance().format(new Date())); |
154 |
} |
155 |
|
156 |
/**
|
157 |
* DOCUMENT ME!
|
158 |
*
|
159 |
* @return DOCUMENT ME!
|
160 |
*/
|
161 |
public XMLEntity getXMLEntity() {
|
162 |
XMLEntity xml = super.getXMLEntity();
|
163 |
//xml.putProperty("nameClass", this.getClass().getName());
|
164 |
xml.putProperty("numTables", numTables);
|
165 |
xml.addChild(modelo.getXMLEntity()); |
166 |
|
167 |
Object di = LayerFactory.getDataSourceFactory().getDriverInfo(modelo.getName());
|
168 |
|
169 |
if (associatedTable != null) { |
170 |
xml.putProperty("layerName", ((FLayer) associatedTable).getName());
|
171 |
xml.putProperty("viewName",
|
172 |
project.getView((FLayer) associatedTable)); |
173 |
} |
174 |
|
175 |
if (di instanceof ReadDriver) { |
176 |
ReadDriver driver = (ReadDriver) di; |
177 |
xml.putProperty("type", "sameDriverFile"); |
178 |
} else if (di instanceof DataSourceFactory.FileDriverInfo) { |
179 |
DataSourceFactory.FileDriverInfo vfdi = (DataSourceFactory.FileDriverInfo) di; |
180 |
xml.putProperty("type", "otherDriverFile"); |
181 |
xml.putProperty("gdbmsname", vfdi.name);
|
182 |
xml.putProperty("dbms", vfdi.dbms);
|
183 |
xml.putProperty("file", vfdi.file);
|
184 |
xml.putProperty("driverName", vfdi.driverName);
|
185 |
} else if (di instanceof DataSourceFactory.DBDriverInfo) { |
186 |
xml.putProperty("type", "db"); |
187 |
|
188 |
DataSourceFactory.DBTableDriverInfo dbdi = (DataSourceFactory.DBTableDriverInfo) di; |
189 |
|
190 |
xml.putProperty("gdbmsname", dbdi.name);
|
191 |
xml.putProperty("dbms", dbdi.dbms);
|
192 |
xml.putProperty("host", dbdi.host);
|
193 |
xml.putProperty("port", dbdi.port);
|
194 |
xml.putProperty("user", dbdi.user);
|
195 |
xml.putProperty("password", dbdi.password);
|
196 |
xml.putProperty("dbName", dbdi.dbName);
|
197 |
xml.putProperty("tableName", dbdi.tableName);
|
198 |
xml.putProperty("driverInfo", dbdi.driverInfo);
|
199 |
} |
200 |
|
201 |
return xml;
|
202 |
} |
203 |
|
204 |
private void setSelectableDataSource(XMLEntity xml) throws XMLException, DriverException{ |
205 |
String layerName = null; |
206 |
|
207 |
if (xml.contains("layerName")) |
208 |
layerName = xml.getStringProperty("layerName");
|
209 |
|
210 |
if (layerName == null) { |
211 |
DataSource dataSource;
|
212 |
|
213 |
try {
|
214 |
dataSource = LayerFactory.getDataSourceFactory().createRandomDataSource(xml.getStringProperty( |
215 |
"gdbmsname"));
|
216 |
} catch (NoSuchTableException e) {
|
217 |
throw new XMLException(e); |
218 |
} catch (DriverLoadException e) {
|
219 |
throw new XMLException(e); |
220 |
} |
221 |
|
222 |
SelectableDataSource sds = new SelectableDataSource(dataSource);
|
223 |
|
224 |
sds.setXMLEntity(xml.getChild(0));
|
225 |
|
226 |
setDataSource(sds); |
227 |
} else {
|
228 |
ProjectView vista = project.getViewByName(xml.getStringProperty( |
229 |
"viewName"));
|
230 |
FLayer layer = vista.getMapContext().getLayers().getLayer(layerName); |
231 |
|
232 |
modelo = ((AlphanumericData) layer).getRecordset(); |
233 |
associatedTable = (AlphanumericData) layer; |
234 |
} |
235 |
} |
236 |
|
237 |
/**
|
238 |
* DOCUMENT ME!
|
239 |
*
|
240 |
* @param xml DOCUMENT ME!
|
241 |
* @param p DOCUMENT ME!
|
242 |
*
|
243 |
* @throws XMLException
|
244 |
* @throws DriverException
|
245 |
*
|
246 |
* @see com.iver.cit.gvsig.project.ProjectElement#setXMLEntity(com.iver.utiles.XMLEntity)
|
247 |
*/
|
248 |
public void setXMLEntity(XMLEntity xml, Project p) |
249 |
throws XMLException, DriverException {
|
250 |
numTables = xml.getIntProperty("numTables");
|
251 |
|
252 |
|
253 |
|
254 |
if (xml.getStringProperty("type").equals("otherDriverFile")) { |
255 |
LayerFactory.getDataSourceFactory().addFileDataSource(xml.getStringProperty( |
256 |
"driverName"), xml.getStringProperty("gdbmsname"), |
257 |
xml.getStringProperty("file"), xml.getStringProperty("dbms")); |
258 |
|
259 |
setSelectableDataSource(xml); |
260 |
} else if (xml.getStringProperty("type").equals("sameDriverFile")) { |
261 |
String layerName = xml.getStringProperty("layerName"); |
262 |
|
263 |
ProjectView vista = project.getViewByName(xml.getStringProperty( |
264 |
"viewName"));
|
265 |
FLayer layer = vista.getMapContext().getLayers().getLayer(layerName); |
266 |
|
267 |
modelo = ((AlphanumericData) layer).getRecordset(); |
268 |
associatedTable = (AlphanumericData) layer; |
269 |
|
270 |
//DataSourceFactory.addFileDataSource(xml.getStringProperty("gdbmsname"),
|
271 |
//xml.getStringProperty("file"), xml.getStringProperty("dbms"), (FileDriver) ((SingleLayer)layer).getSource().getDriver());
|
272 |
} else if (xml.getStringProperty("type").equals("db")) { |
273 |
try {
|
274 |
LayerFactory.getDataSourceFactory().addDBDataSource(xml.getStringProperty("gdbmsname"),
|
275 |
xml.getStringProperty("host"), xml.getIntProperty("port"), |
276 |
xml.getStringProperty("user"),
|
277 |
xml.getStringProperty("password"),
|
278 |
xml.getStringProperty("dbName"),
|
279 |
xml.getStringProperty("tableName"), null, |
280 |
xml.getStringProperty("driverInfo"));
|
281 |
} catch (ParseException e) { |
282 |
throw new XMLException(e); |
283 |
} |
284 |
|
285 |
setSelectableDataSource(xml); |
286 |
} |
287 |
|
288 |
setName(xml.getStringProperty("name"));
|
289 |
} |
290 |
|
291 |
/**
|
292 |
* DOCUMENT ME!
|
293 |
*
|
294 |
* @return DOCUMENT ME!
|
295 |
*/
|
296 |
public AlphanumericData getAssociatedTable() {
|
297 |
return associatedTable;
|
298 |
} |
299 |
|
300 |
/**
|
301 |
* DOCUMENT ME!
|
302 |
*
|
303 |
* @param associatedTable DOCUMENT ME!
|
304 |
*/
|
305 |
public void setAssociatedTable(AlphanumericData associatedTable) { |
306 |
this.associatedTable = associatedTable;
|
307 |
} |
308 |
} |