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