[mapguide-commits] r7491 - in trunk/Tools/Maestro: Maestro.Base Maestro.Base/Commands/SiteExplorer Maestro.Editors Maestro.Editors/FeatureSource OSGeo.MapGuide.MaestroAPI OSGeo.MapGuide.MaestroAPI/Commands

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Sun May 12 10:47:04 PDT 2013


Author: jng
Date: 2013-05-12 10:47:03 -0700 (Sun, 12 May 2013)
New Revision: 7491

Added:
   trunk/Tools/Maestro/Maestro.Base/Commands/SiteExplorer/CreateLayersFromFeatureSourceCommand.cs
   trunk/Tools/Maestro/Maestro.Base/Commands/SiteExplorer/TestFeatureSourceCommand.cs
   trunk/Tools/Maestro/Maestro.Editors/FeatureSource/CreateLayersFromFeatureSourceDialog.Designer.cs
   trunk/Tools/Maestro/Maestro.Editors/FeatureSource/CreateLayersFromFeatureSourceDialog.cs
   trunk/Tools/Maestro/Maestro.Editors/FeatureSource/CreateLayersFromFeatureSourceDialog.resx
Modified:
   trunk/Tools/Maestro/Maestro.Base/Maestro.Base.addin
   trunk/Tools/Maestro/Maestro.Base/Maestro.Base.csproj
   trunk/Tools/Maestro/Maestro.Base/Strings.Designer.cs
   trunk/Tools/Maestro/Maestro.Base/Strings.resx
   trunk/Tools/Maestro/Maestro.Editors/Maestro.Editors.csproj
   trunk/Tools/Maestro/Maestro.Editors/Strings.Designer.cs
   trunk/Tools/Maestro/Maestro.Editors/Strings.resx
   trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Commands/ExecuteLoadProcedure.cs
   trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Utility.cs
Log:
This submission contains the following changes:
 - #2262: Implement shortcut to create default layers from a feature source.
 - Implement a context menu shortcut to test a feature source connection (without needing to open it in an editor)

Added: trunk/Tools/Maestro/Maestro.Base/Commands/SiteExplorer/CreateLayersFromFeatureSourceCommand.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/Commands/SiteExplorer/CreateLayersFromFeatureSourceCommand.cs	                        (rev 0)
+++ trunk/Tools/Maestro/Maestro.Base/Commands/SiteExplorer/CreateLayersFromFeatureSourceCommand.cs	2013-05-12 17:47:03 UTC (rev 7491)
@@ -0,0 +1,99 @@
+#region Disclaimer / License
+// Copyright (C) 2013, 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 ICSharpCode.Core;
+using Maestro.Base.Services;
+using Maestro.Editors.FeatureSource;
+using Maestro.Shared.UI;
+using OSGeo.MapGuide.MaestroAPI;
+using OSGeo.MapGuide.MaestroAPI.Schema;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+
+namespace Maestro.Base.Commands.SiteExplorer
+{
+    internal class CreateLayersFromFeatureSourceCommand : AbstractMenuCommand
+    {
+        public override void Run()
+        {
+            var wb = Workbench.Instance;
+            var exp = wb.ActiveSiteExplorer;
+            if (exp != null && exp.SelectedItems != null && exp.SelectedItems.Length == 1)
+            {
+                var connMgr = ServiceRegistry.GetService<ServerConnectionManager>();
+                var conn = connMgr.GetConnection(wb.ActiveSiteExplorer.ConnectionName);
+                var item = exp.SelectedItems[0];
+
+                var diag = new CreateLayersFromFeatureSourceDialog(conn, item.ResourceId);
+                if (diag.ShowDialog() == System.Windows.Forms.DialogResult.OK)
+                {
+                    CreateLayers(conn, diag.FeatureSource, diag.TargetFolder, diag.FeatureClasses);
+                }
+            }
+        }
+
+        static object DoBackgroundWorker(BackgroundWorker wrk, DoWorkEventArgs e, params object[] args)
+        {
+            var items = (List<ClassDefinition>)args[0];
+            var conn = (IServerConnection)args[1];
+            string featureSource = (string)args[2];
+            string targetFolder = (string)args[3];
+
+            LengthyOperationProgressCallBack cb = (o, pe) =>
+            {
+                wrk.ReportProgress(pe.Progress, o);
+            };
+
+            var result = new HashSet<string>();
+            int processed = 0;
+            foreach (var cls in items)
+            {
+                var lyrId = Utility.CreateDefaultLayer(conn, featureSource, cls, targetFolder);
+                if (lyrId != null)
+                    result.Add(lyrId);
+
+                processed++;
+                cb(null, new LengthyOperationProgressArgs(string.Empty, (int)((processed / items.Count) * 100)));
+            }
+
+            return result;
+        }
+
+        static void CreateLayers(IServerConnection conn, string featureSource, string targetFolder, string[] featureClasses)
+        {
+            var wb = Workbench.Instance;
+            List<ClassDefinition> classes = new List<ClassDefinition>();
+            foreach (var clsName in featureClasses)
+            {
+                classes.Add(conn.FeatureService.GetClassDefinition(featureSource, clsName));
+            }
+            var prg = new ProgressDialog();
+            var results = (ICollection<string>)prg.RunOperationAsync(wb, DoBackgroundWorker, classes, conn, featureSource, targetFolder);
+            var exp = wb.ActiveSiteExplorer;
+            if (exp != null)
+            {
+                exp.RefreshModel(exp.ConnectionName, targetFolder);
+                exp.ExpandNode(exp.ConnectionName, targetFolder);
+            }
+        }
+    }
+}

Added: trunk/Tools/Maestro/Maestro.Base/Commands/SiteExplorer/TestFeatureSourceCommand.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/Commands/SiteExplorer/TestFeatureSourceCommand.cs	                        (rev 0)
+++ trunk/Tools/Maestro/Maestro.Base/Commands/SiteExplorer/TestFeatureSourceCommand.cs	2013-05-12 17:47:03 UTC (rev 7491)
@@ -0,0 +1,56 @@
+#region Disclaimer / License
+// Copyright (C) 2013, 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 ICSharpCode.Core;
+using Maestro.Base.Services;
+using OSGeo.MapGuide.MaestroAPI;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Windows.Forms;
+
+namespace Maestro.Base.Commands.SiteExplorer
+{
+    internal class TestFeatureSourceCommand : AbstractMenuCommand
+    {
+        public override void Run()
+        {
+            var wb = Workbench.Instance;
+            var exp = wb.ActiveSiteExplorer;
+            if (exp != null && exp.SelectedItems != null && exp.SelectedItems.Length == 1)
+            {
+                var connMgr = ServiceRegistry.GetService<ServerConnectionManager>();
+                var conn = connMgr.GetConnection(wb.ActiveSiteExplorer.ConnectionName);
+                var item = exp.SelectedItems[0];
+                try
+                {
+                    if (Utility.IsSuccessfulConnectionTestResult(conn.FeatureService.TestConnection(item.ResourceId)))
+                        MessageBox.Show(Strings.ConnectionTestOk);
+                    else
+                        MessageBox.Show(string.Format(Strings.ConnectionTestFailed, false));
+                }
+                catch (Exception ex)
+                {
+                    MessageBox.Show(string.Format(Strings.ConnectionTestFailed, ex.Message));
+                }
+            }
+        }
+    }
+}

Modified: trunk/Tools/Maestro/Maestro.Base/Maestro.Base.addin
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/Maestro.Base.addin	2013-05-12 15:40:44 UTC (rev 7490)
+++ trunk/Tools/Maestro/Maestro.Base/Maestro.Base.addin	2013-05-12 17:47:03 UTC (rev 7491)
@@ -549,6 +549,13 @@
                           class="Maestro.Base.Commands.SiteExplorer.PurgeFeatureSourceCacheCommand" />
             </Condition>
             <Condition action="Disable" name="ResourceType" types="FeatureSource">
+                <MenuItem id="TestFeatureSource"
+                          label="${res:SiteExplorer_TestFeatureSource}"
+                          icon="tick"
+                          class="Maestro.Base.Commands.SiteExplorer.TestFeatureSourceCommand" />
+                <MenuItem id="CreateLayersFromFeatureSource"
+                          label="${res:SiteExplorer_CreateLayersFromFeatureSource}"
+                          class="Maestro.Base.Commands.SiteExplorer.CreateLayersFromFeatureSourceCommand" />
                 <MenuItem id="ShowSpatialContexts"
                           label="${res:SiteExplorer_ShowSpatialContexts}"
                           class="Maestro.Base.Commands.SiteExplorer.ShowSpatialContextsCommand" />

Modified: trunk/Tools/Maestro/Maestro.Base/Maestro.Base.csproj
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/Maestro.Base.csproj	2013-05-12 15:40:44 UTC (rev 7490)
+++ trunk/Tools/Maestro/Maestro.Base/Maestro.Base.csproj	2013-05-12 17:47:03 UTC (rev 7491)
@@ -98,6 +98,7 @@
     <Compile Include="Commands\LiveMapEditorCommand.cs" />
     <Compile Include="Commands\OpenResourceIdCommand.cs" />
     <Compile Include="Commands\RtMapInspectorCommand.cs" />
+    <Compile Include="Commands\SiteExplorer\CreateLayersFromFeatureSourceCommand.cs" />
     <Compile Include="Commands\SiteExplorer\EditResourceHeaderCommand.cs" />
     <Compile Include="Commands\LoadPackageCommand.cs" />
     <Compile Include="Commands\LocalFeatureSourcePreviewCommand.cs" />
@@ -133,6 +134,7 @@
     <Compile Include="Commands\SiteExplorer\ResourcePropertiesCommand.cs" />
     <Compile Include="Commands\SiteExplorer\SetupFolderStructureCommand.cs" />
     <Compile Include="Commands\SiteExplorer\ShowSpatialContextsCommand.cs" />
+    <Compile Include="Commands\SiteExplorer\TestFeatureSourceCommand.cs" />
     <Compile Include="Commands\SiteExplorer\ValidateCommand.cs" />
     <Compile Include="Commands\StartupCommand.cs" />
     <Compile Include="Commands\SiteExplorer\TestResourceCompatibilityCommand.cs" />

Modified: trunk/Tools/Maestro/Maestro.Base/Strings.Designer.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/Strings.Designer.cs	2013-05-12 15:40:44 UTC (rev 7490)
+++ trunk/Tools/Maestro/Maestro.Base/Strings.Designer.cs	2013-05-12 17:47:03 UTC (rev 7491)
@@ -1,7 +1,7 @@
 //------------------------------------------------------------------------------
 // <auto-generated>
 //     This code was generated by a tool.
-//     Runtime Version:4.0.30319.17929
+//     Runtime Version:4.0.30319.18034
 //
 //     Changes to this file may cause incorrect behavior and will be lost if
 //     the code is regenerated.
@@ -397,6 +397,24 @@
         }
         
         /// <summary>
+        ///   Looks up a localized string similar to Connection Test Failed: {0}.
+        /// </summary>
+        internal static string ConnectionTestFailed {
+            get {
+                return ResourceManager.GetString("ConnectionTestFailed", resourceCulture);
+            }
+        }
+        
+        /// <summary>
+        ///   Looks up a localized string similar to Connection Test OK.
+        /// </summary>
+        internal static string ConnectionTestOk {
+            get {
+                return ResourceManager.GetString("ConnectionTestOk", resourceCulture);
+            }
+        }
+        
+        /// <summary>
         ///   Looks up a localized string similar to Messages.
         /// </summary>
         internal static string Content_Messages {
@@ -1898,6 +1916,15 @@
         }
         
         /// <summary>
+        ///   Looks up a localized string similar to Create Layers from Feature Source.
+        /// </summary>
+        internal static string SiteExplorer_CreateLayersFromFeatureSource {
+            get {
+                return ResourceManager.GetString("SiteExplorer_CreateLayersFromFeatureSource", resourceCulture);
+            }
+        }
+        
+        /// <summary>
         ///   Looks up a localized string similar to Disconnect.
         /// </summary>
         internal static string SiteExplorer_Disconnect {
@@ -2087,6 +2114,15 @@
         }
         
         /// <summary>
+        ///   Looks up a localized string similar to Test Feature Source Connection.
+        /// </summary>
+        internal static string SiteExplorer_TestFeatureSource {
+            get {
+                return ResourceManager.GetString("SiteExplorer_TestFeatureSource", resourceCulture);
+            }
+        }
+        
+        /// <summary>
         ///   Looks up a localized string similar to Test Resource Compatibility.
         /// </summary>
         internal static string SiteExplorer_TestResourceCompatibility {

Modified: trunk/Tools/Maestro/Maestro.Base/Strings.resx
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/Strings.resx	2013-05-12 15:40:44 UTC (rev 7490)
+++ trunk/Tools/Maestro/Maestro.Base/Strings.resx	2013-05-12 17:47:03 UTC (rev 7491)
@@ -992,4 +992,16 @@
   <data name="FailedToCalculateFeatureSourceExtents" xml:space="preserve">
     <value>Could not calculate the extents of the Feature Source. Preview is not possible</value>
   </data>
+  <data name="SiteExplorer_CreateLayersFromFeatureSource" xml:space="preserve">
+    <value>Create Layers from Feature Source</value>
+  </data>
+  <data name="SiteExplorer_TestFeatureSource" xml:space="preserve">
+    <value>Test Feature Source Connection</value>
+  </data>
+  <data name="ConnectionTestFailed" xml:space="preserve">
+    <value>Connection Test Failed: {0}</value>
+  </data>
+  <data name="ConnectionTestOk" xml:space="preserve">
+    <value>Connection Test OK</value>
+  </data>
 </root>
\ No newline at end of file

Added: trunk/Tools/Maestro/Maestro.Editors/FeatureSource/CreateLayersFromFeatureSourceDialog.Designer.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Editors/FeatureSource/CreateLayersFromFeatureSourceDialog.Designer.cs	                        (rev 0)
+++ trunk/Tools/Maestro/Maestro.Editors/FeatureSource/CreateLayersFromFeatureSourceDialog.Designer.cs	2013-05-12 17:47:03 UTC (rev 7491)
@@ -0,0 +1,176 @@
+namespace Maestro.Editors.FeatureSource
+{
+    partial class CreateLayersFromFeatureSourceDialog
+    {
+        /// <summary>
+        /// Required designer variable.
+        /// </summary>
+        private System.ComponentModel.IContainer components = null;
+
+        /// <summary>
+        /// Clean up any resources being used.
+        /// </summary>
+        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
+        protected override void Dispose(bool disposing)
+        {
+            if (disposing && (components != null))
+            {
+                components.Dispose();
+            }
+            base.Dispose(disposing);
+        }
+
+        #region Windows Form Designer generated code
+
+        /// <summary>
+        /// Required method for Designer support - do not modify
+        /// the contents of this method with the code editor.
+        /// </summary>
+        private void InitializeComponent()
+        {
+            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(CreateLayersFromFeatureSourceDialog));
+            this.label1 = new System.Windows.Forms.Label();
+            this.txtFeatureSource = new System.Windows.Forms.TextBox();
+            this.label2 = new System.Windows.Forms.Label();
+            this.txtCreateTargetFolder = new System.Windows.Forms.TextBox();
+            this.groupBox1 = new System.Windows.Forms.GroupBox();
+            this.lstFeatureClasses = new System.Windows.Forms.ListBox();
+            this.label3 = new System.Windows.Forms.Label();
+            this.btnFeatureSource = new System.Windows.Forms.Button();
+            this.btnCreateTarget = new System.Windows.Forms.Button();
+            this.btnCreate = new System.Windows.Forms.Button();
+            this.btnCancel = new System.Windows.Forms.Button();
+            this.lnkSelectAll = new System.Windows.Forms.LinkLabel();
+            this.lnkClear = new System.Windows.Forms.LinkLabel();
+            this.groupBox1.SuspendLayout();
+            this.SuspendLayout();
+            // 
+            // label1
+            // 
+            resources.ApplyResources(this.label1, "label1");
+            this.label1.Name = "label1";
+            // 
+            // txtFeatureSource
+            // 
+            resources.ApplyResources(this.txtFeatureSource, "txtFeatureSource");
+            this.txtFeatureSource.Name = "txtFeatureSource";
+            this.txtFeatureSource.ReadOnly = true;
+            // 
+            // label2
+            // 
+            resources.ApplyResources(this.label2, "label2");
+            this.label2.Name = "label2";
+            // 
+            // txtCreateTargetFolder
+            // 
+            resources.ApplyResources(this.txtCreateTargetFolder, "txtCreateTargetFolder");
+            this.txtCreateTargetFolder.Name = "txtCreateTargetFolder";
+            this.txtCreateTargetFolder.ReadOnly = true;
+            // 
+            // groupBox1
+            // 
+            resources.ApplyResources(this.groupBox1, "groupBox1");
+            this.groupBox1.Controls.Add(this.lnkClear);
+            this.groupBox1.Controls.Add(this.lnkSelectAll);
+            this.groupBox1.Controls.Add(this.lstFeatureClasses);
+            this.groupBox1.Controls.Add(this.label3);
+            this.groupBox1.Name = "groupBox1";
+            this.groupBox1.TabStop = false;
+            // 
+            // lstFeatureClasses
+            // 
+            resources.ApplyResources(this.lstFeatureClasses, "lstFeatureClasses");
+            this.lstFeatureClasses.FormattingEnabled = true;
+            this.lstFeatureClasses.Name = "lstFeatureClasses";
+            this.lstFeatureClasses.SelectionMode = System.Windows.Forms.SelectionMode.MultiSimple;
+            this.lstFeatureClasses.SelectedIndexChanged += new System.EventHandler(this.lstFeatureClasses_SelectedIndexChanged);
+            // 
+            // label3
+            // 
+            resources.ApplyResources(this.label3, "label3");
+            this.label3.Name = "label3";
+            // 
+            // btnFeatureSource
+            // 
+            resources.ApplyResources(this.btnFeatureSource, "btnFeatureSource");
+            this.btnFeatureSource.Name = "btnFeatureSource";
+            this.btnFeatureSource.UseVisualStyleBackColor = true;
+            this.btnFeatureSource.Click += new System.EventHandler(this.btnFeatureSource_Click);
+            // 
+            // btnCreateTarget
+            // 
+            resources.ApplyResources(this.btnCreateTarget, "btnCreateTarget");
+            this.btnCreateTarget.Name = "btnCreateTarget";
+            this.btnCreateTarget.UseVisualStyleBackColor = true;
+            this.btnCreateTarget.Click += new System.EventHandler(this.btnCreateTarget_Click);
+            // 
+            // btnCreate
+            // 
+            resources.ApplyResources(this.btnCreate, "btnCreate");
+            this.btnCreate.Name = "btnCreate";
+            this.btnCreate.UseVisualStyleBackColor = true;
+            this.btnCreate.Click += new System.EventHandler(this.btnCreate_Click);
+            // 
+            // btnCancel
+            // 
+            this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
+            resources.ApplyResources(this.btnCancel, "btnCancel");
+            this.btnCancel.Name = "btnCancel";
+            this.btnCancel.UseVisualStyleBackColor = true;
+            this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
+            // 
+            // lnkSelectAll
+            // 
+            resources.ApplyResources(this.lnkSelectAll, "lnkSelectAll");
+            this.lnkSelectAll.Name = "lnkSelectAll";
+            this.lnkSelectAll.TabStop = true;
+            this.lnkSelectAll.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.lnkSelectAll_LinkClicked);
+            // 
+            // lnkClear
+            // 
+            resources.ApplyResources(this.lnkClear, "lnkClear");
+            this.lnkClear.Name = "lnkClear";
+            this.lnkClear.TabStop = true;
+            this.lnkClear.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.lnkClear_LinkClicked);
+            // 
+            // CreateLayersFromFeatureSourceDialog
+            // 
+            this.AcceptButton = this.btnCreate;
+            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
+            this.CancelButton = this.btnCancel;
+            resources.ApplyResources(this, "$this");
+            this.ControlBox = false;
+            this.Controls.Add(this.btnCancel);
+            this.Controls.Add(this.btnCreate);
+            this.Controls.Add(this.btnCreateTarget);
+            this.Controls.Add(this.btnFeatureSource);
+            this.Controls.Add(this.groupBox1);
+            this.Controls.Add(this.txtCreateTargetFolder);
+            this.Controls.Add(this.label2);
+            this.Controls.Add(this.txtFeatureSource);
+            this.Controls.Add(this.label1);
+            this.Name = "CreateLayersFromFeatureSourceDialog";
+            this.groupBox1.ResumeLayout(false);
+            this.groupBox1.PerformLayout();
+            this.ResumeLayout(false);
+            this.PerformLayout();
+
+        }
+
+        #endregion
+
+        private System.Windows.Forms.Label label1;
+        private System.Windows.Forms.TextBox txtFeatureSource;
+        private System.Windows.Forms.Label label2;
+        private System.Windows.Forms.TextBox txtCreateTargetFolder;
+        private System.Windows.Forms.GroupBox groupBox1;
+        private System.Windows.Forms.ListBox lstFeatureClasses;
+        private System.Windows.Forms.Label label3;
+        private System.Windows.Forms.Button btnFeatureSource;
+        private System.Windows.Forms.Button btnCreateTarget;
+        private System.Windows.Forms.Button btnCreate;
+        private System.Windows.Forms.Button btnCancel;
+        private System.Windows.Forms.LinkLabel lnkClear;
+        private System.Windows.Forms.LinkLabel lnkSelectAll;
+    }
+}
\ No newline at end of file

Added: trunk/Tools/Maestro/Maestro.Editors/FeatureSource/CreateLayersFromFeatureSourceDialog.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Editors/FeatureSource/CreateLayersFromFeatureSourceDialog.cs	                        (rev 0)
+++ trunk/Tools/Maestro/Maestro.Editors/FeatureSource/CreateLayersFromFeatureSourceDialog.cs	2013-05-12 17:47:03 UTC (rev 7491)
@@ -0,0 +1,165 @@
+#region Disclaimer / License
+// Copyright (C) 2013, 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 Maestro.Editors.Generic;
+using Maestro.Shared.UI;
+using OSGeo.MapGuide.MaestroAPI;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Windows.Forms;
+
+namespace Maestro.Editors.FeatureSource
+{
+    public partial class CreateLayersFromFeatureSourceDialog : Form
+    {
+        private CreateLayersFromFeatureSourceDialog()
+        {
+            InitializeComponent();
+        }
+
+        private IServerConnection _conn;
+
+        public CreateLayersFromFeatureSourceDialog(IServerConnection conn, string featureSource)
+            : this()
+        {
+            _conn = conn;
+            txtFeatureSource.Text = featureSource;
+        }
+
+        protected override void OnLoad(EventArgs e)
+        {
+            LoadFeatureClassesAsync();
+        }
+
+        private void LoadFeatureClassesAsync()
+        {
+            btnCreate.Enabled = false;
+
+            string fsId = txtFeatureSource.Text;
+            BusyWaitDialog.Run(null, () =>
+            {
+                return _conn.FeatureService.GetClassNames(fsId, null);
+            }, (result, ex) =>
+            {
+                if (ex != null)
+                {
+                    ErrorDialog.Show(ex);
+                }
+                else
+                {
+                    lstFeatureClasses.DataSource = result;
+                    EvalButtonState();
+                }
+            });
+        }
+
+        private void EvalButtonState()
+        {
+            btnCreate.Enabled = !string.IsNullOrEmpty(txtFeatureSource.Text) &&
+                                !string.IsNullOrEmpty(txtCreateTargetFolder.Text) &&
+                                lstFeatureClasses.SelectedItems.Count > 0;
+        }
+
+        public string FeatureSource
+        {
+            get { return txtFeatureSource.Text; }
+        }
+
+        public string TargetFolder
+        {
+            get { return txtCreateTargetFolder.Text; }
+        }
+
+        public string[] FeatureClasses
+        {
+            get
+            {
+                var items = new List<string>();
+                var selected = lstFeatureClasses.SelectedItems;
+                for (int i = 0; i < selected.Count; i++)
+                {
+                    items.Add(selected[i].ToString());
+                }
+                return items.ToArray();
+            }
+        }
+
+        private void btnCancel_Click(object sender, EventArgs e)
+        {
+            this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
+        }
+
+        private void btnCreate_Click(object sender, EventArgs e)
+        {
+            this.DialogResult = System.Windows.Forms.DialogResult.OK;
+        }
+
+        private void btnFeatureSource_Click(object sender, EventArgs e)
+        {
+            using (var picker = new ResourcePicker(_conn.ResourceService, ResourceTypes.FeatureSource, ResourcePickerMode.OpenResource))
+            {
+                if (picker.ShowDialog() == System.Windows.Forms.DialogResult.OK)
+                {
+                    txtFeatureSource.Text = picker.ResourceID;
+                    LoadFeatureClassesAsync();
+                }
+            }
+        }
+
+        private void btnCreateTarget_Click(object sender, EventArgs e)
+        {
+            using (var picker = new ResourcePicker(_conn.ResourceService, ResourcePickerMode.OpenFolder))
+            {
+                if (picker.ShowDialog() == System.Windows.Forms.DialogResult.OK)
+                {
+                    txtCreateTargetFolder.Text = picker.ResourceID;
+                    EvalButtonState();
+                }
+            }
+        }
+
+        private void lstFeatureClasses_SelectedIndexChanged(object sender, EventArgs e)
+        {
+            EvalButtonState();
+        }
+
+        private void lnkSelectAll_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
+        {
+            for (int i = 0; i < lstFeatureClasses.Items.Count; i++)
+            {
+                lstFeatureClasses.SetSelected(i, true);
+            }
+            EvalButtonState();
+        }
+
+        private void lnkClear_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
+        {
+            for (int i = 0; i < lstFeatureClasses.Items.Count; i++)
+            {
+                lstFeatureClasses.SetSelected(i, false);
+            }
+            EvalButtonState();
+        }
+    }
+}

Added: trunk/Tools/Maestro/Maestro.Editors/FeatureSource/CreateLayersFromFeatureSourceDialog.resx
===================================================================
--- trunk/Tools/Maestro/Maestro.Editors/FeatureSource/CreateLayersFromFeatureSourceDialog.resx	                        (rev 0)
+++ trunk/Tools/Maestro/Maestro.Editors/FeatureSource/CreateLayersFromFeatureSourceDialog.resx	2013-05-12 17:47:03 UTC (rev 7491)
@@ -0,0 +1,480 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+  <!-- 
+    Microsoft ResX Schema 
+    
+    Version 2.0
+    
+    The primary goals of this format is to allow a simple XML format 
+    that is mostly human readable. The generation and parsing of the 
+    various data types are done through the TypeConverter classes 
+    associated with the data types.
+    
+    Example:
+    
+    ... ado.net/XML headers & schema ...
+    <resheader name="resmimetype">text/microsoft-resx</resheader>
+    <resheader name="version">2.0</resheader>
+    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+        <value>[base64 mime encoded serialized .NET Framework object]</value>
+    </data>
+    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+        <comment>This is a comment</comment>
+    </data>
+                
+    There are any number of "resheader" rows that contain simple 
+    name/value pairs.
+    
+    Each data row contains a name, and value. The row also contains a 
+    type or mimetype. Type corresponds to a .NET class that support 
+    text/value conversion through the TypeConverter architecture. 
+    Classes that don't support this are serialized and stored with the 
+    mimetype set.
+    
+    The mimetype is used for serialized objects, and tells the 
+    ResXResourceReader how to depersist the object. This is currently not 
+    extensible. For a given mimetype the value must be set accordingly:
+    
+    Note - application/x-microsoft.net.object.binary.base64 is the format 
+    that the ResXResourceWriter will generate, however the reader can 
+    read any of the formats listed below.
+    
+    mimetype: application/x-microsoft.net.object.binary.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+            : and then encoded with base64 encoding.
+    
+    mimetype: application/x-microsoft.net.object.soap.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+            : and then encoded with base64 encoding.
+
+    mimetype: application/x-microsoft.net.object.bytearray.base64
+    value   : The object must be serialized into a byte array 
+            : using a System.ComponentModel.TypeConverter
+            : and then encoded with base64 encoding.
+    -->
+  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+    <xsd:element name="root" msdata:IsDataSet="true">
+      <xsd:complexType>
+        <xsd:choice maxOccurs="unbounded">
+          <xsd:element name="metadata">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" />
+              </xsd:sequence>
+              <xsd:attribute name="name" use="required" type="xsd:string" />
+              <xsd:attribute name="type" type="xsd:string" />
+              <xsd:attribute name="mimetype" type="xsd:string" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="assembly">
+            <xsd:complexType>
+              <xsd:attribute name="alias" type="xsd:string" />
+              <xsd:attribute name="name" type="xsd:string" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="data">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="resheader">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" />
+            </xsd:complexType>
+          </xsd:element>
+        </xsd:choice>
+      </xsd:complexType>
+    </xsd:element>
+  </xsd:schema>
+  <resheader name="resmimetype">
+    <value>text/microsoft-resx</value>
+  </resheader>
+  <resheader name="version">
+    <value>2.0</value>
+  </resheader>
+  <resheader name="reader">
+    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <resheader name="writer">
+    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <assembly alias="mscorlib" name="mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
+  <data name="label1.AutoSize" type="System.Boolean, mscorlib">
+    <value>True</value>
+  </data>
+  <assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
+  <data name="label1.Location" type="System.Drawing.Point, System.Drawing">
+    <value>13, 13</value>
+  </data>
+  <data name="label1.Size" type="System.Drawing.Size, System.Drawing">
+    <value>80, 13</value>
+  </data>
+  <data name="label1.TabIndex" type="System.Int32, mscorlib">
+    <value>0</value>
+  </data>
+  <data name="label1.Text" xml:space="preserve">
+    <value>Feature Source</value>
+  </data>
+  <data name=">>label1.Name" xml:space="preserve">
+    <value>label1</value>
+  </data>
+  <data name=">>label1.Type" xml:space="preserve">
+    <value>System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </data>
+  <data name=">>label1.Parent" xml:space="preserve">
+    <value>$this</value>
+  </data>
+  <data name=">>label1.ZOrder" xml:space="preserve">
+    <value>8</value>
+  </data>
+  <assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
+  <data name="txtFeatureSource.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
+    <value>Top, Left, Right</value>
+  </data>
+  <data name="txtFeatureSource.Location" type="System.Drawing.Point, System.Drawing">
+    <value>114, 10</value>
+  </data>
+  <data name="txtFeatureSource.Size" type="System.Drawing.Size, System.Drawing">
+    <value>294, 20</value>
+  </data>
+  <data name="txtFeatureSource.TabIndex" type="System.Int32, mscorlib">
+    <value>1</value>
+  </data>
+  <data name=">>txtFeatureSource.Name" xml:space="preserve">
+    <value>txtFeatureSource</value>
+  </data>
+  <data name=">>txtFeatureSource.Type" xml:space="preserve">
+    <value>System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </data>
+  <data name=">>txtFeatureSource.Parent" xml:space="preserve">
+    <value>$this</value>
+  </data>
+  <data name=">>txtFeatureSource.ZOrder" xml:space="preserve">
+    <value>7</value>
+  </data>
+  <data name="label2.AutoSize" type="System.Boolean, mscorlib">
+    <value>True</value>
+  </data>
+  <data name="label2.Location" type="System.Drawing.Point, System.Drawing">
+    <value>13, 42</value>
+  </data>
+  <data name="label2.Size" type="System.Drawing.Size, System.Drawing">
+    <value>83, 13</value>
+  </data>
+  <data name="label2.TabIndex" type="System.Int32, mscorlib">
+    <value>2</value>
+  </data>
+  <data name="label2.Text" xml:space="preserve">
+    <value>Create Layers in</value>
+  </data>
+  <data name=">>label2.Name" xml:space="preserve">
+    <value>label2</value>
+  </data>
+  <data name=">>label2.Type" xml:space="preserve">
+    <value>System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </data>
+  <data name=">>label2.Parent" xml:space="preserve">
+    <value>$this</value>
+  </data>
+  <data name=">>label2.ZOrder" xml:space="preserve">
+    <value>6</value>
+  </data>
+  <data name="txtCreateTargetFolder.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
+    <value>Top, Left, Right</value>
+  </data>
+  <data name="txtCreateTargetFolder.Location" type="System.Drawing.Point, System.Drawing">
+    <value>114, 39</value>
+  </data>
+  <data name="txtCreateTargetFolder.Size" type="System.Drawing.Size, System.Drawing">
+    <value>294, 20</value>
+  </data>
+  <data name="txtCreateTargetFolder.TabIndex" type="System.Int32, mscorlib">
+    <value>3</value>
+  </data>
+  <data name=">>txtCreateTargetFolder.Name" xml:space="preserve">
+    <value>txtCreateTargetFolder</value>
+  </data>
+  <data name=">>txtCreateTargetFolder.Type" xml:space="preserve">
+    <value>System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </data>
+  <data name=">>txtCreateTargetFolder.Parent" xml:space="preserve">
+    <value>$this</value>
+  </data>
+  <data name=">>txtCreateTargetFolder.ZOrder" xml:space="preserve">
+    <value>5</value>
+  </data>
+  <data name="groupBox1.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
+    <value>Top, Bottom, Left, Right</value>
+  </data>
+  <data name="lnkClear.AutoSize" type="System.Boolean, mscorlib">
+    <value>True</value>
+  </data>
+  <data name="lnkClear.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms">
+    <value>NoControl</value>
+  </data>
+  <data name="lnkClear.Location" type="System.Drawing.Point, System.Drawing">
+    <value>330, 26</value>
+  </data>
+  <data name="lnkClear.Size" type="System.Drawing.Size, System.Drawing">
+    <value>37, 13</value>
+  </data>
+  <data name="lnkClear.TabIndex" type="System.Int32, mscorlib">
+    <value>3</value>
+  </data>
+  <data name="lnkClear.Text" xml:space="preserve">
+    <value>(Clear)</value>
+  </data>
+  <data name=">>lnkClear.Name" xml:space="preserve">
+    <value>lnkClear</value>
+  </data>
+  <data name=">>lnkClear.Type" xml:space="preserve">
+    <value>System.Windows.Forms.LinkLabel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </data>
+  <data name=">>lnkClear.Parent" xml:space="preserve">
+    <value>groupBox1</value>
+  </data>
+  <data name=">>lnkClear.ZOrder" xml:space="preserve">
+    <value>0</value>
+  </data>
+  <data name="lnkSelectAll.AutoSize" type="System.Boolean, mscorlib">
+    <value>True</value>
+  </data>
+  <data name="lnkSelectAll.Location" type="System.Drawing.Point, System.Drawing">
+    <value>267, 26</value>
+  </data>
+  <data name="lnkSelectAll.Size" type="System.Drawing.Size, System.Drawing">
+    <value>57, 13</value>
+  </data>
+  <data name="lnkSelectAll.TabIndex" type="System.Int32, mscorlib">
+    <value>2</value>
+  </data>
+  <data name="lnkSelectAll.Text" xml:space="preserve">
+    <value>(Select All)</value>
+  </data>
+  <data name=">>lnkSelectAll.Name" xml:space="preserve">
+    <value>lnkSelectAll</value>
+  </data>
+  <data name=">>lnkSelectAll.Type" xml:space="preserve">
+    <value>System.Windows.Forms.LinkLabel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </data>
+  <data name=">>lnkSelectAll.Parent" xml:space="preserve">
+    <value>groupBox1</value>
+  </data>
+  <data name=">>lnkSelectAll.ZOrder" xml:space="preserve">
+    <value>1</value>
+  </data>
+  <data name="lstFeatureClasses.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
+    <value>Top, Bottom, Left, Right</value>
+  </data>
+  <data name="lstFeatureClasses.Location" type="System.Drawing.Point, System.Drawing">
+    <value>22, 52</value>
+  </data>
+  <data name="lstFeatureClasses.Size" type="System.Drawing.Size, System.Drawing">
+    <value>385, 173</value>
+  </data>
+  <data name="lstFeatureClasses.TabIndex" type="System.Int32, mscorlib">
+    <value>1</value>
+  </data>
+  <data name=">>lstFeatureClasses.Name" xml:space="preserve">
+    <value>lstFeatureClasses</value>
+  </data>
+  <data name=">>lstFeatureClasses.Type" xml:space="preserve">
+    <value>System.Windows.Forms.ListBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </data>
+  <data name=">>lstFeatureClasses.Parent" xml:space="preserve">
+    <value>groupBox1</value>
+  </data>
+  <data name=">>lstFeatureClasses.ZOrder" xml:space="preserve">
+    <value>2</value>
+  </data>
+  <data name="label3.AutoSize" type="System.Boolean, mscorlib">
+    <value>True</value>
+  </data>
+  <data name="label3.Location" type="System.Drawing.Point, System.Drawing">
+    <value>19, 26</value>
+  </data>
+  <data name="label3.Size" type="System.Drawing.Size, System.Drawing">
+    <value>231, 13</value>
+  </data>
+  <data name="label3.TabIndex" type="System.Int32, mscorlib">
+    <value>0</value>
+  </data>
+  <data name="label3.Text" xml:space="preserve">
+    <value>Select the Feature Classes to create layers from</value>
+  </data>
+  <data name=">>label3.Name" xml:space="preserve">
+    <value>label3</value>
+  </data>
+  <data name=">>label3.Type" xml:space="preserve">
+    <value>System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </data>
+  <data name=">>label3.Parent" xml:space="preserve">
+    <value>groupBox1</value>
+  </data>
+  <data name=">>label3.ZOrder" xml:space="preserve">
+    <value>3</value>
+  </data>
+  <data name="groupBox1.Location" type="System.Drawing.Point, System.Drawing">
+    <value>16, 70</value>
+  </data>
+  <data name="groupBox1.Size" type="System.Drawing.Size, System.Drawing">
+    <value>426, 243</value>
+  </data>
+  <data name="groupBox1.TabIndex" type="System.Int32, mscorlib">
+    <value>4</value>
+  </data>
+  <data name="groupBox1.Text" xml:space="preserve">
+    <value>Feature Classes</value>
+  </data>
+  <data name=">>groupBox1.Name" xml:space="preserve">
+    <value>groupBox1</value>
+  </data>
+  <data name=">>groupBox1.Type" xml:space="preserve">
+    <value>System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </data>
+  <data name=">>groupBox1.Parent" xml:space="preserve">
+    <value>$this</value>
+  </data>
+  <data name=">>groupBox1.ZOrder" xml:space="preserve">
+    <value>4</value>
+  </data>
+  <data name="btnFeatureSource.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
+    <value>Top, Right</value>
+  </data>
+  <data name="btnFeatureSource.Location" type="System.Drawing.Point, System.Drawing">
+    <value>414, 8</value>
+  </data>
+  <data name="btnFeatureSource.Size" type="System.Drawing.Size, System.Drawing">
+    <value>28, 23</value>
+  </data>
+  <data name="btnFeatureSource.TabIndex" type="System.Int32, mscorlib">
+    <value>5</value>
+  </data>
+  <data name="btnFeatureSource.Text" xml:space="preserve">
+    <value>...</value>
+  </data>
+  <data name=">>btnFeatureSource.Name" xml:space="preserve">
+    <value>btnFeatureSource</value>
+  </data>
+  <data name=">>btnFeatureSource.Type" xml:space="preserve">
+    <value>System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </data>
+  <data name=">>btnFeatureSource.Parent" xml:space="preserve">
+    <value>$this</value>
+  </data>
+  <data name=">>btnFeatureSource.ZOrder" xml:space="preserve">
+    <value>3</value>
+  </data>
+  <data name="btnCreateTarget.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
+    <value>Top, Right</value>
+  </data>
+  <data name="btnCreateTarget.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms">
+    <value>NoControl</value>
+  </data>
+  <data name="btnCreateTarget.Location" type="System.Drawing.Point, System.Drawing">
+    <value>414, 37</value>
+  </data>
+  <data name="btnCreateTarget.Size" type="System.Drawing.Size, System.Drawing">
+    <value>28, 23</value>
+  </data>
+  <data name="btnCreateTarget.TabIndex" type="System.Int32, mscorlib">
+    <value>6</value>
+  </data>
+  <data name="btnCreateTarget.Text" xml:space="preserve">
+    <value>...</value>
+  </data>
+  <data name=">>btnCreateTarget.Name" xml:space="preserve">
+    <value>btnCreateTarget</value>
+  </data>
+  <data name=">>btnCreateTarget.Type" xml:space="preserve">
+    <value>System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </data>
+  <data name=">>btnCreateTarget.Parent" xml:space="preserve">
+    <value>$this</value>
+  </data>
+  <data name=">>btnCreateTarget.ZOrder" xml:space="preserve">
+    <value>2</value>
+  </data>
+  <data name="btnCreate.Location" type="System.Drawing.Point, System.Drawing">
+    <value>286, 328</value>
+  </data>
+  <data name="btnCreate.Size" type="System.Drawing.Size, System.Drawing">
+    <value>75, 23</value>
+  </data>
+  <data name="btnCreate.TabIndex" type="System.Int32, mscorlib">
+    <value>7</value>
+  </data>
+  <data name="btnCreate.Text" xml:space="preserve">
+    <value>Create</value>
+  </data>
+  <data name=">>btnCreate.Name" xml:space="preserve">
+    <value>btnCreate</value>
+  </data>
+  <data name=">>btnCreate.Type" xml:space="preserve">
+    <value>System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </data>
+  <data name=">>btnCreate.Parent" xml:space="preserve">
+    <value>$this</value>
+  </data>
+  <data name=">>btnCreate.ZOrder" xml:space="preserve">
+    <value>1</value>
+  </data>
+  <data name="btnCancel.Location" type="System.Drawing.Point, System.Drawing">
+    <value>367, 328</value>
+  </data>
+  <data name="btnCancel.Size" type="System.Drawing.Size, System.Drawing">
+    <value>75, 23</value>
+  </data>
+  <data name="btnCancel.TabIndex" type="System.Int32, mscorlib">
+    <value>8</value>
+  </data>
+  <data name="btnCancel.Text" xml:space="preserve">
+    <value>Cancel</value>
+  </data>
+  <data name=">>btnCancel.Name" xml:space="preserve">
+    <value>btnCancel</value>
+  </data>
+  <data name=">>btnCancel.Type" xml:space="preserve">
+    <value>System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </data>
+  <data name=">>btnCancel.Parent" xml:space="preserve">
+    <value>$this</value>
+  </data>
+  <data name=">>btnCancel.ZOrder" xml:space="preserve">
+    <value>0</value>
+  </data>
+  <metadata name="$this.Localizable" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+    <value>True</value>
+  </metadata>
+  <data name="$this.ClientSize" type="System.Drawing.Size, System.Drawing">
+    <value>454, 363</value>
+  </data>
+  <data name="$this.Text" xml:space="preserve">
+    <value>Create Layers From Feature Source</value>
+  </data>
+  <data name=">>$this.Name" xml:space="preserve">
+    <value>CreateLayersFromFeatureSourceDialog</value>
+  </data>
+  <data name=">>$this.Type" xml:space="preserve">
+    <value>System.Windows.Forms.Form, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </data>
+</root>
\ No newline at end of file

Modified: trunk/Tools/Maestro/Maestro.Editors/Maestro.Editors.csproj
===================================================================
--- trunk/Tools/Maestro/Maestro.Editors/Maestro.Editors.csproj	2013-05-12 15:40:44 UTC (rev 7490)
+++ trunk/Tools/Maestro/Maestro.Editors/Maestro.Editors.csproj	2013-05-12 17:47:03 UTC (rev 7491)
@@ -224,6 +224,12 @@
     <Compile Include="FeatureSource\CoordSys\CoordSysOverrideDialog.Designer.cs">
       <DependentUpon>CoordSysOverrideDialog.cs</DependentUpon>
     </Compile>
+    <Compile Include="FeatureSource\CreateLayersFromFeatureSourceDialog.cs">
+      <SubType>Form</SubType>
+    </Compile>
+    <Compile Include="FeatureSource\CreateLayersFromFeatureSourceDialog.Designer.cs">
+      <DependentUpon>CreateLayersFromFeatureSourceDialog.cs</DependentUpon>
+    </Compile>
     <Compile Include="FeatureSource\ExtensionsCtrl.cs">
       <SubType>UserControl</SubType>
     </Compile>
@@ -1259,6 +1265,9 @@
       <DependentUpon>CoordSysOverrideDialog.cs</DependentUpon>
       <SubType>Designer</SubType>
     </EmbeddedResource>
+    <EmbeddedResource Include="FeatureSource\CreateLayersFromFeatureSourceDialog.resx">
+      <DependentUpon>CreateLayersFromFeatureSourceDialog.cs</DependentUpon>
+    </EmbeddedResource>
     <EmbeddedResource Include="FeatureSource\ExtensionsCtrl.resx">
       <DependentUpon>ExtensionsCtrl.cs</DependentUpon>
       <SubType>Designer</SubType>

Modified: trunk/Tools/Maestro/Maestro.Editors/Strings.Designer.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Editors/Strings.Designer.cs	2013-05-12 15:40:44 UTC (rev 7490)
+++ trunk/Tools/Maestro/Maestro.Editors/Strings.Designer.cs	2013-05-12 17:47:03 UTC (rev 7491)
@@ -1,7 +1,7 @@
 //------------------------------------------------------------------------------
 // <auto-generated>
 //     This code was generated by a tool.
-//     Runtime Version:4.0.30319.17929
+//     Runtime Version:4.0.30319.18034
 //
 //     Changes to this file may cause incorrect behavior and will be lost if
 //     the code is regenerated.
@@ -1346,6 +1346,15 @@
         }
         
         /// <summary>
+        ///   Looks up a localized string similar to Loading Feature Classes.
+        /// </summary>
+        internal static string LoadingFeatureClasses {
+            get {
+                return ResourceManager.GetString("LoadingFeatureClasses", resourceCulture);
+            }
+        }
+        
+        /// <summary>
         ///   Looks up a localized string similar to This connection does not support executing this type of Load Procedure.
         /// </summary>
         internal static string LoadProcedureVersionExecutionNotSupported {

Modified: trunk/Tools/Maestro/Maestro.Editors/Strings.resx
===================================================================
--- trunk/Tools/Maestro/Maestro.Editors/Strings.resx	2013-05-12 15:40:44 UTC (rev 7490)
+++ trunk/Tools/Maestro/Maestro.Editors/Strings.resx	2013-05-12 17:47:03 UTC (rev 7491)
@@ -1461,4 +1461,7 @@
   <data name="Func_URLENCODE_StringValueDescription" xml:space="preserve">
     <value>String to URL encode</value>
   </data>
+  <data name="LoadingFeatureClasses" xml:space="preserve">
+    <value>Loading Feature Classes</value>
+  </data>
 </root>
\ No newline at end of file

Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Commands/ExecuteLoadProcedure.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Commands/ExecuteLoadProcedure.cs	2013-05-12 15:40:44 UTC (rev 7490)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Commands/ExecuteLoadProcedure.cs	2013-05-12 17:47:03 UTC (rev 7491)
@@ -328,8 +328,7 @@
                             //Step 3: Test to make sure we're all good so far
                             string result = this.Parent.FeatureService.TestConnection(fsId);
 
-                            //LocalNativeConnection returns this string, so I'm assuming this is the "success" result
-                            if (result == "No errors" || result.ToLower() == "true") //NOXLATE
+                            if (Utility.IsSuccessfulConnectionTestResult(result))
                             {
                                 //Step 4: Test to see if default cs needs to be specified
                                 FdoSpatialContextList spatialContexts = this.Parent.FeatureService.GetSpatialContextInfo(fsId, false);

Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Utility.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Utility.cs	2013-05-12 15:40:44 UTC (rev 7490)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Utility.cs	2013-05-12 17:47:03 UTC (rev 7491)
@@ -112,6 +112,17 @@
         }
 
         /// <summary>
+        /// Checks if the given result is a successful test connection result
+        /// </summary>
+        /// <param name="sResult"></param>
+        /// <returns></returns>
+        public static bool IsSuccessfulConnectionTestResult(string sResult)
+        {
+            //LocalNativeConnection returns this string, so I'm assuming this is the "success" result
+            return (sResult == "No errors" || sResult.ToLower() == "true"); //NOXLATE
+        }
+
+        /// <summary>
         /// Parses a color in HTML notation (ea. #ffaabbff)
         /// </summary>
         /// <param name="color">The HTML representation of the color</param>
@@ -1075,6 +1086,83 @@
         const string RESERVED_CHARS = "\\:*?\"<>|&'%=/";
 
         /// <summary>
+        /// Creates a default Layer Definition from the given Class Definition
+        /// </summary>
+        /// <param name="conn"></param>
+        /// <param name="fsId"></param>
+        /// <param name="clsDef"></param>
+        /// <param name="targetFolder"></param>
+        /// <returns></returns>
+        public static string CreateDefaultLayer(IServerConnection conn, string fsId, ClassDefinition clsDef, string targetFolder)
+        {
+            GeometricPropertyDefinition geom = null;
+            //Try designated
+            if (!string.IsNullOrEmpty(clsDef.DefaultGeometryPropertyName))
+            {
+                geom = clsDef.FindProperty(clsDef.DefaultGeometryPropertyName) as GeometricPropertyDefinition;
+            }
+            //Try first geom property
+            if (geom == null)
+            {
+                foreach (PropertyDefinition pd in clsDef.Properties)
+                {
+                    if (pd.Type == PropertyDefinitionType.Geometry)
+                    {
+                        geom = (GeometricPropertyDefinition)pd;
+                        break;
+                    }
+                }
+            }
+            //Can't proceed without a geometry
+            if (geom == null)
+                return null;
+
+            //Compute target resource id
+            var prefix = targetFolder;
+            if (!prefix.EndsWith("/")) //NOXLATE
+                prefix += "/";
+            var lyrId = prefix + clsDef.Name + ".LayerDefinition"; //NOXLATE
+
+            int counter = 0;
+            while (conn.ResourceService.ResourceExists(lyrId))
+            {
+                counter++;
+                lyrId = prefix + clsDef.Name + "(" + counter + ").LayerDefinition"; //NOXLATE
+            }
+
+            var ld = ObjectFactory.CreateDefaultLayer(conn, LayerType.Vector, new Version(1, 0, 0));
+
+            //Assign default properties
+            ld.ResourceID = lyrId;
+            var vld = ld.SubLayer as IVectorLayerDefinition;
+            vld.ResourceId = fsId;
+            vld.FeatureName = clsDef.QualifiedName;
+            vld.Geometry = geom.Name;
+
+            //Infer geometry storage support and remove unsupported styles
+            var scale = vld.GetScaleRangeAt(0);
+            var geomTypes = geom.GetIndividualGeometricTypes();
+            var remove = new List<string>();
+            if (Array.IndexOf(geomTypes, FeatureGeometricType.Point) < 0)
+            {
+                remove.Add(FeatureGeometricType.Point.ToString().ToLower());
+            }
+            if (Array.IndexOf(geomTypes, FeatureGeometricType.Curve) < 0)
+            {
+                remove.Add(FeatureGeometricType.Curve.ToString().ToLower());
+            }
+            if (Array.IndexOf(geomTypes, FeatureGeometricType.Surface) < 0)
+            {
+                remove.Add(FeatureGeometricType.Surface.ToString().ToLower());
+            }
+
+            scale.RemoveStyles(remove);
+            conn.ResourceService.SaveResource(ld);
+
+            return lyrId;
+        }
+
+        /// <summary>
         /// Generates a unique layer name for a given vector rule
         /// </summary>
         /// <param name="layerFormat"></param>



More information about the mapguide-commits mailing list