root / trunk / extensions / extCAD / src / com / iver / cit / gvsig / StopEditingToGT2Shp.java @ 3808
History | View | Annotate | Download (4.16 KB)
1 |
package com.iver.cit.gvsig; |
---|---|
2 |
|
3 |
import java.awt.Component; |
4 |
import java.io.File; |
5 |
import java.net.URL; |
6 |
|
7 |
import javax.swing.JFileChooser; |
8 |
|
9 |
import org.geotools.data.FeatureStore; |
10 |
import org.geotools.data.FeatureWriter; |
11 |
import org.geotools.data.shapefile.ShapefileDataStore; |
12 |
import org.geotools.feature.FeatureType; |
13 |
|
14 |
import com.iver.andami.PluginServices; |
15 |
import com.iver.andami.plugins.Extension; |
16 |
import com.iver.cit.gvsig.fmap.FMap; |
17 |
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter; |
18 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
19 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
20 |
import com.iver.cit.gvsig.gui.View; |
21 |
import com.iver.cit.gvsig.project.ProjectView; |
22 |
import com.iver.cit.gvsig.writers.WriterGT2; |
23 |
import com.iver.utiles.SimpleFileFilter; |
24 |
|
25 |
|
26 |
/**
|
27 |
* DOCUMENT ME!
|
28 |
*
|
29 |
* @author Vicente Caballero Navarro
|
30 |
*/
|
31 |
public class StopEditingToGT2Shp implements Extension { |
32 |
/**
|
33 |
* @see com.iver.andami.plugins.Extension#inicializar()
|
34 |
*/
|
35 |
public void inicializar() { |
36 |
} |
37 |
|
38 |
/**
|
39 |
* @see com.iver.andami.plugins.Extension#execute(java.lang.String)
|
40 |
*/
|
41 |
public void execute(String s) { |
42 |
com.iver.andami.ui.mdiManager.View f = PluginServices.getMDIManager() |
43 |
.getActiveView(); |
44 |
|
45 |
View vista = (View) f; |
46 |
ProjectView model = vista.getModel(); |
47 |
FMap mapa = model.getMapContext(); |
48 |
FLayers layers = mapa.getLayers(); |
49 |
if (s.equals("STOPEDITING")){ |
50 |
for (int i = 0; i < layers.getLayersCount(); i++) { |
51 |
if (layers.getLayer(i) instanceof FLyrVect && |
52 |
layers.getLayer(i).isEditing()) { |
53 |
FLyrVect lv = (FLyrVect) layers.getLayer(i); |
54 |
stopEditing(lv); |
55 |
|
56 |
return;
|
57 |
} |
58 |
} |
59 |
} |
60 |
PluginServices.getMainFrame().enableControls(); |
61 |
} |
62 |
|
63 |
/**
|
64 |
* @see com.iver.andami.plugins.Extension#isEnabled()
|
65 |
*/
|
66 |
public boolean isEnabled() { |
67 |
return true; |
68 |
} |
69 |
|
70 |
|
71 |
|
72 |
|
73 |
/**
|
74 |
* DOCUMENT ME!
|
75 |
*/
|
76 |
public void stopEditing(FLyrVect layer) { |
77 |
try {
|
78 |
// WriterGT2Shp writer = new WriterGT2Shp(layer);
|
79 |
|
80 |
|
81 |
JFileChooser jfc = new JFileChooser(); |
82 |
// if (jfc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
|
83 |
/*
|
84 |
* FLyrVect layer = (FLyrVect) test.createLayer("prueba",
|
85 |
* (VectorialFileDriver) driverManager.getDriver( "gvSIG shp
|
86 |
* driver"), original, ProjectionPool.get("EPSG:23030"));
|
87 |
*/
|
88 |
SimpleFileFilter filterShp = new SimpleFileFilter(".shp", "Ficheros .shp"); |
89 |
jfc.setFileFilter(filterShp); |
90 |
if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) |
91 |
{ |
92 |
File newFile = jfc.getSelectedFile();
|
93 |
FeatureType featType = WriterGT2.getFeatureType(layer, "the_geom",
|
94 |
newFile.getName()); |
95 |
URL theUrl = newFile.toURL();
|
96 |
ShapefileDataStore dataStore = new ShapefileDataStore(theUrl);
|
97 |
dataStore.createSchema(featType); |
98 |
|
99 |
String featureName = dataStore.getTypeNames()[0]; |
100 |
FeatureStore featStore = (FeatureStore) dataStore.getFeatureSource(featureName); |
101 |
|
102 |
// Necesitamos crear de verdad los ficheros antes de usarlos
|
103 |
// para meter las features
|
104 |
FeatureWriter featWriter = dataStore.getFeatureWriterAppend(featureName, featStore.getTransaction()); |
105 |
featWriter.close(); |
106 |
// Aqu? ya tenemos un fichero vac?o, listo para usar.
|
107 |
|
108 |
|
109 |
WriterGT2 writer = new WriterGT2(featStore, true); |
110 |
|
111 |
VectorialEditableAdapter vea = (VectorialEditableAdapter) layer.getSource(); |
112 |
vea.stopEdition(writer); |
113 |
layer.setSource(vea.getOriginalAdapter()); |
114 |
layer.setEditing(false);
|
115 |
} |
116 |
} catch (Exception e) { |
117 |
e.printStackTrace(); |
118 |
} |
119 |
} |
120 |
|
121 |
|
122 |
/**
|
123 |
* @see com.iver.andami.plugins.Extension#isVisible()
|
124 |
*/
|
125 |
public boolean isVisible() { |
126 |
if (EditionUtilities.getEditionStatus() == EditionUtilities.EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE)
|
127 |
return true; |
128 |
else
|
129 |
return false; |
130 |
|
131 |
} |
132 |
} |
133 |
|