svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / ProjectTable.java @ 1836
History | View | Annotate | Download (8.41 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.io.IOException; |
44 |
import java.text.DateFormat; |
45 |
import java.util.Date; |
46 |
|
47 |
import com.hardcode.driverManager.DriverLoadException; |
48 |
import com.hardcode.gdbms.engine.data.DataSource; |
49 |
import com.hardcode.gdbms.engine.data.NoSuchTableException; |
50 |
import com.hardcode.gdbms.engine.data.db.DBDriverInfo; |
51 |
import com.hardcode.gdbms.engine.data.db.DBTableDriverInfo; |
52 |
import com.hardcode.gdbms.engine.data.file.FileDriverInfo; |
53 |
import com.hardcode.gdbms.engine.data.object.ObjectDriverInfo; |
54 |
import com.hardcode.gdbms.engine.data.persistence.DataSourceLayerMemento; |
55 |
import com.hardcode.gdbms.engine.data.persistence.Memento; |
56 |
import com.hardcode.gdbms.engine.data.persistence.MementoException; |
57 |
import com.hardcode.gdbms.engine.data.persistence.OperationLayerMemento; |
58 |
import com.hardcode.gdbms.engine.instruction.SemanticException; |
59 |
import com.hardcode.gdbms.parser.ParseException; |
60 |
import com.iver.cit.gvsig.fmap.DriverException; |
61 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
62 |
import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
63 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
64 |
import com.iver.cit.gvsig.fmap.layers.XMLException; |
65 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
66 |
import com.iver.utiles.XMLEntity; |
67 |
|
68 |
|
69 |
/**
|
70 |
* Tabla del proyecto
|
71 |
*
|
72 |
* @author Fernando Gonz?lez Cort?s
|
73 |
*/
|
74 |
public class ProjectTable extends ProjectElement { |
75 |
private static int numTables = 0; |
76 |
private SelectableDataSource modelo;
|
77 |
private SelectableDataSource original;
|
78 |
|
79 |
/* No es necesaria para operar, s?lo para guardar el proyecto */
|
80 |
private AlphanumericData associatedTable;
|
81 |
|
82 |
/**
|
83 |
* Establece a true el bit index-?simo del bitmap de campos visibles. Los
|
84 |
* campos cuyos bits est?n a true se considerar?n visibles y viceversa
|
85 |
*
|
86 |
* @param index indice del bit que se quiere establecer a true
|
87 |
*/
|
88 |
public void set(int index) { |
89 |
//TODO implementar bien
|
90 |
// modelo.set(index);
|
91 |
change.firePropertyChange("visibles", true, true); |
92 |
} |
93 |
|
94 |
/**
|
95 |
* Obtiene el valor del bit index-?simo del bitmap de campos visibles
|
96 |
*
|
97 |
* @param index indice del bit que se quiere obtener
|
98 |
*
|
99 |
* @return devuelve true si el campo index-?simo es visible y false en caso
|
100 |
* contrario
|
101 |
*/
|
102 |
public boolean get(int index) { |
103 |
//TODO implementar bien
|
104 |
// return modelo.get(index);
|
105 |
return false; |
106 |
} |
107 |
|
108 |
/**
|
109 |
* Obtiene el modelo de la Tabla. Es decir, una clase con capacidad para
|
110 |
* leer la informaci?n de la tabla
|
111 |
*
|
112 |
* @return
|
113 |
*/
|
114 |
public SelectableDataSource getModelo() {
|
115 |
return modelo;
|
116 |
} |
117 |
|
118 |
/**
|
119 |
* Establece el valor del bit index-?simo al valor 'value'
|
120 |
*
|
121 |
* @param bitIndex indice del bit que se quiere tocar
|
122 |
* @param value valor que se quiere establecer en el bit indicado
|
123 |
*/
|
124 |
public void set(int bitIndex, boolean value) { |
125 |
//TODO implementar bien
|
126 |
// modelo.set(bitIndex, value);
|
127 |
change.firePropertyChange("visibles", value, value);
|
128 |
} |
129 |
|
130 |
/**
|
131 |
* DOCUMENT ME!
|
132 |
*
|
133 |
* @param sds DOCUMENT ME!
|
134 |
*
|
135 |
* @return
|
136 |
*/
|
137 |
public static ProjectTable createTable(String name, SelectableDataSource sds) { |
138 |
ProjectTable t = new ProjectTable();
|
139 |
t.modelo = sds; |
140 |
|
141 |
t.setName(name); |
142 |
t.setCreationDate(DateFormat.getInstance().format(new Date())); |
143 |
numTables++; |
144 |
|
145 |
return t;
|
146 |
} |
147 |
|
148 |
/**
|
149 |
* DOCUMENT ME!
|
150 |
*
|
151 |
* @param sds DOCUMENT ME!
|
152 |
*/
|
153 |
public void setDataSource(SelectableDataSource sds) { |
154 |
modelo = sds; |
155 |
|
156 |
setName(sds.getName()); |
157 |
setCreationDate(DateFormat.getInstance().format(new Date())); |
158 |
change.firePropertyChange("model", modelo, modelo);
|
159 |
} |
160 |
|
161 |
public void replaceDataSource(SelectableDataSource ds){ |
162 |
original = modelo; |
163 |
modelo = ds; |
164 |
change.firePropertyChange("model", original, modelo);
|
165 |
} |
166 |
|
167 |
public void restoreDataSource(){ |
168 |
modelo = original; |
169 |
original = null;
|
170 |
change.firePropertyChange("model", original, modelo);
|
171 |
} |
172 |
|
173 |
/**
|
174 |
* DOCUMENT ME!
|
175 |
*
|
176 |
* @return DOCUMENT ME!
|
177 |
* @throws XMLException
|
178 |
*/
|
179 |
public XMLEntity getXMLEntity() throws XMLException { |
180 |
XMLEntity xml = super.getXMLEntity();
|
181 |
//xml.putProperty("nameClass", this.getClass().getName());
|
182 |
xml.putProperty("numTables", numTables);
|
183 |
if (getOriginal() != null){ |
184 |
xml.addChild(getOriginal().getXMLEntity()); |
185 |
} |
186 |
xml.addChild(modelo.getXMLEntity()); |
187 |
|
188 |
Object di = LayerFactory.getDataSourceFactory().getDriverInfo(modelo.getName());
|
189 |
|
190 |
if (associatedTable != null) { |
191 |
xml.putProperty("layerName", ((FLayer) associatedTable).getName());
|
192 |
xml.putProperty("viewName",
|
193 |
project.getView((FLayer) associatedTable)); |
194 |
} |
195 |
return xml;
|
196 |
} |
197 |
|
198 |
/**
|
199 |
* DOCUMENT ME!
|
200 |
*
|
201 |
* @param xml DOCUMENT ME!
|
202 |
* @param p DOCUMENT ME!
|
203 |
*
|
204 |
* @throws XMLException
|
205 |
* @throws DriverException
|
206 |
*
|
207 |
* @see com.iver.cit.gvsig.project.ProjectElement#setXMLEntity(com.iver.utiles.XMLEntity)
|
208 |
*/
|
209 |
public void setXMLEntity(XMLEntity xml, Project p) |
210 |
throws XMLException, DriverException {
|
211 |
setName(xml.getStringProperty("name"));
|
212 |
numTables = xml.getIntProperty("numTables");
|
213 |
|
214 |
setSelectableDataSource(xml); |
215 |
/*
|
216 |
if (xml.getStringProperty("type").equals("otherDriverFile")) {
|
217 |
} else if (xml.getStringProperty("type").equals("sameDriverFile")) {
|
218 |
String layerName = xml.getStringProperty("layerName");
|
219 |
|
220 |
ProjectView vista = project.getViewByName(xml.getStringProperty(
|
221 |
"viewName"));
|
222 |
FLayer layer = vista.getMapContext().getLayers().getLayer(layerName);
|
223 |
|
224 |
modelo = ((AlphanumericData) layer).getRecordset();
|
225 |
associatedTable = (AlphanumericData) layer;
|
226 |
} else if (xml.getStringProperty("type").equals("db")) {
|
227 |
setSelectableDataSource(xml);
|
228 |
}
|
229 |
*/
|
230 |
|
231 |
setName(xml.getStringProperty("name"));
|
232 |
} |
233 |
|
234 |
private void setSelectableDataSource(XMLEntity xml) throws XMLException, DriverException{ |
235 |
String layerName = null; |
236 |
|
237 |
if (xml.contains("layerName")) |
238 |
layerName = xml.getStringProperty("layerName");
|
239 |
|
240 |
SelectableDataSource sds; |
241 |
try {
|
242 |
sds = SelectableDataSource.createSelectableDataSource(xml.getChild(0));
|
243 |
setDataSource(sds); |
244 |
|
245 |
if (xml.getNumChild() == 2){ |
246 |
replaceDataSource(SelectableDataSource.createSelectableDataSource(xml.getChild(1)));
|
247 |
} |
248 |
} catch (NoSuchTableException e) {
|
249 |
throw new XMLException(e); |
250 |
} catch (ParseException e) { |
251 |
throw new XMLException(e); |
252 |
} catch (DriverLoadException e) {
|
253 |
throw new XMLException(e); |
254 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
255 |
throw new XMLException(e); |
256 |
} catch (SemanticException e) {
|
257 |
throw new XMLException(e); |
258 |
} catch (IOException e) { |
259 |
throw new XMLException(e); |
260 |
} |
261 |
|
262 |
if (layerName != null){ |
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 |
} |
271 |
|
272 |
/**
|
273 |
* DOCUMENT ME!
|
274 |
*
|
275 |
* @return DOCUMENT ME!
|
276 |
*/
|
277 |
public AlphanumericData getAssociatedTable() {
|
278 |
return associatedTable;
|
279 |
} |
280 |
|
281 |
/**
|
282 |
* DOCUMENT ME!
|
283 |
*
|
284 |
* @param associatedTable DOCUMENT ME!
|
285 |
*/
|
286 |
public void setAssociatedTable(AlphanumericData associatedTable) { |
287 |
this.associatedTable = associatedTable;
|
288 |
} |
289 |
|
290 |
/**
|
291 |
* Obtiene la fuente de datos original de la tabla si se ha invocado
|
292 |
* replaceDataSource. Si no se invoc? este m?todo o se invoc?
|
293 |
* posteriormente restoreDataSource se devuelve null
|
294 |
*
|
295 |
* @return Returns the original.
|
296 |
*/
|
297 |
public SelectableDataSource getOriginal() {
|
298 |
return original;
|
299 |
} |
300 |
} |