[mapguide-commits] r6031 - in trunk/Tools/Maestro:
Maestro.Base/Editor Maestro.Base/Properties Maestro.Editors
Maestro.Editors/Properties
svn_mapguide at osgeo.org
svn_mapguide at osgeo.org
Thu Aug 4 08:19:32 EDT 2011
Author: jng
Date: 2011-08-04 05:19:32 -0700 (Thu, 04 Aug 2011)
New Revision: 6031
Added:
trunk/Tools/Maestro/Maestro.Editors/ResourceEditorServiceBase.cs
Modified:
trunk/Tools/Maestro/Maestro.Base/Editor/ResourceEditorService.cs
trunk/Tools/Maestro/Maestro.Base/Properties/Resources.Designer.cs
trunk/Tools/Maestro/Maestro.Base/Properties/Resources.resx
trunk/Tools/Maestro/Maestro.Editors/Maestro.Editors.csproj
trunk/Tools/Maestro/Maestro.Editors/Properties/Resources.Designer.cs
trunk/Tools/Maestro/Maestro.Editors/Properties/Resources.resx
Log:
Refactor out ResourceEditorService into a common abstract base class
Modified: trunk/Tools/Maestro/Maestro.Base/Editor/ResourceEditorService.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/Editor/ResourceEditorService.cs 2011-08-04 11:56:09 UTC (rev 6030)
+++ trunk/Tools/Maestro/Maestro.Base/Editor/ResourceEditorService.cs 2011-08-04 12:19:32 UTC (rev 6031)
@@ -35,308 +35,49 @@
namespace Maestro.Base.Editor
{
- public class ResourceEditorService : IEditorService
+ public class ResourceEditorService : ResourceEditorServiceBase
{
private IUrlLauncherService _launcher;
- private IServerConnection _conn;
private ISiteExplorer _siteExp;
-
- private IResource _editCopy;
private OpenResourceManager _orm;
public ResourceEditorService(string resourceID, IServerConnection conn, IUrlLauncherService launcher, ISiteExplorer siteExp, OpenResourceManager orm)
+ : base(resourceID, conn)
{
- this.IsNew = ResourceIdentifier.IsSessionBased(resourceID);
- this.ResourceID = resourceID;
_siteExp = siteExp;
- _conn = conn;
_launcher = launcher;
_orm = orm;
}
- public event EventHandler DirtyStateChanged;
-
- public string EditExpression(string currentExpr, ClassDefinition schema, string providerName, string featureSourceId)
- {
- var ed = new ExpressionEditor();
- var caps = this.FeatureService.GetProviderCapabilities(providerName);
- ed.Initialize(this.FeatureService, caps, schema, featureSourceId);
- ed.Expression = currentExpr;
- if (ed.ShowDialog() == System.Windows.Forms.DialogResult.OK)
- {
- return ed.Expression;
- }
- return null;
- }
-
internal void ReReadSessionResource()
{
_editCopy = _conn.ResourceService.GetResource(this.EditedResourceID);
_editCopy.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(OnResourcePropertyChanged);
}
- public IResource GetEditedResource()
+ public override void OpenUrl(string url)
{
- if (_editCopy == null)
- {
- string copy = _conn.GenerateSessionResourceId(ResourceIdentifier.GetResourceType(this.ResourceID));
-
- _conn.ResourceService.CopyResource(this.ResourceID, copy, true);
-
- _editCopy = _conn.ResourceService.GetResource(copy);
- _editCopy.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(OnResourcePropertyChanged);
- }
- return _editCopy;
- }
-
- void OnResourcePropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
- {
- MarkDirty();
- }
-
- void OnDirtyStateChanged()
- {
- var handler = this.DirtyStateChanged;
- if (handler != null)
- handler(this, EventArgs.Empty);
- }
-
- public bool IsDirty
- {
- get;
- private set;
- }
-
- public void MarkDirty()
- {
- this.IsDirty = true;
- OnDirtyStateChanged();
- }
-
- public bool IsNew
- {
- get;
- private set;
- }
-
- public void OpenUrl(string url)
- {
_launcher.OpenUrl(url);
}
- public string ResourceID { get; private set; }
-
- public string SelectAnyResource()
+ public override string SelectUnmanagedData(string startPath, System.Collections.Specialized.NameValueCollection fileTypes)
{
- var picker = new ResourcePicker(_conn.ResourceService, ResourcePickerMode.OpenResource);
- if (picker.ShowDialog() == System.Windows.Forms.DialogResult.OK)
- {
- return picker.ResourceID;
- }
- return string.Empty;
- }
-
- public string SelectResource(OSGeo.MapGuide.MaestroAPI.ResourceTypes resType)
- {
- var picker = new ResourcePicker(_conn.ResourceService, resType, ResourcePickerMode.OpenResource);
- if (picker.ShowDialog() == System.Windows.Forms.DialogResult.OK)
- {
- return picker.ResourceID;
- }
- return string.Empty;
- }
-
- public string SelectFolder()
- {
- var picker = new ResourcePicker(_conn.ResourceService, ResourcePickerMode.OpenFolder);
- if (picker.ShowDialog() == System.Windows.Forms.DialogResult.OK)
- {
- return picker.ResourceID;
- }
- return string.Empty;
- }
-
- public string SelectUnmanagedData(string startPath, System.Collections.Specialized.NameValueCollection fileTypes)
- {
throw new NotImplementedException();
}
- public void Save()
+ public override void RequestRefresh()
{
- if (!OnBeforeSave())
- {
- _conn.ResourceService.CopyResource(this.EditedResourceID, this.ResourceID, true);
-
- this.IsDirty = false;
- OnDirtyStateChanged();
- OnSaved();
- }
- }
-
- public void SaveAs(string resourceID)
- {
- if (ResourceIdentifier.IsSessionBased(resourceID))
- throw new ArgumentException(Properties.Resources.NotSessionBasedId); //LOCALIZE
-
- if (!OnBeforeSave())
- {
- _conn.ResourceService.SaveResourceAs(_editCopy, resourceID);
- //Don't forget to copy attached resource data!
- _editCopy.CopyResourceDataTo(resourceID);
- this.ResourceID = resourceID;
- this.IsNew = false;
- this.IsDirty = false;
- OnDirtyStateChanged();
- OnSaved();
- }
- }
-
- public bool IsUpgradeAvailable
- {
- get
- {
- if (_editCopy == null)
- return false;
- return _conn.Capabilities.GetMaxSupportedResourceVersion(_editCopy.ResourceType) > _editCopy.ResourceVersion;
- }
- }
-
- public string EditedResourceID
- {
- get { return _editCopy.ResourceID; }
- }
-
- public void RegisterCustomNotifier(INotifyResourceChanged irc)
- {
- irc.ResourceChanged += (sender, e) =>
- {
- this.IsDirty = true;
- OnDirtyStateChanged();
- };
- }
-
-
- public void UpdateResourceContent(string xml)
- {
- using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(xml)))
- {
- _conn.ResourceService.SetResourceXmlData(this.EditedResourceID, ms);
- }
- }
-
- private bool OnBeforeSave()
- {
- var e = new CancelEventArgs();
- var handler = this.BeforeSave;
- if (handler != null)
- handler(this, e);
-
- return e.Cancel;
- }
-
- public event System.ComponentModel.CancelEventHandler BeforeSave;
-
- public IFeatureService FeatureService
- {
- get { return _conn.FeatureService; }
- }
-
- public IResourceService ResourceService
- {
- get { return _conn.ResourceService; }
- }
-
-
- public string GetCoordinateSystem()
- {
- var dlg = new CoordinateSystemPicker(_conn.CoordinateSystemCatalog);
- if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
- {
- return dlg.SelectedCoordSys.WKT;
- }
- return string.Empty;
- }
-
-
- public IDrawingService DrawingService
- {
- get { return (IDrawingService)_conn.GetService((int)ServiceType.Drawing); }
- }
-
- public void HasChanged()
- {
- this.IsDirty = true;
- OnDirtyStateChanged();
- }
-
- public string SessionID
- {
- get { return _conn.SessionID; }
- }
-
- public bool SupportsCommand(OSGeo.MapGuide.MaestroAPI.Commands.CommandType cmdType)
- {
- return Array.IndexOf(_conn.Capabilities.SupportedCommands, (int)cmdType) >= 0;
- }
-
- public OSGeo.MapGuide.MaestroAPI.Commands.ICommand CreateCommand(OSGeo.MapGuide.MaestroAPI.Commands.CommandType cmdType)
- {
- return _conn.CreateCommand((int)cmdType);
- }
-
- public void RequestRefresh()
- {
_siteExp.RefreshModel();
}
- public void RequestRefresh(string folderId)
+ public override void RequestRefresh(string folderId)
{
_siteExp.RefreshModel(folderId);
}
- private void OnSaved()
+ public override void OpenResource(string resourceId)
{
- var handler = this.Saved;
- if (handler != null)
- handler(this, EventArgs.Empty);
- }
-
- public event EventHandler Saved;
-
- public void SyncSessionCopy()
- {
- this.ResourceService.SetResourceXmlData(_editCopy.ResourceID, _editCopy.SerializeToStream());
- }
-
- public Version SiteVersion
- {
- get { return _conn.SiteVersion; }
- }
-
- public void OpenResource(string resourceId)
- {
_orm.Open(resourceId, _conn, false, _siteExp);
}
-
- public string SuggestedSaveFolder
- {
- get;
- set;
- }
-
- public object GetCustomProperty(string name)
- {
- return _conn.GetCustomProperty(name);
- }
-
- public IService GetService(int serviceType)
- {
- return _conn.GetService(serviceType);
- }
-
- public int[] SupportedServiceTypes
- {
- get { return _conn.Capabilities.SupportedServices; }
- }
}
}
Modified: trunk/Tools/Maestro/Maestro.Base/Properties/Resources.Designer.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/Properties/Resources.Designer.cs 2011-08-04 11:56:09 UTC (rev 6030)
+++ trunk/Tools/Maestro/Maestro.Base/Properties/Resources.Designer.cs 2011-08-04 12:19:32 UTC (rev 6031)
@@ -1305,15 +1305,6 @@
}
/// <summary>
- /// Looks up a localized string similar to Resource ID must not be session based.
- /// </summary>
- internal static string NotSessionBasedId {
- get {
- return ResourceManager.GetString("NotSessionBasedId", resourceCulture);
- }
- }
-
- /// <summary>
/// Looks up a localized string similar to Skipping registration of editor: {0} because an existing editor is already registered to handle {1} v{2}.
/// </summary>
internal static string OpenResourceManager_SkipEditorRegistration {
Modified: trunk/Tools/Maestro/Maestro.Base/Properties/Resources.resx
===================================================================
--- trunk/Tools/Maestro/Maestro.Base/Properties/Resources.resx 2011-08-04 11:56:09 UTC (rev 6030)
+++ trunk/Tools/Maestro/Maestro.Base/Properties/Resources.resx 2011-08-04 12:19:32 UTC (rev 6031)
@@ -772,9 +772,6 @@
<data name="NewMap" xml:space="preserve">
<value>New Map</value>
</data>
- <data name="NotSessionBasedId" xml:space="preserve">
- <value>Resource ID must not be session based</value>
- </data>
<data name="PreviewMap" xml:space="preserve">
<value>Preview Map</value>
</data>
Modified: trunk/Tools/Maestro/Maestro.Editors/Maestro.Editors.csproj
===================================================================
--- trunk/Tools/Maestro/Maestro.Editors/Maestro.Editors.csproj 2011-08-04 11:56:09 UTC (rev 6030)
+++ trunk/Tools/Maestro/Maestro.Editors/Maestro.Editors.csproj 2011-08-04 12:19:32 UTC (rev 6031)
@@ -909,6 +909,7 @@
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
+ <Compile Include="ResourceEditorServiceBase.cs" />
<Compile Include="SymbolDefinition\AdvancedSettingsCtrl.cs">
<SubType>UserControl</SubType>
</Compile>
Modified: trunk/Tools/Maestro/Maestro.Editors/Properties/Resources.Designer.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Editors/Properties/Resources.Designer.cs 2011-08-04 11:56:09 UTC (rev 6030)
+++ trunk/Tools/Maestro/Maestro.Editors/Properties/Resources.Designer.cs 2011-08-04 12:19:32 UTC (rev 6031)
@@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
-// Runtime Version:2.0.50727.4952
+// Runtime Version:2.0.50727.4959
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
@@ -2049,6 +2049,15 @@
}
/// <summary>
+ /// Looks up a localized string similar to Resource ID must not be session based.
+ /// </summary>
+ internal static string NotSessionBasedId {
+ get {
+ return ResourceManager.GetString("NotSessionBasedId", resourceCulture);
+ }
+ }
+
+ /// <summary>
/// Looks up a localized string similar to You must select at least one type.
/// </summary>
internal static string NoTypesSelected {
Modified: trunk/Tools/Maestro/Maestro.Editors/Properties/Resources.resx
===================================================================
--- trunk/Tools/Maestro/Maestro.Editors/Properties/Resources.resx 2011-08-04 11:56:09 UTC (rev 6030)
+++ trunk/Tools/Maestro/Maestro.Editors/Properties/Resources.resx 2011-08-04 12:19:32 UTC (rev 6031)
@@ -1247,4 +1247,7 @@
<data name="ParameterOverrideExists" xml:space="preserve">
<value>Parameter Override already specified</value>
</data>
+ <data name="NotSessionBasedId" xml:space="preserve">
+ <value>Resource ID must not be session based</value>
+ </data>
</root>
\ No newline at end of file
Added: trunk/Tools/Maestro/Maestro.Editors/ResourceEditorServiceBase.cs
===================================================================
--- trunk/Tools/Maestro/Maestro.Editors/ResourceEditorServiceBase.cs (rev 0)
+++ trunk/Tools/Maestro/Maestro.Editors/ResourceEditorServiceBase.cs 2011-08-04 12:19:32 UTC (rev 6031)
@@ -0,0 +1,308 @@
+#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.Services;
+using Maestro.Editors.Common;
+using System.ComponentModel;
+using System.IO;
+using OSGeo.MapGuide.MaestroAPI.Resource;
+using Maestro.Editors.Generic;
+using OSGeo.MapGuide.MaestroAPI;
+using OSGeo.MapGuide.MaestroAPI.Schema;
+
+namespace Maestro.Editors
+{
+ public abstract class ResourceEditorServiceBase : IEditorService
+ {
+ protected IServerConnection _conn;
+ protected IResource _editCopy;
+
+ protected ResourceEditorServiceBase(string resourceID, IServerConnection conn)
+ {
+ this.IsNew = ResourceIdentifier.IsSessionBased(resourceID);
+ this.ResourceID = resourceID;
+ _conn = conn;
+ }
+
+ public event EventHandler DirtyStateChanged;
+
+ public string EditExpression(string currentExpr, ClassDefinition classDef, string providerName, string featureSourceId)
+ {
+ var ed = new ExpressionEditor();
+ var caps = this.FeatureService.GetProviderCapabilities(providerName);
+ ed.Initialize(this.FeatureService, caps, classDef, featureSourceId);
+ ed.Expression = currentExpr;
+ if (ed.ShowDialog() == System.Windows.Forms.DialogResult.OK)
+ {
+ return ed.Expression;
+ }
+ return null;
+ }
+
+ public IResource GetEditedResource()
+ {
+ if (_editCopy == null)
+ {
+ string copy = _conn.GenerateSessionResourceId(ResourceIdentifier.GetResourceType(this.ResourceID));
+
+ _conn.ResourceService.CopyResource(this.ResourceID, copy, true);
+
+ _editCopy = _conn.ResourceService.GetResource(copy);
+ _editCopy.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(OnResourcePropertyChanged);
+ }
+ return _editCopy;
+ }
+
+ protected void OnResourcePropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
+ {
+ MarkDirty();
+ }
+
+ protected void OnDirtyStateChanged()
+ {
+ var handler = this.DirtyStateChanged;
+ if (handler != null)
+ handler(this, EventArgs.Empty);
+ }
+
+ public bool IsDirty
+ {
+ get;
+ private set;
+ }
+
+ public void MarkDirty()
+ {
+ this.IsDirty = true;
+ OnDirtyStateChanged();
+ }
+
+ public bool IsNew
+ {
+ get;
+ private set;
+ }
+
+ public abstract void OpenUrl(string url);
+
+ public string ResourceID { get; private set; }
+
+ public string SelectAnyResource()
+ {
+ var picker = new ResourcePicker(_conn.ResourceService, ResourcePickerMode.OpenResource);
+ if (picker.ShowDialog() == System.Windows.Forms.DialogResult.OK)
+ {
+ return picker.ResourceID;
+ }
+ return string.Empty;
+ }
+
+ public string SelectResource(OSGeo.MapGuide.MaestroAPI.ResourceTypes resType)
+ {
+ var picker = new ResourcePicker(_conn.ResourceService, resType, ResourcePickerMode.OpenResource);
+ if (picker.ShowDialog() == System.Windows.Forms.DialogResult.OK)
+ {
+ return picker.ResourceID;
+ }
+ return string.Empty;
+ }
+
+ public string SelectFolder()
+ {
+ var picker = new ResourcePicker(_conn.ResourceService, ResourcePickerMode.OpenFolder);
+ if (picker.ShowDialog() == System.Windows.Forms.DialogResult.OK)
+ {
+ return picker.ResourceID;
+ }
+ return string.Empty;
+ }
+
+ public abstract string SelectUnmanagedData(string startPath, System.Collections.Specialized.NameValueCollection fileTypes);
+
+ public void Save()
+ {
+ if (!OnBeforeSave())
+ {
+ _conn.ResourceService.CopyResource(this.EditedResourceID, this.ResourceID, true);
+
+ this.IsDirty = false;
+ OnDirtyStateChanged();
+ OnSaved();
+ }
+ }
+
+ public void SaveAs(string resourceID)
+ {
+ if (ResourceIdentifier.IsSessionBased(resourceID))
+ throw new ArgumentException(Properties.Resources.NotSessionBasedId); //LOCALIZE
+
+ if (!OnBeforeSave())
+ {
+ _conn.ResourceService.SaveResourceAs(_editCopy, resourceID);
+ //Don't forget to copy attached resource data!
+ _editCopy.CopyResourceDataTo(resourceID);
+ this.ResourceID = resourceID;
+ this.IsNew = false;
+ this.IsDirty = false;
+ OnDirtyStateChanged();
+ OnSaved();
+ }
+ }
+
+ public bool IsUpgradeAvailable
+ {
+ get
+ {
+ if (_editCopy == null)
+ return false;
+ return _conn.Capabilities.GetMaxSupportedResourceVersion(_editCopy.ResourceType) > _editCopy.ResourceVersion;
+ }
+ }
+
+ public string EditedResourceID
+ {
+ get { return _editCopy.ResourceID; }
+ }
+
+ public void RegisterCustomNotifier(INotifyResourceChanged irc)
+ {
+ irc.ResourceChanged += (sender, e) =>
+ {
+ this.IsDirty = true;
+ OnDirtyStateChanged();
+ };
+ }
+
+ public void UpdateResourceContent(string xml)
+ {
+ using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(xml)))
+ {
+ _conn.ResourceService.SetResourceXmlData(this.EditedResourceID, ms);
+ }
+ }
+
+ private bool OnBeforeSave()
+ {
+ var e = new CancelEventArgs();
+ var handler = this.BeforeSave;
+ if (handler != null)
+ handler(this, e);
+
+ return e.Cancel;
+ }
+
+ public event System.ComponentModel.CancelEventHandler BeforeSave;
+
+ public IFeatureService FeatureService
+ {
+ get { return _conn.FeatureService; }
+ }
+
+ public IResourceService ResourceService
+ {
+ get { return _conn.ResourceService; }
+ }
+
+ public string GetCoordinateSystem()
+ {
+ var dlg = new CoordinateSystemPicker(_conn.CoordinateSystemCatalog);
+ if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
+ {
+ return dlg.SelectedCoordSys.WKT;
+ }
+ return string.Empty;
+ }
+
+
+ public IDrawingService DrawingService
+ {
+ get { return (IDrawingService)_conn.GetService((int)ServiceType.Drawing); }
+ }
+
+ public void HasChanged()
+ {
+ this.IsDirty = true;
+ OnDirtyStateChanged();
+ }
+
+ public string SessionID
+ {
+ get { return _conn.SessionID; }
+ }
+
+ public bool SupportsCommand(OSGeo.MapGuide.MaestroAPI.Commands.CommandType cmdType)
+ {
+ return Array.IndexOf(_conn.Capabilities.SupportedCommands, (int)cmdType) >= 0;
+ }
+
+ public OSGeo.MapGuide.MaestroAPI.Commands.ICommand CreateCommand(OSGeo.MapGuide.MaestroAPI.Commands.CommandType cmdType)
+ {
+ return _conn.CreateCommand((int)cmdType);
+ }
+
+ public abstract void RequestRefresh();
+
+ public abstract void RequestRefresh(string folderId);
+
+ protected void OnSaved()
+ {
+ var handler = this.Saved;
+ if (handler != null)
+ handler(this, EventArgs.Empty);
+ }
+
+ public event EventHandler Saved;
+
+ public void SyncSessionCopy()
+ {
+ this.ResourceService.SetResourceXmlData(_editCopy.ResourceID, _editCopy.SerializeToStream());
+ }
+
+ public Version SiteVersion
+ {
+ get { return _conn.SiteVersion; }
+ }
+
+ public abstract void OpenResource(string resourceId);
+
+ public string SuggestedSaveFolder
+ {
+ get;
+ set;
+ }
+
+ public object GetCustomProperty(string name)
+ {
+ return _conn.GetCustomProperty(name);
+ }
+
+ public IService GetService(int serviceType)
+ {
+ return _conn.GetService(serviceType);
+ }
+
+ public int[] SupportedServiceTypes
+ {
+ get { return _conn.Capabilities.SupportedServices; }
+ }
+ }
+}
More information about the mapguide-commits
mailing list