/* * Copyright © 2005, Mathew Hall * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * - Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * - Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY * OF SUCH DAMAGE. */ using System; using System.ComponentModel; using System.ComponentModel.Design; using XPTable.Events; using XPTable.Models; namespace XPTable.Models.Design { /// /// Provides a user interface that can edit collections of Rows /// at design time /// public class RowCollectionEditor : HelpfulCollectionEditor { /// /// The RowCollection being edited /// private RowCollection rows; /// /// Initializes a new instance of the RowCollectionEditor class /// using the specified collection type /// /// The type of the collection for this editor to edit public RowCollectionEditor(Type type) : base(type) { this.rows = null; } /// /// Edits the value of the specified object using the specified /// service provider and context /// /// An ITypeDescriptorContext that can be /// used to gain additional context information /// A service provider object through which /// editing services can be obtained /// The object to edit the value of /// The new value of the object. If the value of the /// object has not changed, this should return the same object /// it was passed public override object EditValue(ITypeDescriptorContext context, IServiceProvider isp, object value) { this.rows = (RowCollection) value; object returnObject = base.EditValue(context, isp, value); TableModel model = (TableModel) context.Instance; // make sure the TableModel's Table redraws any additions/deletions if (model.Table != null) { model.Table.PerformLayout(); model.Table.Refresh(); } return returnObject; } /// /// Creates a new instance of the specified collection item type /// /// The type of item to create /// A new instance of the specified object protected override object CreateInstance(Type itemType) { Row row = (Row) base.CreateInstance(itemType); // newly created items aren't added to the collection // until editing has finished. we'd like the newly // created row to show up in the table immediately // so we'll add it to the RowCollection now this.rows.Add(row); return row; } /// /// Destroys the specified instance of the object /// /// The object to destroy protected override void DestroyInstance(object instance) { if (instance != null && instance is Row) { Row row = (Row) instance; // the specified row is about to be destroyed so // we need to remove it from the RowCollection first this.rows.Remove(row); } base.DestroyInstance(instance); } } }