Skip to content

Commit

Permalink
#17 Container, Date
Browse files Browse the repository at this point in the history
Basic structure for this added.
Implemented for Contianer & Date
  • Loading branch information
shashisadasivan committed Oct 9, 2019
1 parent a4fe1e5 commit e991ccf
Show file tree
Hide file tree
Showing 11 changed files with 163 additions and 0 deletions.
Binary file modified OutputDlls/SSD365VSAddIn.dll
Binary file not shown.
Binary file modified SSD365VSAddIn/.vs/SSD365VSAddIn/v14/.suo
Binary file not shown.
9 changes: 9 additions & 0 deletions SSD365VSAddIn/SSD365VSAddIn/AddinResources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions SSD365VSAddIn/SSD365VSAddIn/AddinResources.resx
Expand Up @@ -163,6 +163,9 @@
<data name="ShowTheLabelMenuAddIn" xml:space="preserve">
<value>Show the label (SS D365)</value>
</data>
<data name="TableFieldEDTCreatorMenuAddIn" xml:space="preserve">
<value>Create EDT (SS D365)</value>
</data>
<data name="TableFormCreatorMenuAddIn" xml:space="preserve">
<value>Create Form (SS D365)</value>
</data>
Expand Down
1 change: 1 addition & 0 deletions SSD365VSAddIn/SSD365VSAddIn/SSD365VSAddIn.csproj
Expand Up @@ -141,6 +141,7 @@
<DependentUpon>ModelSettingsUI.cs</DependentUpon>
</Compile>
<Compile Include="ShowTheLabel\ShowtheLabelMenuAddIn.cs" />
<Compile Include="Tables\TableFieldEDTCreatorMenuAddIn.cs" />
<Compile Include="Tables\TableFormCreatorMenuAddIn.cs" />
<Compile Include="Tables\TableHelper.cs" />
</ItemGroup>
Expand Down
150 changes: 150 additions & 0 deletions SSD365VSAddIn/SSD365VSAddIn/Tables/TableFieldEDTCreatorMenuAddIn.cs
@@ -0,0 +1,150 @@
using Microsoft.Dynamics.AX.Metadata.MetaModel;
using Microsoft.Dynamics.Framework.Tools.Extensibility;
using Microsoft.Dynamics.Framework.Tools.MetaModel.Automation.Tables;
using Microsoft.Dynamics.Framework.Tools.MetaModel.Core;
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SSD365VSAddIn.Tables
{
/// <summary>
/// Creates EDT's for the table field
/// </summary>
[Export(typeof(IDesignerMenu))]
// If you need to specify any other element, change this AutomationNodeType value.
// You can specify multiple DesignerMenuExportMetadata attributes to meet your needs
//[DesignerMenuExportMetadata(AutomationNodeType = typeof(IBaseField))] // once all the other types are created, then Change it to IBaseField
[DesignerMenuExportMetadata(AutomationNodeType = typeof(IFieldContainer))]
[DesignerMenuExportMetadata(AutomationNodeType = typeof(IFieldDate))]
class TableFieldEDTCreatorMenuAddIn : DesignerMenuBase
{
#region Member variables
private const string addinName = "SSD365VSAddIn.TableFieldEDTCreatorMenuAddIn";
#endregion

#region Properties
/// <summary>
/// Caption for the menu item. This is what users would see in the menu.
/// </summary>
public override string Caption
{
get
{
return AddinResources.TableFieldEDTCreatorMenuAddIn;
}
}

/// <summary>
/// Unique name of the add-in
/// </summary>
public override string Name
{
get
{
return TableFieldEDTCreatorMenuAddIn.addinName;
}
}
#endregion

#region Callbacks
/// <summary>
/// Called when user clicks on the add-in menu
/// </summary>
/// <param name="e">The context of the VS tools and metadata</param>
public override void OnClick(AddinDesignerEventArgs e)
{
//Microsoft.Dynamics.AX.Metadata.Core.MetaModel.EntryPointType entryPointType;
try
{
// we will create 2 security privileges for the menu item with the same name + Maintain, +View
var selectedElement = e.SelectedElement as IBaseField;
if (selectedElement != null)
{
this.CreateEDT(selectedElement);
}
}
catch (Exception ex)
{
CoreUtility.HandleExceptionWithErrorMessage(ex);
}
}

#endregion

protected void CreateEDT(IBaseField baseField)
{
if(String.IsNullOrEmpty(baseField.ExtendedDataType) == false)
{
// There is already a EDT defined for this field
return;
}

// The Name of the edt to create should have the prefix as per the Settings
// If the Prefix already exists on the
var modelSettings = Settings.FetchSettings.FindOrCreateSettings();
var edtName = baseField.Name;
if(String.IsNullOrEmpty(modelSettings.Prefix) == false
&& edtName.StartsWith(modelSettings.Prefix, StringComparison.InvariantCultureIgnoreCase) == false)
{
edtName = modelSettings.Prefix + edtName;
}
AxEdt edtToCreate = null;

if(baseField is IFieldContainer)
{
//var currentField = baseField as IFieldContainer;
edtToCreate = new Microsoft.Dynamics.AX.Metadata.MetaModel.AxEdtContainer();
}
else if (baseField is IFieldDate)
{
edtToCreate = new Microsoft.Dynamics.AX.Metadata.MetaModel.AxEdtDate();
}

this.copyProperties(baseField, edtToCreate);
edtToCreate.Name = edtName;

if (edtToCreate != null)
{
// Find current model
var modelSaveInfo = Common.CommonUtil.GetCurrentModelSaveInfo();

//Create menu item in the right model
var metaModelProviders = ServiceLocator.GetService(typeof(IMetaModelProviders)) as IMetaModelProviders;
var metaModelService = metaModelProviders.CurrentMetaModelService;

metaModelService.CreateExtendedDataType(edtToCreate, modelSaveInfo);

//Update the table field with the EDT, also remove any labels from the field
baseField.ExtendedDataType = edtToCreate.Name;
baseField.Label = String.Empty;
baseField.HelpText = String.Empty;

// Add to the current active project
Common.CommonUtil.AddElementToProject(edtToCreate);
}
}
private void copyProperties(object source, object target)
{
foreach (var prop in source.GetType().GetProperties())
{
var targetProperty = target.GetType().GetProperty(prop.Name);
if (targetProperty != null)
{
targetProperty.SetValue(target, prop.GetValue(source));
}
}
foreach (var fields in source.GetType().GetFields())
{
var targetField = target.GetType().GetField(fields.Name);
if(targetField != null)
{
targetField.SetValue(target, fields.GetValue(source));
}
}
}
}
}
Binary file not shown.
Binary file not shown.
Binary file modified SSD365VSAddIn/SSD365VSAddIn/obj/Debug/SSD365VSAddIn.dll
Binary file not shown.
Binary file modified SSD365VSAddIn/SSD365VSAddIn/obj/Debug/SSD365VSAddIn.pdb
Binary file not shown.
Binary file not shown.

0 comments on commit e991ccf

Please sign in to comment.