[mapguide-commits] r5724 - in trunk/Tools/Maestro:
Maestro.Editors/FeatureSource/Providers/Gdal
OSGeo.MapGuide.MaestroAPI/SchemaOverrides
svn_mapguide at osgeo.org
svn_mapguide at osgeo.org
Thu Apr 28 08:09:53 EDT 2011
Author: jng
Date: 2011-04-28 05:09:53 -0700 (Thu, 28 Apr 2011)
New Revision: 5724
Modified:
trunk/Tools/Maestro/Maestro.Editors/FeatureSource/Providers/Gdal/CompositeFileCtrl.Designer.cs
trunk/Tools/Maestro/Maestro.Editors/FeatureSource/Providers/Gdal/CompositeFileCtrl.cs
trunk/Tools/Maestro/Maestro.Editors/FeatureSource/Providers/Gdal/CompositeFileCtrl.resx
trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/SchemaOverrides/GdalRasterItem.cs
Log:
#1664: Add support for adding aliased raster files to a GDAL configuration document. I am told this worked in previous releases.
Modified: trunk/Tools/Maestro/Maestro.Editors/FeatureSource/Providers/Gdal/CompositeFileCtrl.Designer.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Editors/FeatureSource/Providers/Gdal/CompositeFileCtrl.Designer.cs 2011-04-28 10:46:25 UTC (rev 5723)
+++ trunk/Tools/Maestro/Maestro.Editors/FeatureSource/Providers/Gdal/CompositeFileCtrl.Designer.cs 2011-04-28 12:09:53 UTC (rev 5724)
@@ -31,6 +31,9 @@
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(CompositeFileCtrl));
this.toolStrip1 = new System.Windows.Forms.ToolStrip();
+ this.btnAdd = new System.Windows.Forms.ToolStripDropDownButton();
+ this.browseFilesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.browseFolderToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.btnDelete = new System.Windows.Forms.ToolStripButton();
this.lstView = new System.Windows.Forms.ListView();
this.imgList = new System.Windows.Forms.ImageList(this.components);
@@ -38,9 +41,9 @@
this.btnRebuild = new System.Windows.Forms.Button();
this.folderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog();
this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
- this.btnAdd = new System.Windows.Forms.ToolStripDropDownButton();
- this.browseFilesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
- this.browseFolderToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.browseAliasedFileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.browseAliasedFolderToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
this.toolStrip1.SuspendLayout();
this.SuspendLayout();
//
@@ -55,6 +58,36 @@
this.toolStrip1.TabIndex = 0;
this.toolStrip1.Text = "toolStrip1";
//
+ // btnAdd
+ //
+ this.btnAdd.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.browseFilesToolStripMenuItem,
+ this.browseFolderToolStripMenuItem,
+ this.toolStripSeparator1,
+ this.browseAliasedFileToolStripMenuItem,
+ this.browseAliasedFolderToolStripMenuItem});
+ this.btnAdd.Image = global::Maestro.Editors.Properties.Resources.plus_circle;
+ this.btnAdd.ImageTransparentColor = System.Drawing.Color.Magenta;
+ this.btnAdd.Name = "btnAdd";
+ this.btnAdd.Size = new System.Drawing.Size(58, 22);
+ this.btnAdd.Text = "Add";
+ //
+ // browseFilesToolStripMenuItem
+ //
+ this.browseFilesToolStripMenuItem.Image = global::Maestro.Editors.Properties.Resources.document;
+ this.browseFilesToolStripMenuItem.Name = "browseFilesToolStripMenuItem";
+ this.browseFilesToolStripMenuItem.Size = new System.Drawing.Size(189, 22);
+ this.browseFilesToolStripMenuItem.Text = "Browse Files";
+ this.browseFilesToolStripMenuItem.Click += new System.EventHandler(this.browseFilesToolStripMenuItem_Click);
+ //
+ // browseFolderToolStripMenuItem
+ //
+ this.browseFolderToolStripMenuItem.Image = global::Maestro.Editors.Properties.Resources.folder_horizontal;
+ this.browseFolderToolStripMenuItem.Name = "browseFolderToolStripMenuItem";
+ this.browseFolderToolStripMenuItem.Size = new System.Drawing.Size(189, 22);
+ this.browseFolderToolStripMenuItem.Text = "Browse Folder";
+ this.browseFolderToolStripMenuItem.Click += new System.EventHandler(this.browseFolderToolStripMenuItem_Click);
+ //
// btnDelete
//
this.btnDelete.Enabled = false;
@@ -113,32 +146,26 @@
//
this.openFileDialog.Multiselect = true;
//
- // btnAdd
+ // browseAliasedFileToolStripMenuItem
//
- this.btnAdd.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
- this.browseFilesToolStripMenuItem,
- this.browseFolderToolStripMenuItem});
- this.btnAdd.Image = global::Maestro.Editors.Properties.Resources.plus_circle;
- this.btnAdd.ImageTransparentColor = System.Drawing.Color.Magenta;
- this.btnAdd.Name = "btnAdd";
- this.btnAdd.Size = new System.Drawing.Size(58, 22);
- this.btnAdd.Text = "Add";
+ this.browseAliasedFileToolStripMenuItem.Image = global::Maestro.Editors.Properties.Resources.document;
+ this.browseAliasedFileToolStripMenuItem.Name = "browseAliasedFileToolStripMenuItem";
+ this.browseAliasedFileToolStripMenuItem.Size = new System.Drawing.Size(189, 22);
+ this.browseAliasedFileToolStripMenuItem.Text = "Browse Aliased File";
+ this.browseAliasedFileToolStripMenuItem.Click += new System.EventHandler(this.browseAliasedFileToolStripMenuItem_Click);
//
- // browseFilesToolStripMenuItem
+ // browseAliasedFolderToolStripMenuItem
//
- this.browseFilesToolStripMenuItem.Image = global::Maestro.Editors.Properties.Resources.document;
- this.browseFilesToolStripMenuItem.Name = "browseFilesToolStripMenuItem";
- this.browseFilesToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
- this.browseFilesToolStripMenuItem.Text = "Browse Files";
- this.browseFilesToolStripMenuItem.Click += new System.EventHandler(this.browseFilesToolStripMenuItem_Click);
+ this.browseAliasedFolderToolStripMenuItem.Image = global::Maestro.Editors.Properties.Resources.folder_horizontal;
+ this.browseAliasedFolderToolStripMenuItem.Name = "browseAliasedFolderToolStripMenuItem";
+ this.browseAliasedFolderToolStripMenuItem.Size = new System.Drawing.Size(189, 22);
+ this.browseAliasedFolderToolStripMenuItem.Text = "Browse Aliased Folder";
+ this.browseAliasedFolderToolStripMenuItem.Click += new System.EventHandler(this.browseAliasedFolderToolStripMenuItem_Click);
//
- // browseFolderToolStripMenuItem
+ // toolStripSeparator1
//
- this.browseFolderToolStripMenuItem.Image = global::Maestro.Editors.Properties.Resources.folder_horizontal;
- this.browseFolderToolStripMenuItem.Name = "browseFolderToolStripMenuItem";
- this.browseFolderToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
- this.browseFolderToolStripMenuItem.Text = "Browse Folder";
- this.browseFolderToolStripMenuItem.Click += new System.EventHandler(this.browseFolderToolStripMenuItem_Click);
+ this.toolStripSeparator1.Name = "toolStripSeparator1";
+ this.toolStripSeparator1.Size = new System.Drawing.Size(186, 6);
//
// CompositeFileCtrl
//
@@ -170,5 +197,8 @@
private System.Windows.Forms.ToolStripDropDownButton btnAdd;
private System.Windows.Forms.ToolStripMenuItem browseFilesToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem browseFolderToolStripMenuItem;
+ private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
+ private System.Windows.Forms.ToolStripMenuItem browseAliasedFileToolStripMenuItem;
+ private System.Windows.Forms.ToolStripMenuItem browseAliasedFolderToolStripMenuItem;
}
}
Modified: trunk/Tools/Maestro/Maestro.Editors/FeatureSource/Providers/Gdal/CompositeFileCtrl.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Editors/FeatureSource/Providers/Gdal/CompositeFileCtrl.cs 2011-04-28 10:46:25 UTC (rev 5723)
+++ trunk/Tools/Maestro/Maestro.Editors/FeatureSource/Providers/Gdal/CompositeFileCtrl.cs 2011-04-28 12:09:53 UTC (rev 5724)
@@ -34,6 +34,7 @@
using OSGeo.MapGuide.ObjectModels;
using OSGeo.MapGuide.MaestroAPI;
using System.Collections.Specialized;
+using Maestro.Editors.Common;
namespace Maestro.Editors.FeatureSource.Providers.Gdal
{
@@ -90,6 +91,13 @@
private void AddRasterItem(string dir, GdalRasterItem item)
{
+ foreach (ListViewItem li in lstView.Items)
+ {
+ //A list view item of the same file name exist. Abort.
+ if (((GdalRasterItem)li.Tag).FileName == item.FileName)
+ return;
+ }
+
ListViewItem lvi = new ListViewItem();
lvi.Name = Path.Combine(dir, item.FileName);
lvi.Text = lvi.Name;
@@ -155,13 +163,18 @@
private void DoUpdateConfiguration(string[] toAdd, string[] toRemove)
{
+ DoUpdateConfiguration(toAdd, toRemove, false);
+ }
+
+ private void DoUpdateConfiguration(string[] toAdd, string[] toRemove, bool isAlias)
+ {
if (_conf == null)
BuildDefaultDocument();
var pdlg = new ProgressDialog();
pdlg.CancelAbortsThread = true;
var worker = new ProgressDialog.DoBackgroundWork(UpdateConfigurationDocument);
- var result = (UpdateConfigResult)pdlg.RunOperationAsync(null, worker, _conf, _fs.CurrentConnection, toAdd, toRemove);
+ var result = (UpdateConfigResult)pdlg.RunOperationAsync(null, worker, _conf, _fs.CurrentConnection, toAdd, toRemove, isAlias);
if (result.Added.Count > 0 || result.Removed.Count > 0)
{
_fs.SetConfigurationContent(_conf.ToXml());
@@ -173,8 +186,18 @@
}
foreach (var added in result.Added)
{
- var dir = Path.GetDirectoryName(added);
- var fileName = Path.GetFileName(added);
+ string dir = null;
+ string fileName = null;
+ if (isAlias)
+ {
+ dir = added.Substring(0, added.LastIndexOf("\\"));
+ fileName = added.Substring(added.LastIndexOf("\\") + 1);
+ }
+ else
+ {
+ dir = Path.GetDirectoryName(added);
+ fileName = Path.GetFileName(added);
+ }
foreach (var loc in _conf.RasterLocations)
{
@@ -208,6 +231,7 @@
IServerConnection conn = (IServerConnection)args[1];
string [] toAdd = args[2] as string[];
string [] toRemove = args[3] as string[];
+ bool isAlias = (bool)args[4];
worker.ReportProgress(0, Properties.Resources.UpdatingConfiguration);
@@ -220,11 +244,21 @@
//Remove first
foreach (var remove in toRemove)
{
- var dir = Path.GetDirectoryName(remove);
+ string dir = null;
+ if (isAlias)
+ {
+ dir = remove.Substring(0, remove.LastIndexOf("\\"));
+ }
+ else
+ {
+ dir = Path.GetDirectoryName(remove);
+ }
+
var loc = FindLocation(conf, dir);
if (null != loc)
{
- loc.RemoveItem(Path.GetFileName(remove));
+ string f = isAlias ? remove.Substring(remove.LastIndexOf("\\") + 1) : Path.GetFileName(remove);
+ loc.RemoveItem(f);
result.Removed.Add(remove);
if (loc.Items.Length == 0)
conf.RemoveLocation(loc);
@@ -236,7 +270,15 @@
//Then add
foreach (var add in toAdd)
{
- var dir = Path.GetDirectoryName(add);
+ string dir = null;
+ if (isAlias)
+ {
+ dir = add.Substring(0, add.LastIndexOf("/"));
+ }
+ else
+ {
+ dir = Path.GetDirectoryName(add);
+ }
var loc = conf.AddLocation(dir);
//Create a temp feature source to attempt interrogation of extents
@@ -252,7 +294,7 @@
var raster = new GdalRasterItem()
{
- FileName = Path.GetFileName(add)
+ FileName = isAlias ? add.Substring(add.LastIndexOf("/") + 1) : Path.GetFileName(add)
};
if (scList.SpatialContext.Count > 0)
@@ -310,5 +352,68 @@
DoUpdateConfiguration(files.ToArray(), new string[0]);
}
}
+
+ private void browseAliasedFileToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ using (var picker = new UnmanagedFileBrowser(_service.ResourceService))
+ {
+ picker.AllowMultipleSelection = true;
+ if (picker.ShowDialog() == DialogResult.OK)
+ {
+ DoUpdateConfiguration(picker.SelectedItems, new string[0], true);
+ }
+ }
+ }
+
+ private void browseAliasedFolderToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ using (var picker = new UnmanagedFileBrowser(_service.ResourceService))
+ {
+ picker.AllowMultipleSelection = false;
+ picker.SelectFoldersOnly = true;
+ if (picker.ShowDialog() == DialogResult.OK)
+ {
+ List<string> files = new List<string>();
+ var folder = picker.SelectedItem;
+ if (!string.IsNullOrEmpty(folder))
+ {
+ folder = folder.Replace("%MG_DATA_PATH_ALIAS[", "[")
+ .Replace("]%", "]");
+ }
+ var list = _service.ResourceService.EnumerateUnmanagedData(folder, string.Empty, false, UnmanagedDataTypes.Files);
+ var extensions = new List<string>(new string[] {
+ ".png",
+ ".jpg",
+ ".jpeg",
+ ".tif",
+ ".tiff",
+ ".ecw",
+ ".sid",
+ ".dem",
+ ".gif",
+ ".bmp"
+ });
+ foreach (var f in list.Items)
+ {
+ var file = f as OSGeo.MapGuide.ObjectModels.Common.UnmanagedDataListUnmanagedDataFile;
+ if (file != null)
+ {
+ foreach (var ext in extensions)
+ {
+ if (file.FileName.ToLower().EndsWith(ext))
+ {
+ var leftpart = file.UnmanagedDataId.Substring(0, file.UnmanagedDataId.IndexOf("]"));
+ var rightpart = file.UnmanagedDataId.Substring(file.UnmanagedDataId.IndexOf("]") + 1);
+ var item = "%MG_DATA_PATH_ALIAS" + leftpart + "]%" + rightpart;
+ files.Add(item);
+ break;
+ }
+ }
+ }
+ }
+ DoUpdateConfiguration(files.ToArray(), new string[0], true);
+ }
+ }
+ }
}
}
Modified: trunk/Tools/Maestro/Maestro.Editors/FeatureSource/Providers/Gdal/CompositeFileCtrl.resx
===================================================================
--- trunk/Tools/Maestro/Maestro.Editors/FeatureSource/Providers/Gdal/CompositeFileCtrl.resx 2011-04-28 10:46:25 UTC (rev 5723)
+++ trunk/Tools/Maestro/Maestro.Editors/FeatureSource/Providers/Gdal/CompositeFileCtrl.resx 2011-04-28 12:09:53 UTC (rev 5724)
@@ -128,7 +128,7 @@
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj0yLjAuMC4w
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAADQ
- BwAAAk1TRnQBSQFMAwEBAAFIAQABSAEAARABAAEQAQAE/wEJAQAI/wFCAU0BNgEEBgABNgEEAgABKAMA
+ BwAAAk1TRnQBSQFMAwEBAAFQAQABUAEAARABAAEQAQAE/wEJAQAI/wFCAU0BNgEEBgABNgEEAgABKAMA
AUADAAEQAwABAQEAAQgGAAEEGAABgAIAAYADAAKAAQABgAMAAYABAAGAAQACgAIAA8ABAAHAAdwBwAEA
AfABygGmAQABMwUAATMBAAEzAQABMwEAAjMCAAMWAQADHAEAAyIBAAMpAQADVQEAA00BAANCAQADOQEA
AYABfAH/AQACUAH/AQABkwEAAdYBAAH/AewBzAEAAcYB1gHvAQAB1gLnAQABkAGpAa0CAAH/ATMDAAFm
Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/SchemaOverrides/GdalRasterItem.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/SchemaOverrides/GdalRasterItem.cs 2011-04-28 10:46:25 UTC (rev 5723)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/SchemaOverrides/GdalRasterItem.cs 2011-04-28 12:09:53 UTC (rev 5724)
@@ -27,15 +27,24 @@
{
public class GdalRasterLocationItem : IFdoSerializable
{
- private List<GdalRasterItem> _items = new List<GdalRasterItem>();
+ private Dictionary<string, GdalRasterItem> _items = new Dictionary<string, GdalRasterItem>();
public string Location { get; set; }
- public void AddItem(GdalRasterItem item) { _items.Add(item); }
+ public void AddItem(GdalRasterItem item)
+ {
+ if (!_items.ContainsKey(item.FileName))
+ _items.Add(item.FileName, item);
+ else
+ _items[item.FileName] = item;
+ }
- public void RemoveItem(GdalRasterItem item) { _items.Remove(item); }
+ public void RemoveItem(GdalRasterItem item)
+ {
+ _items.Remove(item.FileName);
+ }
- public GdalRasterItem[] Items { get { return _items.ToArray(); } }
+ public GdalRasterItem[] Items { get { return new List<GdalRasterItem>(_items.Values).ToArray(); } }
public void WriteXml(System.Xml.XmlDocument doc, System.Xml.XmlNode currentNode)
{
@@ -44,7 +53,7 @@
locName.Value = this.Location;
loc.Attributes.Append(locName);
- foreach (var item in _items)
+ foreach (var item in _items.Values)
{
item.WriteXml(doc, loc);
}
@@ -71,17 +80,7 @@
public void RemoveItem(string fileName)
{
- GdalRasterItem item = null;
- foreach (var raster in _items)
- {
- if (raster.FileName == fileName)
- {
- item = raster;
- }
- }
-
- if (item != null)
- _items.Remove(item);
+ _items.Remove(fileName);
}
}
More information about the mapguide-commits
mailing list