[mapguide-commits] r6101 - in trunk/Tools/Maestro/Maestro.Base: . Properties Services Services/DragDropHandlers UI

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Sun Aug 28 13:15:38 EDT 2011


Author: jng
Date: 2011-08-28 10:15:37 -0700 (Sun, 28 Aug 2011)
New Revision: 6101

Added:
   trunk/Tools/Maestro/Maestro.Base/Services/DragDropHandlers/DwfFileHandler.cs
Modified:
   trunk/Tools/Maestro/Maestro.Base/Maestro.Base.addin
   trunk/Tools/Maestro/Maestro.Base/Maestro.Base.csproj
   trunk/Tools/Maestro/Maestro.Base/Properties/Resources.Designer.cs
   trunk/Tools/Maestro/Maestro.Base/Properties/Resources.resx
   trunk/Tools/Maestro/Maestro.Base/Services/DragDropHandlers/PackageFileHandler.cs
   trunk/Tools/Maestro/Maestro.Base/Services/DragDropHandlers/SdfFileHandler.cs
   trunk/Tools/Maestro/Maestro.Base/Services/DragDropHandlers/ShpFileHandler.cs
   trunk/Tools/Maestro/Maestro.Base/Services/DragDropHandlers/SltFileHandler.cs
   trunk/Tools/Maestro/Maestro.Base/Services/DragDropHandlers/XmlResFileHandler.cs
   trunk/Tools/Maestro/Maestro.Base/Services/IDragDropHandler.cs
   trunk/Tools/Maestro/Maestro.Base/Services/OpenResourceManager.cs
   trunk/Tools/Maestro/Maestro.Base/UI/SiteExplorerDragDropHandler.cs
Log:
#1794: Support creating Drawing Sources from drag/dropped DWF files. Also fix drag/drop handlers to be multi-site aware

Modified: trunk/Tools/Maestro/Maestro.Base/Maestro.Base.addin
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/Maestro.Base.addin	2011-08-28 16:40:57 UTC (rev 6100)
+++ trunk/Tools/Maestro/Maestro.Base/Maestro.Base.addin	2011-08-28 17:15:37 UTC (rev 6101)
@@ -34,6 +34,7 @@
     <Path name="/Maestro/DragDropHandlers">
         <Class id="MgpHandler" class="Maestro.Base.Services.DragDropHandlers.PackageFileHandler" />
         <Class id="SdfHandler" class="Maestro.Base.Services.DragDropHandlers.SdfFileHandler" />
+        <Class id="DwfHandler" class="Maestro.Base.Services.DragDropHandlers.DwfFileHandler" />
         <Class id="ShpHandler" class="Maestro.Base.Services.DragDropHandlers.ShpFileHandler" />
         <Class id="SltHandler" class="Maestro.Base.Services.DragDropHandlers.SltFileHandler" />
         <Class id="XmlResHandler" class="Maestro.Base.Services.DragDropHandlers.XmlResFileHandler" />

Modified: trunk/Tools/Maestro/Maestro.Base/Maestro.Base.csproj
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/Maestro.Base.csproj	2011-08-28 16:40:57 UTC (rev 6100)
+++ trunk/Tools/Maestro/Maestro.Base/Maestro.Base.csproj	2011-08-28 17:15:37 UTC (rev 6101)
@@ -244,6 +244,7 @@
     </Compile>
     <Compile Include="Services\ClipboardService.cs" />
     <Compile Include="Services\DragDropHandlerService.cs" />
+    <Compile Include="Services\DragDropHandlers\DwfFileHandler.cs" />
     <Compile Include="Services\DragDropHandlers\PackageFileHandler.cs" />
     <Compile Include="Services\DragDropHandlers\SltFileHandler.cs" />
     <Compile Include="Services\DragDropHandlers\SdfFileHandler.cs" />

Modified: trunk/Tools/Maestro/Maestro.Base/Properties/Resources.Designer.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/Properties/Resources.Designer.cs	2011-08-28 16:40:57 UTC (rev 6100)
+++ trunk/Tools/Maestro/Maestro.Base/Properties/Resources.Designer.cs	2011-08-28 17:15:37 UTC (rev 6101)
@@ -646,6 +646,15 @@
             }
         }
         
+        /// <summary>
+        ///   Looks up a localized string similar to Create a Drawing Source.
+        /// </summary>
+        internal static string DwfHandlerAction {
+            get {
+                return ResourceManager.GetString("DwfHandlerAction", resourceCulture);
+            }
+        }
+        
         internal static System.Drawing.Bitmap edit {
             get {
                 object obj = ResourceManager.GetObject("edit", resourceCulture);

Modified: trunk/Tools/Maestro/Maestro.Base/Properties/Resources.resx
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/Properties/Resources.resx	2011-08-28 16:40:57 UTC (rev 6100)
+++ trunk/Tools/Maestro/Maestro.Base/Properties/Resources.resx	2011-08-28 17:15:37 UTC (rev 6101)
@@ -1064,4 +1064,7 @@
   <data name="EditorTitleTemplate" xml:space="preserve">
     <value>Resource ID: {0}{1}Connection: {2}</value>
   </data>
+  <data name="DwfHandlerAction" xml:space="preserve">
+    <value>Create a Drawing Source</value>
+  </data>
 </root>
\ No newline at end of file

Added: trunk/Tools/Maestro/Maestro.Base/Services/DragDropHandlers/DwfFileHandler.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/Services/DragDropHandlers/DwfFileHandler.cs	                        (rev 0)
+++ trunk/Tools/Maestro/Maestro.Base/Services/DragDropHandlers/DwfFileHandler.cs	2011-08-28 17:15:37 UTC (rev 6101)
@@ -0,0 +1,83 @@
+#region Disclaimer / License
+// Copyright (C) 2011, Jackie Ng
+// http://trac.osgeo.org/mapguide/wiki/maestro, jumpinjackie at gmail.com
+// 
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// 
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+// 
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+// 
+#endregion
+using System;
+using System.Collections.Generic;
+using System.Text;
+using OSGeo.MapGuide.MaestroAPI.Resource;
+using System.IO;
+using ICSharpCode.Core;
+using OSGeo.MapGuide.ObjectModels;
+using Maestro.Shared.UI;
+using OSGeo.MapGuide.MaestroAPI;
+
+namespace Maestro.Base.Services.DragDropHandlers
+{
+    public class DwfFileHandler : IDragDropHandler
+    {
+        public string HandlerAction
+        {
+            get { return Properties.Resources.DwfHandlerAction; }
+        }
+
+        string[] extensions = { ".dwf" };
+
+        public string[] FileExtensions
+        {
+            get { return extensions; }
+        }
+
+        public bool HandleDrop(IServerConnection conn, string file, string folderId)
+        {
+            try
+            {
+                var wb = Workbench.Instance;
+                var exp = wb.ActiveSiteExplorer;
+                var ds = ObjectFactory.CreateDrawingSource(conn);
+
+                string fileName = Path.GetFileName(file);
+                string resName = Path.GetFileNameWithoutExtension(file);
+                int counter = 0;
+                string resId = folderId + resName + ".DrawingSource";
+                while (conn.ResourceService.ResourceExists(resId))
+                {
+                    counter++;
+                    resId = folderId + resName + " (" + counter + ").DrawingSource";
+                }
+                ds.ResourceID = resId;
+                //fs.SetConnectionProperty("File", "%MG_DATA_FILE_PATH%" + fileName);
+
+                ds.SourceName = fileName;
+                conn.ResourceService.SaveResource(ds);
+
+                using (var stream = File.Open(file, FileMode.Open))
+                {
+                    ds.SetResourceData(fileName, OSGeo.MapGuide.ObjectModels.Common.ResourceDataType.File, stream);
+                }
+
+                return true;
+            }
+            catch (Exception ex)
+            {
+                ErrorDialog.Show(ex);
+                return false;
+            }
+        }
+    }
+}

Modified: trunk/Tools/Maestro/Maestro.Base/Services/DragDropHandlers/PackageFileHandler.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/Services/DragDropHandlers/PackageFileHandler.cs	2011-08-28 16:40:57 UTC (rev 6100)
+++ trunk/Tools/Maestro/Maestro.Base/Services/DragDropHandlers/PackageFileHandler.cs	2011-08-28 17:15:37 UTC (rev 6101)
@@ -24,6 +24,7 @@
 using ICSharpCode.Core;
 using Maestro.Packaging;
 using Maestro.Shared.UI;
+using OSGeo.MapGuide.MaestroAPI;
 
 namespace Maestro.Base.Services.DragDropHandlers
 {
@@ -41,7 +42,7 @@
             get { return extensions; }
         }
 
-        public bool HandleDrop(string file, string folderId)
+        public bool HandleDrop(IServerConnection conn, string file, string folderId)
         {
             try
             {
@@ -50,8 +51,6 @@
 
                 var wb = Workbench.Instance;
                 var exp = wb.ActiveSiteExplorer;
-                var mgr = ServiceRegistry.GetService<ServerConnectionManager>();
-                var conn = mgr.GetConnection(exp.ConnectionName);
                 var res = PackageProgress.UploadPackage(
                         wb,
                         conn,

Modified: trunk/Tools/Maestro/Maestro.Base/Services/DragDropHandlers/SdfFileHandler.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/Services/DragDropHandlers/SdfFileHandler.cs	2011-08-28 16:40:57 UTC (rev 6100)
+++ trunk/Tools/Maestro/Maestro.Base/Services/DragDropHandlers/SdfFileHandler.cs	2011-08-28 17:15:37 UTC (rev 6101)
@@ -25,6 +25,7 @@
 using ICSharpCode.Core;
 using OSGeo.MapGuide.ObjectModels;
 using Maestro.Shared.UI;
+using OSGeo.MapGuide.MaestroAPI;
 
 namespace Maestro.Base.Services.DragDropHandlers
 {
@@ -42,14 +43,12 @@
             get { return extensions; }
         }
 
-        public bool HandleDrop(string file, string folderId)
+        public bool HandleDrop(IServerConnection conn, string file, string folderId)
         {
             try
             {
                 var wb = Workbench.Instance;
                 var exp = wb.ActiveSiteExplorer;
-                var mgr = ServiceRegistry.GetService<ServerConnectionManager>();
-                var conn = mgr.GetConnection(exp.ConnectionName);
                 var fs = ObjectFactory.CreateFeatureSource(conn, "OSGeo.SDF");
 
                 string fileName = Path.GetFileName(file);

Modified: trunk/Tools/Maestro/Maestro.Base/Services/DragDropHandlers/ShpFileHandler.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/Services/DragDropHandlers/ShpFileHandler.cs	2011-08-28 16:40:57 UTC (rev 6100)
+++ trunk/Tools/Maestro/Maestro.Base/Services/DragDropHandlers/ShpFileHandler.cs	2011-08-28 17:15:37 UTC (rev 6101)
@@ -25,6 +25,7 @@
 using ICSharpCode.Core;
 using OSGeo.MapGuide.MaestroAPI.Resource;
 using Maestro.Shared.UI;
+using OSGeo.MapGuide.MaestroAPI;
 
 namespace Maestro.Base.Services.DragDropHandlers
 {
@@ -42,14 +43,12 @@
             get { return extensions; }
         }
 
-        public bool HandleDrop(string file, string folderId)
+        public bool HandleDrop(IServerConnection conn, string file, string folderId)
         {
             try
             {
                 var wb = Workbench.Instance;
                 var exp = wb.ActiveSiteExplorer;
-                var mgr = ServiceRegistry.GetService<ServerConnectionManager>();
-                var conn = mgr.GetConnection(exp.ConnectionName);
                 var fs = ObjectFactory.CreateFeatureSource(conn, "OSGeo.SHP");
 
                 string fileName = Path.GetFileName(file);

Modified: trunk/Tools/Maestro/Maestro.Base/Services/DragDropHandlers/SltFileHandler.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/Services/DragDropHandlers/SltFileHandler.cs	2011-08-28 16:40:57 UTC (rev 6100)
+++ trunk/Tools/Maestro/Maestro.Base/Services/DragDropHandlers/SltFileHandler.cs	2011-08-28 17:15:37 UTC (rev 6101)
@@ -25,6 +25,7 @@
 using ICSharpCode.Core;
 using OSGeo.MapGuide.ObjectModels;
 using Maestro.Shared.UI;
+using OSGeo.MapGuide.MaestroAPI;
 
 namespace Maestro.Base.Services.DragDropHandlers
 {
@@ -42,14 +43,12 @@
             get { return extensions; }
         }
 
-        public bool HandleDrop(string file, string folderId)
+        public bool HandleDrop(IServerConnection conn, string file, string folderId)
         {
             try
             {
                 var wb = Workbench.Instance;
                 var exp = wb.ActiveSiteExplorer;
-                var mgr = ServiceRegistry.GetService<ServerConnectionManager>();
-                var conn = mgr.GetConnection(exp.ConnectionName);
                 var fs = ObjectFactory.CreateFeatureSource(conn, "OSGeo.SQLite");
 
                 string fileName = Path.GetFileName(file);

Modified: trunk/Tools/Maestro/Maestro.Base/Services/DragDropHandlers/XmlResFileHandler.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/Services/DragDropHandlers/XmlResFileHandler.cs	2011-08-28 16:40:57 UTC (rev 6100)
+++ trunk/Tools/Maestro/Maestro.Base/Services/DragDropHandlers/XmlResFileHandler.cs	2011-08-28 17:15:37 UTC (rev 6101)
@@ -51,14 +51,12 @@
             get { return extensions; }
         }
 
-        public bool HandleDrop(string file, string folderId)
+        public bool HandleDrop(IServerConnection conn, string file, string folderId)
         {
             try
             {
                 var wb = Workbench.Instance;
                 var exp = wb.ActiveSiteExplorer;
-                var mgr = ServiceRegistry.GetService<ServerConnectionManager>();
-                var conn = mgr.GetConnection(exp.ConnectionName);
 
                 //The easiest way to tell if this XML file is legit
                 var res = ResourceTypeRegistry.Deserialize(File.ReadAllText(file));

Modified: trunk/Tools/Maestro/Maestro.Base/Services/IDragDropHandler.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/Services/IDragDropHandler.cs	2011-08-28 16:40:57 UTC (rev 6100)
+++ trunk/Tools/Maestro/Maestro.Base/Services/IDragDropHandler.cs	2011-08-28 17:15:37 UTC (rev 6101)
@@ -20,6 +20,7 @@
 using System;
 using System.Collections.Generic;
 using System.Text;
+using OSGeo.MapGuide.MaestroAPI;
 
 namespace Maestro.Base.Services
 {
@@ -41,9 +42,10 @@
         /// <summary>
         /// Handles the file drop
         /// </summary>
+        /// <param name="conn">The connection this drop affects</param>
         /// <param name="file">The file being dropped</param>
         /// <param name="folderId">The site explorer folder this drop was performed</param>
         /// <returns>true if the drop was successfully handled</returns>
-        bool HandleDrop(string file, string folderId);
+        bool HandleDrop(IServerConnection conn, string file, string folderId);
     }
 }

Modified: trunk/Tools/Maestro/Maestro.Base/Services/OpenResourceManager.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/Services/OpenResourceManager.cs	2011-08-28 16:40:57 UTC (rev 6100)
+++ trunk/Tools/Maestro/Maestro.Base/Services/OpenResourceManager.cs	2011-08-28 17:15:37 UTC (rev 6101)
@@ -193,7 +193,7 @@
                 };
                 ed.DirtyStateChanged += (sender, e) =>
                 {
-                    siteExp.FlagNode(key, ed.IsDirty ? NodeFlagAction.HighlightDirty : NodeFlagAction.HighlightOpen);
+                    siteExp.FlagNode(conn.DisplayName, res.ResourceID, ed.IsDirty ? NodeFlagAction.HighlightDirty : NodeFlagAction.HighlightOpen);
                 };
             }
             _openItems[key].Activate();

Modified: trunk/Tools/Maestro/Maestro.Base/UI/SiteExplorerDragDropHandler.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/UI/SiteExplorerDragDropHandler.cs	2011-08-28 16:40:57 UTC (rev 6100)
+++ trunk/Tools/Maestro/Maestro.Base/UI/SiteExplorerDragDropHandler.cs	2011-08-28 17:15:37 UTC (rev 6101)
@@ -24,6 +24,7 @@
 using Maestro.Base.Services;
 using Maestro.Shared.UI;
 using Aga.Controls.Tree;
+using OSGeo.MapGuide.MaestroAPI;
 
 namespace Maestro.Base.UI
 {
@@ -49,6 +50,9 @@
         {
             //If drop node specified, extract relevant folder, otherwise default to root (Library://)
             string folderId = "Library://";
+            IServerConnection conn = null;
+            var mgr = ServiceRegistry.GetService<ServerConnectionManager>();
+                
             if (droppedNode != null)
             {
                 var ri = droppedNode.Tag as RepositoryItem;
@@ -59,7 +63,12 @@
                     else
                         folderId = ri.Parent != null ? ri.Parent.ResourceId : "Library://";
                 }
+                conn = mgr.GetConnection(ri.ConnectionName);
             }
+            else
+            {
+                return;
+            }
 
             Array a = e.Data.GetData(DataFormats.FileDrop) as Array;
             bool refresh = false;
@@ -79,7 +88,7 @@
                     {
                         using (new WaitCursor(Workbench.Instance))
                         {
-                            if (handlers[0].HandleDrop(file, folderId))
+                            if (handlers[0].HandleDrop(conn, file, folderId))
                                 refresh = true;
                         }
                     }
@@ -91,7 +100,7 @@
                 }
             }
             if (refresh)
-                sender.RefreshModel(folderId);
+                sender.RefreshModel(conn.DisplayName, folderId);
         }
     }
 }



More information about the mapguide-commits mailing list