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