root / tags / v1_0_2_Build_892 / extensions / extCAD / src / com / iver / cit / gvsig / StopEditingToGT2PostGIS.java @ 10278
History | View | Annotate | Download (5.41 KB)
1 |
package com.iver.cit.gvsig; |
---|---|
2 |
|
3 |
import java.io.IOException; |
4 |
import java.util.HashMap; |
5 |
|
6 |
import org.geotools.data.FeatureStore; |
7 |
import org.geotools.data.FeatureWriter; |
8 |
import org.geotools.data.postgis.PostgisDataStore; |
9 |
import org.geotools.data.postgis.PostgisDataStoreFactory; |
10 |
import org.geotools.factory.FactoryConfigurationError; |
11 |
import org.geotools.feature.FeatureType; |
12 |
import org.geotools.feature.SchemaException; |
13 |
|
14 |
import com.hardcode.gdbms.engine.data.driver.DriverException; |
15 |
import com.iver.andami.PluginServices; |
16 |
import com.iver.andami.plugins.Extension; |
17 |
import com.iver.cit.gvsig.fmap.MapContext; |
18 |
import com.iver.cit.gvsig.fmap.edition.EditionEvent; |
19 |
import com.iver.cit.gvsig.fmap.edition.EditionException; |
20 |
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter; |
21 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
22 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
23 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
24 |
import com.iver.cit.gvsig.fmap.layers.LayersIterator; |
25 |
import com.iver.cit.gvsig.jdbc_spatial.DlgConnection; |
26 |
import com.iver.cit.gvsig.jdbc_spatial.gui.jdbcwizard.ConnectionSettings; |
27 |
import com.iver.cit.gvsig.project.documents.view.IProjectView; |
28 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
29 |
import com.iver.cit.gvsig.writers.WriterGT2; |
30 |
|
31 |
|
32 |
/**
|
33 |
* DOCUMENT ME!
|
34 |
*
|
35 |
* @author Vicente Caballero Navarro
|
36 |
*/
|
37 |
public class StopEditingToGT2PostGIS extends Extension { |
38 |
static PostgisDataStoreFactory postGisFactory = new PostgisDataStoreFactory(); |
39 |
/**
|
40 |
* @see com.iver.andami.plugins.IExtension#initialize()
|
41 |
*/
|
42 |
public void initialize() { |
43 |
} |
44 |
|
45 |
/**
|
46 |
* @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
|
47 |
*/
|
48 |
public void execute(String s) { |
49 |
com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
50 |
.getActiveWindow(); |
51 |
|
52 |
View vista = (View) f; |
53 |
IProjectView model = vista.getModel(); |
54 |
MapContext mapa = model.getMapContext(); |
55 |
FLayers layers = mapa.getLayers(); |
56 |
if (s.equals("STOPEDITING")){ |
57 |
LayersIterator iter = new LayersIterator(layers);
|
58 |
FLayer layer; |
59 |
while (iter.hasNext()) {
|
60 |
layer = iter.nextLayer(); |
61 |
if (layer instanceof FLyrVect && |
62 |
layer.isEditing()) { |
63 |
stopEditing((FLyrVect)layer); |
64 |
|
65 |
return;
|
66 |
} |
67 |
} |
68 |
} |
69 |
PluginServices.getMainFrame().enableControls(); |
70 |
} |
71 |
|
72 |
/**
|
73 |
* @see com.iver.andami.plugins.IExtension#isEnabled()
|
74 |
*/
|
75 |
public boolean isEnabled() { |
76 |
return true; |
77 |
} |
78 |
|
79 |
|
80 |
|
81 |
|
82 |
/**
|
83 |
* DOCUMENT ME!
|
84 |
*/
|
85 |
public void stopEditing(FLyrVect layer) { |
86 |
DlgConnection dlg; |
87 |
try {
|
88 |
dlg = new DlgConnection();
|
89 |
dlg.setModal(true);
|
90 |
dlg.setVisible(true);
|
91 |
ConnectionSettings cs = dlg.getConnSettings(); |
92 |
if (cs == null) |
93 |
return;
|
94 |
|
95 |
PostgisDataStore dataStore; |
96 |
HashMap params = new HashMap(); |
97 |
// Param[] dbParams = postGisFactory.getParametersInfo();
|
98 |
params.put("dbtype", "postgis"); //$NON-NLS-1$ |
99 |
params.put("host", cs.getHost());
|
100 |
params.put("port", new Integer(cs.getPort())); |
101 |
|
102 |
params.put("database", cs.getDb());
|
103 |
|
104 |
params.put("user", cs.getUser());
|
105 |
params.put("passwd", cs.getPassw());
|
106 |
|
107 |
params.put("wkb enabled", Boolean.TRUE); |
108 |
params.put("loose bbox", Boolean.TRUE); |
109 |
|
110 |
params.put("namespace", ""); //$NON-NLS-1$ |
111 |
|
112 |
dataStore = (PostgisDataStore) postGisFactory.createDataStore(params); |
113 |
|
114 |
FeatureType featType = WriterGT2.getFeatureType(layer, "the_geom",
|
115 |
"autopist2");
|
116 |
// dataStore.createSchema(featType);
|
117 |
|
118 |
String featureName = "autopist2"; // dataStore.getTypeNames()["autopist2"]; |
119 |
FeatureStore featStore = (FeatureStore) dataStore.getFeatureSource(featureName); |
120 |
|
121 |
// Necesitamos crear de verdad los ficheros antes de usarlos
|
122 |
// para meter las features
|
123 |
FeatureWriter featWriter = dataStore.getFeatureWriterAppend(featureName, featStore.getTransaction()); |
124 |
featWriter.close(); |
125 |
// Aqu? ya tenemos un fichero vac?o, listo para usar.
|
126 |
|
127 |
|
128 |
WriterGT2 writer = new WriterGT2(featStore, true); |
129 |
|
130 |
VectorialEditableAdapter vea = (VectorialEditableAdapter) layer.getSource(); |
131 |
vea.stopEdition(writer,EditionEvent.GRAPHIC); |
132 |
layer.setSource(vea.getOriginalAdapter()); |
133 |
layer.setEditing(false);
|
134 |
} catch (IOException e) { |
135 |
// TODO Auto-generated catch block
|
136 |
e.printStackTrace(); |
137 |
} catch (EditionException e) {
|
138 |
// TODO Auto-generated catch block
|
139 |
e.printStackTrace(); |
140 |
} catch (DriverException e) {
|
141 |
// TODO Auto-generated catch block
|
142 |
e.printStackTrace(); |
143 |
} catch (com.iver.cit.gvsig.fmap.DriverException e) {
|
144 |
// TODO Auto-generated catch block
|
145 |
e.printStackTrace(); |
146 |
} catch (FactoryConfigurationError e) { |
147 |
// TODO Auto-generated catch block
|
148 |
e.printStackTrace(); |
149 |
} catch (SchemaException e) {
|
150 |
// TODO Auto-generated catch block
|
151 |
e.printStackTrace(); |
152 |
} |
153 |
|
154 |
} |
155 |
|
156 |
|
157 |
/**
|
158 |
* @see com.iver.andami.plugins.IExtension#isVisible()
|
159 |
*/
|
160 |
public boolean isVisible() { |
161 |
if (EditionUtilities.getEditionStatus() == EditionUtilities.EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE)
|
162 |
return true; |
163 |
return false; |
164 |
|
165 |
} |
166 |
} |
167 |
|