Index: AppTopologyServices.java
===================================================================
--- AppTopologyServices.java	(revision 726)
+++ AppTopologyServices.java	(revision 727)
@@ -23,30 +23,55 @@
  */
 package org.gvsig.topology.app.mainplugin;
 
+import java.io.File;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import javax.swing.ImageIcon;
 import javax.swing.tree.TreeModel;
 import org.apache.commons.lang3.mutable.Mutable;
 import org.apache.commons.lang3.mutable.MutableObject;
+import org.gvsig.andami.IconThemeHelper;
+import org.gvsig.andami.PluginsLocator;
 import org.gvsig.app.ApplicationLocator;
 import org.gvsig.app.ApplicationManager;
 import org.gvsig.app.project.Project;
 import org.gvsig.app.project.documents.Document;
 import org.gvsig.app.project.documents.view.ViewDocument;
 import org.gvsig.app.project.documents.view.ViewManager;
+import org.gvsig.fmap.dal.EditingNotification;
+import org.gvsig.fmap.dal.EditingNotificationManager;
 import org.gvsig.fmap.dal.feature.FeatureStore;
+import org.gvsig.fmap.dal.swing.DALSwingLocator;
+import org.gvsig.fmap.geom.Geometry;
+import org.gvsig.fmap.geom.aggregate.MultiCurve;
+import org.gvsig.fmap.geom.aggregate.MultiPoint;
+import org.gvsig.fmap.geom.aggregate.MultiSurface;
+import org.gvsig.fmap.geom.primitive.Curve;
 import org.gvsig.fmap.geom.primitive.Envelope;
 import org.gvsig.fmap.geom.primitive.Point;
+import org.gvsig.fmap.geom.primitive.Surface;
+import org.gvsig.fmap.mapcontext.MapContext;
+import org.gvsig.fmap.mapcontext.MapContextLocator;
 import org.gvsig.fmap.mapcontext.ViewPort;
 import org.gvsig.fmap.mapcontext.events.ColorEvent;
 import org.gvsig.fmap.mapcontext.events.ExtentEvent;
 import org.gvsig.fmap.mapcontext.events.ProjectionEvent;
 import org.gvsig.fmap.mapcontext.events.listeners.ViewPortListener;
+import org.gvsig.fmap.mapcontext.layers.FLayer;
 import org.gvsig.fmap.mapcontext.layers.FLayers;
 import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
+import org.gvsig.fmap.mapcontext.layers.vectorial.GraphicLayer;
+import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
+import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol_v2;
+import org.gvsig.fmap.mapcontrol.MapControlLocator;
+import org.gvsig.fmap.mapcontrol.swing.dynobject.DynObjectEditor;
+import org.gvsig.tools.dynobject.DynObject;
 import org.gvsig.tools.exception.BaseException;
+import org.gvsig.tools.observer.Observable;
+import org.gvsig.tools.observer.Observer;
+import org.gvsig.tools.swing.api.ListElement;
 import org.gvsig.tools.visitor.VisitCanceledException;
 import org.gvsig.tools.visitor.Visitor;
 import org.gvsig.topology.lib.api.TopologyDataSet;
@@ -62,12 +87,12 @@
 public class AppTopologyServices implements TopologySwingServices {
 
     private static final Logger LOGGER = LoggerFactory.getLogger(AppTopologyServices.class);
- 
+
     private class WorkingAreaViewPortListener implements ViewPortListener {
-    
+
         private WorkingAreaChangedListener workingAreaChangedListener;
         private ViewPort viewPort;
-        
+
         public WorkingAreaViewPortListener(ViewPort viewPort, WorkingAreaChangedListener workingAreaChangedListener) {
             this.workingAreaChangedListener = workingAreaChangedListener;
             this.viewPort = viewPort;
@@ -76,7 +101,7 @@
         public ViewPort getViewPort() {
             return this.viewPort;
         }
-        
+
         @Override
         public void extentChanged(ExtentEvent e) {
             this.workingAreaChangedListener.workingAreaChanged(e.getNewExtent());
@@ -91,12 +116,43 @@
         }
     }
 
+    private class EditingNotificationObserver implements Observer {
+
+        public EditingNotificationObserver() {
+
+        }
+
+        @Override
+        public void update(Observable o, Object notification) {
+            EditingNotification n = (EditingNotification) notification;
+            if (n.isCancelable() && n.getFeature() != null) {
+                try {
+                    DynObject data = n.getFeature().getAsDynObject();
+                    DynObjectEditor editor = new DynObjectEditor(data);
+                    editor.setTitle("Topology - " + n.getFeature().getType().getName());
+                    editor.editObject(true);
+                    if (editor.isCanceled()) {
+                        n.cancel();
+                    } else {
+                        editor.getData(data);
+                    }
+                } catch (Exception ex) {
+                    LOGGER.warn("Problems showing the feature in a form.", ex);
+                }
+            }
+        }
+    }
+
     private Map<WorkingAreaChangedListener, WorkingAreaViewPortListener> workingAreaListener;
-    
+    private ISymbol errorPolygonSymbol = null;
+    private ISymbol errorPointSymbol = null;
+    private ISymbol errorLineSymbol = null;
+    private EditingNotificationObserver editingNotificationObserver = null;
+
     public AppTopologyServices() {
         this.workingAreaListener = new HashMap<>();
     }
-    
+
     @Override
     public TreeModel getDataSetTreeModel() {
         ApplicationManager application = ApplicationLocator.getManager();
@@ -108,26 +164,26 @@
     public FeatureStore getFeatureStore(final TopologyDataSet dataSet) {
         final Mutable<FeatureStore> store = new MutableObject<>();
         store.setValue(null);
-        
+
         ApplicationManager application = ApplicationLocator.getManager();
         Project project = application.getCurrentProject();
-        
+
         List<Document> views = new ArrayList<>();
         views.add(project.getActiveDocument(ViewManager.TYPENAME));
 //        views.addAll(project.getDocuments(ViewManager.TYPENAME));
 
         for (Document view : views) {
-            if( view == null ) {
+            if (view == null) {
                 continue;
             }
-            FLayers layers = ((ViewDocument)view).getMapContext().getLayers();
+            FLayers layers = ((ViewDocument) view).getMapContext().getLayers();
             try {
                 layers.accept(new Visitor() {
                     @Override
                     public void visit(Object o) throws VisitCanceledException, BaseException {
-                        if( o instanceof FLyrVect ) {
+                        if (o instanceof FLyrVect) {
                             FLyrVect layer = (FLyrVect) o;
-                            if( dataSet.isThisStore(layer.getFeatureStore()) ) {
+                            if (dataSet.isThisStore(layer.getFeatureStore())) {
                                 store.setValue(layer.getFeatureStore());
                                 throw new VisitCanceledException();
                             }
@@ -147,7 +203,7 @@
     public void zoomTo(Envelope envelope) {
         ApplicationManager application = ApplicationLocator.getManager();
         ViewDocument viewdoc = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME);
-        if( viewdoc == null ) {
+        if (viewdoc == null) {
             return;
         }
         ViewPort viewPort = viewdoc.getMapContext().getViewPort();
@@ -159,7 +215,7 @@
         try {
             ApplicationManager application = ApplicationLocator.getManager();
             ViewDocument viewdoc = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME);
-            if( viewdoc == null ) {
+            if (viewdoc == null) {
                 return;
             }
             viewdoc.getMapContext().invalidate();
@@ -167,13 +223,13 @@
             LOGGER.warn("Cant refresh view", ex);
         }
     }
-    
+
     @Override
     public void centerTo(Point point) {
         try {
             ApplicationManager application = ApplicationLocator.getManager();
             ViewDocument viewdoc = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME);
-            if( viewdoc == null ) {
+            if (viewdoc == null) {
                 return;
             }
             ViewPort viewPort = viewdoc.getMapContext().getViewPort();
@@ -189,7 +245,7 @@
     public Envelope getWorkingArea() {
         ApplicationManager application = ApplicationLocator.getManager();
         ViewDocument viewdoc = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME);
-        if( viewdoc == null ) {
+        if (viewdoc == null) {
             return null;
         }
         ViewPort viewPort = viewdoc.getMapContext().getViewPort();
@@ -200,16 +256,16 @@
     public void addWorkingAreaChangedListener(WorkingAreaChangedListener listener) {
         ApplicationManager application = ApplicationLocator.getManager();
         ViewDocument viewdoc = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME);
-        if( viewdoc == null ) {
+        if (viewdoc == null) {
             return;
         }
         ViewPort viewPort = viewdoc.getMapContext().getViewPort();
         WorkingAreaViewPortListener viewPortListener = this.workingAreaListener.get(listener);
-        if( viewPortListener==null ) {
+        if (viewPortListener == null) {
             viewPortListener = new WorkingAreaViewPortListener(viewPort, listener);
             this.workingAreaListener.put(listener, viewPortListener);
         } else {
-            if( viewPort != viewPortListener.getViewPort() ) {
+            if (viewPort != viewPortListener.getViewPort()) {
                 viewPortListener.getViewPort().removeViewPortListener(viewPortListener);
                 viewPortListener = new WorkingAreaViewPortListener(viewPort, listener);
                 this.workingAreaListener.put(listener, viewPortListener);
@@ -221,11 +277,80 @@
     @Override
     public void removeWorkingAreaChangedListener(WorkingAreaChangedListener listener) {
         WorkingAreaViewPortListener viewPortListener = this.workingAreaListener.get(listener);
-        if( viewPortListener==null ) {
+        if (viewPortListener == null) {
             return;
         }
-        viewPortListener.getViewPort().removeViewPortListener(viewPortListener);     
+        viewPortListener.getViewPort().removeViewPortListener(viewPortListener);
     }
-    
-    
+
+    @Override
+    public void addError(Geometry geom) {
+        if (this.errorPointSymbol == null) {
+            try {
+                File pluginfolder = PluginsLocator.getManager().getPlugin(this).getPluginDirectory();
+                File folder = new File(pluginfolder, "symbols");
+                ISymbol[] symbols = MapContextLocator.getSymbolManager().loadSymbols(folder);
+                for (ISymbol symbol : symbols) {
+                    if (symbol instanceof ISymbol_v2) {
+                        String symbolid = ((ISymbol_v2) symbol).getID();
+                        switch(symbolid) {
+                            case "topology-error-polygon":
+                                this.errorPolygonSymbol = symbol;
+                                break;
+                            case "topology-error-line":
+                                this.errorLineSymbol = symbol;
+                                break;
+                            case "topology-error-point":
+                                this.errorPointSymbol = symbol;
+                                break;
+                        }
+                    }
+                }
+            } catch (Exception ex) {
+            }
+        }
+        ApplicationManager application = ApplicationLocator.getManager();
+        ViewDocument viewdoc = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME);
+        MapContext mapContext = viewdoc.getMapContext();
+        GraphicLayer gl = mapContext.getGraphicsLayer();
+        gl.removeGraphics("topology-errors");
+        if ( geom!=null ) {
+            ISymbol symbol = null;
+            if( geom instanceof Point || geom instanceof MultiPoint) {
+                symbol = this.errorPointSymbol;
+            } else if( geom instanceof Curve || geom instanceof MultiCurve ) {
+                symbol = this.errorLineSymbol;
+            } else if( geom instanceof Surface || geom instanceof MultiSurface ) {
+                symbol = this.errorPolygonSymbol;
+            }
+            if (symbol != null) {
+                int symbolid = gl.getSymbolId(symbol);
+                if (symbolid < 0) {
+                    gl.addSymbol(symbol);
+                    symbolid = gl.getSymbolId(symbol);
+                }
+                gl.addGraphic("topology-errors", geom, symbolid);
+            }
+        }
+        mapContext.invalidate();
+    }
+
+    @Override
+    public void setShowFormWhenEdit(boolean showFormWhenEdit) {
+        if (this.editingNotificationObserver == null) {
+            this.editingNotificationObserver = new EditingNotificationObserver();
+        }
+        EditingNotificationManager editingNotificationManager = DALSwingLocator.getEditingNotificationManager();
+        if (showFormWhenEdit) {
+            editingNotificationManager.addObserver(this.editingNotificationObserver);
+        } else {
+            editingNotificationManager.deleteObserver(this.editingNotificationObserver);
+        }
+    }
+
+    @Override
+    public ImageIcon getTreeIcon(TreeModel model, Object item) {
+        return ((DataSetsTreeModel)model).getTreeIcon(item);
+    }
+
 }
