root / branches / v2_0_0_prep / extensions / extEditing / src / org / gvsig / editing / StartEditing.java @ 29616
History | View | Annotate | Download (7.64 KB)
1 |
package org.gvsig.editing; |
---|---|
2 |
|
3 |
import java.awt.Component; |
4 |
|
5 |
import javax.swing.JOptionPane; |
6 |
|
7 |
import org.gvsig.andami.PluginServices; |
8 |
import org.gvsig.andami.messages.NotificationManager; |
9 |
import org.gvsig.andami.plugins.Extension; |
10 |
import org.gvsig.app.extension.ProjectExtension; |
11 |
import org.gvsig.app.project.documents.table.FeatureTableDocument; |
12 |
import org.gvsig.app.project.documents.view.IProjectView; |
13 |
import org.gvsig.app.project.documents.view.gui.View; |
14 |
import org.gvsig.editing.gui.cad.CADTool; |
15 |
import org.gvsig.editing.gui.tokenmarker.ConsoleToken; |
16 |
import org.gvsig.fmap.dal.exception.DataException; |
17 |
import org.gvsig.fmap.dal.exception.ReadException; |
18 |
import org.gvsig.fmap.dal.feature.FeatureType; |
19 |
import org.gvsig.fmap.mapcontext.exceptions.StartEditionLayerException; |
20 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
21 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
22 |
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
23 |
import org.gvsig.fmap.mapcontrol.MapControl; |
24 |
import org.gvsig.utils.XMLException; |
25 |
import org.gvsig.utils.console.jedit.KeywordMap; |
26 |
import org.gvsig.utils.console.jedit.Token; |
27 |
|
28 |
|
29 |
/**
|
30 |
* DOCUMENT ME!
|
31 |
*
|
32 |
* @author Vicente Caballero Navarro
|
33 |
*/
|
34 |
public class StartEditing extends Extension { |
35 |
|
36 |
// private class MyAction extends AbstractAction
|
37 |
// {
|
38 |
//
|
39 |
// public void actionPerformed(ActionEvent e) {
|
40 |
// System.err.println("F3");
|
41 |
// }
|
42 |
//
|
43 |
// }
|
44 |
|
45 |
//View vista;
|
46 |
/**
|
47 |
* @see org.gvsig.andami.plugins.IExtension#initialize()
|
48 |
*/
|
49 |
public void initialize() { |
50 |
} |
51 |
|
52 |
/**
|
53 |
* @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String)
|
54 |
*/
|
55 |
public void execute(String actionCommand) { |
56 |
CADExtension.initFocus(); |
57 |
org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
58 |
.getActiveWindow(); |
59 |
|
60 |
if (f instanceof View) { |
61 |
View vista = (View) f; |
62 |
|
63 |
MapControl mapControl = vista.getMapControl(); |
64 |
mapControl.initializeSnapping(); |
65 |
IProjectView model = vista.getModel(); |
66 |
FLayer[] actives = model.getMapContext().getLayers().getActives();
|
67 |
|
68 |
boolean bEditingStarted = false; |
69 |
if (actives.length == 1 && actives[0] instanceof FLyrVect) { |
70 |
|
71 |
vista.showConsole(); |
72 |
EditionManager editionManager=CADExtension.getEditionManager(); |
73 |
editionManager.setMapControl(mapControl); |
74 |
/*
|
75 |
* for (int j = 0; j < i; j++) {
|
76 |
* layers.getLayer(j).setVisible(false); }
|
77 |
*/
|
78 |
|
79 |
FLyrVect lv = (FLyrVect) actives[0];
|
80 |
// lv.setVisible(true);
|
81 |
lv.addLayerListener(editionManager); |
82 |
try {
|
83 |
ILegend legendOriginal=lv.getLegend().cloneLegend(); |
84 |
|
85 |
if (!lv.isWritable())
|
86 |
{ |
87 |
JOptionPane.showMessageDialog(
|
88 |
(Component) PluginServices.getMDIManager().getActiveWindow(),
|
89 |
PluginServices.getText(this, "this_layer_is_not_self_editable"), |
90 |
PluginServices.getText(this, "warning_title"), |
91 |
JOptionPane.WARNING_MESSAGE);
|
92 |
} |
93 |
|
94 |
lv.setEditing(true);
|
95 |
// FeatureType featureType=lv.getFeatureStore().getDefaultFeatureType();
|
96 |
// featureType.getRules().clear();
|
97 |
// if (lv.getShapeType()==Geometry.TYPES.SURFACE){
|
98 |
// FeatureRule rulePol = new FeatureRulePolygon("PolygonRule", "Sentido correcto de un pol?gono");
|
99 |
// featureType.addRule(rulePol);
|
100 |
// }
|
101 |
|
102 |
// if (!(lv.getSource().getDriver() instanceof IndexedShpDriver)){
|
103 |
// VectorialLayerEdited vle=(VectorialLayerEdited)editionManager.getLayerEdited(lv);
|
104 |
// vle.setLegend(legendOriginal);
|
105 |
// }
|
106 |
lv.getFeatureStore().addObserver(mapControl); |
107 |
// vea.getCommandRecord().addCommandListener(mapControl);
|
108 |
// Si existe una tabla asociada a esta capa se cambia su
|
109 |
// modelo por el VectorialEditableAdapter.
|
110 |
ProjectExtension pe = (ProjectExtension) PluginServices |
111 |
.getExtension(ProjectExtension.class); |
112 |
FeatureTableDocument pt = pe.getProject().getTable(lv); |
113 |
if (pt != null){ |
114 |
pt.setStore(lv.getFeatureStore()); |
115 |
// changeModelTable(pt,vea);
|
116 |
} |
117 |
|
118 |
startCommandsApplicable(vista,lv); |
119 |
vista.repaintMap(); |
120 |
|
121 |
} catch (XMLException e) {
|
122 |
NotificationManager.addError(e.getMessage(),e); |
123 |
} catch (StartEditionLayerException e) {
|
124 |
NotificationManager.addError(e.getMessage(),e); |
125 |
} catch (ReadException e) {
|
126 |
NotificationManager.addError(e.getMessage(),e); |
127 |
} catch (DataException e) {
|
128 |
NotificationManager.addError(e.getMessage(),e); |
129 |
} |
130 |
|
131 |
// return;
|
132 |
} |
133 |
} |
134 |
|
135 |
/*
|
136 |
* PluginServices.getMDIManager().setWaitCursor(); try { if
|
137 |
* (((FLyrVect) capa).getSource().getDriver().getClass() ==
|
138 |
* DXFCadDriver.class) { if (JOptionPane.showConfirmDialog(
|
139 |
* (Component) PluginServices.getMainFrame(), "Todas las geometr?as
|
140 |
* del formato DXF no se pueden editar, de momento podemos editar:
|
141 |
* Line, Point, Polyline, Arc, Circle y Ellipse. \n El resto de
|
142 |
* geometr?as se perder?n con la edici?n. \n ?Desea continuar?") ==
|
143 |
* JOptionPane.YES_OPTION) { capa.startEdition();
|
144 |
* vista.getMapControl().setCadTool("selection"); } else { } } else {
|
145 |
* capa.startEdition();
|
146 |
* vista.getMapControl().setCadTool("selection"); } } catch
|
147 |
* (EditionException e) { // TODO Auto-generated catch block
|
148 |
* e.printStackTrace(); }
|
149 |
* PluginServices.getMDIManager().restoreCursor();
|
150 |
*/
|
151 |
// vista.getMapControl().drawMap(false);
|
152 |
} |
153 |
|
154 |
// private void registerKeyStrokes() {
|
155 |
// JComponent theComponent = vista.getConsolePanel().getTxt();
|
156 |
//
|
157 |
// // The actions
|
158 |
// Action F3Action = new AbstractAction("REFENT") {
|
159 |
// public void actionPerformed(ActionEvent evt) {
|
160 |
// System.err.println("SOY F3");
|
161 |
// }
|
162 |
// };
|
163 |
//
|
164 |
// InputMap inputMap = theComponent.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
|
165 |
// inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0), F3Action.getValue(Action.NAME));
|
166 |
//
|
167 |
// ActionMap actionMap = theComponent.getActionMap();
|
168 |
// // actionMap.put("REFENT", new MyAction());
|
169 |
// actionMap.put(F3Action.getValue(Action.NAME), F3Action);
|
170 |
//
|
171 |
// }
|
172 |
|
173 |
public static void startCommandsApplicable(View vista,FLyrVect lv) { |
174 |
if (vista==null) |
175 |
vista=(View)PluginServices.getMDIManager().getActiveWindow();
|
176 |
CADTool[] cadtools = CADExtension.getCADTools();
|
177 |
KeywordMap keywordMap = new KeywordMap(true); |
178 |
for (int i = 0; i < cadtools.length; i++) { |
179 |
try {
|
180 |
if (cadtools[i].isApplicable(lv.getShapeType())){
|
181 |
keywordMap.add(cadtools[i].getName(), Token.KEYWORD2); |
182 |
keywordMap.add(cadtools[i].toString(), Token.KEYWORD3); |
183 |
} |
184 |
} catch (ReadException e) {
|
185 |
NotificationManager.addError(e.getMessage(),e); |
186 |
} |
187 |
|
188 |
} |
189 |
ConsoleToken consoletoken = new ConsoleToken(keywordMap);
|
190 |
vista.getConsolePanel().setTokenMarker(consoletoken); |
191 |
|
192 |
} |
193 |
|
194 |
// private void changeModelTable(ProjectTable pt, VectorialEditableAdapter vea){
|
195 |
// com.iver.andami.ui.mdiManager.IWindow[] views = PluginServices.getMDIManager().getAllWindows();
|
196 |
//
|
197 |
// for (int i=0 ; i<views.length ; i++){
|
198 |
// if (views[i] instanceof Table){
|
199 |
// Table table=(Table)views[i];
|
200 |
// ProjectTable model =table.getModel();
|
201 |
// if (model.equals(pt)){
|
202 |
// table.setModel(pt);
|
203 |
// vea.getCommandRecord().addCommandListener(table);
|
204 |
// }
|
205 |
// }
|
206 |
// }
|
207 |
// }
|
208 |
/**
|
209 |
* @see org.gvsig.andami.plugins.IExtension#isEnabled()
|
210 |
*/
|
211 |
public boolean isEnabled() { |
212 |
View f = (View) PluginServices.getMDIManager().getActiveWindow(); |
213 |
|
214 |
if (f == null) { |
215 |
return false; |
216 |
} |
217 |
|
218 |
FLayer[] selected = f.getModel().getMapContext().getLayers()
|
219 |
.getActives(); |
220 |
if (selected.length == 1 && selected[0].isAvailable() && selected[0] instanceof FLyrVect) { |
221 |
if (selected[0].isEditing()) |
222 |
return false; |
223 |
return true; |
224 |
} |
225 |
return false; |
226 |
} |
227 |
|
228 |
/**
|
229 |
* @see org.gvsig.andami.plugins.IExtension#isVisible()
|
230 |
*/
|
231 |
public boolean isVisible() { |
232 |
org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
233 |
.getActiveWindow(); |
234 |
|
235 |
if (f == null) { |
236 |
return false; |
237 |
} |
238 |
|
239 |
if (f instanceof View) |
240 |
return true; |
241 |
return false; |
242 |
} |
243 |
} |