root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / ProjectView.java @ 38050
History | View | Annotate | Download (10.2 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.layers.FLayer; |
54 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
55 |
import com.iver.cit.gvsig.fmap.layers.LayersIterator; |
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.gui.preferencespage.ViewPage; |
59 |
import com.iver.cit.gvsig.project.Project; |
60 |
import com.iver.cit.gvsig.project.documents.ProjectDocument; |
61 |
import com.iver.cit.gvsig.project.documents.ProjectDocumentFactory; |
62 |
import com.iver.cit.gvsig.project.documents.exceptions.OpenException; |
63 |
import com.iver.cit.gvsig.project.documents.exceptions.SaveException; |
64 |
import com.iver.cit.gvsig.project.documents.table.ProjectTable; |
65 |
import com.iver.cit.gvsig.project.documents.table.ProjectTableFactory; |
66 |
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 |
public class ProjectView extends ProjectViewBase { |
76 |
|
77 |
public XMLEntity getXMLEntity() throws SaveException { |
78 |
XMLEntity xml = super.getXMLEntity();
|
79 |
try{
|
80 |
int numViews=((Integer)ProjectDocument.NUMS.get(ProjectViewFactory.registerName)).intValue(); |
81 |
|
82 |
xml.putProperty("numViews", numViews);
|
83 |
|
84 |
xml.addChild(mapContext.getXMLEntity()); |
85 |
|
86 |
if (mapOverViewContext != null) { |
87 |
if (mapOverViewContext.getViewPort() != null) { |
88 |
xml.putProperty("mapOverView", true); |
89 |
xml.addChild(mapOverViewContext.getXMLEntity()); |
90 |
} else {
|
91 |
xml.putProperty("mapOverView", false); |
92 |
} |
93 |
} else {
|
94 |
xml.putProperty("mapOverView", false); |
95 |
} |
96 |
}catch (Exception e) { |
97 |
throw new SaveException(e,this.getClass().getName()); |
98 |
} |
99 |
return xml;
|
100 |
} |
101 |
|
102 |
/**
|
103 |
* @see com.iver.cit.gvsig.project.documents.ProjectDocument#setXMLEntity(com.iver.utiles.XMLEntity)
|
104 |
*/
|
105 |
public void setXMLEntity03(XMLEntity xml) |
106 |
throws XMLException, ReadDriverException {
|
107 |
super.setXMLEntity03(xml);
|
108 |
int numViews = xml.getIntProperty("numViews"); |
109 |
ProjectDocument.NUMS.put(ProjectViewFactory.registerName,new Integer(numViews)); |
110 |
|
111 |
m_selectedField = xml.getStringProperty("m_selectedField");
|
112 |
m_typeLink = xml.getIntProperty("m_typeLink");
|
113 |
m_extLink = xml.getStringProperty("m_extLink");
|
114 |
setMapContext(MapContext.createFromXML03(xml.getChild(0)));
|
115 |
|
116 |
if (xml.getBooleanProperty("mapOverView")) { |
117 |
setMapOverViewContext(MapContext.createFromXML03(xml.getChild(1)));
|
118 |
} |
119 |
|
120 |
} |
121 |
|
122 |
/**
|
123 |
* @see com.iver.cit.gvsig.project.documents.ProjectDocument#setXMLEntity(com.iver.utiles.XMLEntity)
|
124 |
*/
|
125 |
public void setXMLEntity(XMLEntity xml) |
126 |
throws XMLException, ReadDriverException, OpenException {
|
127 |
try{
|
128 |
super.setXMLEntity(xml);
|
129 |
int currentChild=0; |
130 |
int numViews = xml.getIntProperty("numViews"); |
131 |
ProjectDocument.NUMS.put(ProjectViewFactory.registerName,new Integer(numViews)); |
132 |
|
133 |
setMapContext(MapContext.createFromXML(xml.getChild(currentChild))); |
134 |
currentChild++; |
135 |
if (xml.getBooleanProperty("mapOverView")) { |
136 |
setMapOverViewContext(MapContext.createFromXML(xml.getChild(currentChild))); |
137 |
currentChild++; |
138 |
} |
139 |
|
140 |
// legacy hyperlink stuff
|
141 |
if (xml.contains("m_selectedField")) { |
142 |
String selectedField, extension=null; |
143 |
int type=-1; |
144 |
selectedField = xml.getStringProperty("m_selectedField");
|
145 |
if (xml.contains("m_typeLink")) { |
146 |
type = xml.getIntProperty("m_typeLink");
|
147 |
} |
148 |
if (xml.contains("m_extLink")) { |
149 |
extension = xml.getStringProperty("m_extLink");
|
150 |
} |
151 |
applyHyperlinkToLayers(selectedField, type, extension); |
152 |
} |
153 |
|
154 |
showErrors(); |
155 |
}catch (Exception e) { |
156 |
throw new OpenException(e,this.getClass().getName()); |
157 |
} |
158 |
} |
159 |
|
160 |
/**
|
161 |
* <p>Legacy code to keep compatibility with old 1.1.x hyperlink.</p>
|
162 |
*
|
163 |
* @param selectedField
|
164 |
* @param type
|
165 |
* @param extension
|
166 |
*/
|
167 |
private void applyHyperlinkToLayers(String selectedField, int type, String extension) { |
168 |
final String LAYERPROPERTYNAME = "org.gvsig.hyperlink.config"; |
169 |
|
170 |
LayersIterator iterator = new LayersIterator(getMapContext().getLayers());
|
171 |
while (iterator.hasNext()) {
|
172 |
FLayer layer = iterator.nextLayer(); |
173 |
// don't apply 1.1.x compatibility if a property from 1.9 alpha hyperlink is found
|
174 |
String auxFieldName = (String) layer.getProperty("legacy.hyperlink.selectedField"); |
175 |
|
176 |
if (auxFieldName == null && selectedField!=null) { |
177 |
layer.setProperty("legacy.hyperlink.selectedField", selectedField);
|
178 |
layer.setProperty("legacy.hyperlink.type", new Integer(type)); |
179 |
if (extension!=null) { |
180 |
layer.setProperty("legacy.hyperlink.extension", extension);
|
181 |
} |
182 |
} |
183 |
} |
184 |
|
185 |
} |
186 |
|
187 |
|
188 |
public String getFrameName() { |
189 |
return PluginServices.getText(this,"Vista"); |
190 |
} |
191 |
|
192 |
public IWindow createWindow() {
|
193 |
com.iver.cit.gvsig.project.documents.view.gui.View view = new com.iver.cit.gvsig.project.documents.view.gui.View();
|
194 |
if (windowData != null) |
195 |
view.setWindowData(windowData); |
196 |
view.initialize(this.getMapContext());
|
197 |
view.setModel(this);
|
198 |
XMLEntity xml = PluginServices.getPluginServices(this)
|
199 |
.getPersistentXML(); |
200 |
if (xml.contains(ViewPage.OPEN_VIEW_WINDOW_MAXIMIZED)) {
|
201 |
view.getWindowInfo() |
202 |
.setMaximized( |
203 |
xml.getBooleanProperty(ViewPage.OPEN_VIEW_WINDOW_MAXIMIZED)); |
204 |
} |
205 |
callCreateWindow(view); |
206 |
return view;
|
207 |
} |
208 |
|
209 |
public IWindow getProperties() {
|
210 |
return new ViewProperties(this); |
211 |
} |
212 |
|
213 |
public void exportToXML(XMLEntity root, Project project) throws SaveException { |
214 |
XMLEntity viewsRoot = project.getExportXMLTypeRootNode(root,ProjectViewFactory.registerName); |
215 |
viewsRoot.addChild(this.getXMLEntity());
|
216 |
this.exportToXMLLayerDependencies(this.getMapContext().getLayers(),root,project); |
217 |
if (this.getMapOverViewContext() != null) { |
218 |
this.exportToXMLLayerDependencies(this.getMapOverViewContext().getLayers(),root,project); |
219 |
} |
220 |
} |
221 |
|
222 |
private void exportToXMLLayerDependencies(FLayer layer, XMLEntity root,Project project) |
223 |
throws SaveException {
|
224 |
|
225 |
if (layer instanceof FLayers) { |
226 |
FLayers layers = (FLayers)layer; |
227 |
for (int i=0;i< layers.getLayersCount();i++) { |
228 |
this.exportToXMLLayerDependencies(layers.getLayer(i),root,project);
|
229 |
} |
230 |
} else {
|
231 |
if (layer instanceof AlphanumericData) { |
232 |
try {
|
233 |
project.exportToXMLDataSource(root,((AlphanumericData)layer).getRecordset().getName()); |
234 |
} catch (ReadDriverException e) {
|
235 |
throw new SaveException(e,layer.getName()); |
236 |
} |
237 |
|
238 |
ProjectTable pt = project.getTable((AlphanumericData) layer); |
239 |
if (pt != null) { |
240 |
pt.exportToXML(root,project); |
241 |
} |
242 |
} |
243 |
} |
244 |
} |
245 |
|
246 |
public void importFromXML(XMLEntity root, XMLEntity typeRoot, int elementIndex, Project project, boolean removeDocumentsFromRoot) throws XMLException, ReadDriverException, OpenException { |
247 |
XMLEntity element = typeRoot.getChild(elementIndex); |
248 |
this.setXMLEntity(element);
|
249 |
project.addDocument(this);
|
250 |
if (removeDocumentsFromRoot) {
|
251 |
typeRoot.removeChild(elementIndex); |
252 |
} |
253 |
|
254 |
|
255 |
//Cargamos las tables vinculadas:
|
256 |
|
257 |
//Recuperamos todos los nombres
|
258 |
XMLEntity tablesRoot = project.getExportXMLTypeRootNode(root,ProjectTableFactory.registerName); |
259 |
XMLEntity child; |
260 |
// Lo hacemos en un map por si una vista se usa varias veces
|
261 |
HashMap<String, String> tablesName = new HashMap<String, String>(); |
262 |
Iterator<XMLEntity> iterTables = tablesRoot.findChildren("viewName",this.getName()); |
263 |
while (iterTables.hasNext()){
|
264 |
child = iterTables.next(); |
265 |
tablesName.put(child.getStringProperty("name"),child.getStringProperty("name")); |
266 |
} |
267 |
|
268 |
|
269 |
XMLEntity tableXML; |
270 |
|
271 |
// Construimos un diccionario ordenado inversamente por el indice
|
272 |
// del elemento (por si se van eliminando elementos al importar) y
|
273 |
// como valor el nombre de la vista
|
274 |
TreeMap tablesToImport = new TreeMap( new Comparator() { |
275 |
|
276 |
public int compare(Object o1, Object o2) { |
277 |
|
278 |
if (((Integer)o1).intValue() > ((Integer)o2).intValue()) { |
279 |
return -1; //o1 first |
280 |
} else if (((Integer)o1).intValue() < ((Integer)o2).intValue()){ |
281 |
return 1; //o1 second |
282 |
} |
283 |
return 0; |
284 |
} |
285 |
|
286 |
}); |
287 |
Iterator iterTablesName = tablesName.keySet().iterator();
|
288 |
int tableIndex;
|
289 |
String tableName;
|
290 |
while (iterTablesName.hasNext()) {
|
291 |
tableName = (String)iterTablesName.next();
|
292 |
tableIndex = tablesRoot.firstIndexOfChild("name",tableName);
|
293 |
tablesToImport.put(new Integer(tableIndex),tableName); |
294 |
} |
295 |
|
296 |
ProjectTable table; |
297 |
ProjectDocumentFactory tableFactory = project.getProjectDocumentFactory(ProjectTableFactory.registerName); |
298 |
|
299 |
Iterator iterTablesToImport = tablesToImport.entrySet().iterator();
|
300 |
Entry entry; |
301 |
// Nos recorremos las vistas a importar
|
302 |
while (iterTablesToImport.hasNext()) {
|
303 |
entry = (Entry)iterTablesToImport.next(); |
304 |
tableName = (String)entry.getValue();
|
305 |
tableIndex = ((Integer)entry.getKey()).intValue();
|
306 |
table = (ProjectTable)tableFactory.create(project); |
307 |
table.importFromXML(root,tablesRoot,tableIndex,project,removeDocumentsFromRoot); |
308 |
|
309 |
|
310 |
} |
311 |
|
312 |
} |
313 |
|
314 |
} |