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