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