Revision 672 org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.app/org.gvsig.vectorediting.app.mainplugin/src/main/java/org/gvsig/vectorediting/app/mainplugin/EditingExtension.java
EditingExtension.java | ||
---|---|---|
25 | 25 |
|
26 | 26 |
import java.io.File; |
27 | 27 |
import java.util.ArrayList; |
28 |
import java.util.Iterator; |
|
29 | 28 |
import java.util.List; |
29 |
import javax.swing.JOptionPane; |
|
30 |
import org.apache.commons.io.FileUtils; |
|
30 | 31 |
|
31 | 32 |
import org.slf4j.Logger; |
32 | 33 |
import org.slf4j.LoggerFactory; |
33 | 34 |
|
34 | 35 |
import org.gvsig.andami.IconThemeHelper; |
35 | 36 |
import org.gvsig.andami.PluginServices; |
36 |
import org.gvsig.andami.PluginsLocator; |
|
37 |
import org.gvsig.andami.actioninfo.ActionInfoManager; |
|
38 | 37 |
import org.gvsig.andami.plugins.Extension; |
39 | 38 |
import org.gvsig.andami.plugins.IExtension; |
40 | 39 |
import org.gvsig.andami.plugins.status.IExtensionStatus; |
... | ... | |
44 | 43 |
import org.gvsig.andami.ui.mdiManager.SingletonWindow; |
45 | 44 |
import org.gvsig.app.ApplicationLocator; |
46 | 45 |
import org.gvsig.app.ApplicationManager; |
47 |
import org.gvsig.app.project.DocumentsContainer;
|
|
46 |
import org.gvsig.app.project.Project;
|
|
48 | 47 |
import org.gvsig.app.project.documents.Document; |
49 | 48 |
import org.gvsig.app.project.documents.gui.IDocumentWindow; |
50 | 49 |
import org.gvsig.app.project.documents.view.ViewDocument; |
50 |
import org.gvsig.app.project.documents.view.ViewManager; |
|
51 | 51 |
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
52 | 52 |
import org.gvsig.app.project.documents.view.gui.IView; |
53 | 53 |
import org.gvsig.app.project.documents.view.toc.actions.EndEditingTocMenuEntry; |
... | ... | |
82 | 82 |
|
83 | 83 |
public class EditingExtension extends Extension implements Observer { |
84 | 84 |
|
85 |
private static Logger logger = LoggerFactory.getLogger(EditingExtension.class); |
|
85 |
private static final Logger logger = LoggerFactory.getLogger(EditingExtension.class);
|
|
86 | 86 |
|
87 |
@Override |
|
87 | 88 |
public void execute(String actionCommand) { |
88 | 89 |
|
90 |
ApplicationManager application = ApplicationLocator.getManager(); |
|
89 | 91 |
IView view = getActiveView(); |
90 |
EditingSwingManager swingManager = |
|
91 |
EditingSwingLocator.getSwingManager(); |
|
92 |
EditingSwingManager swingManager = EditingSwingLocator.getSwingManager(); |
|
92 | 93 |
|
93 | 94 |
if (view != null) { |
94 | 95 |
|
95 | 96 |
FLyrVect layer = getActiveLayer(view); |
96 |
EditingContext editingContext =
|
|
97 |
swingManager.getEditingContext(view.getMapControl());
|
|
97 |
MapControl mapControl = view.getMapControl();
|
|
98 |
EditingContext editingContext = swingManager.getEditingContext(mapControl);
|
|
98 | 99 |
|
99 | 100 |
if ("start-editing".equals(actionCommand)) { |
100 | 101 |
|
101 | 102 |
if (canBeEdited(layer)) { |
102 |
MapControl mapControl = view.getMapControl(); |
|
103 |
StatusBarListener sbl = new StatusBarListener(mapControl); |
|
103 |
if( !mapControl.getProjection().equals(layer.getProjection()) ) { |
|
104 |
String msg = "_The_layer_is_reproyected_on_the_fly" |
|
105 |
+ "_Not_all_editing_tools_work_properly" |
|
106 |
+ "_When_you_finish_editing" |
|
107 |
+ "_will_only_export_the_changes_to_another_layer"; |
|
108 |
application.messageDialog(msg, "_Warning", JOptionPane.WARNING_MESSAGE); |
|
109 |
} |
|
104 | 110 |
editingContext.beginEdition(layer); |
105 | 111 |
editingContext.addObserver(this); |
106 | 112 |
ApplicationLocator.getManager().refreshMenusAndToolBars(); |
... | ... | |
117 | 123 |
} |
118 | 124 |
} |
119 | 125 |
|
126 |
@Override |
|
120 | 127 |
public void initialize() { |
121 | 128 |
registerIcons(); |
122 | 129 |
|
... | ... | |
148 | 155 |
|
149 | 156 |
MapControlLocator.getMapControlManager().addMapControlCreationListener(new MapControlCreationListener() { |
150 | 157 |
|
158 |
@Override |
|
151 | 159 |
public MapControl mapControlCreated(MapControl mapControl) { |
152 | 160 |
EditingContext editingContext = EditingSwingLocator.getSwingManager().getEditingContext(mapControl); |
153 | 161 |
StatusBarListener sbl = new StatusBarListener(mapControl); |
... | ... | |
166 | 174 |
*/ |
167 | 175 |
private void registerSymbols() { |
168 | 176 |
|
169 |
EditingProviderManager providerManager = |
|
170 |
EditingProviderLocator.getProviderManager(); |
|
177 |
EditingProviderManager providerManager = EditingProviderLocator.getProviderManager(); |
|
171 | 178 |
|
172 | 179 |
SymbolManager symbolManager = MapContextLocator.getSymbolManager(); |
173 |
File pluginFolder = getPlugin().getPluginDirectory(); |
|
174 |
String pathSeparator = System.getProperty("file.separator"); |
|
175 |
String symbolsPath = pluginFolder.getAbsolutePath()+pathSeparator+"symbols"+pathSeparator+"editing"; |
|
176 |
File symbolsFolder = new File(symbolsPath); |
|
180 |
File symbolsFolder = FileUtils.getFile(getPlugin().getPluginDirectory(), "symbols","editing"); |
|
177 | 181 |
ISymbol[] symbols = null; |
178 | 182 |
try { |
179 | 183 |
symbols = symbolManager.loadSymbols(symbolsFolder); |
180 | 184 |
} catch (SymbolException e) { |
181 |
logger.warn("No symbols loaded from "+symbolsPath, e);
|
|
185 |
logger.warn("No symbols loaded from "+symbolsFolder.getAbsolutePath(), e);
|
|
182 | 186 |
} |
183 | 187 |
|
184 | 188 |
if (symbols != null) { |
185 |
for (int i = 0; i < symbols.length; i++) { |
|
186 |
ISymbol symbol = symbols[i]; |
|
189 |
for (ISymbol symbol : symbols) { |
|
187 | 190 |
String description = symbol.getDescription(); |
188 | 191 |
providerManager.registerSymbol(description, symbol); |
189 | 192 |
} |
190 | 193 |
} |
191 | 194 |
} |
192 | 195 |
|
196 |
@Override |
|
193 | 197 |
public boolean isEnabled() { |
194 | 198 |
return true; |
195 | 199 |
} |
196 | 200 |
|
201 |
@Override |
|
197 | 202 |
public boolean isVisible() { |
198 | 203 |
return true; |
199 | 204 |
} |
... | ... | |
269 | 274 |
return null; |
270 | 275 |
} |
271 | 276 |
|
277 |
@Override |
|
272 | 278 |
public void update(Observable observable, Object notification) { |
273 | 279 |
|
274 | 280 |
if (notification instanceof Notification){ |
... | ... | |
277 | 283 |
Notification n = (Notification)notification; |
278 | 284 |
if (n.getType().equalsIgnoreCase(EditingContext.CHANGE_SELECTED_TOOL_NOTIFICATION)){ |
279 | 285 |
String name = (String)n.getValue(); |
280 |
logger.info("Changed selected tool to '{}'", name);
|
|
286 |
logger.trace("Changed selected tool to '{}'", name);
|
|
281 | 287 |
PluginServices.getMainFrame().setSelectedTool(name); |
282 | 288 |
appManager.refreshMenusAndToolBars(); |
283 | 289 |
|
... | ... | |
288 | 294 |
} |
289 | 295 |
|
290 | 296 |
private List<FLyrVect> getEditedLayers(){ |
291 |
List<FLyrVect> editedLayers = new ArrayList<FLyrVect>(); |
|
292 |
|
|
293 | 297 |
ApplicationManager application = ApplicationLocator.getManager(); |
294 |
IWindow[] windows = application.getUIManager().getOrderedWindows(); |
|
295 |
for (int i = 0; i < windows.length; i++) { |
|
296 |
IWindow window = windows[i]; |
|
297 |
if (window instanceof SingletonWindow && window instanceof IDocumentWindow) { |
|
298 |
// Recorremos las ventanas. |
|
299 |
// Cogemos el model de aquellas que sea de tipo Document. |
|
300 |
// Si el model es de tipo View, |
|
301 |
// comprobamos que adem?s sean de tipo View. |
|
302 |
// Le pedimos al mapContext de la View las layers |
|
303 |
// y a?adimos a editedLayers aquellas layers vectoriales que est?n en edici?n. |
|
304 |
Document document; |
|
305 |
try { |
|
306 |
document = (Document) ((SingletonWindow) window).getWindowModel(); |
|
307 |
} catch (ClassCastException e) { |
|
308 |
// Do nothing, skip this window |
|
309 |
continue; |
|
310 |
} |
|
311 |
if (ViewDocument.class.isAssignableFrom(document.getClass())) { |
|
312 |
ViewDocument view = (ViewDocument) document; |
|
313 |
MapContext mapContext = view.getMapContext(); |
|
314 |
if (mapContext != null) { |
|
315 |
FLayers layers = mapContext.getLayers(); |
|
316 |
for (int j = 0; j < layers.getLayersCount(); j++) { |
|
317 |
FLayer lyr = layers.getLayer(j); |
|
318 |
if (lyr instanceof FLyrVect) { |
|
319 |
FLyrVect layerVect = (FLyrVect) lyr; |
|
320 |
if (layerVect.isEditing()) { |
|
321 |
editedLayers.add(layerVect); |
|
322 |
} |
|
323 |
} |
|
298 |
List<FLyrVect> editedLayers = new ArrayList<>(); |
|
299 |
|
|
300 |
Project project = application.getCurrentProject(); |
|
301 |
for( Document document : project.getDocuments(ViewManager.TYPENAME) ) { |
|
302 |
ViewDocument view = (ViewDocument) document; |
|
303 |
MapContext mapContext = view.getMapContext(); |
|
304 |
if (mapContext != null) { |
|
305 |
FLayers layers = mapContext.getLayers(); |
|
306 |
for (int j = 0; j < layers.getLayersCount(); j++) { |
|
307 |
FLayer lyr = layers.getLayer(j); |
|
308 |
if (lyr instanceof FLyrVect) { |
|
309 |
FLyrVect layerVect = (FLyrVect) lyr; |
|
310 |
if (layerVect.isEditing()) { |
|
311 |
editedLayers.add(layerVect); |
|
324 | 312 |
} |
325 | 313 |
} |
326 | 314 |
} |
... | ... | |
330 | 318 |
} |
331 | 319 |
|
332 | 320 |
private List<IUnsavedData> getUnsavedData(List<FLyrVect> editedLayers){ |
333 |
List<IUnsavedData> unsavedData = new ArrayList<IUnsavedData>(); |
|
334 |
for (Iterator iterator = editedLayers.iterator(); iterator.hasNext();) { |
|
335 |
FLyrVect editedLayer = (FLyrVect) iterator.next(); |
|
321 |
List<IUnsavedData> unsavedData = new ArrayList<>(); |
|
322 |
for (FLyrVect editedLayer : editedLayers) { |
|
336 | 323 |
IUnsavedData unsavedDataLayer = new UnsavedLayer(this, editedLayer); |
337 | 324 |
unsavedData.add(unsavedDataLayer); |
338 | 325 |
} |
... | ... | |
341 | 328 |
} |
342 | 329 |
|
343 | 330 |
private static class UnsavedLayer extends UnsavedData { |
344 |
private FLyrVect layer; |
|
331 |
private final FLyrVect layer;
|
|
345 | 332 |
|
346 | 333 |
public UnsavedLayer(IExtension extension, FLyrVect layer) { |
347 | 334 |
super(extension); |
... | ... | |
380 | 367 |
|
381 | 368 |
return new IExtensionStatus() { |
382 | 369 |
|
370 |
@Override |
|
383 | 371 |
public boolean hasUnsavedData() { |
384 | 372 |
if(unsavedData == null){ |
385 | 373 |
return false; |
... | ... | |
387 | 375 |
return !unsavedData.isEmpty(); |
388 | 376 |
} |
389 | 377 |
|
378 |
@Override |
|
390 | 379 |
public boolean hasRunningProcesses() { |
391 | 380 |
return false; |
392 | 381 |
} |
393 | 382 |
|
383 |
@Override |
|
394 | 384 |
public IUnsavedData[] getUnsavedData() { |
395 | 385 |
if(unsavedData == null){ |
396 | 386 |
return null; |
... | ... | |
398 | 388 |
return unsavedData.toArray(new IUnsavedData[0]); |
399 | 389 |
} |
400 | 390 |
|
391 |
@Override |
|
401 | 392 |
public IMonitorableTask[] getRunningProcesses() { |
402 | 393 |
return null; |
403 | 394 |
} |
Also available in: Unified diff