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