svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extCAD / src / com / iver / cit / gvsig / StopEditing.java @ 23535
History | View | Annotate | Download (16.1 KB)
1 | 4421 | fjp | package com.iver.cit.gvsig; |
---|---|---|---|
2 | |||
3 | 5807 | caballero | import java.awt.Component; |
4 | 12739 | caballero | import java.util.ArrayList; |
5 | 5267 | fjp | |
6 | 12739 | caballero | import javax.swing.ImageIcon; |
7 | 5267 | fjp | import javax.swing.JOptionPane; |
8 | |||
9 | 21911 | jmvivo | import org.gvsig.fmap.data.ReadException; |
10 | 23424 | vcaballero | import org.gvsig.fmap.data.WriteException; |
11 | import org.gvsig.fmap.data.feature.FeatureStore; |
||
12 | 22373 | jmvivo | import org.gvsig.fmap.data.feature.InitializeWriterException; |
13 | 21666 | vcaballero | import org.gvsig.fmap.mapcontext.MapContext; |
14 | import org.gvsig.fmap.mapcontext.exceptions.CancelEditingLayerException; |
||
15 | import org.gvsig.fmap.mapcontext.exceptions.LegendLayerException; |
||
16 | import org.gvsig.fmap.mapcontext.exceptions.StartEditionLayerException; |
||
17 | import org.gvsig.fmap.mapcontext.layers.FLayer; |
||
18 | import org.gvsig.fmap.mapcontext.layers.FLayers; |
||
19 | import org.gvsig.fmap.mapcontext.layers.LayersIterator; |
||
20 | import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
||
21 | import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend; |
||
22 | import org.gvsig.fmap.mapcontrol.MapControl; |
||
23 | |||
24 | 4421 | fjp | import com.iver.andami.PluginServices; |
25 | 5267 | fjp | import com.iver.andami.messages.NotificationManager; |
26 | 4421 | fjp | import com.iver.andami.plugins.Extension; |
27 | 12739 | caballero | import com.iver.andami.plugins.IExtension; |
28 | 12780 | caballero | import com.iver.andami.plugins.status.IExtensionStatus; |
29 | import com.iver.andami.plugins.status.IUnsavedData; |
||
30 | import com.iver.andami.plugins.status.UnsavedData; |
||
31 | 6002 | fjp | import com.iver.cit.gvsig.layers.VectorialLayerEdited; |
32 | 21666 | vcaballero | import com.iver.cit.gvsig.project.documents.table.exceptions.CancelEditingTableException; |
33 | 7304 | caballero | import com.iver.cit.gvsig.project.documents.table.gui.Table; |
34 | 7410 | caballero | import com.iver.cit.gvsig.project.documents.view.IProjectView; |
35 | 12739 | caballero | import com.iver.cit.gvsig.project.documents.view.ProjectView; |
36 | import com.iver.cit.gvsig.project.documents.view.ProjectViewFactory; |
||
37 | 7304 | caballero | import com.iver.cit.gvsig.project.documents.view.gui.View; |
38 | 12739 | caballero | import com.iver.cit.gvsig.project.documents.view.legend.CreateSpatialIndexMonitorableTask; |
39 | import com.iver.utiles.swing.threads.IMonitorableTask; |
||
40 | 4421 | fjp | |
41 | /**
|
||
42 | * @author Francisco Jos?
|
||
43 | 5482 | caballero | *
|
44 | 4430 | fjp | * Cuando un tema se pone en edici?n, puede que su driver implemente
|
45 | * ISpatialWriter. En ese caso, es capaz de guardarse sobre s? mismo. Si no lo
|
||
46 | * implementa, esta opci?n estar? deshabilitada y la ?nica posibilidad de
|
||
47 | * guardar este tema ser? "Guardando como..."
|
||
48 | 4421 | fjp | */
|
49 | 5005 | jorpiell | public class StopEditing extends Extension { |
50 | 4430 | fjp | private View vista; |
51 | |||
52 | 4421 | fjp | /**
|
53 | 5005 | jorpiell | * @see com.iver.andami.plugins.IExtension#initialize()
|
54 | 4430 | fjp | */
|
55 | 5005 | jorpiell | public void initialize() { |
56 | 4430 | fjp | } |
57 | 4421 | fjp | |
58 | 4430 | fjp | /**
|
59 | 5005 | jorpiell | * @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
|
60 | 4430 | fjp | */
|
61 | public void execute(String s) { |
||
62 | 6877 | cesar | com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
63 | 6880 | cesar | .getActiveWindow(); |
64 | 4421 | fjp | |
65 | 4430 | fjp | vista = (View) f;
|
66 | 5807 | caballero | boolean isStop=false; |
67 | 7410 | caballero | IProjectView model = vista.getModel(); |
68 | 6878 | cesar | MapContext mapa = model.getMapContext(); |
69 | 4430 | fjp | FLayers layers = mapa.getLayers(); |
70 | 4475 | fjp | EditionManager edMan = CADExtension.getEditionManager(); |
71 | 4430 | fjp | if (s.equals("STOPEDITING")) { |
72 | 18453 | vcaballero | vista.getMapControl().getCanceldraw().setCanceled(true);
|
73 | 4430 | fjp | FLayer[] actives = layers.getActives();
|
74 | // TODO: Comprobar que solo hay una activa, o al menos
|
||
75 | // que solo hay una en edici?n que est? activa, etc, etc
|
||
76 | for (int i = 0; i < actives.length; i++) { |
||
77 | if (actives[i] instanceof FLyrVect && actives[i].isEditing()) { |
||
78 | FLyrVect lv = (FLyrVect) actives[i]; |
||
79 | 6604 | caballero | MapControl mapControl = vista.getMapControl(); |
80 | 14877 | vcaballero | VectorialLayerEdited lyrEd = (VectorialLayerEdited) edMan.getActiveLayerEdited(); |
81 | try {
|
||
82 | 23424 | vcaballero | lv.getFeatureStore().deleteObservers(); |
83 | 21666 | vcaballero | } catch (ReadException e) {
|
84 | 14877 | vcaballero | NotificationManager.addError("Remove Selection Listener",e);
|
85 | } |
||
86 | 5807 | caballero | isStop=stopEditing(lv, mapControl); |
87 | 7833 | jmvivo | if (isStop){
|
88 | 8934 | caballero | lv.removeLayerListener(edMan); |
89 | 23424 | vcaballero | // if (lv instanceof FLyrAnnotation){
|
90 | // FLyrAnnotation lva=(FLyrAnnotation)lv;
|
||
91 | // lva.setMapping(lva.getMapping());
|
||
92 | // }
|
||
93 | 7833 | jmvivo | } |
94 | 4430 | fjp | } |
95 | } |
||
96 | 5807 | caballero | if (isStop) {
|
97 | vista.getMapControl().setTool("zoomIn");
|
||
98 | vista.hideConsole(); |
||
99 | 14482 | vcaballero | vista.repaintMap(); |
100 | 7833 | jmvivo | CADExtension.clearView(); |
101 | 8934 | caballero | |
102 | 5807 | caballero | } |
103 | 4430 | fjp | } |
104 | PluginServices.getMainFrame().enableControls(); |
||
105 | } |
||
106 | 4421 | fjp | |
107 | 4430 | fjp | /**
|
108 | 5005 | jorpiell | * @see com.iver.andami.plugins.IExtension#isEnabled()
|
109 | 4430 | fjp | */
|
110 | 5267 | fjp | public boolean isEnabled() { |
111 | 4430 | fjp | FLayer[] lyrs = EditionUtilities.getActiveAndEditedLayers();
|
112 | 5267 | fjp | if (lyrs == null) |
113 | return false; |
||
114 | 4430 | fjp | FLyrVect lyrVect = (FLyrVect) lyrs[0];
|
115 | 23086 | vcaballero | if (lyrVect.isEditing()) {
|
116 | 5807 | caballero | return true; |
117 | 4950 | caballero | } |
118 | return false; |
||
119 | 5267 | fjp | } |
120 | 4430 | fjp | /**
|
121 | * DOCUMENT ME!
|
||
122 | */
|
||
123 | 5807 | caballero | public boolean stopEditing(FLyrVect layer, MapControl mapControl) { |
124 | 23424 | vcaballero | FeatureStore featureStore=null;
|
125 | try {
|
||
126 | featureStore = layer.getFeatureStore(); |
||
127 | } catch (ReadException e1) {
|
||
128 | // TODO Auto-generated catch block
|
||
129 | e1.printStackTrace(); |
||
130 | } |
||
131 | // VectorialEditableAdapter vea = (VectorialEditableAdapter) layer
|
||
132 | // .getSource();
|
||
133 | 5807 | caballero | int resp = JOptionPane.NO_OPTION; |
134 | 4950 | caballero | |
135 | 4421 | fjp | try {
|
136 | 6856 | fjp | if (layer.isWritable()) {
|
137 | 5807 | caballero | resp = JOptionPane.showConfirmDialog((Component) PluginServices |
138 | .getMainFrame(), PluginServices.getText(this,
|
||
139 | "realmente_desea_guardar_la_capa")
|
||
140 | 12295 | caballero | + " : " + layer.getName()+"?", PluginServices.getText(this, |
141 | 5807 | caballero | "guardar"), JOptionPane.YES_NO_OPTION); |
142 | if (resp != JOptionPane.YES_OPTION) { // CANCEL EDITING |
||
143 | cancelEdition(layer); |
||
144 | } else { // GUARDAMOS EL TEMA |
||
145 | saveLayer(layer); |
||
146 | 5267 | fjp | } |
147 | 5807 | caballero | |
148 | 23424 | vcaballero | featureStore.getCommandsRecord().deleteObservers(); |
149 | 5807 | caballero | layer.setEditing(false);
|
150 | 23424 | vcaballero | // if (layer.isSpatiallyIndexed())
|
151 | // {
|
||
152 | // if(vea.getSpatialIndex() != null)
|
||
153 | // {
|
||
154 | // layer.setISpatialIndex(vea.getSpatialIndex());
|
||
155 | // if(layer.getISpatialIndex() instanceof IPersistentSpatialIndex)
|
||
156 | // ((IPersistentSpatialIndex) layer.getISpatialIndex()).flush();
|
||
157 | // PluginServices.
|
||
158 | // cancelableBackgroundExecution(new CreateSpatialIndexMonitorableTask(layer));
|
||
159 | //
|
||
160 | // }
|
||
161 | // }
|
||
162 | 18248 | vcaballero | |
163 | 5807 | caballero | return true; |
164 | 6604 | caballero | } |
165 | // Si no existe writer para la capa que tenemos en edici?n
|
||
166 | 5807 | caballero | resp = JOptionPane
|
167 | .showConfirmDialog( |
||
168 | (Component) PluginServices.getMainFrame(),
|
||
169 | PluginServices |
||
170 | .getText( |
||
171 | this,
|
||
172 | 6856 | fjp | "no_existe_writer_para_este_formato_de_capa_o_no_tiene_permisos_de_escritura_los_datos_no_se_guardaran_desea_continuar")
|
173 | 5807 | caballero | + " : " + layer.getName(),
|
174 | 6856 | fjp | PluginServices.getText(this, "cancelar_edicion"), |
175 | 5807 | caballero | JOptionPane.YES_NO_OPTION);
|
176 | if (resp == JOptionPane.YES_OPTION) { // CANCEL EDITING |
||
177 | cancelEdition(layer); |
||
178 | 15803 | vcaballero | |
179 | 23424 | vcaballero | featureStore.getCommandsRecord().deleteObservers(); |
180 | // if (!(layer.getSource().getDriver() instanceof IndexedShpDriver)){
|
||
181 | // VectorialLayerEdited vle=(VectorialLayerEdited)CADExtension.getEditionManager().getLayerEdited(layer);
|
||
182 | // layer.setLegend((IVectorLegend)vle.getLegend());
|
||
183 | // }
|
||
184 | 15803 | vcaballero | layer.setEditing(false);
|
185 | 5807 | caballero | return true; |
186 | 5571 | jmvivo | } |
187 | 6604 | caballero | |
188 | 10626 | caballero | } catch (StartEditionLayerException e) {
|
189 | 5267 | fjp | NotificationManager.addError(e); |
190 | 21666 | vcaballero | } catch (ReadException e) {
|
191 | 5807 | caballero | NotificationManager.addError(e); |
192 | 10626 | caballero | } catch (InitializeWriterException e) {
|
193 | NotificationManager.addError(e); |
||
194 | } catch (CancelEditingTableException e) {
|
||
195 | NotificationManager.addError(e); |
||
196 | 11468 | caballero | } catch (CancelEditingLayerException e) {
|
197 | NotificationManager.addError(e); |
||
198 | 4421 | fjp | } |
199 | 5807 | caballero | return false; |
200 | 4950 | caballero | |
201 | 5267 | fjp | } |
202 | |||
203 | 5807 | caballero | |
204 | 23424 | vcaballero | private void saveLayer(FLyrVect layer) throws ReadException, InitializeWriterException{ |
205 | 12739 | caballero | layer.setProperty("stoppingEditing",new Boolean(true)); |
206 | 23424 | vcaballero | FeatureStore featureStore=layer.getFeatureStore(); |
207 | // VectorialEditableAdapter vea = (VectorialEditableAdapter) layer
|
||
208 | // .getSource();
|
||
209 | 5807 | caballero | |
210 | 23424 | vcaballero | // ISpatialWriter writer = (ISpatialWriter) vea.getWriter();
|
211 | 6877 | cesar | com.iver.andami.ui.mdiManager.IWindow[] views = PluginServices
|
212 | 6880 | cesar | .getMDIManager().getAllWindows(); |
213 | 5807 | caballero | for (int j = 0; j < views.length; j++) { |
214 | if (views[j] instanceof Table) { |
||
215 | Table table = (Table) views[j]; |
||
216 | if (table.getModel().getAssociatedTable() != null |
||
217 | && table.getModel().getAssociatedTable().equals(layer)) { |
||
218 | table.stopEditingCell(); |
||
219 | } |
||
220 | } |
||
221 | } |
||
222 | 23424 | vcaballero | // vea.cleanSelectableDatasource();
|
223 | // layer.setRecordset(vea.getRecordset()); // Queremos que el recordset del layer
|
||
224 | 6483 | fjp | // refleje los cambios en los campos.
|
225 | 23424 | vcaballero | // ILayerDefinition lyrDef = EditionUtilities.createLayerDefinition(layer);
|
226 | 6483 | fjp | String aux="FIELDS:"; |
227 | 23424 | vcaballero | // FieldDescription[] flds = lyrDef.getFieldsDesc();
|
228 | // for (int i=0; i < flds.length; i++){
|
||
229 | // aux = aux + ", " + flds[i].getFieldAlias();
|
||
230 | // }
|
||
231 | // System.err.println("Escribiendo la capa " + lyrDef.getName() +
|
||
232 | // " con los campos " + aux);
|
||
233 | // lyrDef.setShapeType(layer.getShapeType());
|
||
234 | // writer.initialize(lyrDef);
|
||
235 | // vea.stopEdition(writer, EditionEvent.GRAPHIC);
|
||
236 | try {
|
||
237 | featureStore.finishEditing(); |
||
238 | } catch (WriteException e) {
|
||
239 | // TODO Auto-generated catch block
|
||
240 | e.printStackTrace(); |
||
241 | 6483 | fjp | } |
242 | 12739 | caballero | layer.setProperty("stoppingEditing",new Boolean(false)); |
243 | 5807 | caballero | } |
244 | |||
245 | 11468 | caballero | private void cancelEdition(FLyrVect layer) throws CancelEditingTableException, CancelEditingLayerException { |
246 | 12739 | caballero | layer.setProperty("stoppingEditing",new Boolean(true)); |
247 | 6877 | cesar | com.iver.andami.ui.mdiManager.IWindow[] views = PluginServices
|
248 | 6880 | cesar | .getMDIManager().getAllWindows(); |
249 | 23424 | vcaballero | FeatureStore featureStore=null;
|
250 | try {
|
||
251 | featureStore = layer.getFeatureStore(); |
||
252 | } catch (ReadException e) {
|
||
253 | // TODO Auto-generated catch block
|
||
254 | e.printStackTrace(); |
||
255 | } |
||
256 | featureStore.cancelEditing(); |
||
257 | // VectorialEditableAdapter vea = (VectorialEditableAdapter) layer
|
||
258 | // .getSource();
|
||
259 | // vea.cancelEdition(EditionEvent.GRAPHIC);
|
||
260 | 5807 | caballero | for (int j = 0; j < views.length; j++) { |
261 | if (views[j] instanceof Table) { |
||
262 | Table table = (Table) views[j]; |
||
263 | if (table.getModel().getAssociatedTable() != null |
||
264 | && table.getModel().getAssociatedTable().equals(layer)) { |
||
265 | table.cancelEditing(); |
||
266 | } |
||
267 | } |
||
268 | } |
||
269 | 12739 | caballero | layer.setProperty("stoppingEditing",new Boolean(false)); |
270 | 5807 | caballero | } |
271 | 4430 | fjp | /**
|
272 | 5005 | jorpiell | * @see com.iver.andami.plugins.IExtension#isVisible()
|
273 | 4430 | fjp | */
|
274 | public boolean isVisible() { |
||
275 | if (EditionUtilities.getEditionStatus() == EditionUtilities.EDITION_STATUS_ONE_VECTORIAL_LAYER_ACTIVE_AND_EDITABLE)
|
||
276 | return true; |
||
277 | 6604 | caballero | return false; |
278 | 4421 | fjp | |
279 | 4430 | fjp | } |
280 | 12739 | caballero | public IExtensionStatus getStatus() {
|
281 | return new StopEditingStatus(); |
||
282 | } |
||
283 | /**
|
||
284 | * Show the dialogs to save the layer without ask if don't like to save.
|
||
285 | * @param layer Layer to save.
|
||
286 | */
|
||
287 | public boolean executeSaveLayer(FLyrVect layer ) { |
||
288 | EditionManager edMan = CADExtension.getEditionManager(); |
||
289 | VectorialLayerEdited lyrEd = (VectorialLayerEdited) edMan.getLayerEdited(layer); |
||
290 | boolean isStop=false; |
||
291 | try {
|
||
292 | lyrEd.clearSelection(false);
|
||
293 | |||
294 | |||
295 | if (layer.isWritable()) {
|
||
296 | saveLayer(layer); |
||
297 | layer.setEditing(false);
|
||
298 | 23424 | vcaballero | // if (layer.isSpatiallyIndexed())
|
299 | // {
|
||
300 | // if(layer.getISpatialIndex() != null)
|
||
301 | // {
|
||
302 | // PluginServices.
|
||
303 | // cancelableBackgroundExecution(new CreateSpatialIndexMonitorableTask((FLyrVect)layer));
|
||
304 | // }
|
||
305 | // }
|
||
306 | 12739 | caballero | |
307 | isStop=true;
|
||
308 | }else {
|
||
309 | // Si no existe writer para la capa que tenemos en edici?n
|
||
310 | int resp = JOptionPane |
||
311 | .showConfirmDialog( |
||
312 | (Component) PluginServices.getMainFrame(),
|
||
313 | PluginServices |
||
314 | .getText( |
||
315 | this,
|
||
316 | "no_existe_writer_para_este_formato_de_capa_o_no_tiene_permisos_de_escritura_los_datos_no_se_guardaran_desea_continuar")
|
||
317 | + " : " + layer.getName(),
|
||
318 | PluginServices.getText(this, "cancelar_edicion"), |
||
319 | JOptionPane.YES_NO_OPTION);
|
||
320 | if (resp == JOptionPane.YES_OPTION) { // CANCEL EDITING |
||
321 | try {
|
||
322 | cancelEdition(layer); |
||
323 | layer.setEditing(false);
|
||
324 | 23424 | vcaballero | // if (!(layer.getSource().getDriver() instanceof IndexedShpDriver)){
|
325 | // VectorialLayerEdited vle=(VectorialLayerEdited)CADExtension.getEditionManager().getLayerEdited(layer);
|
||
326 | // layer.setLegend((IVectorLegend)vle.getLegend());
|
||
327 | // }
|
||
328 | 12739 | caballero | } catch (CancelEditingTableException e) {
|
329 | PluginServices.getLogger().error(e.getMessage(),e); |
||
330 | // NotificationManager.addError(e.getMessage(),e);
|
||
331 | return isStop;
|
||
332 | } catch (CancelEditingLayerException e) {
|
||
333 | PluginServices.getLogger().error(e.getMessage(),e); |
||
334 | // NotificationManager.addError(e.getMessage(),e);
|
||
335 | return isStop;
|
||
336 | } |
||
337 | isStop=true;
|
||
338 | } |
||
339 | |||
340 | } |
||
341 | // boolean isStop=stopEditing((FLyrVect)layer, null);
|
||
342 | if (isStop){
|
||
343 | layer.removeLayerListener(edMan); |
||
344 | 23424 | vcaballero | // if (layer instanceof FLyrAnnotation){
|
345 | // FLyrAnnotation lva=(FLyrAnnotation)layer;
|
||
346 | // lva.setMapping(lva.getMapping());
|
||
347 | // }
|
||
348 | 12739 | caballero | com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
349 | .getActiveWindow(); |
||
350 | if (f instanceof View) { |
||
351 | vista = (View) f;
|
||
352 | if (vista.getMapControl().getMapContext().getLayers().getLayer(layer.getName()).equals(layer)) {
|
||
353 | vista.getMapControl().setTool("zoomIn");
|
||
354 | vista.hideConsole(); |
||
355 | vista.repaintMap(); |
||
356 | CADExtension.clearView(); |
||
357 | } |
||
358 | } |
||
359 | } |
||
360 | 21666 | vcaballero | } catch (ReadException e1) {
|
361 | 12739 | caballero | PluginServices.getLogger().error(e1.getMessage(),e1); |
362 | // NotificationManager.addError(e.getMessage(),e);
|
||
363 | } catch (StartEditionLayerException e) {
|
||
364 | PluginServices.getLogger().error(e.getMessage(),e); |
||
365 | // NotificationManager.addError(e.getMessage(),e);
|
||
366 | } catch (InitializeWriterException e) {
|
||
367 | PluginServices.getLogger().error(e.getMessage(),e); |
||
368 | // NotificationManager.addError(e.getMessage(),e);
|
||
369 | } |
||
370 | return isStop;
|
||
371 | } |
||
372 | |||
373 | private class UnsavedLayer extends UnsavedData{ |
||
374 | |||
375 | private FLayer layer;
|
||
376 | |||
377 | public UnsavedLayer(IExtension extension) {
|
||
378 | super(extension);
|
||
379 | } |
||
380 | |||
381 | public String getDescription() { |
||
382 | return PluginServices.getText(this,"editing_layer_unsaved"); |
||
383 | } |
||
384 | |||
385 | public String getResourceName() { |
||
386 | return layer.getName();
|
||
387 | } |
||
388 | |||
389 | |||
390 | |||
391 | public boolean saveData() { |
||
392 | return executeSaveLayer((FLyrVect)layer);
|
||
393 | } |
||
394 | |||
395 | public void setLayer(FLayer layer) { |
||
396 | this.layer=layer;
|
||
397 | |||
398 | } |
||
399 | |||
400 | public ImageIcon getIcon() { |
||
401 | return layer.getTocImageIcon();
|
||
402 | } |
||
403 | |||
404 | } |
||
405 | |||
406 | /**
|
||
407 | * <p>This class provides the status of extensions.
|
||
408 | * If this extension has some unsaved editing layer (and save them), and methods
|
||
409 | * to check if the extension has some associated background tasks.
|
||
410 | *
|
||
411 | * @author Vicente Caballero Navarro
|
||
412 | *
|
||
413 | */
|
||
414 | private class StopEditingStatus implements IExtensionStatus { |
||
415 | /**
|
||
416 | * This method is used to check if this extension has some unsaved editing layer.
|
||
417 | *
|
||
418 | * @return true if the extension has some unsaved editing layer, false otherwise.
|
||
419 | */
|
||
420 | public boolean hasUnsavedData() { |
||
421 | ProjectExtension pe=(ProjectExtension)PluginServices.getExtension(ProjectExtension.class); |
||
422 | ProjectView[] views=(ProjectView[])pe.getProject().getDocumentsByType(ProjectViewFactory.registerName).toArray(new ProjectView[0]); |
||
423 | for (int i=0;i<views.length;i++) { |
||
424 | FLayers layers=views[i].getMapContext().getLayers(); |
||
425 | LayersIterator iter = getEditingLayer(layers); |
||
426 | if (iter.hasNext()) {
|
||
427 | return true; |
||
428 | } |
||
429 | } |
||
430 | return false; |
||
431 | } |
||
432 | /**
|
||
433 | * This method is used to check if the extension has some associated
|
||
434 | * background process which is currently running.
|
||
435 | *
|
||
436 | * @return true if the extension has some associated background process,
|
||
437 | * false otherwise.
|
||
438 | */
|
||
439 | public boolean hasRunningProcesses() { |
||
440 | return false; |
||
441 | } |
||
442 | /**
|
||
443 | * <p>Gets an array of the traceable background tasks associated with this
|
||
444 | * extension. These tasks may be tracked, canceled, etc.</p>
|
||
445 | *
|
||
446 | * @return An array of the associated background tasks, or null in case there is
|
||
447 | * no associated background tasks.
|
||
448 | */
|
||
449 | public IMonitorableTask[] getRunningProcesses() { |
||
450 | return null; |
||
451 | } |
||
452 | /**
|
||
453 | * <p>Gets an array of the UnsavedData objects, which contain information about
|
||
454 | * the unsaved editing layers and allows to save it.</p>
|
||
455 | *
|
||
456 | * @return An array of the associated unsaved editing layers, or null in case the extension
|
||
457 | * has not unsaved editing layers.
|
||
458 | */
|
||
459 | public IUnsavedData[] getUnsavedData() { |
||
460 | ProjectExtension pe=(ProjectExtension)PluginServices.getExtension(ProjectExtension.class); |
||
461 | ProjectView[] views=(ProjectView[])pe.getProject().getDocumentsByType(ProjectViewFactory.registerName).toArray(new ProjectView[0]); |
||
462 | ArrayList unsavedLayers=new ArrayList(); |
||
463 | for (int i=0;i<views.length;i++) { |
||
464 | FLayers layers = views[i].getMapContext().getLayers(); |
||
465 | LayersIterator iter = getEditingLayer(layers); |
||
466 | while (iter.hasNext()){
|
||
467 | UnsavedLayer ul=new UnsavedLayer(StopEditing.this);
|
||
468 | ul.setLayer(iter.nextLayer()); |
||
469 | unsavedLayers.add(ul); |
||
470 | } |
||
471 | } |
||
472 | return (IUnsavedData[])unsavedLayers.toArray(new IUnsavedData[0]); |
||
473 | } |
||
474 | } |
||
475 | private LayersIterator getEditingLayer(FLayers layers){
|
||
476 | return new LayersIterator(layers){ |
||
477 | public boolean evaluate(FLayer layer) { |
||
478 | return layer.isEditing();
|
||
479 | } |
||
480 | }; |
||
481 | } |
||
482 | 4421 | fjp | } |