[mapguide-commits] r6079 - in trunk/Tools/Maestro/Maestro.Base: . UI

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Tue Aug 16 05:52:31 EDT 2011


Author: jng
Date: 2011-08-16 02:52:31 -0700 (Tue, 16 Aug 2011)
New Revision: 6079

Modified:
   trunk/Tools/Maestro/Maestro.Base/Maestro.Base.csproj
   trunk/Tools/Maestro/Maestro.Base/UI/ISiteExplorer.cs
   trunk/Tools/Maestro/Maestro.Base/UI/RepositoryTreeModel.cs
   trunk/Tools/Maestro/Maestro.Base/UI/SiteExplorer.cs
Log:
#1784: Update the Site Explorer to be aware of multiple connections (theoretically speaking, we'll find out if things break once we actually do add multiple connections to the site explorer).


Modified: trunk/Tools/Maestro/Maestro.Base/Maestro.Base.csproj
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/Maestro.Base.csproj	2011-08-16 06:54:10 UTC (rev 6078)
+++ trunk/Tools/Maestro/Maestro.Base/Maestro.Base.csproj	2011-08-16 09:52:31 UTC (rev 6079)
@@ -51,6 +51,11 @@
       <SpecificVersion>False</SpecificVersion>
       <HintPath>..\SDK\bin\Maestro.Shared.UI.dll</HintPath>
     </Reference>
+    <Reference Include="NetTopologySuite.Merged, Version=1.8.0.0, Culture=neutral, PublicKeyToken=f580a05016ebada1, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>..\Thirdparty\NTS\NetTopologySuite.Merged.dll</HintPath>
+      <Private>False</Private>
+    </Reference>
     <Reference Include="OSGeo.MapGuide.MaestroAPI, Version=3.0.0.5475, Culture=neutral, PublicKeyToken=f526c48929fda856, processorArchitecture=MSIL">
       <SpecificVersion>False</SpecificVersion>
       <HintPath>..\SDK\bin\OSGeo.MapGuide.MaestroAPI.dll</HintPath>

Modified: trunk/Tools/Maestro/Maestro.Base/UI/ISiteExplorer.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/UI/ISiteExplorer.cs	2011-08-16 06:54:10 UTC (rev 6078)
+++ trunk/Tools/Maestro/Maestro.Base/UI/ISiteExplorer.cs	2011-08-16 09:52:31 UTC (rev 6079)
@@ -20,45 +20,52 @@
 using System;
 using System.Collections.Generic;
 using System.Text;
+using OSGeo.MapGuide.MaestroAPI;
 
 namespace Maestro.Base.UI
 {
     public interface ISiteExplorer : IViewContent
     {
         /// <summary>
-        /// The name of the <see cref="IServerConnection"/> associated with this site explorer
+        /// The name of the active <see cref="IServerConnection"/> associated with this site explorer. The active connection
+        /// is the connection whose node or child nodes is currently selected
         /// </summary>
         string ConnectionName { get; }
 
         /// <summary>
+        /// Gets the array of connection names.
+        /// </summary>
+        string[] ConnectionNames { get; }
+
+        /// <summary>
         /// Refreshes the tree model
         /// </summary>
-        void RefreshModel();
+        void RefreshModel(string connectionName);
 
         /// <summary>
         /// Refreshes the tree model from the specified resource id 
         /// </summary>
         /// <param name="resId"></param>
-        void RefreshModel(string resId);
+        void RefreshModel(string connectionName, string resId);
 
         /// <summary>
         /// Expands the node indicated by the specified id
         /// </summary>
         /// <param name="folderId"></param>
-        void ExpandNode(string folderId);
+        void ExpandNode(string connectionName, string folderId);
 
         /// <summary>
         /// Selects the node indicated by the specified id
         /// </summary>
         /// <param name="resourceId"></param>
-        void SelectNode(string resourceId);
+        void SelectNode(string connectionName, string resourceId);
 
         /// <summary>
         /// Flags the node indicated by the specified action
         /// </summary>
         /// <param name="resourceId"></param>
         /// <param name="action"></param>
-        void FlagNode(string resourceId, NodeFlagAction action);
+        void FlagNode(string connectionName, string resourceId, NodeFlagAction action);
 
         /// <summary>
         /// Gets the items currently selected
@@ -91,3 +98,37 @@
         None
     }
 }
+
+//This is a compatibility shim. Most existing consumers of these APIs operate based on the active connection anyway
+
+namespace Maestro.Base
+{
+    using UI;
+
+    internal static class SiteExplorerShims
+    {
+        public static void RefreshModel(this ISiteExplorer explorer)
+        {
+            Check.NotNull(explorer, "explorer");
+            explorer.RefreshModel(explorer.ConnectionName);
+        }
+
+        public static void ExpandNode(this ISiteExplorer explorer, string resId)
+        {
+            Check.NotNull(explorer, "explorer");
+            explorer.ExpandNode(explorer.ConnectionName, resId);
+        }
+
+        public static void FlagNode(this ISiteExplorer explorer, string resId, NodeFlagAction action)
+        {
+            Check.NotNull(explorer, "explorer");
+            explorer.FlagNode(explorer.ConnectionName, resId, action);
+        }
+
+        public static void SelectNode(this ISiteExplorer explorer, string resId)
+        {
+            Check.NotNull(explorer, "explorer");
+            explorer.SelectNode(explorer.ConnectionName, resId);
+        }
+    }
+}
\ No newline at end of file

Modified: trunk/Tools/Maestro/Maestro.Base/UI/RepositoryTreeModel.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/UI/RepositoryTreeModel.cs	2011-08-16 06:54:10 UTC (rev 6078)
+++ trunk/Tools/Maestro/Maestro.Base/UI/RepositoryTreeModel.cs	2011-08-16 09:52:31 UTC (rev 6079)
@@ -40,11 +40,12 @@
 
         private bool _notify = false;
 
-        public RepositoryItem(IRepositoryItem item)
+        public RepositoryItem(string connectionName, IRepositoryItem item)
         {
             _name = string.Empty;
             _children = new Dictionary<string, RepositoryItem>();
 
+            this.ConnectionName = connectionName;
             this.CreatedDate = item.CreatedDate;
             this.ModifiedDate = item.ModifiedDate;
             this.Owner = item.Owner;
@@ -205,6 +206,12 @@
             internal set;
         }
 
+        public string ConnectionName
+        {
+            get;
+            internal set;
+        }
+
         private string _name;
 
         public string Name
@@ -378,31 +385,28 @@
     /// </summary>
     public class RepositoryTreeModel : TreeModelBase
     {
-        private RepositoryItem _rootNode;
         private TreeViewAdv _tree;
-        private string _connectionName;
 
-        private IServerConnection _conn;
+        private ServerConnectionManager _connManager;
         private OpenResourceManager _openResMgr;
         private ClipboardService _clip;
 
-        public RepositoryTreeModel(IServerConnection conn, TreeViewAdv tree, string connName, OpenResourceManager openResMgr, ClipboardService clip)
+        public RepositoryTreeModel(ServerConnectionManager connManager, TreeViewAdv tree, OpenResourceManager openResMgr, ClipboardService clip)
         {
-            _conn = conn;
+            _connManager = connManager;
             _tree = tree;
-            _connectionName = connName;
             _openResMgr = openResMgr;
             _clip = clip;
         }
 
-        private System.Collections.IEnumerable GetSorted(ResourceList list)
+        private System.Collections.IEnumerable GetSorted(string connectionName, ResourceList list)
         {
             //Sort them before returning them
             SortedList<string, RepositoryItem> folders = new SortedList<string, RepositoryItem>();
             SortedList<string, RepositoryItem> docs = new SortedList<string, RepositoryItem>();
             foreach (var item in list.Children)
             {
-                var it = new RepositoryItem(item);
+                var it = new RepositoryItem(connectionName, item);
                 it.Model = this;
                 if (it.IsFolder)
                     folders.Add(it.ResourceId, it);
@@ -435,31 +439,45 @@
             item.ClipboardState = _clip.GetClipboardState(item.ResourceId);
         }
 
+        private Dictionary<string, RepositoryItem> _rootNodes = new Dictionary<string, RepositoryItem>();
+
         public override System.Collections.IEnumerable GetChildren(TreePath treePath)
         {
             if (treePath.IsEmpty())
             {
-                var list = _conn.ResourceService.GetRepositoryResources("Library://", 0);
-                if (list.Items.Count != 1)
+                foreach (var connName in _connManager.GetConnectionNames())
                 {
-                    throw new InvalidOperationException(); //Huh?
+                    var conn = _connManager.GetConnection(connName);
+
+                    var list = conn.ResourceService.GetRepositoryResources("Library://", 0);
+                    if (list.Items.Count != 1)
+                    {
+                        throw new InvalidOperationException(); //Huh?
+                    }
+                    var connNode = new RepositoryItem(connName, (IRepositoryItem)list.Items[0]);
+                    Debug.Assert(connNode.Parent == null);
+                    Debug.Assert(connNode.IsRoot);
+                    connNode.Name = connName;
+                    connNode.Model = this;
+                    _rootNodes[connName] = connNode;
+                    yield return connNode;
                 }
-                _rootNode = new RepositoryItem((IRepositoryItem)list.Items[0]);
-                _rootNode.Name = _connectionName;
-                _rootNode.Model = this;
-                yield return _rootNode;
             }
             else
             {
                 var node = treePath.LastNode as RepositoryItem;
                 if (node != null && node.IsFolder) //Can't enumerate children of documents
                 {
+                    string connName = GetParentConnectionName(node);
+                    var conn = _connManager.GetConnection(connName);
                     node.ClearChildrenWithoutNotification();
-                    var list = _conn.ResourceService.GetRepositoryResources(node.ResourceId, "", 1, false);
-                    foreach (RepositoryItem item in GetSorted(list))
+                    var list = conn.ResourceService.GetRepositoryResources(node.ResourceId, "", 1, false);
+                    foreach (RepositoryItem item in GetSorted(connName, list))
                     {
                         node.AddChildWithoutNotification(item);
                         ApplyCurrentItemState(item);
+                        Debug.Assert(item.Parent != null);
+                        Debug.Assert(!item.IsRoot);
                         yield return item;
                     }
                 }
@@ -470,6 +488,29 @@
             }
         }
 
+        internal static string GetParentConnectionName(RepositoryItem item)
+        {
+            if (!string.IsNullOrEmpty(item.ConnectionName))
+                return item.ConnectionName;
+
+            var current = item.Parent;
+            if (current != null)
+            {
+                current = item.Parent;
+                while (current != null)
+                {
+                    current = current.Parent;
+                }
+                Debug.Assert(!string.IsNullOrEmpty(current.ConnectionName));
+                return current.ConnectionName;
+            }
+            else 
+            {
+                Debug.Assert(!string.IsNullOrEmpty(item.ConnectionName));
+                return item.ConnectionName;
+            }
+        }
+
         public override void Refresh()
         {
             //We have to override this because the base impl does not 
@@ -494,14 +535,14 @@
 
         internal TreePath GetPath(RepositoryItem node)
         {
-            if (node == _rootNode)
+            if (node.IsRoot)
             {
                 return new TreePath(node);
             }
             else
             {
                 Stack<object> stack = new Stack<object>();
-                while (node != _rootNode)
+                while (!node.IsRoot)
                 {
                     stack.Push(node);
                     node = node.Parent;
@@ -516,10 +557,11 @@
             base.OnStructureChanged(args);
         }
 
-        internal TreePath GetPathFromResourceId(string resId)
+        internal TreePath GetPathFromResourceId(string connectionName, string resId)
         {
+            var rootNode = _rootNodes[connectionName];
             if ("Library://".Equals(resId))
-                return GetPath(_rootNode);
+                return GetPath(rootNode);
             
             string[] components = ResourceIdentifier.GetPath(resId).Split('/');
             if (!ResourceIdentifier.IsFolderResource(resId))
@@ -527,7 +569,7 @@
                 //Fix extension to last component
                 components[components.Length - 1] = components[components.Length - 1] + "." + ResourceIdentifier.GetResourceType(resId).ToString();
             }
-            RepositoryItem current = _rootNode;
+            RepositoryItem current = rootNode;
             for (int i = 0; i < components.Length; i++)
             {
                 if (current.Contains(components[i]))

Modified: trunk/Tools/Maestro/Maestro.Base/UI/SiteExplorer.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/UI/SiteExplorer.cs	2011-08-16 06:54:10 UTC (rev 6078)
+++ trunk/Tools/Maestro/Maestro.Base/UI/SiteExplorer.cs	2011-08-16 09:52:31 UTC (rev 6079)
@@ -34,13 +34,12 @@
 using Maestro.Shared.UI;
 using Maestro.Base.Commands.SiteExplorer;
 using Maestro.Base.Commands;
+using System.Linq;
 
 namespace Maestro.Base.UI
 {
     public partial class SiteExplorer : ViewContentBase, ISiteExplorer
     {
-        private IServerConnection _conn;
-
         /// <summary>
         /// Internal use only. Do not invoke directly. Use <see cref="ViewContentManager"/> for that
         /// </summary>
@@ -73,6 +72,7 @@
         }
 
         private RepositoryTreeModel _model;
+        private ServerConnectionManager _connManager;
 
         protected override void OnLoad(EventArgs e)
         {
@@ -82,12 +82,11 @@
             var ts = ToolbarService.CreateToolStripItems("/Maestro/Shell/SiteExplorer/Toolbar", this, true);
             tsSiteExplorer.Items.AddRange(ts);
 
-            var mgr = ServiceRegistry.GetService<ServerConnectionManager>();
-            _conn = mgr.GetConnection(this.ConnectionName);
+            _connManager = ServiceRegistry.GetService<ServerConnectionManager>();
 
             var omgr = ServiceRegistry.GetService<OpenResourceManager>();
-            var clip = ServiceRegistry.GetService<ClipboardService>(); 
-            _model = new RepositoryTreeModel(_conn, trvResources, this.ConnectionName, omgr, clip);
+            var clip = ServiceRegistry.GetService<ClipboardService>();
+            _model = new RepositoryTreeModel(_connManager, trvResources, omgr, clip);
             trvResources.Model = _model;
         }
 
@@ -107,12 +106,12 @@
             }
         }
 
-        public void RefreshModel()
+        public void RefreshModel(string connectionName)
         {
-            RefreshModel(null);
+            RefreshModel(connectionName, null);
         }
 
-        public void RefreshModel(string resId)
+        public void RefreshModel(string connectionName, string resId)
         {
             if (!string.IsNullOrEmpty(resId))
             {
@@ -121,13 +120,13 @@
                     resId = rid.ParentFolder;
 
                 //If this node is not initially expanded, we get NRE on refresh
-                ExpandNode(resId);
+                ExpandNode(connectionName, resId);
 
-                var path = _model.GetPathFromResourceId(resId);
+                var path = _model.GetPathFromResourceId(connectionName, resId);
                 while (path == null)
                 {
                     resId = ResourceIdentifier.GetParentFolder(resId);
-                    path = _model.GetPathFromResourceId(resId);
+                    path = _model.GetPathFromResourceId(connectionName, resId);
                 }
 
                 var node = trvResources.FindNode(path, true);
@@ -151,8 +150,9 @@
                 var item = node.Tag as RepositoryItem;
                 if (item != null && !item.IsFolder)
                 {
+                    var conn = _connManager.GetConnection(RepositoryTreeModel.GetParentConnectionName(item));
                     var resMgr = ServiceRegistry.GetService<OpenResourceManager>();
-                    resMgr.Open(item.ResourceId, _conn, false, this);
+                    resMgr.Open(item.ResourceId, conn, false, this);
                 }
             }
         }
@@ -248,12 +248,12 @@
         }
 
 
-        public void ExpandNode(string folderId)
+        public void ExpandNode(string connectionName, string folderId)
         {
             if ("Library://".Equals(folderId))
                 return;
 
-            var path = _model.GetPathFromResourceId(folderId);
+            var path = _model.GetPathFromResourceId(connectionName, folderId);
             if (path != null)
             {
                 var node = trvResources.FindNode(path, true);
@@ -264,9 +264,9 @@
             }
         }
 
-        public void SelectNode(string resourceId)
+        public void SelectNode(string connectionName, string resourceId)
         {
-            var path = _model.GetPathFromResourceId(resourceId);
+            var path = _model.GetPathFromResourceId(connectionName, resourceId);
             if (path != null)
             {
                 var node = trvResources.FindNode(path, true);
@@ -277,9 +277,9 @@
             }
         }
 
-        public void FlagNode(string resourceId, NodeFlagAction action)
+        public void FlagNode(string connectionName, string resourceId, NodeFlagAction action)
         {
-            var path = _model.GetPathFromResourceId(resourceId);
+            var path = _model.GetPathFromResourceId(connectionName, resourceId);
             if (path != null)
             {
                 var node = trvResources.FindNode(path, true);
@@ -362,6 +362,7 @@
                 var item = node.Tag as RepositoryItem;
                 if (item != null && item.IsFolder)
                 {
+                    string connectionName = RepositoryTreeModel.GetParentConnectionName(item);
                     string folderId = item.ResourceId;
                     List<string> resIds = new List<string>();
                     foreach (var n in data)
@@ -376,7 +377,7 @@
                             return;
                     }
 
-                    string[] folders = MoveResources(resIds, folderId);
+                    string[] folders = MoveResources(connectionName, resIds, folderId);
 
                     foreach (var fid in folders)
                     {
@@ -423,12 +424,14 @@
             // (eg. Create a Feature Source from a dragged SDF file)
         }
 
-        private string [] MoveResources(ICollection<string> resIds, string folderId)
+        private string [] MoveResources(string connectionName, ICollection<string> resIds, string folderId)
         {
             var wb = Workbench.Instance;
             var notMovedToTarget = new List<string>();
             var notMovedFromSource = new List<string>();
             var omgr = ServiceRegistry.GetService<OpenResourceManager>();
+            var conn = _connManager.GetConnection(connectionName);
+
             var dlg = new ProgressDialog();
             var worker = new ProgressDialog.DoBackgroundWork((w, e, args) =>
             {
@@ -449,7 +452,7 @@
                         //moved instead of the folder itself!
                         var rid = new ResourceIdentifier(r);
                         var target = folderId + rid.Name + "/";
-                        _conn.ResourceService.MoveResourceWithReferences(r, target, null, cb);
+                        conn.ResourceService.MoveResourceWithReferences(r, target, null, cb);
                     }
                     else
                     {
@@ -462,7 +465,7 @@
                         }
 
                         if (!omgr.IsOpen(target))
-                            _conn.ResourceService.MoveResourceWithReferences(r, target, null, cb);
+                            conn.ResourceService.MoveResourceWithReferences(r, target, null, cb);
                         else
                             notMovedToTarget.Add(r);
                     }
@@ -533,5 +536,10 @@
                 }
             }
         }
+
+        public string[] ConnectionNames
+        {
+            get { return _connManager.GetConnectionNames().ToArray(); }
+        }
     }
 }



More information about the mapguide-commits mailing list