Revision 1837
trunk/applications/appgvSIG/src/com/iver/cit/gvsig/project/Project.java | ||
---|---|---|
113 | 113 |
// change.addPropertyChangeListener(this); |
114 | 114 |
creationDate = DateFormat.getDateInstance().format(new Date()); |
115 | 115 |
modificationDate = creationDate; |
116 |
LayerFactory.setDriversPath(PluginServices.getPluginServices(this) |
|
116 |
/* LayerFactory.setDriversPath(PluginServices.getPluginServices(this)
|
|
117 | 117 |
.getPluginDirectory() |
118 | 118 |
.getAbsolutePath() + |
119 | 119 |
File.separator + "drivers"); |
120 |
} |
|
120 |
*/}
|
|
121 | 121 |
|
122 | 122 |
/** |
123 | 123 |
* Obtiene la fecha de creaci?n del proyecto |
trunk/applications/appgvSIG/src/com/iver/cit/gvsig/test/Persistence.java | ||
---|---|---|
1 |
package com.iver.cit.gvsig.test; |
|
2 |
|
|
3 |
import java.awt.Dimension; |
|
4 |
import java.io.File; |
|
5 |
|
|
6 |
import junit.framework.TestCase; |
|
7 |
|
|
8 |
import org.cresques.cts.ProjectionPool; |
|
9 |
|
|
10 |
import com.hardcode.gdbms.engine.data.DataSourceFactory; |
|
11 |
import com.iver.cit.gvsig.ProjectExtension; |
|
12 |
import com.iver.cit.gvsig.fmap.FMap; |
|
13 |
import com.iver.cit.gvsig.fmap.ViewPort; |
|
14 |
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver; |
|
15 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
|
16 |
import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
|
17 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
|
18 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
|
19 |
import com.iver.cit.gvsig.project.Project; |
|
20 |
import com.iver.cit.gvsig.project.ProjectTable; |
|
21 |
import com.iver.cit.gvsig.project.ProjectView; |
|
22 |
|
|
23 |
/** |
|
24 |
* @author Fernando Gonz?lez Cort?s |
|
25 |
*/ |
|
26 |
public class Persistence extends TestCase { |
|
27 |
private ProjectExtension pe; |
|
28 |
|
|
29 |
/* |
|
30 |
* @see TestCase#setUp() |
|
31 |
*/ |
|
32 |
protected void setUp() throws Exception { |
|
33 |
pe = new ProjectExtension(); |
|
34 |
// pe.inicializar(); |
|
35 |
LayerFactory.setDriversPath( |
|
36 |
"/root/workspace/Andami/gvSIG/extensiones/com.iver.cit.gvsig/drivers"); |
|
37 |
|
|
38 |
LayerFactory.getDataSourceFactory().addFileDataSource("gdbms dbf driver", "prueba", |
|
39 |
"test/cities.dbf", "test/cities.dbf", null); |
|
40 |
|
|
41 |
} |
|
42 |
|
|
43 |
public void testPersist() throws Throwable { |
|
44 |
Project p = new Project(); |
|
45 |
|
|
46 |
/* |
|
47 |
* A?adimos una vista con una capa |
|
48 |
*/ |
|
49 |
ProjectView v = new ProjectView(); |
|
50 |
ViewPort vp = new ViewPort(ProjectionPool.get("EPSG:23030")); |
|
51 |
vp.setImageSize(new Dimension(500, 500)); |
|
52 |
|
|
53 |
FMap fmap = new FMap(vp); |
|
54 |
v.setMapContext(fmap); |
|
55 |
FLayer l = LayerFactory.createLayer("Vias", |
|
56 |
(VectorialFileDriver) LayerFactory.getDM().getDriver("gvSIG shp driver"), |
|
57 |
new File("test/cities.shp"), |
|
58 |
ProjectionPool.get("EPSG:23030")); |
|
59 |
fmap.getLayers().addLayer(l); |
|
60 |
|
|
61 |
/* |
|
62 |
* A?adimos la tabla del tema anterior |
|
63 |
*/ |
|
64 |
SelectableDataSource sds1 = ((AlphanumericData) l).getRecordset(); |
|
65 |
ProjectTable pt1 = ProjectTable.createTable("tabla", sds1); |
|
66 |
p.addTable(pt1); |
|
67 |
|
|
68 |
/* |
|
69 |
* A?adimos otra tabla |
|
70 |
*/ |
|
71 |
SelectableDataSource sds2 = new SelectableDataSource(LayerFactory.getDataSourceFactory().createRandomDataSource("prueba", DataSourceFactory.MANUAL_MODE)); |
|
72 |
ProjectTable pt2 = ProjectTable.createTable("tabla2", sds2); |
|
73 |
p.addTable(pt2); |
|
74 |
|
|
75 |
/* |
|
76 |
* Creamos un join |
|
77 |
*/ |
|
78 |
String sql = "custom com_iver_cit_gvsig_arcjoin tables '"+ |
|
79 |
sds1.getName()+"', '"+sds1.getName()+"' values(NAME,NAME);"; |
|
80 |
|
|
81 |
SelectableDataSource result = new SelectableDataSource( |
|
82 |
LayerFactory.getDataSourceFactory() |
|
83 |
.executeSQL(sql, DataSourceFactory.MANUAL_MODE)); |
|
84 |
pt1.replaceDataSource(result); |
|
85 |
|
|
86 |
/* |
|
87 |
* Guardamos y cargamos |
|
88 |
*/ |
|
89 |
File temp = File.createTempFile("junit-", ".gvp"); |
|
90 |
temp.deleteOnExit(); |
|
91 |
pe.escribirProyecto(temp, p); |
|
92 |
|
|
93 |
Project p2 = pe.leerProyecto(temp); |
|
94 |
|
|
95 |
/* |
|
96 |
* Comprobamos que las dos tablas son id?nticas |
|
97 |
*/ |
|
98 |
assertTrue(((ProjectTable)p2.getTables().get(0)).getModelo().getAsString().equals(((ProjectTable)p.getTables().get(0)).getModelo().getAsString())); |
|
99 |
assertTrue(((ProjectTable)p2.getTables().get(1)).getModelo().getAsString().equals(((ProjectTable)p.getTables().get(1)).getModelo().getAsString())); |
|
100 |
} |
|
101 |
} |
|
0 | 102 |
trunk/applications/appgvSIG/src/com/iver/cit/gvsig/ProjectExtension.java | ||
---|---|---|
122 | 122 |
guardarDialogo(); |
123 | 123 |
} else { |
124 | 124 |
escribirProyecto(new File(p.getPath()), p); |
125 |
projectFrame.refreshControls(); |
|
125 | 126 |
} |
126 | 127 |
} |
127 | 128 |
private void guardarDialogo(){ |
... | ... | |
135 | 136 |
file=new File(file.getPath()+".gvp"); |
136 | 137 |
} |
137 | 138 |
escribirProyecto(file, p); |
139 |
projectFrame.refreshControls(); |
|
138 | 140 |
} |
139 | 141 |
} |
140 | 142 |
/** |
... | ... | |
214 | 216 |
* @param file Fichero. |
215 | 217 |
* @param p Proyecto. |
216 | 218 |
*/ |
217 |
private void escribirProyecto(File file, Project p) {
|
|
219 |
public void escribirProyecto(File file, Project p) {
|
|
218 | 220 |
// write it out as XML |
219 | 221 |
try { |
220 | 222 |
FileWriter writer = new FileWriter(file.getAbsolutePath()); |
... | ... | |
230 | 232 |
NotificationManager.addError("Error guardando el proyecto", e); |
231 | 233 |
} |
232 | 234 |
|
233 |
projectFrame.refreshControls(); |
|
234 | 235 |
} |
235 | 236 |
|
236 | 237 |
/** |
... | ... | |
249 | 250 |
reader = new FileReader(xmlFile); |
250 | 251 |
|
251 | 252 |
XmlTag tag = (XmlTag) XmlTag.unmarshal(reader); |
252 |
p = Project.createFromXML(new XMLEntity(tag)); |
|
253 |
proj = Project.createFromXML(new XMLEntity(tag));
|
|
253 | 254 |
} catch (FileNotFoundException e) { |
254 | 255 |
NotificationManager.addError("Al leer el proyecto", e); |
255 | 256 |
} catch (MarshalException e) { |
Also available in: Unified diff