/// <summary> /// /Handle the click event in the OnClick method. Here we will test the selected object, get the object’s model and label file, and create the label. /// </summary> /// <param name="e">The context of the VS tools and metadata</param> public override void OnClick(AddinDesignerEventArgs e) { // Dont display Already exists message helper.PromptOnDuplicate = false; try { // Get the metamodelService IMetaModelService metaModelService = helper.MetaModelService; // Is the selected element a table? if (e.SelectedElement is ITable) { ITable table = e.SelectedElement as ITable; helper.setModelAndLabelFile(metaModelService.GetTableModelInfo(table.Name)); helper.createPropertyLabels(table, table.Name); // Loop through each BaseField. Similar logic coulde be added for FieldGroups Ect. foreach (IBaseField baseField in table.BaseFields) { var labelPrefix = String.Format("{0}_{1}", baseField.Table.Name, baseField.Name); helper.createPropertyLabels(baseField, labelPrefix); } } if (e.SelectedElement is IView) { IView view = e.SelectedElement as IView; helper.setModelAndLabelFile(metaModelService.GetViewModelInfo(view.Name)); helper.createPropertyLabels(view, view.Name); // Loop through each BaseField. Similar logic coulde be added for FieldGroups Ect. foreach (IViewBaseField baseField in view.ViewBaseFields) { var labelPrefix = String.Format("{0}_{1}", baseField.View.Name, baseField.Name); helper.createPropertyLabels(baseField, labelPrefix); } } // Is this a Form Design Element? else if (e.SelectedElement is IFormDesign) { IFormDesign formDesign = e.SelectedElement as IFormDesign; var form = formDesign.Form; helper.setModelAndLabelFile(metaModelService.GetFormModelInfo(form.Name)); helper.createPropertyLabels(formDesign, formDesign.Form.Name); // Loop through all children FormControls. this.crawlDesignControls(formDesign.VisualChildren, form.Name); } else if (e.SelectedElement is IBaseEnum) { IBaseEnum axEnum = e.SelectedElement as IBaseEnum; helper.setModelAndLabelFile(metaModelService.GetEnumModelInfo(axEnum.Name)); var labelPrefix = String.Format("{0}_{1}", Tags.EnumTag, axEnum.Name); helper.createPropertyLabels(axEnum, labelPrefix); // Was unable to locate a way of finding the parent enum of a enumValue. No model could be found without it. // Loop through all values foreach (IBaseEnumValue enumValue in axEnum.BaseEnumValues) { var enumValueLabelPrefix = String.Format("{0}_{1}_{2}", Tags.EnumTag, axEnum.Name, enumValue.Name); helper.createPropertyLabels(enumValue, enumValueLabelPrefix); } } else if (e.SelectedElement is IReport) { IReport Report = e.SelectedElement as IReport; helper.setModelAndLabelFile(metaModelService.GetReportModelInfo(Report.Name)); foreach (IReportDataSet dataSet in Report.DataSets) { foreach (IReportDataSetField dataField in dataSet.Fields) { var labelPrefix = String.Format("{0}_{1}_{2}", dataSet.Report.Name, dataSet.Name, dataField.Name); helper.createPropertyLabels(dataField, labelPrefix); } } } else if (e.SelectedElement is IReportDataSet) { IReportDataSet dataSet = e.SelectedElement as IReportDataSet; helper.setModelAndLabelFile(metaModelService.GetReportModelInfo(dataSet.Report.Name)); foreach (IReportDataSetField dataField in dataSet.Fields) { var labelPrefix = String.Format("{0}_{1}_{2}", dataSet.Report.Name, dataSet.Name, dataField.Name); helper.createPropertyLabels(dataField, labelPrefix); } } } catch (Exception ex) { Microsoft.Dynamics.Framework.Tools.MetaModel.Core.CoreUtility.HandleExceptionWithErrorMessage(ex); } }
/// <summary> /// /Handle the click event in the OnClick method. Here we will test the selected object, get the object’s model and label file, and create the label. /// </summary> /// <param name="e">The context of the VS tools and metadata</param> public override void OnClick(AddinDesignerEventArgs e) { try { // Get the metamodel service IMetaModelService metaModelService = helper.MetaModelService; // Is the selected element a table? if (e.SelectedElement is ITable) { ITable table = e.SelectedElement as ITable; helper.setModelAndLabelFile(metaModelService.GetTableModelInfo(table.Name)); labelPrefix = table.Name; } else if (e.SelectedElement is IBaseField) { IBaseField baseField = e.SelectedElement as IBaseField; var table = baseField.Table; helper.setModelAndLabelFile(metaModelService.GetTableModelInfo(table.Name)); labelPrefix = String.Format("{0}_{1}", baseField.Table.Name, baseField.Name); } if (e.SelectedElement is IView) { IView view = e.SelectedElement as IView; helper.setModelAndLabelFile(metaModelService.GetTableModelInfo(view.Name)); labelPrefix = view.Name; } else if (e.SelectedElement is IViewBaseField) { IViewBaseField baseField = e.SelectedElement as IViewBaseField; var view = baseField.View; helper.setModelAndLabelFile(metaModelService.GetViewModelInfo(view.Name)); labelPrefix = String.Format("{0}_{1}", baseField.View.Name, baseField.Name); } else if (e.SelectedElement is IFormDesign) { IFormDesign formDesign = e.SelectedElement as IFormDesign; var form = formDesign.Form; helper.setModelAndLabelFile(metaModelService.GetFormModelInfo(form.Name)); labelPrefix = formDesign.Form.Name; } else if (e.SelectedElement is IFormControl) { IFormControl formControl = e.SelectedElement as IFormControl; IRootElement rootElement = formControl.RootElement as IRootElement; if (rootElement is IFormExtension) { helper.setModelAndLabelFile(metaModelService.GetFormExtensionModelInfo(rootElement.Name)); labelPrefix = String.Format("{0}_{1}", rootElement.Name, formControl.Name); labelPrefix = labelPrefix.Replace(".","_"); } else { helper.setModelAndLabelFile(metaModelService.GetFormModelInfo(rootElement.Name)); labelPrefix = String.Format("{0}_{1}", rootElement.Name, formControl.Name); } } else if (e.SelectedElement is ISecurityPrivilege) { ISecurityPrivilege securityObject = e.SelectedElement as ISecurityPrivilege; helper.setModelAndLabelFile(metaModelService.GetSecurityPrivilegeModelInfo(securityObject.Name)); labelPrefix = String.Format("{0}_{1}", Tags.PrivilegeTag, securityObject.Name); } else if (e.SelectedElement is ISecurityDuty) { ISecurityDuty securityObject = e.SelectedElement as ISecurityDuty; helper.setModelAndLabelFile(metaModelService.GetSecurityDutyModelInfo(securityObject.Name)); labelPrefix = String.Format("{0}_{1}", Tags.DutyTag, securityObject.Name); } else if (e.SelectedElement is ISecurityRole) { ISecurityRole securityObject = e.SelectedElement as ISecurityRole; helper.setModelAndLabelFile(metaModelService.GetSecurityRoleModelInfo(securityObject.Name)); labelPrefix = String.Format("{0}_{1}", Tags.RoleTag, securityObject.Name); } else if (e.SelectedElement is IEdtBase) { IEdtBase edt = e.SelectedElement as IEdtBase; helper.setModelAndLabelFile(metaModelService.GetExtendedDataTypeModelInfo(edt.Name)); labelPrefix = String.Format("{0}_{1}", Tags.EDTTag, edt.Name); } else if (e.SelectedElement is IMenuItem) { IMenuItem AxMenuItem = e.SelectedElement as IMenuItem; labelPrefix = String.Format("{0}_{1}", Tags.MenuItemTag, AxMenuItem.Name); if (AxMenuItem is IMenuItemAction) { helper.setModelAndLabelFile(metaModelService.GetMenuItemActionModelInfo(AxMenuItem.Name)); } else if (AxMenuItem is IMenuItemDisplay) { helper.setModelAndLabelFile(metaModelService.GetMenuItemDisplayModelInfo(AxMenuItem.Name)); } else if (AxMenuItem is IMenuItemOutput) { helper.setModelAndLabelFile(metaModelService.GetMenuItemOutputModelInfo(AxMenuItem.Name)); } } else if (e.SelectedElement is IReportDataSetField) { IReportDataSetField dataField = e.SelectedElement as IReportDataSetField; helper.setModelAndLabelFile(metaModelService.GetReportModelInfo(dataField.DataSet.Report.Name)); labelPrefix = String.Format("{0}_{1}_{2}", dataField.DataSet.Report.Name, dataField.DataSet.Name, dataField.Name); } helper.createPropertyLabels(e.SelectedElement, labelPrefix); } catch (Exception ex) { Microsoft.Dynamics.Framework.Tools.MetaModel.Core.CoreUtility.HandleExceptionWithErrorMessage(ex); } }