root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / ProjectView.java @ 10679
History | View | Annotate | Download (11.5 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.documents.view; |
42 |
|
43 |
import java.util.Comparator; |
44 |
import java.util.HashMap; |
45 |
import java.util.Iterator; |
46 |
import java.util.TreeMap; |
47 |
import java.util.Map.Entry; |
48 |
|
49 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
50 |
import com.iver.andami.PluginServices; |
51 |
import com.iver.andami.ui.mdiManager.IWindow; |
52 |
import com.iver.cit.gvsig.fmap.MapContext; |
53 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
54 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
55 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
56 |
import com.iver.cit.gvsig.fmap.layers.XMLException; |
57 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
58 |
import com.iver.cit.gvsig.project.Project; |
59 |
import com.iver.cit.gvsig.project.documents.ProjectDocument; |
60 |
import com.iver.cit.gvsig.project.documents.ProjectDocumentFactory; |
61 |
import com.iver.cit.gvsig.project.documents.exceptions.OpenException; |
62 |
import com.iver.cit.gvsig.project.documents.exceptions.SaveException; |
63 |
import com.iver.cit.gvsig.project.documents.table.ProjectTable; |
64 |
import com.iver.cit.gvsig.project.documents.table.ProjectTableFactory; |
65 |
import com.iver.cit.gvsig.project.documents.view.gui.ViewProperties; |
66 |
import com.iver.utiles.XMLEntity; |
67 |
|
68 |
|
69 |
/**
|
70 |
* Clase que representa una vista del proyecto
|
71 |
*
|
72 |
* @author Fernando Gonz?lez Cort?s
|
73 |
*/
|
74 |
public class ProjectView extends ProjectViewBase { |
75 |
//public static int numViews = 0;
|
76 |
|
77 |
//public static int METROS = 0;
|
78 |
//public static int KILOMETROS = 1;
|
79 |
//public static int[] unidades = new int[] { METROS, KILOMETROS };
|
80 |
///private Color backgroundColor = new Color(255, 255, 255);
|
81 |
|
82 |
/**
|
83 |
* DOCUMENT ME!
|
84 |
*
|
85 |
* @return DOCUMENT ME!
|
86 |
* @throws XMLException
|
87 |
* @throws SaveException
|
88 |
*/
|
89 |
public XMLEntity getXMLEntity() throws SaveException { |
90 |
XMLEntity xml = super.getXMLEntity();
|
91 |
//xml.putProperty("nameClass", this.getClass().getName());
|
92 |
try{
|
93 |
int numViews=((Integer)ProjectDocument.NUMS.get(ProjectViewFactory.registerName)).intValue(); |
94 |
|
95 |
xml.putProperty("numViews", numViews);
|
96 |
xml.putProperty("m_selectedField", m_selectedField);
|
97 |
xml.putProperty("m_typeLink", m_typeLink);
|
98 |
xml.putProperty("m_extLink", m_extLink);
|
99 |
xml.addChild(mapContext.getXMLEntity()); |
100 |
|
101 |
if (mapOverViewContext != null) { |
102 |
if (mapOverViewContext.getViewPort() != null) { |
103 |
xml.putProperty("mapOverView", true); |
104 |
xml.addChild(mapOverViewContext.getXMLEntity()); |
105 |
} else {
|
106 |
xml.putProperty("mapOverView", false); |
107 |
} |
108 |
} else {
|
109 |
xml.putProperty("mapOverView", false); |
110 |
} |
111 |
}catch (Exception e) { |
112 |
throw new SaveException(e,this.getClass().getName()); |
113 |
} |
114 |
return xml;
|
115 |
} |
116 |
|
117 |
/**
|
118 |
* DOCUMENT ME!
|
119 |
*
|
120 |
* @param xml DOCUMENT ME!
|
121 |
* @param p DOCUMENT ME!
|
122 |
* @throws XMLException
|
123 |
* @throws DriverException
|
124 |
* @throws DriverIOException
|
125 |
*
|
126 |
* @see com.iver.cit.gvsig.project.documents.ProjectDocument#setXMLEntity(com.iver.utiles.XMLEntity)
|
127 |
*/
|
128 |
public void setXMLEntity03(XMLEntity xml) |
129 |
throws XMLException, ReadDriverException {
|
130 |
super.setXMLEntity03(xml);
|
131 |
int numViews = xml.getIntProperty("numViews"); |
132 |
ProjectDocument.NUMS.put(ProjectViewFactory.registerName,new Integer(numViews)); |
133 |
|
134 |
m_selectedField = xml.getStringProperty("m_selectedField");
|
135 |
m_typeLink = xml.getIntProperty("m_typeLink");
|
136 |
m_extLink = xml.getStringProperty("m_extLink");
|
137 |
setMapContext(MapContext.createFromXML03(xml.getChild(0)));
|
138 |
|
139 |
if (xml.getBooleanProperty("mapOverView")) { |
140 |
setMapOverViewContext(MapContext.createFromXML03(xml.getChild(1)));
|
141 |
} |
142 |
|
143 |
} |
144 |
|
145 |
/**
|
146 |
* DOCUMENT ME!
|
147 |
*
|
148 |
* @param xml DOCUMENT ME!
|
149 |
* @param p DOCUMENT ME!
|
150 |
* @throws XMLException
|
151 |
* @throws DriverException
|
152 |
* @throws DriverIOException
|
153 |
* @throws OpenException
|
154 |
*
|
155 |
* @see com.iver.cit.gvsig.project.documents.ProjectDocument#setXMLEntity(com.iver.utiles.XMLEntity)
|
156 |
*/
|
157 |
public void setXMLEntity(XMLEntity xml) |
158 |
throws XMLException, ReadDriverException, OpenException {
|
159 |
try{
|
160 |
super.setXMLEntity(xml);
|
161 |
int currentChild=0; |
162 |
int numViews = xml.getIntProperty("numViews"); |
163 |
ProjectDocument.NUMS.put(ProjectViewFactory.registerName,new Integer(numViews)); |
164 |
|
165 |
if (xml.contains("m_selectedField")) |
166 |
m_selectedField = xml.getStringProperty("m_selectedField");
|
167 |
m_typeLink = xml.getIntProperty("m_typeLink");
|
168 |
if (xml.contains("m_extLink")) |
169 |
m_extLink = xml.getStringProperty("m_extLink");
|
170 |
|
171 |
setMapContext(MapContext.createFromXML(xml.getChild(currentChild))); |
172 |
currentChild++; |
173 |
if (xml.getBooleanProperty("mapOverView")) { |
174 |
setMapOverViewContext(MapContext.createFromXML(xml.getChild(currentChild))); |
175 |
currentChild++; |
176 |
} |
177 |
showErrors(); |
178 |
}catch (Exception e) { |
179 |
throw new OpenException(e,this.getClass().getName()); |
180 |
} |
181 |
} |
182 |
|
183 |
/**
|
184 |
* DOCUMENT ME!
|
185 |
*
|
186 |
* @param p DOCUMENT ME!
|
187 |
*
|
188 |
* @return DOCUMENT ME!
|
189 |
* @throws XMLException
|
190 |
* @throws DriverException
|
191 |
* @throws DriverIOException
|
192 |
* @throws OpenException
|
193 |
*/
|
194 |
/*public ProjectView cloneProjectView(Project p)
|
195 |
throws XMLException, DriverException, DriverIOException, OpenException {
|
196 |
return (ProjectView) createFromXML(getXMLEntity(), p);
|
197 |
}
|
198 |
*/
|
199 |
|
200 |
public String getFrameName() { |
201 |
return PluginServices.getText(this,"Vista"); |
202 |
} |
203 |
|
204 |
public IWindow createWindow() {
|
205 |
com.iver.cit.gvsig.project.documents.view.gui.View view = new com.iver.cit.gvsig.project.documents.view.gui.View();
|
206 |
if (windowData != null) |
207 |
view.setWindowData(windowData); |
208 |
view.initialize(); |
209 |
view.setModel(this);
|
210 |
return view;
|
211 |
} |
212 |
|
213 |
public IWindow getProperties() {
|
214 |
return new ViewProperties(this); |
215 |
} |
216 |
|
217 |
public void exportToXML(XMLEntity root, Project project) throws SaveException { |
218 |
XMLEntity viewsRoot = project.getExportXMLTypeRootNode(root,ProjectViewFactory.registerName); |
219 |
viewsRoot.addChild(this.getXMLEntity());
|
220 |
this.exportToXMLLayerDependencies(this.getMapContext().getLayers(),root,project); |
221 |
if (this.getMapOverViewContext() != null) { |
222 |
this.exportToXMLLayerDependencies(this.getMapOverViewContext().getLayers(),root,project); |
223 |
} |
224 |
} |
225 |
|
226 |
private void exportToXMLLayerDependencies(FLayer layer, XMLEntity root,Project project) |
227 |
throws SaveException {
|
228 |
|
229 |
if (layer instanceof FLayers) { |
230 |
FLayers layers = (FLayers)layer; |
231 |
for (int i=0;i< layers.getLayersCount();i++) { |
232 |
this.exportToXMLLayerDependencies(layers.getLayer(i),root,project);
|
233 |
} |
234 |
} else {
|
235 |
if (layer instanceof AlphanumericData) { |
236 |
try {
|
237 |
project.exportToXMLDataSource(root,((AlphanumericData)layer).getRecordset().getName()); |
238 |
} catch (ReadDriverException e) {
|
239 |
throw new SaveException(e,layer.getName()); |
240 |
} |
241 |
|
242 |
ProjectTable pt = project.getTable((AlphanumericData) layer); |
243 |
if (pt != null) { |
244 |
pt.exportToXML(root,project); |
245 |
} |
246 |
} |
247 |
} |
248 |
} |
249 |
|
250 |
public void importFromXML(XMLEntity root, XMLEntity typeRoot, int elementIndex, Project project, boolean removeDocumentsFromRoot) throws XMLException, ReadDriverException, OpenException { |
251 |
XMLEntity element = typeRoot.getChild(elementIndex); |
252 |
this.setXMLEntity(element);
|
253 |
project.addDocument(this);
|
254 |
if (removeDocumentsFromRoot) {
|
255 |
typeRoot.removeChild(elementIndex); |
256 |
} |
257 |
|
258 |
|
259 |
|
260 |
|
261 |
//Cargamos las tables vinculadas:
|
262 |
|
263 |
//Recuperamos todos los nombres
|
264 |
XMLEntity tablesRoot = project.getExportXMLTypeRootNode(root,ProjectTableFactory.registerName); |
265 |
int childIndex;
|
266 |
XMLEntity child; |
267 |
// Lo hacemos en un map por si una vista se usa varias veces
|
268 |
HashMap tablesName = new HashMap(); |
269 |
Iterator iterTables = tablesRoot.findChildren("viewName",this.getName()); |
270 |
while (iterTables.hasNext()){
|
271 |
child = (XMLEntity)iterTables.next(); |
272 |
tablesName.put(child.getStringProperty("name"),child.getStringProperty("name")); |
273 |
} |
274 |
|
275 |
|
276 |
XMLEntity tableXML; |
277 |
|
278 |
// Construimos un diccionario ordenado inversamente por el indice
|
279 |
// del elemento (por si se van eliminando elementos al importar) y
|
280 |
// como valor el nombre de la vista
|
281 |
TreeMap tablesToImport = new TreeMap( new Comparator() { |
282 |
|
283 |
public int compare(Object o1, Object o2) { |
284 |
|
285 |
if (((Integer)o1).intValue() > ((Integer)o2).intValue()) { |
286 |
return -1; //o1 first |
287 |
} else if (((Integer)o1).intValue() < ((Integer)o2).intValue()){ |
288 |
return 1; //o1 second |
289 |
} |
290 |
return 0; |
291 |
} |
292 |
|
293 |
}); |
294 |
Iterator iterTablesName = tablesName.keySet().iterator();
|
295 |
int tableIndex;
|
296 |
String tableName;
|
297 |
while (iterTablesName.hasNext()) {
|
298 |
tableName = (String)iterTablesName.next();
|
299 |
tableIndex = tablesRoot.firstIndexOfChild("name",tableName);
|
300 |
tablesToImport.put(new Integer(tableIndex),tableName); |
301 |
} |
302 |
|
303 |
ProjectTable table; |
304 |
ProjectDocumentFactory tableFactory = project.getProjectDocumentFactory(ProjectTableFactory.registerName); |
305 |
|
306 |
Iterator iterTablesToImport = tablesToImport.entrySet().iterator();
|
307 |
Entry entry; |
308 |
// Nos recorremos las vistas a importar
|
309 |
while (iterTablesToImport.hasNext()) {
|
310 |
entry = (Entry)iterTablesToImport.next(); |
311 |
tableName = (String)entry.getValue();
|
312 |
tableIndex = ((Integer)entry.getKey()).intValue();
|
313 |
table = (ProjectTable)tableFactory.create(project); |
314 |
table.importFromXML(root,tablesRoot,tableIndex,project,removeDocumentsFromRoot); |
315 |
|
316 |
|
317 |
} |
318 |
|
319 |
} |
320 |
|
321 |
// public int computeSignature() {
|
322 |
// int result = 17;
|
323 |
//
|
324 |
// Class clazz = getClass();
|
325 |
// Field[] fields = clazz.getDeclaredFields();
|
326 |
// for (int i = 0; i < fields.length; i++) {
|
327 |
// try {
|
328 |
// String type = fields[i].getType().getName();
|
329 |
// if (type.equals("boolean")) {
|
330 |
// result += 37 + ((fields[i].getBoolean(this)) ? 1 : 0);
|
331 |
// } else if (type.equals("java.lang.String")) {
|
332 |
// Object v = fields[i].get(this);
|
333 |
// if (v == null) {
|
334 |
// result += 37;
|
335 |
// continue;
|
336 |
// }
|
337 |
// char[] chars = ((String) v).toCharArray();
|
338 |
// for (int j = 0; j < chars.length; j++) {
|
339 |
// result += 37 + (int) chars[i];
|
340 |
// }
|
341 |
// } else if (type.equals("byte")) {
|
342 |
// result += 37 + (int) fields[i].getByte(this);
|
343 |
// } else if (type.equals("char")) {
|
344 |
// result += 37 + (int) fields[i].getChar(this);
|
345 |
// } else if (type.equals("short")) {
|
346 |
// result += 37 + (int) fields[i].getShort(this);
|
347 |
// } else if (type.equals("int")) {
|
348 |
// result += 37 + fields[i].getInt(this);
|
349 |
// } else if (type.equals("long")) {
|
350 |
// long f = fields[i].getLong(this) ;
|
351 |
// result += 37 + (f ^ (f >>> 32));
|
352 |
// } else if (type.equals("float")) {
|
353 |
// result += 37 + Float.floatToIntBits(fields[i].getFloat(this));
|
354 |
// } else if (type.equals("double")) {
|
355 |
// long f = Double.doubleToLongBits(fields[i].getDouble(this));
|
356 |
// result += 37 + (f ^ (f >>> 32));
|
357 |
// } else {
|
358 |
// Object obj = fields[i].get(this);
|
359 |
// result += 37 + ((obj != null)? obj.hashCode() : 0);
|
360 |
// }
|
361 |
// } catch (Exception e) { e.printStackTrace(); }
|
362 |
//
|
363 |
// }
|
364 |
// return result;
|
365 |
// }
|
366 |
} |