Index: Core/Common/src/Core.Common.Gui/Core.Common.Gui.csproj =================================================================== diff -u -r2b9e80f0d003d30c57fae2f16f25acaf9b58d2d2 -r8d069bd17ce1b0f7ec017385f9f4e5fd84ed1f6f --- Core/Common/src/Core.Common.Gui/Core.Common.Gui.csproj (.../Core.Common.Gui.csproj) (revision 2b9e80f0d003d30c57fae2f16f25acaf9b58d2d2) +++ Core/Common/src/Core.Common.Gui/Core.Common.Gui.csproj (.../Core.Common.Gui.csproj) (revision 8d069bd17ce1b0f7ec017385f9f4e5fd84ed1f6f) @@ -135,6 +135,7 @@ ActivityProgressDialog.cs + Index: Core/Common/src/Core.Common.Gui/Forms/PropertyGridView/IPropertyResolver.cs =================================================================== diff -u --- Core/Common/src/Core.Common.Gui/Forms/PropertyGridView/IPropertyResolver.cs (revision 0) +++ Core/Common/src/Core.Common.Gui/Forms/PropertyGridView/IPropertyResolver.cs (revision 8d069bd17ce1b0f7ec017385f9f4e5fd84ed1f6f) @@ -0,0 +1,11 @@ +namespace Core.Common.Gui.Forms.PropertyGridView +{ + public interface IPropertyResolver { + /// + /// Returns object properties based on the provided . + /// + /// The source data to get the object properties for. + /// An object properties object, or null when no relevant properties object is found. + object GetObjectProperties(object sourceData); + } +} \ No newline at end of file Index: Core/Common/src/Core.Common.Gui/Forms/PropertyGridView/PropertyGridView.cs =================================================================== diff -u -r83b9621346f7f3ca887096468de965815eb609ac -r8d069bd17ce1b0f7ec017385f9f4e5fd84ed1f6f --- Core/Common/src/Core.Common.Gui/Forms/PropertyGridView/PropertyGridView.cs (.../PropertyGridView.cs) (revision 83b9621346f7f3ca887096468de965815eb609ac) +++ Core/Common/src/Core.Common.Gui/Forms/PropertyGridView/PropertyGridView.cs (.../PropertyGridView.cs) (revision 8d069bd17ce1b0f7ec017385f9f4e5fd84ed1f6f) @@ -138,7 +138,7 @@ /// public object GetObjectProperties(object sourceData) { - return gui != null ? PropertyResolver.GetObjectProperties(gui.Plugins.SelectMany(p => p.GetPropertyInfos()).ToList(), sourceData) : null; + return gui != null ? gui.PropertyResolver.GetObjectProperties(sourceData) : null; } public ViewInfo ViewInfo { get; set; } Index: Core/Common/src/Core.Common.Gui/Forms/PropertyGridView/PropertyResolver.cs =================================================================== diff -u -reee6c7815d1e418eac38c1c552fb279c0887ef55 -r8d069bd17ce1b0f7ec017385f9f4e5fd84ed1f6f --- Core/Common/src/Core.Common.Gui/Forms/PropertyGridView/PropertyResolver.cs (.../PropertyResolver.cs) (revision eee6c7815d1e418eac38c1c552fb279c0887ef55) +++ Core/Common/src/Core.Common.Gui/Forms/PropertyGridView/PropertyResolver.cs (.../PropertyResolver.cs) (revision 8d069bd17ce1b0f7ec017385f9f4e5fd84ed1f6f) @@ -1,22 +1,37 @@ using System; using System.Collections.Generic; using System.Linq; +using Core.Common.Gui.Properties; using Core.Common.Utils.PropertyBag.Dynamic; namespace Core.Common.Gui.Forms.PropertyGridView { /// /// Helper class for resolving object properties. /// - public static class PropertyResolver + public class PropertyResolver : IPropertyResolver { + private List propertyInfos; + /// - /// Returns object properties based on the provided and . + /// Creates a new instance of with the given . /// /// The list of property information objects to obtain the object properties from. + public PropertyResolver(IEnumerable propertyInfos) + { + if (propertyInfos == null) + { + throw new ArgumentNullException("propertyInfos", Resources.PropertyResolver_PropertyResolver_Cannot_create_PropertyResolver_without_list_of_PropertyInfo); + } + this.propertyInfos = propertyInfos.ToList(); + } + + /// + /// Returns object properties based on the provided . + /// /// The source data to get the object properties for. /// An object properties object, or null when no relevant properties object is found. - public static object GetObjectProperties(List propertyInfos, object sourceData) + public object GetObjectProperties(object sourceData) { if (sourceData == null) { Index: Core/Common/src/Core.Common.Gui/GuiCommandHandler.cs =================================================================== diff -u -r6aa508233ca39077a4a10ec8275619d61ddab47b -r8d069bd17ce1b0f7ec017385f9f4e5fd84ed1f6f --- Core/Common/src/Core.Common.Gui/GuiCommandHandler.cs (.../GuiCommandHandler.cs) (revision 6aa508233ca39077a4a10ec8275619d61ddab47b) +++ Core/Common/src/Core.Common.Gui/GuiCommandHandler.cs (.../GuiCommandHandler.cs) (revision 8d069bd17ce1b0f7ec017385f9f4e5fd84ed1f6f) @@ -145,7 +145,7 @@ public bool CanShowPropertiesFor(object obj) { - return PropertyResolver.GetObjectProperties(gui.Plugins.SelectMany(p => p.GetPropertyInfos()).ToList(), obj) != null; + return gui.PropertyResolver.GetObjectProperties(obj) != null; } public void ImportOn(object target, IFileImporter importer = null) Index: Core/Common/src/Core.Common.Gui/IGui.cs =================================================================== diff -u -r1f79b34c12554e2b9878f6296168d18232cc9852 -r8d069bd17ce1b0f7ec017385f9f4e5fd84ed1f6f --- Core/Common/src/Core.Common.Gui/IGui.cs (.../IGui.cs) (revision 1f79b34c12554e2b9878f6296168d18232cc9852) +++ Core/Common/src/Core.Common.Gui/IGui.cs (.../IGui.cs) (revision 8d069bd17ce1b0f7ec017385f9f4e5fd84ed1f6f) @@ -12,6 +12,7 @@ using Core.Common.Base.Data; using Core.Common.Base.Plugin; using Core.Common.Gui.Forms.MainWindow; +using Core.Common.Gui.Forms.PropertyGridView; namespace Core.Common.Gui { @@ -65,6 +66,11 @@ IViewResolver DocumentViewsResolver { get; } /// + /// Resolves property info objects. + /// + IPropertyResolver PropertyResolver { get; } + + /// /// Gets main window of the graphical user interface. /// IMainWindow MainWindow { get; } Index: Core/Common/src/Core.Common.Gui/Properties/Resources.Designer.cs =================================================================== diff -u -r6aa508233ca39077a4a10ec8275619d61ddab47b -r8d069bd17ce1b0f7ec017385f9f4e5fd84ed1f6f --- Core/Common/src/Core.Common.Gui/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 6aa508233ca39077a4a10ec8275619d61ddab47b) +++ Core/Common/src/Core.Common.Gui/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 8d069bd17ce1b0f7ec017385f9f4e5fd84ed1f6f) @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.18444 +// Runtime Version:4.0.30319.34209 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -1807,6 +1807,16 @@ } /// + /// Looks up a localized string similar to Kan geen PropertyResolver maken zonder een lijst van PropertyInfo.. + /// + public static string PropertyResolver_PropertyResolver_Cannot_create_PropertyResolver_without_list_of_PropertyInfo { + get { + return ResourceManager.GetString("PropertyResolver_PropertyResolver_Cannot_create_PropertyResolver_without_list_of_" + + "PropertyInfo", resourceCulture); + } + } + + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// public static System.Drawing.Bitmap RelationshipsHS { Index: Core/Common/src/Core.Common.Gui/Properties/Resources.resx =================================================================== diff -u -r6aa508233ca39077a4a10ec8275619d61ddab47b -r8d069bd17ce1b0f7ec017385f9f4e5fd84ed1f6f --- Core/Common/src/Core.Common.Gui/Properties/Resources.resx (.../Resources.resx) (revision 6aa508233ca39077a4a10ec8275619d61ddab47b) +++ Core/Common/src/Core.Common.Gui/Properties/Resources.resx (.../Resources.resx) (revision 8d069bd17ce1b0f7ec017385f9f4e5fd84ed1f6f) @@ -893,4 +893,7 @@ Shape-bestand (*.shp)|*.shp + + Kan geen PropertyResolver maken zonder een lijst van PropertyInfo. + \ No newline at end of file Index: Core/Common/src/Core.Common.Gui/RingtoetsGui.cs =================================================================== diff -u -r2b9e80f0d003d30c57fae2f16f25acaf9b58d2d2 -r8d069bd17ce1b0f7ec017385f9f4e5fd84ed1f6f --- Core/Common/src/Core.Common.Gui/RingtoetsGui.cs (.../RingtoetsGui.cs) (revision 2b9e80f0d003d30c57fae2f16f25acaf9b58d2d2) +++ Core/Common/src/Core.Common.Gui/RingtoetsGui.cs (.../RingtoetsGui.cs) (revision 8d069bd17ce1b0f7ec017385f9f4e5fd84ed1f6f) @@ -16,6 +16,7 @@ using Core.Common.Gui.ContextMenu; using Core.Common.Gui.Forms.MainWindow; using Core.Common.Gui.Forms.MessageWindow; +using Core.Common.Gui.Forms.PropertyGridView; using Core.Common.Gui.Forms.SplashScreen; using Core.Common.Gui.Forms.ViewManager; using Core.Common.Gui.Properties; @@ -194,6 +195,8 @@ public IViewResolver DocumentViewsResolver { get; private set; } + public IPropertyResolver PropertyResolver { get; private set; } + public IViewList ToolWindowViews { get @@ -780,6 +783,7 @@ documentViews = documentViewManager; DocumentViewsResolver = new ViewResolver(documentViews, Plugins.SelectMany(p => p.GetViewInfoObjects())); + PropertyResolver = new PropertyResolver(Plugins.SelectMany(p => p.GetPropertyInfos())); var allowedToolWindowLocations = new[] { Index: Core/Common/test/Core.Common.Gui.Test/GuiCommandHandlerTest.cs =================================================================== diff -u -r6aa508233ca39077a4a10ec8275619d61ddab47b -r8d069bd17ce1b0f7ec017385f9f4e5fd84ed1f6f --- Core/Common/test/Core.Common.Gui.Test/GuiCommandHandlerTest.cs (.../GuiCommandHandlerTest.cs) (revision 6aa508233ca39077a4a10ec8275619d61ddab47b) +++ Core/Common/test/Core.Common.Gui.Test/GuiCommandHandlerTest.cs (.../GuiCommandHandlerTest.cs) (revision 8d069bd17ce1b0f7ec017385f9f4e5fd84ed1f6f) @@ -1,4 +1,5 @@ using System.Collections.Generic; +using Core.Common.Gui.Forms.PropertyGridView; using NUnit.Framework; using Rhino.Mocks; @@ -19,9 +20,12 @@ { // Setup var gui = mocks.DynamicMock(); + var propertyResolverMock = mocks.StrictMock(); var anObject = new AnObject(); - gui.Expect(g => g.Plugins).Return(new GuiPlugin[] {new TestGuiPlugin()}); + propertyResolverMock.Expect(pr => pr.GetObjectProperties(anObject)).Return(new object()); + gui.Expect(g => g.PropertyResolver).Return(propertyResolverMock); + mocks.ReplayAll(); var guiCommandHandler = new GuiCommandHandler(gui); @@ -41,8 +45,11 @@ // Setup var gui = mocks.DynamicMock(); var aSubObject = new ASubObject(); - gui.Expect(g => g.Plugins).Return(new GuiPlugin[] {new TestGuiPlugin()}); + var propertyResolverMock = mocks.StrictMock(); + propertyResolverMock.Expect(pr => pr.GetObjectProperties(aSubObject)).Return(new object()); + gui.Expect(g => g.PropertyResolver).Return(propertyResolverMock); + mocks.ReplayAll(); var guiCommandHandler = new GuiCommandHandler(gui); Index: Core/Common/test/Core.Common.Test/Gui/Forms/PropertyGridView/PropertyResolverTest.cs =================================================================== diff -u -r41c77f9f36ae74a406fd382187426cc06d2b0200 -r8d069bd17ce1b0f7ec017385f9f4e5fd84ed1f6f --- Core/Common/test/Core.Common.Test/Gui/Forms/PropertyGridView/PropertyResolverTest.cs (.../PropertyResolverTest.cs) (revision 41c77f9f36ae74a406fd382187426cc06d2b0200) +++ Core/Common/test/Core.Common.Test/Gui/Forms/PropertyGridView/PropertyResolverTest.cs (.../PropertyResolverTest.cs) (revision 8d069bd17ce1b0f7ec017385f9f4e5fd84ed1f6f) @@ -1,6 +1,8 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using Core.Common.Gui; using Core.Common.Gui.Forms.PropertyGridView; +using Core.Common.Gui.Properties; using Core.Common.Utils.PropertyBag.Dynamic; using NUnit.Framework; @@ -9,13 +11,36 @@ [TestFixture] public class PropertyResolverTest { - # region GetObjectProperties tests + [Test] + public void Constructor_WithoutPropertyInfoList_ArgumentNullException() + { + // Call + TestDelegate test = () => new PropertyResolver(null); + // Assert + var message = Assert.Throws(test).Message; + StringAssert.StartsWith(Resources.PropertyResolver_PropertyResolver_Cannot_create_PropertyResolver_without_list_of_PropertyInfo, message); + StringAssert.EndsWith("propertyInfos", message); + } + [Test] + public void Constructor_WithParams_NewInstance() + { + // Call + var result = new PropertyResolver(new List()); + + // Assert + Assert.IsInstanceOf(result); + } + + [Test] public void GetObjectProperties_WhenNoPropertyInfoIsFound_ReturnNull() { + // Setup + var resolver = new PropertyResolver(new List()); + // Assert - Assert.IsNull(PropertyResolver.GetObjectProperties(new List(), 1.0)); + Assert.IsNull(resolver.GetObjectProperties(1.0)); } [Test] @@ -26,9 +51,10 @@ { new PropertyInfo>() }; + var resolver = new PropertyResolver(propertyInfos); // Call - var objectProperties = PropertyResolver.GetObjectProperties(propertyInfos, new A()); + var objectProperties = resolver.GetObjectProperties(new A()); // Assert Assert.IsTrue(objectProperties is DynamicPropertyBag); @@ -46,9 +72,10 @@ AdditionalDataCheck = o => false } }; + var resolver = new PropertyResolver(propertyInfos); // Call - var objectProperties = PropertyResolver.GetObjectProperties(propertyInfos, new A()); + var objectProperties = resolver.GetObjectProperties(new A()); // Assert Assert.IsNull(objectProperties); @@ -66,9 +93,10 @@ }, new PropertyInfo>() }; + var resolver = new PropertyResolver(propertyInfos); // Call - var objectProperties = PropertyResolver.GetObjectProperties(propertyInfos, new C()); + var objectProperties = resolver.GetObjectProperties(new C()); // Assert Assert.AreSame(typeof(SimpleProperties), @@ -84,9 +112,10 @@ new PropertyInfo>(), new PropertyInfo>() }; + var resolver = new PropertyResolver(propertyInfos); // Call - var objectProperties = PropertyResolver.GetObjectProperties(propertyInfos, new D()); + var objectProperties = resolver.GetObjectProperties(new D()); // Assert Assert.IsTrue(objectProperties is DynamicPropertyBag); @@ -102,9 +131,10 @@ new PropertyInfo>(), new PropertyInfo>() }; + var resolver = new PropertyResolver(propertyInfos); // Call - var objectProperties = PropertyResolver.GetObjectProperties(propertyInfos, new D()); + var objectProperties = resolver.GetObjectProperties(new D()); // Assert Assert.IsTrue(objectProperties is DynamicPropertyBag); @@ -126,9 +156,10 @@ AdditionalDataCheck = o => true } }; + var resolver = new PropertyResolver(propertyInfos); // Call - var objectProperties = PropertyResolver.GetObjectProperties(propertyInfos, new D()); + var objectProperties = resolver.GetObjectProperties(new D()); // Assert Assert.IsTrue(objectProperties is DynamicPropertyBag); @@ -147,9 +178,10 @@ }, new PropertyInfo>() }; + var resolver = new PropertyResolver(propertyInfos); // Call - var objectProperties = PropertyResolver.GetObjectProperties(propertyInfos, new B()); + var objectProperties = resolver.GetObjectProperties(new B()); // Assert Assert.IsTrue(objectProperties is DynamicPropertyBag); @@ -168,9 +200,10 @@ }, new PropertyInfo>() }; + var resolver = new PropertyResolver(propertyInfos); // Call - var objectProperties = PropertyResolver.GetObjectProperties(propertyInfos, new B()); + var objectProperties = resolver.GetObjectProperties(new B()); // Assert Assert.IsTrue(objectProperties is DynamicPropertyBag); @@ -186,9 +219,10 @@ new PropertyInfo>(), new PropertyInfo>() }; + var resolver = new PropertyResolver(propertyInfos); // Call - var objectProperties = PropertyResolver.GetObjectProperties(propertyInfos, new B()); + var objectProperties = resolver.GetObjectProperties(new B()); // Assert Assert.IsTrue(objectProperties is DynamicPropertyBag); @@ -210,9 +244,10 @@ AdditionalDataCheck = o => true } }; + var resolver = new PropertyResolver(propertyInfos); // Call - var objectProperties = PropertyResolver.GetObjectProperties(propertyInfos, new B()); + var objectProperties = resolver.GetObjectProperties(new B()); // Assert Assert.IsTrue(objectProperties is DynamicPropertyBag); @@ -228,9 +263,10 @@ new PropertyInfo>(), new PropertyInfo>() }; + var resolver = new PropertyResolver(propertyInfos); // Call - var objectProperties = PropertyResolver.GetObjectProperties(propertyInfos, new B()); + var objectProperties = resolver.GetObjectProperties(new B()); // Assert Assert.IsNull(objectProperties); @@ -263,17 +299,16 @@ AdditionalDataCheck = o => true } // Most specific! }; + var resolver = new PropertyResolver(propertyInfos); // Call - var objectProperties = PropertyResolver.GetObjectProperties(propertyInfos, new C()); + var objectProperties = resolver.GetObjectProperties(new C()); // Assert Assert.IsTrue(objectProperties is DynamicPropertyBag); Assert.AreSame(typeof(DerivedSimpleProperties), ((DynamicPropertyBag) objectProperties).GetContentType()); } - # endregion - # region Nested types /*