public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { oldAnnotations = new AnnotationCollection(); microsoftAnnotations = new List<Annotation>(); editedAnnotations = new List<Annotation>(); object returnValue = value; try { if ((provider != null) && (((IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService))) != null)) { ((AnnotationCollection)value).CopyTo(oldAnnotations); form = new Form(); form.Icon = BIDSHelper.Resources.Common.BIDSHelper; form.Text = "BIDS Helper Attributes Editor"; form.MaximizeBox = true; form.MinimizeBox = false; form.Width = 550; form.Height = 400; form.SizeGripStyle = SizeGripStyle.Show; form.MinimumSize = new System.Drawing.Size(form.Width,form.Height); check = new CheckBox(); check.Anchor = AnchorStyles.Left | AnchorStyles.Top; check.Text = "Hide Microsoft Annotations?"; check.Click += new EventHandler(check_Click); check.Width = 160; check.Left = 5; check.Checked = true; form.Controls.Add(check); Label labelAnnotation = new Label(); labelAnnotation.Text = "Annotation:"; labelAnnotation.Top = 25; labelAnnotation.Left = 5; labelAnnotation.Width = 65; labelAnnotation.Anchor = AnchorStyles.Left | AnchorStyles.Top; labelAnnotation.TextAlign = System.Drawing.ContentAlignment.TopRight; form.Controls.Add(labelAnnotation); combo = new ComboBox(); combo.DropDownStyle = ComboBoxStyle.DropDownList; combo.Width = form.Width - 40 - labelAnnotation.Width; combo.Left = labelAnnotation.Right + 5; combo.Top = 25; combo.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top; combo.SelectedIndexChanged += new EventHandler(combo_SelectedIndexChanged); form.Controls.Add(combo); foreach (Annotation a in oldAnnotations) { if (!a.Name.StartsWith("http://schemas.microsoft.com")) { combo.Items.Add(a.Name); editedAnnotations.Add(a); } else { microsoftAnnotations.Add(a); } } combo.Items.Add("<Add New Annotation>"); combo.SelectedIndex = -1; check.Left = combo.Left; Label labelName = new Label(); labelName.Text = "Name:"; labelName.Top = 50; labelName.Left = 5; labelName.Width = 65; labelName.TextAlign = System.Drawing.ContentAlignment.TopRight; labelName.Anchor = AnchorStyles.Left | AnchorStyles.Top; form.Controls.Add(labelName); textName = new TextBox(); textName.Text = ""; textName.Top = labelName.Top; textName.Left = labelName.Right + 5; textName.Width = combo.Width; textName.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top; textName.Enabled = false; textName.Leave += new EventHandler(textName_Leave); form.Controls.Add(textName); Label labelValue = new Label(); labelValue.Text = "Value:"; labelValue.Top = 75; labelValue.Left = 5; labelValue.Width = 65; labelValue.TextAlign = System.Drawing.ContentAlignment.TopRight; labelValue.Anchor = AnchorStyles.Left | AnchorStyles.Top; form.Controls.Add(labelValue); textValue = new TextBox(); textValue.Text = ""; textValue.Top = labelValue.Top; textValue.Left = labelName.Right + 5; textValue.Width = combo.Width; textValue.ScrollBars = ScrollBars.Vertical; textValue.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom; textValue.Enabled = false; textValue.Multiline = true; textValue.Height = form.Height - 85 - textValue.Top; textValue.Leave += new EventHandler(textValue_Leave); form.Controls.Add(textValue); Button okButton = new Button(); okButton.Text = "OK"; okButton.Anchor = AnchorStyles.Right | AnchorStyles.Bottom; okButton.Left = form.Right - okButton.Width * 2 - 40; okButton.Top = form.Bottom - okButton.Height*2 - 20; okButton.Click += new EventHandler(okButton_Click); //form.AcceptButton = okButton; //don't want enter to cause this window to close because of multiline value textbox form.Controls.Add(okButton); Button cancelButton = new Button(); cancelButton.Text = "Cancel"; cancelButton.Anchor = AnchorStyles.Right | AnchorStyles.Bottom; cancelButton.Left = okButton.Right + 10; cancelButton.Top = okButton.Top; form.CancelButton = cancelButton; form.Controls.Add(cancelButton); deleteButton = new Button(); deleteButton.Text = "Delete Annotation"; deleteButton.Anchor = AnchorStyles.Left | AnchorStyles.Bottom; deleteButton.Left = textValue.Left; deleteButton.Top = okButton.Top; deleteButton.Width += 30; deleteButton.Enabled = false; deleteButton.Click += new EventHandler(deleteButton_Click); form.Controls.Add(deleteButton); DialogResult result = form.ShowDialog(); if (result == DialogResult.OK) { AnnotationCollection coll = new AnnotationCollection(); foreach (Annotation a in this.microsoftAnnotations) coll.Add(a.Clone()); foreach (Annotation a in this.editedAnnotations) coll.Add(a.Clone()); DesignerTransaction transaction1 = null; try { IDesignerHost host1 = (IDesignerHost)provider.GetService(typeof(IDesignerHost)); transaction1 = host1.CreateTransaction("BidsHelperAnnotationCollectionEditorUndoBatchDesc"); IComponentChangeService service1 = (IComponentChangeService)context.GetService(typeof(IComponentChangeService)); Microsoft.DataWarehouse.VsIntegration.Designer.NamedCustomTypeDescriptor instance = (Microsoft.DataWarehouse.VsIntegration.Designer.NamedCustomTypeDescriptor)context.Instance; ModelComponent m = (ModelComponent)instance.BrowsableObject; //use ModelComponent from which Cube, Dimension, Measure, etc. are derived... ModelComponent contains the definition for Annotations service1.OnComponentChanging(m, null); m.Annotations.Clear(); coll.CopyTo(m.Annotations); service1.OnComponentChanged(m, null, null, null); returnValue = coll; return returnValue; } catch (CheckoutException exception1) { if (transaction1 != null) transaction1.Cancel(); if (exception1 != CheckoutException.Canceled) { throw exception1; } return returnValue; } finally { if (transaction1 != null) transaction1.Commit(); } } else { returnValue = oldAnnotations; } form.Dispose(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } return returnValue; }
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { oldAnnotations = new AnnotationCollection(); microsoftAnnotations = new List <Annotation>(); editedAnnotations = new List <Annotation>(); object returnValue = value; try { if ((provider != null) && (((IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService))) != null)) { ((AnnotationCollection)value).CopyTo(oldAnnotations); form = new Form(); form.Icon = BIDSHelper.Resources.Common.BIDSHelper; form.Text = "BIDS Helper Attributes Editor"; form.MaximizeBox = true; form.MinimizeBox = false; form.Width = 550; form.Height = 400; form.SizeGripStyle = SizeGripStyle.Show; form.MinimumSize = new System.Drawing.Size(form.Width, form.Height); check = new CheckBox(); check.Anchor = AnchorStyles.Left | AnchorStyles.Top; check.Text = "Hide Microsoft Annotations?"; check.Click += new EventHandler(check_Click); check.Width = 160; check.Left = 5; check.Checked = true; form.Controls.Add(check); Label labelAnnotation = new Label(); labelAnnotation.Text = "Annotation:"; labelAnnotation.Top = 25; labelAnnotation.Left = 5; labelAnnotation.Width = 65; labelAnnotation.Anchor = AnchorStyles.Left | AnchorStyles.Top; labelAnnotation.TextAlign = System.Drawing.ContentAlignment.TopRight; form.Controls.Add(labelAnnotation); combo = new ComboBox(); combo.DropDownStyle = ComboBoxStyle.DropDownList; combo.Width = form.Width - 40 - labelAnnotation.Width; combo.Left = labelAnnotation.Right + 5; combo.Top = 25; combo.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top; combo.SelectedIndexChanged += new EventHandler(combo_SelectedIndexChanged); form.Controls.Add(combo); foreach (Annotation a in oldAnnotations) { if (!a.Name.StartsWith("http://schemas.microsoft.com")) { combo.Items.Add(a.Name); editedAnnotations.Add(a); } else { microsoftAnnotations.Add(a); } } combo.Items.Add("<Add New Annotation>"); combo.SelectedIndex = -1; check.Left = combo.Left; Label labelName = new Label(); labelName.Text = "Name:"; labelName.Top = 50; labelName.Left = 5; labelName.Width = 65; labelName.TextAlign = System.Drawing.ContentAlignment.TopRight; labelName.Anchor = AnchorStyles.Left | AnchorStyles.Top; form.Controls.Add(labelName); textName = new TextBox(); textName.Text = ""; textName.Top = labelName.Top; textName.Left = labelName.Right + 5; textName.Width = combo.Width; textName.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top; textName.Enabled = false; textName.Leave += new EventHandler(textName_Leave); form.Controls.Add(textName); Label labelValue = new Label(); labelValue.Text = "Value:"; labelValue.Top = 75; labelValue.Left = 5; labelValue.Width = 65; labelValue.TextAlign = System.Drawing.ContentAlignment.TopRight; labelValue.Anchor = AnchorStyles.Left | AnchorStyles.Top; form.Controls.Add(labelValue); textValue = new TextBox(); textValue.Text = ""; textValue.Top = labelValue.Top; textValue.Left = labelName.Right + 5; textValue.Width = combo.Width; textValue.ScrollBars = ScrollBars.Vertical; textValue.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom; textValue.Enabled = false; textValue.Multiline = true; textValue.Height = form.Height - 85 - textValue.Top; textValue.Leave += new EventHandler(textValue_Leave); form.Controls.Add(textValue); Button okButton = new Button(); okButton.Text = "OK"; okButton.Anchor = AnchorStyles.Right | AnchorStyles.Bottom; okButton.Left = form.Right - okButton.Width * 2 - 40; okButton.Top = form.Bottom - okButton.Height * 2 - 20; okButton.Click += new EventHandler(okButton_Click); //form.AcceptButton = okButton; //don't want enter to cause this window to close because of multiline value textbox form.Controls.Add(okButton); Button cancelButton = new Button(); cancelButton.Text = "Cancel"; cancelButton.Anchor = AnchorStyles.Right | AnchorStyles.Bottom; cancelButton.Left = okButton.Right + 10; cancelButton.Top = okButton.Top; form.CancelButton = cancelButton; form.Controls.Add(cancelButton); deleteButton = new Button(); deleteButton.Text = "Delete Annotation"; deleteButton.Anchor = AnchorStyles.Left | AnchorStyles.Bottom; deleteButton.Left = textValue.Left; deleteButton.Top = okButton.Top; deleteButton.Width += 30; deleteButton.Enabled = false; deleteButton.Click += new EventHandler(deleteButton_Click); form.Controls.Add(deleteButton); DialogResult result = form.ShowDialog(); if (result == DialogResult.OK) { AnnotationCollection coll = new AnnotationCollection(); foreach (Annotation a in this.microsoftAnnotations) { coll.Add(a.Clone()); } foreach (Annotation a in this.editedAnnotations) { coll.Add(a.Clone()); } DesignerTransaction transaction1 = null; try { IDesignerHost host1 = (IDesignerHost)provider.GetService(typeof(IDesignerHost)); transaction1 = host1.CreateTransaction("BidsHelperAnnotationCollectionEditorUndoBatchDesc"); IComponentChangeService service1 = (IComponentChangeService)context.GetService(typeof(IComponentChangeService)); Microsoft.DataWarehouse.VsIntegration.Designer.NamedCustomTypeDescriptor instance = (Microsoft.DataWarehouse.VsIntegration.Designer.NamedCustomTypeDescriptor)context.Instance; ModelComponent m = (ModelComponent)instance.BrowsableObject; //use ModelComponent from which Cube, Dimension, Measure, etc. are derived... ModelComponent contains the definition for Annotations service1.OnComponentChanging(m, null); m.Annotations.Clear(); coll.CopyTo(m.Annotations); service1.OnComponentChanged(m, null, null, null); returnValue = coll; return(returnValue); } catch (CheckoutException exception1) { if (transaction1 != null) { transaction1.Cancel(); } if (exception1 != CheckoutException.Canceled) { throw exception1; } return(returnValue); } finally { if (transaction1 != null) { transaction1.Commit(); } } } else { returnValue = oldAnnotations; } form.Dispose(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } return(returnValue); }