Skip to content

Commit

Permalink
Merge pull request #49 from albanian-xrm/feature/new-UI
Browse files Browse the repository at this point in the history
Filter entities or attributes and relationships
  • Loading branch information
BetimBeja authored Sep 19, 2021
2 parents 3e1974b + d2b67fc commit 1095a1f
Show file tree
Hide file tree
Showing 16 changed files with 548 additions and 78 deletions.
15 changes: 13 additions & 2 deletions AlbanianXrm.EarlyBound/Factories/MyPluginFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using AlbanianXrm.EarlyBound.Interfaces;
using AlbanianXrm.EarlyBound.Logic;
using Syncfusion.Windows.Forms.Tools;
using Syncfusion.WinForms.ListView;
using System.Windows.Forms;

namespace AlbanianXrm.EarlyBound.Factories
Expand Down Expand Up @@ -44,16 +45,26 @@ public EntitySelectionHandler NewEntitySelectionHandler(TreeViewAdv metadataTree
return new EntitySelectionHandler(myPlugin, backgroundWorkHandler, metadataTree, attributeMetadataHandler, relationshipMetadataHandler);
}

public EntityMetadataHandler NewEntityMetadataHandler(TreeViewAdv metadataTree, EntitySelectionHandler entitySelectionHandler)
public EntityMetadataHandler NewEntityMetadataHandler(TreeViewAdv metadataTree, EntitySelectionHandler entitySelectionHandler, AttributeMetadataHandler attributeMetadataHandler, RelationshipMetadataHandler relationshipMetadataHandler, SfComboBox cmbFindEntity)
{
return new EntityMetadataHandler(myPlugin, backgroundWorkHandler, metadataTree, entitySelectionHandler);
return new EntityMetadataHandler(myPlugin, backgroundWorkHandler, metadataTree, entitySelectionHandler, attributeMetadataHandler, relationshipMetadataHandler, cmbFindEntity);
}

public RelationshipMetadataHandler NewRelationshipMetadataHandler()
{
return new RelationshipMetadataHandler(myPlugin, backgroundWorkHandler);
}

public FilterSelectedHandler NewFilterSelectedHandler(TreeViewAdv metadataTree, CheckBox chkOnlySelected)
{
return new FilterSelectedHandler(pluginViewModel, metadataTree, chkOnlySelected);
}

public FindEntityHandler NewFindEntityHandler(TreeViewAdv metadataTree, SfComboBox cmbFindEntity, SfComboBox cmbFindChild)
{
return new FindEntityHandler(metadataTree, cmbFindEntity, cmbFindChild);
}

public EntityGeneratorHandler NewEntityGeneratorHandler(TreeViewAdv metadataTree, RichTextBox txtOutput)
{
return new EntityGeneratorHandler(myPlugin, backgroundWorkHandler, metadataTree, txtOutput);
Expand Down
9 changes: 0 additions & 9 deletions AlbanianXrm.EarlyBound/Helpers/AlbanianWorkAsyncInfo.cs

This file was deleted.

19 changes: 0 additions & 19 deletions AlbanianXrm.EarlyBound/Helpers/AsyncWorkExecutor.cs

This file was deleted.

36 changes: 36 additions & 0 deletions AlbanianXrm.EarlyBound/Helpers/CollectionEventHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Microsoft.Xrm.Sdk.Metadata;
using Syncfusion.Windows.Forms.Tools;
using Syncfusion.WinForms.ListView;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AlbanianXrm.EarlyBound.Helpers
{
class CollectionEventHandler
{
private readonly TreeNodeAdv attributes;
private readonly string logicalName;
private readonly SfComboBox cmbFindEntity;

public CollectionEventHandler(TreeNodeAdv attributes, string logicalName, SfComboBox cmbFindEntity)
{
this.attributes = attributes;
this.logicalName = logicalName;
this.cmbFindEntity = cmbFindEntity;
}

internal void Nodes_CollectionChanged(object sender, CollectionChangeEventArgs e)
{
attributes.Nodes.CollectionChanged -= Nodes_CollectionChanged;
if(cmbFindEntity.SelectedValue as string == logicalName)
{
cmbFindEntity.SelectedValue = null;
cmbFindEntity.SelectedValue = logicalName;
}
}
}
}
8 changes: 8 additions & 0 deletions AlbanianXrm.EarlyBound/Helpers/ComboItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace AlbanianXrm.EarlyBound.Helpers
{
internal class ComboItem
{
public string Key { get; set; }
public string Value { get; set; }
}
}
5 changes: 4 additions & 1 deletion AlbanianXrm.EarlyBound/Interfaces/IMyPluginFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using AlbanianXrm.BackgroundWorker;
using AlbanianXrm.EarlyBound.Logic;
using Syncfusion.Windows.Forms.Tools;
using Syncfusion.WinForms.ListView;
using System.Windows.Forms;

namespace AlbanianXrm.EarlyBound.Interfaces
Expand All @@ -11,8 +12,10 @@ interface IMyPluginFactory
AlBackgroundWorkHandler NewBackgroundWorkHandler();
AttributeMetadataHandler NewAttributeMetadataHandler();
CoreToolsDownloader NewCoreToolsDownloader();
EntityMetadataHandler NewEntityMetadataHandler(TreeViewAdv metadataTree, EntitySelectionHandler entitySelectionHandler);
EntityMetadataHandler NewEntityMetadataHandler(TreeViewAdv metadataTree, EntitySelectionHandler entitySelectionHandler, AttributeMetadataHandler attributeMetadataHandler, RelationshipMetadataHandler relationshipMetadataHandler, SfComboBox cmbFindEntity);
EntitySelectionHandler NewEntitySelectionHandler(TreeViewAdv metadataTree, AttributeMetadataHandler attributeMetadataHandler, RelationshipMetadataHandler relationshipMetadataHandler);
FilterSelectedHandler NewFilterSelectedHandler(TreeViewAdv metadataTree, CheckBox chkOnlySelected);
FindEntityHandler NewFindEntityHandler(TreeViewAdv metadataTree, SfComboBox cmbFindEntity, SfComboBox cmbFindChild);
RelationshipMetadataHandler NewRelationshipMetadataHandler();
EntityGeneratorHandler NewEntityGeneratorHandler(TreeViewAdv metadataTree, RichTextBox txtOutput);
PluginViewModel NewPluginViewModel();
Expand Down
7 changes: 5 additions & 2 deletions AlbanianXrm.EarlyBound/Logic/AttributeMetadataHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public AttributeMetadataHandler(MyPluginControl myPlugin, AlBackgroundWorkHandle
this.backgroundWorkHandler = backgroundWorkHandler;
}

public void GetAttributes(string entityName, TreeNodeAdv attributesNode, bool checkedState = false, HashSet<string> checkedAttributes = default(HashSet<string>))
public void GetAttributes(string entityName, TreeNodeAdv attributesNode, bool checkedState = false, HashSet<string> checkedAttributes = default)
{
backgroundWorkHandler.EnqueueBackgroundWork(
AlBackgroundWorkerFactory.NewWorker(
Expand Down Expand Up @@ -63,9 +63,10 @@ public AttributeMetadataHandler(MyPluginControl myPlugin, AlBackgroundWorkHandle
);
}

public static void CreateAttributeNodes(TreeNodeAdv attributesNode, EntityMetadata entityMetadata, bool checkedState = false, HashSet<string> checkedAttributes = default(HashSet<string>))
public void CreateAttributeNodes(TreeNodeAdv attributesNode, EntityMetadata entityMetadata, bool checkedState = false, HashSet<string> checkedAttributes = default)
{
attributesNode.ExpandedOnce = true;
var attributeNodeList = new List<TreeNodeAdv>();
foreach (var item in entityMetadata.Attributes.OrderBy(x => x.LogicalName))
{
if (!item.DisplayName.LocalizedLabels.Any()) continue;
Expand All @@ -78,9 +79,11 @@ public AttributeMetadataHandler(MyPluginControl myPlugin, AlBackgroundWorkHandle
Tag = item,
Checked = checkedState || checkedAttributes.Contains(item.LogicalName)
};
attributeNodeList.Add(node);

attributesNode.Nodes.Add(node);
}
myPlugin.pluginViewModel.AllAttributes[entityMetadata.LogicalName] = attributeNodeList.ToArray();
if (entityMetadata.Attributes.Length == 0) attributesNode.Checked = checkedState;
}
}
Expand Down
3 changes: 2 additions & 1 deletion AlbanianXrm.EarlyBound/Logic/EntityGeneratorHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public void GenerateEntities(Options options)
options,
Progress,
GenerateEntitiesEnd
).WithMessage(myPlugin, Resources.GENERATING_ENTITIES));
).WithViewModel(myPlugin.pluginViewModel)
.WithMessage(myPlugin, Resources.GENERATING_ENTITIES));
}

private string GenerateEntitiesInner(Options options, Reporter<string> reporter)
Expand Down
45 changes: 32 additions & 13 deletions AlbanianXrm.EarlyBound/Logic/EntityMetadataHandler.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using AlbanianXrm.BackgroundWorker;
using AlbanianXrm.EarlyBound.Extensions;
using AlbanianXrm.EarlyBound.Helpers;
using AlbanianXrm.EarlyBound.Properties;
using AlbanianXrm.XrmToolBox.Shared;
using AlbanianXrm.XrmToolBox.Shared.Extensions;
using Microsoft.Xrm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Metadata;
using Syncfusion.Windows.Forms.Tools;
using Syncfusion.WinForms.ListView;
using System;
using System.Collections.Generic;
using System.IO;
Expand All @@ -20,24 +21,32 @@ internal class EntityMetadataHandler
private readonly AlBackgroundWorkHandler backgroundWorkHandler;
private readonly TreeViewAdv metadataTree;
private readonly EntitySelectionHandler entitySelectionHandler;
private readonly AttributeMetadataHandler attributeMetadataHandler;
private readonly RelationshipMetadataHandler relationshipMetadataHandler;
private readonly SfComboBox cmbFindEntity;

public EntityMetadataHandler(MyPluginControl myPlugin, AlBackgroundWorkHandler backgroundWorkHandler, TreeViewAdv metadataTree, EntitySelectionHandler entitySelectionHandler)
public EntityMetadataHandler(MyPluginControl myPlugin, AlBackgroundWorkHandler backgroundWorkHandler, TreeViewAdv metadataTree, EntitySelectionHandler entitySelectionHandler, AttributeMetadataHandler attributeMetadataHandler, RelationshipMetadataHandler relationshipMetadataHandler, SfComboBox cmbFindEntity)
{
this.myPlugin = myPlugin;
this.backgroundWorkHandler = backgroundWorkHandler;
this.metadataTree = metadataTree;
this.entitySelectionHandler = entitySelectionHandler;
this.attributeMetadataHandler = attributeMetadataHandler;
this.relationshipMetadataHandler = relationshipMetadataHandler;
this.cmbFindEntity = cmbFindEntity;
}

public void GetEntityList(bool selectAll = false)
{
var options = this.myPlugin.options;
backgroundWorkHandler.EnqueueBackgroundWork(AlBackgroundWorkerFactory.NewWorker(
DoWork,
new Tuple<string, bool>((string.IsNullOrEmpty(options.CurrentOrganizationOptions.Output) ? "Test.cs" : Path.GetFullPath(options.CurrentOrganizationOptions.Output)) + ".alb", selectAll),
WorkEnded
backgroundWorkHandler.EnqueueBackgroundWork(
AlBackgroundWorkerFactory.NewWorker(
DoWork,
new Tuple<string, bool>((string.IsNullOrEmpty(options.CurrentOrganizationOptions.Output) ? "Test.cs" : Path.GetFullPath(options.CurrentOrganizationOptions.Output)) + ".alb", selectAll),
WorkEnded
).WithViewModel(myPlugin.pluginViewModel)
.WithMessage(myPlugin, Resources.GETTING_ENTITY_LIST));
.WithMessage(myPlugin, Resources.GETTING_ENTITY_LIST)
);
}

public Tuple<RetrieveAllEntitiesResponse, Dictionary<string, EntitySelection>> DoWork(Tuple<string, bool> arg)
Expand Down Expand Up @@ -69,12 +78,14 @@ public void WorkEnded(Tuple<string, bool> input, Tuple<RetrieveAllEntitiesRespon
{
MessageBox.Show(exception.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else if (value !=null)
else if (value != null)
{
RetrieveAllEntitiesResponse result = value.Item1;
metadataTree.BackgroundImage = null;
metadataTree.Enabled = true;
metadataTree.Nodes.Clear();
var entityNodes = new List<TreeNodeAdv>();
var dataSource = new List<ComboItem>();
myPlugin.entityMetadatas = result.EntityMetadata;
foreach (var item in result.EntityMetadata.OrderBy(x => x.LogicalName))
{
Expand All @@ -91,8 +102,9 @@ public void WorkEnded(Tuple<string, bool> input, Tuple<RetrieveAllEntitiesRespon
ShowCheckBox = true,
InteractiveCheckBox = true
};

TreeNodeAdv node = new TreeNodeAdv($"{item.LogicalName}: {item.DisplayName.LocalizedLabels[0].Label}",
var entityName = $"{item.LogicalName}: {item.DisplayName.LocalizedLabels[0].Label}";
dataSource.Add(new ComboItem() { Key = item.LogicalName, Value = entityName });
TreeNodeAdv node = new TreeNodeAdv(entityName,
new TreeNodeAdv[] { attributes, relationships })
{
ExpandedOnce = true,
Expand All @@ -101,17 +113,24 @@ public void WorkEnded(Tuple<string, bool> input, Tuple<RetrieveAllEntitiesRespon
Tag = item
};
metadataTree.Nodes.Add(node);
entityNodes.Add(node);
if (input.Item2)
{
AttributeMetadataHandler.CreateAttributeNodes(attributes, item, checkedState: true);
RelationshipMetadataHandler.CreateRelationshipNodes(relationships, item, checkedState: true);
attributeMetadataHandler.CreateAttributeNodes(attributes, item, checkedState: true);
relationshipMetadataHandler.CreateRelationshipNodes(relationships, item, checkedState: true);
}
else
{
attributes.Nodes.CollectionChanged += new CollectionEventHandler(attributes, item.LogicalName, cmbFindEntity).Nodes_CollectionChanged;
relationships.Nodes.CollectionChanged += new CollectionEventHandler(relationships, item.LogicalName, cmbFindEntity).Nodes_CollectionChanged;
}
}
if (!input.Item2)
{
entitySelectionHandler.SelectGenerated();
}

myPlugin.pluginViewModel.AllEntities = entityNodes.ToArray();
cmbFindEntity.DataSource = dataSource;
myPlugin.pluginViewModel.All_Metadata_Requested = input.Item2;
myPlugin.pluginViewModel.Generate_Enabled = true;
}
Expand Down
Loading

0 comments on commit 1095a1f

Please sign in to comment.