root / tags / v1_0_2_Build_912 / extensions / extCAD / src / com / iver / cit / gvsig / StopEditingToGT2Shp.java @ 11422
History | View | Annotate | Download (4.45 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.MapContext; |
17 |
import com.iver.cit.gvsig.fmap.crs.CRSFactory; |
18 |
import com.iver.cit.gvsig.fmap.edition.EditionEvent; |
19 |
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter; |
20 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
21 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
22 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
23 |
import com.iver.cit.gvsig.fmap.layers.LayersIterator; |
24 |
import com.iver.cit.gvsig.project.documents.view.IProjectView; |
25 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
26 |
import com.iver.cit.gvsig.writers.WriterGT2; |
27 |
import com.iver.utiles.SimpleFileFilter; |
28 |
|
29 |
|
30 |
/**
|
31 |
* DOCUMENT ME!
|
32 |
*
|
33 |
* @author Vicente Caballero Navarro
|
34 |
*/
|
35 |
public class StopEditingToGT2Shp extends Extension { |
36 |
/**
|
37 |
* @see com.iver.andami.plugins.IExtension#initialize()
|
38 |
*/
|
39 |
public void initialize() { |
40 |
} |
41 |
|
42 |
/**
|
43 |
* @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
|
44 |
*/
|
45 |
public void execute(String s) { |
46 |
com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
47 |
.getActiveWindow(); |
48 |
|
49 |
View vista = (View) f; |
50 |
IProjectView model = vista.getModel(); |
51 |
MapContext mapa = model.getMapContext(); |
52 |
FLayers layers = mapa.getLayers(); |
53 |
if (s.equals("STOPEDITING")){ |
54 |
LayersIterator iter = new LayersIterator(layers);
|
55 |
FLayer layer; |
56 |
while (iter.hasNext()) {
|
57 |
layer = iter.nextLayer(); |
58 |
if (layer instanceof FLyrVect && |
59 |
layer.isEditing()) { |
60 |
stopEditing((FLyrVect)layer); |
61 |
|
62 |
return;
|
63 |
} |
64 |
} |
65 |
} |
66 |
PluginServices.getMainFrame().enableControls(); |
67 |
} |
68 |
|
69 |
/**
|
70 |
* @see com.iver.andami.plugins.IExtension#isEnabled()
|
71 |
*/
|
72 |
public boolean isEnabled() { |
73 |
return true; |
74 |
} |
75 |
|
76 |
|
77 |
|
78 |
|
79 |
/**
|
80 |
* DOCUMENT ME!
|
81 |
*/
|
82 |
public void stopEditing(FLyrVect layer) { |
83 |
try {
|
84 |
// WriterGT2Shp writer = new WriterGT2Shp(layer);
|
85 |
|
86 |
|
87 |
JFileChooser jfc = new JFileChooser(); |
88 |
// if (jfc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
|
89 |
/*
|
90 |
* FLyrVect layer = (FLyrVect) test.createLayer("prueba",
|
91 |
* (VectorialFileDriver) driverManager.getDriver( "gvSIG shp
|
92 |
* driver"), original, CRSFactory.getCRS("EPSG:23030"));
|
93 |
*/
|
94 |
SimpleFileFilter filterShp = new SimpleFileFilter(".shp", "Ficheros .shp"); |
95 |
jfc.setFileFilter(filterShp); |
96 |
if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) |
97 |
{ |
98 |
File newFile = jfc.getSelectedFile();
|
99 |
FeatureType featType = WriterGT2.getFeatureType(layer, "the_geom",
|
100 |
newFile.getName()); |
101 |
URL theUrl = newFile.toURL();
|
102 |
ShapefileDataStore dataStore = new ShapefileDataStore(theUrl);
|
103 |
dataStore.createSchema(featType); |
104 |
|
105 |
String featureName = dataStore.getTypeNames()[0]; |
106 |
FeatureStore featStore = (FeatureStore) dataStore.getFeatureSource(featureName); |
107 |
|
108 |
// Necesitamos crear de verdad los ficheros antes de usarlos
|
109 |
// para meter las features
|
110 |
FeatureWriter featWriter = dataStore.getFeatureWriterAppend(featureName, featStore.getTransaction()); |
111 |
featWriter.close(); |
112 |
// Aqu? ya tenemos un fichero vac?o, listo para usar.
|
113 |
|
114 |
|
115 |
WriterGT2 writer = new WriterGT2(featStore, true); |
116 |
|
117 |
VectorialEditableAdapter vea = (VectorialEditableAdapter) layer.getSource(); |
118 |
vea.stopEdition(writer,EditionEvent.GRAPHIC); |
119 |
layer.setSource(vea.getOriginalAdapter()); |
120 |
layer.setEditing(false);
|
121 |
} |
122 |
} catch (Exception e) { |
123 |
e.printStackTrace(); |
124 |
} |
125 |
} |
126 |
|
127 |
|
128 |
/**
|
129 |
* @see com.iver.andami.plugins.IExtension#isVisible()
|
130 |
*/
|
131 |
public boolean isVisible() { |
132 |
if (EditionUtilities.getEditionStatus() == EditionUtilities.EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE)
|
133 |
return true; |
134 |
return false; |
135 |
|
136 |
} |
137 |
} |
138 |
|