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