svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / Abrir.java @ 596
History | View | Annotate | Download (3.74 KB)
1 |
package com.iver.cit.gvsig; |
---|---|
2 |
|
3 |
import java.io.File; |
4 |
|
5 |
import org.cresques.cts.IProjection; |
6 |
import org.cresques.cts.ProjectionPool; |
7 |
|
8 |
import com.hardcode.driverManager.DriverLoadException; |
9 |
import com.hardcode.gdbms.engine.data.DBDriver; |
10 |
import com.iver.andami.PluginServices; |
11 |
import com.iver.andami.plugins.Extension; |
12 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
13 |
import com.iver.cit.gvsig.fmap.drivers.GeorreferencedRasterDriver; |
14 |
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver; |
15 |
import com.iver.cit.gvsig.fmap.layers.CancelationException; |
16 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
17 |
import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
18 |
import com.iver.cit.gvsig.gui.DataBaseOpenDialog; |
19 |
import com.iver.cit.gvsig.gui.FOpenDialog; |
20 |
import com.iver.cit.gvsig.gui.FileOpenDialog; |
21 |
import com.iver.cit.gvsig.gui.View; |
22 |
|
23 |
|
24 |
/**
|
25 |
* DOCUMENT ME!
|
26 |
*
|
27 |
* @author Fernando Gonz?lez Cort?s
|
28 |
*/
|
29 |
public class Abrir implements Extension { |
30 |
public FOpenDialog fopen = null; |
31 |
|
32 |
/**
|
33 |
* @see com.iver.mdiApp.plugins.Extension#isVisible()
|
34 |
*/
|
35 |
public boolean isVisible() { |
36 |
com.iver.andami.ui.mdiManager.View f = PluginServices.getMDIManager().getActiveView(); |
37 |
|
38 |
if (f == null) { |
39 |
return false; |
40 |
} |
41 |
|
42 |
return (f.getClass() == View.class); |
43 |
} |
44 |
|
45 |
/**
|
46 |
* @see com.iver.andami.plugins.Extension#inicializar()
|
47 |
*/
|
48 |
public void inicializar() { |
49 |
} |
50 |
|
51 |
/**
|
52 |
* @see com.iver.andami.plugins.Extension#execute(java.lang.String)
|
53 |
*/
|
54 |
public void execute(String actionCommand){ |
55 |
View theView = (View) PluginServices.getMDIManager().getActiveView(); |
56 |
fopen = new FOpenDialog();
|
57 |
|
58 |
FileOpenDialog fileDlg = new FileOpenDialog(new Class[]{VectorialFileDriver.class, GeorreferencedRasterDriver.class}); |
59 |
DataBaseOpenDialog dbop = new DataBaseOpenDialog();
|
60 |
dbop.setClasses(new Class[] { DBDriver.class }); |
61 |
fopen.addTab("Fichero", fileDlg);
|
62 |
fopen.addTab("Base de datos", dbop);
|
63 |
PluginServices.getMDIManager().addView(fopen); |
64 |
|
65 |
if (fopen.isAccepted()) {
|
66 |
// TODO: Hacer lo de la capa WMS tambi?n.
|
67 |
if (fileDlg.getFiles() == null) { |
68 |
return;
|
69 |
} |
70 |
|
71 |
IProjection proj = ProjectionPool.get("ed50utm30");
|
72 |
FLayer lyr = null;
|
73 |
File[] files = fileDlg.getFiles(); |
74 |
|
75 |
for (int iFile = 0; iFile < files.length; iFile++) { |
76 |
File fich = files[iFile];
|
77 |
String layerName = fich.getName();
|
78 |
String layerPath = fich.getAbsolutePath();
|
79 |
|
80 |
try {
|
81 |
lyr = LayerFactory.createLayer(layerName, fileDlg.getDriverName(), |
82 |
fich, proj); |
83 |
|
84 |
if (lyr != null) { |
85 |
try {
|
86 |
|
87 |
lyr.setVisible(true);
|
88 |
theView.getMapControl().getMapContext().getLayers() |
89 |
.addLayer(lyr); |
90 |
} catch (CancelationException e) {
|
91 |
// TODO Auto-generated catch block
|
92 |
e.printStackTrace(); |
93 |
} |
94 |
|
95 |
// TODO: Poner una variable y dibujar solo cuando
|
96 |
// todas las capas hayan sido cargadas.
|
97 |
theView.getMapControl().drawMap(); |
98 |
theView.getTOC().refresh(); |
99 |
} |
100 |
} catch (DriverLoadException e) {
|
101 |
e.printStackTrace(); |
102 |
} catch (DriverIOException e) {
|
103 |
// TODO Auto-generated catch block
|
104 |
e.printStackTrace(); |
105 |
} |
106 |
} // for
|
107 |
} |
108 |
} |
109 |
|
110 |
/**
|
111 |
* @see com.iver.andami.plugins.Extension#isEnabled()
|
112 |
*/
|
113 |
public boolean isEnabled() { |
114 |
return true; |
115 |
} |
116 |
} |