Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic structure for this added. Implemented for Contianer & Date
- Loading branch information
1 parent
a4fe1e5
commit e991ccf
Showing
11 changed files
with
163 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
150 changes: 150 additions & 0 deletions
150
SSD365VSAddIn/SSD365VSAddIn/Tables/TableFieldEDTCreatorMenuAddIn.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 modified
BIN
+93 Bytes
(110%)
SSD365VSAddIn/SSD365VSAddIn/obj/Debug/SSD365VSAddIn.AddinResources.resources
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
SSD365VSAddIn/SSD365VSAddIn/obj/Debug/SSD365VSAddIn.csproj.GenerateResource.Cache
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
SSD365VSAddIn/SSD365VSAddIn/obj/Debug/TempPE/AddinResources.Designer.cs.dll
Binary file not shown.