//-----------------------------------------------------------------------
//  This file is part of the Microsoft Code Samples.
// 
//  Copyright (C) Microsoft Corporation.  All rights reserved.
// 
//This source code is intended only as a supplement to Microsoft
//Development Tools and/or on-line documentation.  See these other
//materials for detailed information regarding Microsoft code samples.
// 
//THIS CODE AND INFORMATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY
//KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
//IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//PARTICULAR PURPOSE.
//-----------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using Microsoft.SqlServer.Management.Smo;

namespace RulesControls
{
    // Abstract control supporting the interactive construction of "Rules"
    // components. The type P is the parent context for the control, e.g.,
    // "TableViewBase" for a "SimpleLeafConditionControl".
    public abstract class RulesUserControl<P> : UserControl
        where P : SqlSmoObject
    {
        // Gets or sets the parent context for the control.
        public P ParentContext
        {
            get { return this.parentContext; }
            set 
            { 
                this.parentContext = value;
                this.UpdateParentContext();
            }
        }

        // Handler for SMO object selection events.
        public void HandleParentContextChange(
            object sender, SmoEventArgs<P> e)
        {
            this.ParentContext = e.ParentContext;
        }

        // Handles changes to the parent context.
        protected abstract void UpdateParentContext();

        protected P parentContext;
    }
}
