root / tags / v1_0_2_Build_908 / extensions / extCAD / src / com / iver / cit / gvsig / StopEditingToShp.java @ 11054
History | View | Annotate | Download (3.86 KB)
1 |
package com.iver.cit.gvsig; |
---|---|
2 |
|
3 |
import java.awt.Component; |
4 |
import java.io.File; |
5 |
|
6 |
import javax.swing.JFileChooser; |
7 |
|
8 |
import com.iver.andami.PluginServices; |
9 |
import com.iver.andami.plugins.Extension; |
10 |
import com.iver.cit.gvsig.fmap.MapContext; |
11 |
import com.iver.cit.gvsig.fmap.MapControl; |
12 |
import com.iver.cit.gvsig.fmap.edition.EditionEvent; |
13 |
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter; |
14 |
import com.iver.cit.gvsig.fmap.edition.writers.shp.ShpWriter; |
15 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
16 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
17 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
18 |
import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
19 |
import com.iver.cit.gvsig.project.documents.view.IProjectView; |
20 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
21 |
import com.iver.utiles.SimpleFileFilter; |
22 |
|
23 |
|
24 |
|
25 |
|
26 |
/**
|
27 |
* DOCUMENT ME!
|
28 |
*
|
29 |
* @author Vicente Caballero Navarro
|
30 |
*/
|
31 |
public class StopEditingToShp extends Extension { |
32 |
private View vista; |
33 |
/**
|
34 |
* @see com.iver.andami.plugins.IExtension#initialize()
|
35 |
*/
|
36 |
public void initialize() { |
37 |
} |
38 |
|
39 |
/**
|
40 |
* @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
|
41 |
*/
|
42 |
public void execute(String s) { |
43 |
com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
44 |
.getActiveWindow(); |
45 |
|
46 |
vista = (View) f;
|
47 |
|
48 |
IProjectView model = vista.getModel(); |
49 |
MapContext mapa = model.getMapContext(); |
50 |
FLayers layers = mapa.getLayers(); |
51 |
if (s.equals("STOPEDITING")) |
52 |
{ |
53 |
FLayer[] actives = layers.getActives();
|
54 |
// TODO: Comprobar que solo hay una activa, o al menos
|
55 |
// que solo hay una en edici?n que est? activa, etc, etc
|
56 |
for (int i = 0; i < actives.length; i++) |
57 |
{ |
58 |
if (actives[i] instanceof FLyrVect && |
59 |
actives[i].isEditing()) |
60 |
{ |
61 |
FLyrVect lv = (FLyrVect) actives[i]; |
62 |
MapControl mapControl = vista.getMapControl(); |
63 |
stopEditing(lv,mapControl); |
64 |
} |
65 |
} |
66 |
} |
67 |
PluginServices.getMainFrame().enableControls(); |
68 |
} |
69 |
|
70 |
/**
|
71 |
* @see com.iver.andami.plugins.IExtension#isEnabled()
|
72 |
*/
|
73 |
public boolean isEnabled() { |
74 |
return true; |
75 |
} |
76 |
|
77 |
/**
|
78 |
* DOCUMENT ME!
|
79 |
*/
|
80 |
public void stopEditing(FLyrVect layer,MapControl mapControl) { |
81 |
try {
|
82 |
JFileChooser jfc = new JFileChooser(); |
83 |
SimpleFileFilter filterShp = new SimpleFileFilter("shp", PluginServices.getText(this,"shp_files")); |
84 |
jfc.setFileFilter(filterShp); |
85 |
if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) { |
86 |
File newFile = jfc.getSelectedFile();
|
87 |
String path = newFile.getAbsolutePath();
|
88 |
if (!(path.toLowerCase().endsWith(".shp"))) |
89 |
{ |
90 |
path = path + ".shp";
|
91 |
} |
92 |
newFile = new File(path); |
93 |
VectorialEditableAdapter vea = (VectorialEditableAdapter) layer.getSource(); |
94 |
// File newFile = vea.getDriver().
|
95 |
|
96 |
ShpWriter writer= (ShpWriter)LayerFactory.getWM().getWriter("Shape Writer");
|
97 |
writer.initialize(layer); |
98 |
|
99 |
vea.stopEdition(writer,EditionEvent.GRAPHIC); |
100 |
vea.getCommandRecord().removeCommandListener(mapControl); |
101 |
|
102 |
layer.setEditing(false);
|
103 |
vista.hideConsole(); |
104 |
} |
105 |
} catch (Exception e) { |
106 |
e.printStackTrace(); |
107 |
} |
108 |
} |
109 |
|
110 |
/**
|
111 |
* @see com.iver.andami.plugins.IExtension#isVisible()
|
112 |
*/
|
113 |
public boolean isVisible() { |
114 |
if (EditionUtilities.getEditionStatus() == EditionUtilities.EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE)
|
115 |
return true; |
116 |
return false; |
117 |
|
118 |
} |
119 |
} |