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