From 6d9c6268f7d290a034b9cd097562aaf14216efef Mon Sep 17 00:00:00 2001
From: Francisco Puga <fpuga@cartolab.es>
Date: Mon, 30 Jan 2012 10:21:55 +0100
Subject: [PATCH 5/6] Get the view from the context instead as the active view
 on wfs wizard

---
 .../iver/cit/gvsig/fmap/layers/FLyrWFSFactory.java |    2 -
 .../gui/dialogs/WFSPropertiesDialogListener.java   |    3 +-
 .../iver/cit/gvsig/gui/panels/WFSAreaPanel.java    |   30 +++++--------------
 .../com/iver/cit/gvsig/gui/wizards/WFSWizard.java  |    1 +
 .../iver/cit/gvsig/gui/wizards/WFSWizardData.java  |   14 +++++++++
 5 files changed, 24 insertions(+), 26 deletions(-)

diff --git a/extensions/extWFS2/src/com/iver/cit/gvsig/fmap/layers/FLyrWFSFactory.java b/extensions/extWFS2/src/com/iver/cit/gvsig/fmap/layers/FLyrWFSFactory.java
index 8ff70a4..e2b54f5 100644
--- a/extensions/extWFS2/src/com/iver/cit/gvsig/fmap/layers/FLyrWFSFactory.java
+++ b/extensions/extWFS2/src/com/iver/cit/gvsig/fmap/layers/FLyrWFSFactory.java
@@ -112,8 +112,6 @@ public class FLyrWFSFactory {
     	adapter.setDriver((VectorialDriver) driver);
     	wfsLayer.setSource(adapter);
 		wfsLayer.setOnlineResource(onlineResource);
-		BaseView activeView = 
-			(BaseView) PluginServices.getMDIManager().getActiveWindow();
 		//The SRS original
 		IProjection projection = CRSFactory.getCRS(getSRS(wfsLayer.getSrs()));
 		wfsLayer.setProjection(projection);
diff --git a/extensions/extWFS2/src/com/iver/cit/gvsig/gui/dialogs/WFSPropertiesDialogListener.java b/extensions/extWFS2/src/com/iver/cit/gvsig/gui/dialogs/WFSPropertiesDialogListener.java
index f3e6aab..f149be2 100755
--- a/extensions/extWFS2/src/com/iver/cit/gvsig/gui/dialogs/WFSPropertiesDialogListener.java
+++ b/extensions/extWFS2/src/com/iver/cit/gvsig/gui/dialogs/WFSPropertiesDialogListener.java
@@ -139,8 +139,7 @@ public class WFSPropertiesDialogListener implements ActionListener {
 				dialog.updateReference(newLayer);
 				
 				// Replace the old layer entry at the TOC with the new one
-				BaseView activeView = (BaseView) PluginServices.getMDIManager().getActiveWindow();
-				MapControl mapCtrl = activeView.getMapControl();
+		MapControl mapCtrl = dialog.getWizardData().getMapCtrl();
 				mapCtrl.getMapContext().getLayers().replaceLayer(oldLayerName, newLayer);
 				//mapCtrl.getMapContext().zoomToExtent(newLayer.getFullExtent());
 
diff --git a/extensions/extWFS2/src/com/iver/cit/gvsig/gui/panels/WFSAreaPanel.java b/extensions/extWFS2/src/com/iver/cit/gvsig/gui/panels/WFSAreaPanel.java
index 30de399..ea358a4 100755
--- a/extensions/extWFS2/src/com/iver/cit/gvsig/gui/panels/WFSAreaPanel.java
+++ b/extensions/extWFS2/src/com/iver/cit/gvsig/gui/panels/WFSAreaPanel.java
@@ -281,10 +281,8 @@ public class WFSAreaPanel extends AbstractWFSPanel {
 	 * Write the view coordinates into the coordinates panel
 	 */
 	private void initCoordinates(){
-		BaseView activeView = (BaseView) PluginServices.getMDIManager().getActiveWindow();
 		// We will use the adjusted extent because increases the usability
-		Rectangle2D r2d = activeView.getMapControl().getViewPort().getAdjustedExtent();
-//		Rectangle2D r2d = activeView.getMapControl().getViewPort().getExtent();
+	Rectangle2D r2d = data.getMapCtrl().getViewPort().getAdjustedExtent();
 
 		if (r2d != null){
 			previousExtentValids.put(r2d);
@@ -456,14 +454,7 @@ public class WFSAreaPanel extends AbstractWFSPanel {
 
 		getCoordinatesPanel().setAllTextFieldsEnabled(true);
 
-		// If the current active view has layers -> set the area in the fields:
-		// Adds the extent of the viewport of the current active view
-		BaseView view = (BaseView) PluginServices.getMDIManager().getActiveWindow();
-		ViewPort vP = view.getMapControl().getMapContext().getViewPort();
-
-		// Update extent (we will use the adjusted extent because increases the usability)
-		Rectangle2D r2D = vP.getAdjustedExtent();
-//		Rectangle2D r2D = vP.getExtent();
+	Rectangle2D r2D = data.getMapCtrl().getViewPort().getAdjustedExtent();
 
 		if (r2D != null) {
 //			getJToggleButtonMove().setEnabled(false);
@@ -732,8 +723,7 @@ public class WFSAreaPanel extends AbstractWFSPanel {
 				 */
 				public void mouseClicked(MouseEvent e) {
 					getSelectableMapAreaPanel().getViewPort().setExtent(getSelectableMapAreaPanel().getMapContext().getLayers().getFullExtent());
-					BaseView view =((BaseView)PluginServices.getMDIManager().getActiveWindow());
-					view.repaintMap();
+		    data.getMapCtrl().drawMap(false);
 				}
 			});
 		}
@@ -929,13 +919,9 @@ public class WFSAreaPanel extends AbstractWFSPanel {
 				mapContext.getLayers().removeLayer(i);
 			}
 			PluginServices.getMainFrame().enableControls();
-			// Adds the extent of the viewport of the current active view
-			BaseView view = (BaseView) PluginServices.getMDIManager().getActiveWindow();
-			ViewPort vP = view.getMapControl().getMapContext().getViewPort();
 
-			// Update extent (we will use the adjusted extent because increases the usability)
-			Rectangle2D r2D = vP.getAdjustedExtent();
-//			Rectangle2D r2D = vP.getExtent();
+	    Rectangle2D r2D = data.getMapCtrl().getViewPort()
+		    .getAdjustedExtent();
 
 			if (r2D == null) {
 				// End To prevent that events that take place(are produced) could be a nuisance to the load of the layers
@@ -951,7 +937,7 @@ public class WFSAreaPanel extends AbstractWFSPanel {
 			mapContext.getViewPort().setExtent(r2D);
 
 			// Adds the active layers of the current active view
-			MapContext mC = view.getMapControl().getMapContext();
+	    MapContext mC = data.getMapCtrl().getMapContext();
 
 			numberOfLayers = mC.getLayers().getLayersCount();
 
@@ -2597,7 +2583,7 @@ public class WFSAreaPanel extends AbstractWFSPanel {
 
 			/* Sets a clone of the current active view map context to this MapControl */
 			try {
-				MapContext mp = ((BaseView) PluginServices.getMDIManager().getActiveWindow()).getMapControl().getMapContext();
+		MapContext mp = data.getMapCtrl().getMapContext();
 
 				this.setMapContext(mp.cloneFMap());
 				ViewPort vP = this.getViewPort();
@@ -2626,7 +2612,7 @@ public class WFSAreaPanel extends AbstractWFSPanel {
 		 */
 		public void refreshWithTheActiveView() {
 			try {
-				MapContext mp = ((BaseView) PluginServices.getMDIManager().getActiveWindow()).getMapControl().getMapContext();
+		MapContext mp = data.getMapCtrl().getMapContext();
 				this.setMapContext(mp.cloneFMap());
 				ViewPort vP = this.getViewPort();
 
diff --git a/extensions/extWFS2/src/com/iver/cit/gvsig/gui/wizards/WFSWizard.java b/extensions/extWFS2/src/com/iver/cit/gvsig/gui/wizards/WFSWizard.java
index b4ea6ba..d97bbf5 100755
--- a/extensions/extWFS2/src/com/iver/cit/gvsig/gui/wizards/WFSWizard.java
+++ b/extensions/extWFS2/src/com/iver/cit/gvsig/gui/wizards/WFSWizard.java
@@ -672,6 +672,7 @@ public class WFSWizard extends WizardPanel {
 	 */
 	public void setDataSource(WFSWizardData source) {
 		dataSource = source;
+	dataSource.setMapCtrl(getMapCtrl());
 	}
 
 	/**
diff --git a/extensions/extWFS2/src/com/iver/cit/gvsig/gui/wizards/WFSWizardData.java b/extensions/extWFS2/src/com/iver/cit/gvsig/gui/wizards/WFSWizardData.java
index 18afd65..50469f0 100755
--- a/extensions/extWFS2/src/com/iver/cit/gvsig/gui/wizards/WFSWizardData.java
+++ b/extensions/extWFS2/src/com/iver/cit/gvsig/gui/wizards/WFSWizardData.java
@@ -10,6 +10,7 @@ import com.iver.andami.PluginServices;
 import com.iver.andami.messages.NotificationManager;
 import com.iver.cit.gvsig.exceptions.layers.ConnectionErrorLayerException;
 import com.iver.cit.gvsig.exceptions.layers.LoadLayerException;
+import com.iver.cit.gvsig.fmap.MapControl;
 import com.iver.cit.gvsig.fmap.drivers.wfs.FMapWFSDriver;
 import com.iver.cit.gvsig.fmap.drivers.wfs.FMapWFSDriverFactory;
 import com.iver.cit.gvsig.fmap.layers.WFSLayerNode;
@@ -113,6 +114,19 @@ public class WFSWizardData {
 	private int buffer = 0;
 	private int timeOut = 0;
 	private String UserName = null;
+    private MapControl mapCtrl;
+
+    public MapControl getMapCtrl() {
+	return mapCtrl;
+    }
+
+    /**
+     * @param mapCtrl
+     *            The mapCtrl to set.
+     */
+    public void setMapCtrl(MapControl mapCtrl) {
+	this.mapCtrl = mapCtrl;
+    }
 
 	/**
 	 * Gets the online resource of the WFS driver.
-- 
1.7.5.4

