/// <summary> /// Called to handle the "edit" action. /// </summary> /// <param name="items">A list of items to edit.</param> /// <param name="editedItems">The list of items that were edited.</param> /// <returns>True if items were edited, false otherwise.</returns> protected override bool EditItems(IList <AddressDetail> items, out IList <AddressDetail> editedItems) { editedItems = new List <AddressDetail>(); AddressDetail oldItem = CollectionUtils.FirstElement(items); AddressDetail newItem = (AddressDetail)oldItem.Clone(); AddressEditorComponent editor = new AddressEditorComponent(newItem, _addressTypes); ApplicationComponentExitCode exitCode = LaunchAsDialog(this.Host.DesktopWindow, editor, SR.TitleUpdateAddress); if (exitCode == ApplicationComponentExitCode.Accepted) { editedItems.Add(newItem); // Since there is no way to use IsSameItem to identify the address before and after are the same // We must manually remove the old and add the new item this.Table.Items.Replace( delegate(AddressDetail x) { return(IsSameItem(oldItem, x)); }, newItem); // Preserve the order of the items int index = _addressList.IndexOf(oldItem); _addressList.Insert(index, newItem); _addressList.Remove(oldItem); return(true); } return(false); }
/// <summary> /// Called to handle the "add" action. /// </summary> /// <param name="addedItems"></param> /// <returns>True if items were added, false otherwise.</returns> protected override bool AddItems(out IList <AddressDetail> addedItems) { addedItems = new List <AddressDetail>(); AddressDetail address = new AddressDetail(); address.Province = CollectionUtils.FirstElement(AddressEditorComponentSettings.Default.ProvinceChoices); address.Country = CollectionUtils.FirstElement(AddressEditorComponentSettings.Default.CountryChoices); address.Type = _addressTypes[0]; AddressEditorComponent editor = new AddressEditorComponent(address, _addressTypes); ApplicationComponentExitCode exitCode = LaunchAsDialog(this.Host.DesktopWindow, editor, SR.TitleAddAddress); if (exitCode == ApplicationComponentExitCode.Accepted) { addedItems.Add(address); _addressList.Add(address); return(true); } return(false); }