Skip to content

Commit

Permalink
Added support for Extended Properties
Browse files Browse the repository at this point in the history
  • Loading branch information
otykier committed Dec 3, 2018
1 parent 95e4506 commit 4c87ea9
Show file tree
Hide file tree
Showing 8 changed files with 2,023 additions and 11 deletions.
@@ -0,0 +1,71 @@
using System;
using System.Collections;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Drawing.Design;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TabularEditor.TOMWrapper;

namespace TabularEditor.PropertyGridUI
{
internal class ExtendedPropertyCollectionEditor : RefreshGridCollectionEditor
{
ExtendedPropertyCollection Collection;

public ExtendedPropertyCollectionEditor() : base(typeof(Collection<ExtendedProperty>))
{
}

protected override object CreateInstance(Type itemType)
{
if(itemType == typeof(StringExtendedProperty))
return new StringExtendedProperty { Name = Collection.Parent.GetNewExtendedPropertyName(), Value = "" };
if(itemType == typeof(JsonExtendedProperty))
return new JsonExtendedProperty { Name = Collection.Parent.GetNewExtendedPropertyName(), Value = "" };

throw new NotSupportedException();
}

protected override bool CanRemoveInstance(object value)
{
return true;
}
protected override Type[] CreateNewItemTypes()
{
return new[] { typeof(StringExtendedProperty), typeof(JsonExtendedProperty) };
}

protected override string GetDisplayText(object value)
{
return (value as ExtendedProperty).Name;
}

protected override object[] GetItems(object editValue)
{
Collection = (editValue as ExtendedPropertyCollection);
return Collection.Keys.Select(k =>
{
var ep = Collection.Parent.GetExtendedPropertyType(k) == ExtendedPropertyType.Json ? new JsonExtendedProperty() : new StringExtendedProperty() as ExtendedProperty;
ep.Name = k;
ep.Value = Collection[k].ToString();
return ep;
}).ToArray();
}

protected override object SetItems(object editValue, object[] value)
{
foreach(ExtendedProperty an in value)
{
Collection.Parent.SetExtendedProperty(an.Name, an.Value, an.Type);
}
foreach(var n in Collection.Keys.ToList().Except(value.OfType<ExtendedProperty>().Select(an => an.Name)))
{
Collection.Parent.RemoveExtendedProperty(n);
}

return Collection;
}
}
}
3 changes: 3 additions & 0 deletions TOMWrapper/TOMWrapper.csproj
Expand Up @@ -70,11 +70,13 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="PropertyGridUI\CollectionEditors\ExtendedPropertyCollectionEditor.cs" />
<Compile Include="PropertyGridUI\Converters\CultureConverter.cs" />
<Compile Include="PropertyGridUI\Converters\HierarchyColumnConverter.cs" />
<Compile Include="PropertyGridUI\DataTypeEnumConverter.cs" />
<Compile Include="TextServices\DAXCharStream.cs" />
<Compile Include="TextServices\DAXLexer.cs" />
<Compile Include="TOMWrapper\ExtendedPropertyCollection.cs" />
<Compile Include="TOMWrapper\Base\WrapperBase.generated.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
Expand All @@ -90,6 +92,7 @@
<Compile Include="TOMWrapper\TabularModelHandler.Database.cs" />
<Compile Include="TOMWrapper\TabularModelHandler.Events.cs" />
<Compile Include="TOMWrapper\TabularModelHandler.FileHandling.cs" />
<Compile Include="UndoFramework\UndoExtendedPropertyAction.cs" />
<Compile Include="Utils\DaxDependencyHelper.cs" />
<Compile Include="TOMWrapper\Indexers\GenericIndexer.cs" />
<Compile Include="TOMWrapper\Relationship.cs" />
Expand Down
5 changes: 3 additions & 2 deletions TOMWrapper/TOMWrapper/Base/Rules.ttinclude
Expand Up @@ -393,7 +393,8 @@ partial class Rules {
"RelationshipEndCardinality",
"HierarchyHideMembersType",
"EncodingHintType",
"RefreshType"
"RefreshType",
"ExtendedPropertyType"
};
public static readonly Type[] EnumTypes = _enumTypes.Select(t => ASType(t)).Where(t => t != null).ToArray();

Expand Down Expand Up @@ -454,7 +455,7 @@ partial class Rules {
{ "SingleColumnRelationship", "Relationship" },
{ "Table", "TabularNamedObject" },
{ "WindowsModelRoleMember", "ModelRoleMember" },
{ "NamedExpression", "TabularNamedObject" }
{ "NamedExpression", "TabularNamedObject" },
};
public static Dictionary<Type, string> ObjectTypes = Convert(_objectTypes).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

Expand Down

0 comments on commit 4c87ea9

Please sign in to comment.