Index: Core/Plugins/src/Core.Plugins.Map/PropertyClasses/FeatureBasedMapDataProperties.cs =================================================================== diff -u -r18827eaade9901a6ba9e602774444dd34df6dac3 -r40867963010e95b9df5c0f4dfa169707e151b514 --- Core/Plugins/src/Core.Plugins.Map/PropertyClasses/FeatureBasedMapDataProperties.cs (.../FeatureBasedMapDataProperties.cs) (revision 18827eaade9901a6ba9e602774444dd34df6dac3) +++ Core/Plugins/src/Core.Plugins.Map/PropertyClasses/FeatureBasedMapDataProperties.cs (.../FeatureBasedMapDataProperties.cs) (revision 40867963010e95b9df5c0f4dfa169707e151b514) @@ -100,26 +100,6 @@ } } - [PropertyOrder(selectedMetaDataAttributePropertyIndex)] - [DynamicVisible] - [DynamicReadOnly] - [Editor(typeof(MetaDataAttributeEditor), typeof(UITypeEditor))] - [ResourcesCategory(typeof(Resources), nameof(Resources.Categories_Label))] - [ResourcesDisplayName(typeof(Resources), nameof(Resources.FeatureBasedMapdata_SelectedMetaDataAttribute_DisplayName))] - [ResourcesDescription(typeof(Resources), nameof(Resources.FeatureBasedMapdata_SelectedMetaDataAttribute_Description))] - public SelectableMetaDataAttribute SelectedMetaDataAttribute - { - get - { - return new SelectableMetaDataAttribute(data.SelectedMetaDataAttribute ?? string.Empty); - } - set - { - data.SelectedMetaDataAttribute = value.MetaDataAttribute; - data.NotifyObservers(); - } - } - [PropertyOrder(styleTypePropertyIndex)] [ResourcesCategory(typeof(Resources), nameof(Resources.Categories_Styling))] [ResourcesDisplayName(typeof(Resources), nameof(Resources.FeatureBasedMapdata_StyleType_DisplayName))] @@ -169,8 +149,28 @@ } } + [PropertyOrder(selectedMetaDataAttributePropertyIndex)] + [DynamicVisible] + [DynamicReadOnly] + [Editor(typeof(MetaDataAttributeEditor), typeof(UITypeEditor))] + [ResourcesCategory(typeof(Resources), nameof(Resources.Categories_Label))] + [ResourcesDisplayName(typeof(Resources), nameof(Resources.FeatureBasedMapdata_SelectedMetaDataAttribute_DisplayName))] + [ResourcesDescription(typeof(Resources), nameof(Resources.FeatureBasedMapdata_SelectedMetaDataAttribute_Description))] + public SelectableMetaDataAttribute SelectedMetaDataAttribute + { + get + { + return new SelectableMetaDataAttribute(data.SelectedMetaDataAttribute ?? string.Empty); + } + set + { + data.SelectedMetaDataAttribute = value.MetaDataAttribute; + data.NotifyObservers(); + } + } + [DynamicReadOnlyValidationMethod] - public bool DynamicReadonlyValidator(string propertyName) + public virtual bool DynamicReadonlyValidator(string propertyName) { if (propertyName == nameof(ShowLabels) || propertyName == nameof(SelectedMetaDataAttribute)) @@ -182,7 +182,7 @@ } [DynamicVisibleValidationMethod] - public bool DynamicVisibleValidationMethod(string propertyName) + public virtual bool DynamicVisibleValidationMethod(string propertyName) { if (propertyName == nameof(SelectedMetaDataAttribute)) { Index: Core/Plugins/src/Core.Plugins.Map/PropertyClasses/MapLineDataProperties.cs =================================================================== diff -u -rac96d7c315129af851634ed5a4a6800b59ede718 -r40867963010e95b9df5c0f4dfa169707e151b514 --- Core/Plugins/src/Core.Plugins.Map/PropertyClasses/MapLineDataProperties.cs (.../MapLineDataProperties.cs) (revision ac96d7c315129af851634ed5a4a6800b59ede718) +++ Core/Plugins/src/Core.Plugins.Map/PropertyClasses/MapLineDataProperties.cs (.../MapLineDataProperties.cs) (revision 40867963010e95b9df5c0f4dfa169707e151b514) @@ -47,6 +47,7 @@ } [PropertyOrder(5)] + [DynamicVisible] [ResourcesCategory(typeof(Resources), nameof(Resources.Categories_Styling))] [ResourcesDisplayName(typeof(Resources), nameof(Resources.MapData_Color_DisplayName))] [ResourcesDescription(typeof(Resources), nameof(Resources.MapLineData_Color_Description))] @@ -66,6 +67,7 @@ } [PropertyOrder(6)] + [DynamicReadOnly] [ResourcesCategory(typeof(Resources), nameof(Resources.Categories_Styling))] [ResourcesDisplayName(typeof(Resources), nameof(Resources.MapData_StrokeThickness_DisplayName))] [ResourcesDescription(typeof(Resources), nameof(Resources.MapLineData_Width_Description))] @@ -83,6 +85,7 @@ } [PropertyOrder(7)] + [DynamicReadOnly] [ResourcesCategory(typeof(Resources), nameof(Resources.Categories_Styling))] [ResourcesDisplayName(typeof(Resources), nameof(Resources.MapLineData_DashStyle_DisplayName))] [ResourcesDescription(typeof(Resources), nameof(Resources.MapLineData_DashStyle_Description))] @@ -99,5 +102,26 @@ data.NotifyObservers(); } } + + public override bool DynamicVisibleValidationMethod(string propertyName) + { + if (propertyName == nameof(Color)) + { + return data.MapTheme == null; + } + + return base.DynamicVisibleValidationMethod(propertyName); + } + + public override bool DynamicReadonlyValidator(string propertyName) + { + if (propertyName == nameof(Width) + || propertyName == nameof(DashStyle)) + { + return data.MapTheme != null; + } + + return base.DynamicReadonlyValidator(propertyName); + } } } \ No newline at end of file Index: Core/Plugins/test/Core.Plugins.Map.Test/PropertyClasses/MapLineDataPropertiesTest.cs =================================================================== diff -u -rd1b19bb139550ae19f474c28f94ff3329cae0236 -r40867963010e95b9df5c0f4dfa169707e151b514 --- Core/Plugins/test/Core.Plugins.Map.Test/PropertyClasses/MapLineDataPropertiesTest.cs (.../MapLineDataPropertiesTest.cs) (revision d1b19bb139550ae19f474c28f94ff3329cae0236) +++ Core/Plugins/test/Core.Plugins.Map.Test/PropertyClasses/MapLineDataPropertiesTest.cs (.../MapLineDataPropertiesTest.cs) (revision 40867963010e95b9df5c0f4dfa169707e151b514) @@ -30,6 +30,8 @@ using Core.Components.Gis.Features; using Core.Components.Gis.Geometries; using Core.Components.Gis.Style; +using Core.Components.Gis.TestUtil; +using Core.Components.Gis.Theme; using Core.Plugins.Map.PropertyClasses; using NUnit.Framework; using Rhino.Mocks; @@ -43,6 +45,9 @@ private const int widthPropertyIndex = 7; private const int stylePropertyIndex = 8; + private const int widthWithMapThemePropertyIndex = 7; + private const int styleWithMapThemePropertyIndex = 9; + [Test] public void Constructor_ExpectedValues() { @@ -56,7 +61,7 @@ } [Test] - public void Constructor_Always_PropertiesHaveExpectedAttributesValues() + public void Constructor_MapLineDataWithoutMapTheme_PropertiesHaveExpectedAttributesValues() { // Setup var mapLineData = new MapLineData("Test") @@ -101,6 +106,50 @@ } [Test] + public void Constructor_MapLineDataWithMapTheme_PropertiesHaveExpectedAttributesValues() + { + // Setup + var mapLineData = new MapLineData("Test") + { + Features = new[] + { + new MapFeature(Enumerable.Empty()) + }, + ShowLabels = true, + MapTheme = new MapTheme("Attribute", new[] + { + CategoryThemeTestFactory.CreateCategoryTheme() + }) + }; + + // Call + var properties = new MapLineDataProperties + { + Data = mapLineData + }; + + // Assert + PropertyDescriptorCollection dynamicProperties = PropertiesTestHelper.GetAllVisiblePropertyDescriptors(properties); + Assert.AreEqual(10, dynamicProperties.Count); + const string styleCategory = "Stijl"; + + PropertyDescriptor widthProperty = dynamicProperties[widthWithMapThemePropertyIndex]; + PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(widthProperty, + styleCategory, + "Lijndikte", + "De dikte van de lijnen waarmee deze kaartlaag wordt weergegeven.", + true); + + PropertyDescriptor styleProperty = dynamicProperties[styleWithMapThemePropertyIndex]; + Assert.IsInstanceOf(styleProperty.Converter); + PropertiesTestHelper.AssertRequiredPropertyDescriptorProperties(styleProperty, + styleCategory, + "Lijnstijl", + "De stijl van de lijnen waarmee deze kaartlaag wordt weergegeven.", + true); + } + + [Test] public void Data_SetNewMapLineDataInstance_ReturnCorrectPropertyValues() { // Setup @@ -168,5 +217,191 @@ Assert.AreEqual(newDashStyle, mapLineData.Style.DashStyle); mocks.VerifyAll(); } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void DynamicReadOnlyValidator_MapHasMetaData_ReturnsExpectedValuesForRelevantProperties(bool hasMetaData) + { + // Setup + var feature = new MapFeature(Enumerable.Empty()); + if (hasMetaData) + { + feature.MetaData["key"] = "value"; + } + + var mapData = new MapLineData("Test") + { + Features = new[] + { + feature + } + }; + + var properties = new MapLineDataProperties + { + Data = mapData + }; + + // Call + bool isShowLabelReadOnly = properties.DynamicReadonlyValidator( + nameof(properties.ShowLabels)); + bool isSelectedMetaDataReadOnly = properties.DynamicReadonlyValidator( + nameof(properties.SelectedMetaDataAttribute)); + + // Assert + Assert.AreNotEqual(hasMetaData, isShowLabelReadOnly); + Assert.AreNotEqual(hasMetaData, isSelectedMetaDataReadOnly); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void DynamicReadOnlyValidator_MapLineDataWithMapTheme_ReturnsExpectedValuesForRelevantProperties(bool hasMapTheme) + { + // Setup + var mapData = new MapLineData("Test") + { + MapTheme = hasMapTheme + ? new MapTheme("Attribute", new[] + { + CategoryThemeTestFactory.CreateCategoryTheme() + }) + : null + }; + + var properties = new MapLineDataProperties + { + Data = mapData + }; + + // Call + bool isWidthReadOnly = properties.DynamicReadonlyValidator( + nameof(MapLineDataProperties.Width)); + bool isDashStyleReadOnly = properties.DynamicReadonlyValidator( + nameof(MapLineDataProperties.DashStyle)); + + // Assert + Assert.AreEqual(hasMapTheme, isWidthReadOnly); + Assert.AreEqual(hasMapTheme, isDashStyleReadOnly); + } + + [Test] + public void DynamicReadOnlyValidator_AnyOtherProperty_ReturnsFalse() + { + // Setup + var feature = new MapFeature(Enumerable.Empty()); + feature.MetaData["Key"] = "value"; + + var mapLineData = new MapLineData("Test") + { + Features = new[] + { + feature + }, + MapTheme = new MapTheme("Attribute", new[] + { + CategoryThemeTestFactory.CreateCategoryTheme() + }) + }; + + var properties = new MapLineDataProperties + { + Data = mapLineData + }; + + // Call + bool isOtherPropertyReadOnly = properties.DynamicReadonlyValidator(string.Empty); + + // Assert + Assert.IsFalse(isOtherPropertyReadOnly); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void DynamicVisibleValidationMethod_ShowLabels_ReturnsExpectedValuesForRelevantProperties(bool showLabels) + { + // Setup + var mapLineData = new MapLineData("Test") + { + ShowLabels = showLabels + }; + + var properties = new MapLineDataProperties + { + Data = mapLineData + }; + + // Call + bool isSelectedMetaDataAttributeVisible = properties.DynamicVisibleValidationMethod( + nameof(MapLineDataProperties.SelectedMetaDataAttribute)); + + // Assert + Assert.AreEqual(showLabels, isSelectedMetaDataAttributeVisible); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void DynamicVisibleValidationMethod_MapDataWithMapTheme_ReturnsExpectedValuesForRelevantProperties(bool hasMapTheme) + { + // Setup + var mapLineData = new MapLineData("Test") + { + MapTheme = hasMapTheme + ? new MapTheme("Attribute", new[] + { + CategoryThemeTestFactory.CreateCategoryTheme() + }) + : null + }; + + var properties = new MapLineDataProperties + { + Data = mapLineData + }; + + // Call + bool isMapThemeAttributeNameVisible = properties.DynamicVisibleValidationMethod( + nameof(MapLineDataProperties.MapThemeAttributeName)); + bool isMapThemeCategoriesVisible = properties.DynamicVisibleValidationMethod( + nameof(MapLineDataProperties.Categories)); + bool isLineColorStyleVisible = properties.DynamicVisibleValidationMethod( + nameof(MapLineDataProperties.Color)); + + // Assert + Assert.AreEqual(hasMapTheme, isMapThemeAttributeNameVisible); + Assert.AreEqual(hasMapTheme, isMapThemeCategoriesVisible); + Assert.AreNotEqual(hasMapTheme, isLineColorStyleVisible); + } + + [Test] + public void DynamicVisibleValidationMethod_AnyOtherProperty_ReturnsTrue() + { + var mapPointData = new MapLineData("Test") + { + Features = new[] + { + new MapFeature(Enumerable.Empty()) + }, + ShowLabels = true, + MapTheme = new MapTheme("Attribute", new[] + { + CategoryThemeTestFactory.CreateCategoryTheme() + }) + }; + + var properties = new MapLineDataProperties + { + Data = mapPointData + }; + + // Call + bool isOtherPropertyVisible = properties.DynamicVisibleValidationMethod(string.Empty); + + // Assert + Assert.IsFalse(isOtherPropertyVisible); + } } } \ No newline at end of file