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