
Namespace Primitives

    ''' <summary>
    ''' Represents a single column of data on a table.
    ''' </summary>
    ''' <remarks></remarks>
    Public Class Column

        ' Variables
        Private _name As String
        Private _caption As String
        Private _table As ObjectTable

        ''' <summary>
        ''' Initializes a new instance of the <see cref="Mercury.Mobile.Forms.Primitives.Column"/> 
        ''' class with the specified column name.
        ''' </summary>
        ''' <param name="name">The name of the column.</param>
        ''' <remarks></remarks>
        Public Sub New(ByVal name As String)
            If String.IsNullOrEmpty(name) Then _
                Throw New ArgumentNullException("name", "Cannot assign an empty value as column name.")
            Me._name = name
            Me._caption = String.Empty
            Me._table = Nothing
        End Sub

        ''' <summary>
        ''' Gets or sets the name of this column.
        ''' </summary>
        ''' <returns>The name of this column.</returns>
        ''' <remarks></remarks>
        Public Property Name() As String
            Get
                Return Me._name
            End Get
            Set(ByVal value As String)
                If String.IsNullOrEmpty(Name) Then _
                    Throw New ArgumentNullException("name", "Cannot assign an empty value as column name.")
                Me._name = value
            End Set
        End Property

        ''' <summary>
        ''' Gets or sets the caption text for this column.  By default, this is the column name.
        ''' </summary>
        ''' <returns>The caption text for this column.</returns>
        Public Property Caption() As String
            Get
                If String.IsNullOrEmpty(Me._caption) Then _
                    Return Me._name
                Return Me._caption
            End Get
            Set(ByVal value As String)
                Me._caption = value
            End Set
        End Property

        ''' <summary>
        ''' Gets the ordinal position of this column in the table.
        ''' </summary>
        ''' <returns>The ordinal position of this column in the table or -1 
        ''' if the column has not been added to a table.</returns>
        ''' <remarks></remarks>
        Public ReadOnly Property Ordinal() As Integer
            Get
                If Me.Table IsNot Nothing Then _
                    Return Me.Table.Columns.IndexOf(Me)
                Return -1
            End Get
        End Property

        ''' <summary>
        ''' Gets the table associated with this column.
        ''' </summary>
        ''' <returns>The table associated with this column.</returns>
        ''' <remarks></remarks>
        Public ReadOnly Property Table() As ObjectTable
            Get
                Return Me._table
            End Get
        End Property

        ''' <summary>
        ''' Sets the table associated with this column.
        ''' </summary>
        ''' <param name="table">The table to associated with this column.</param>
        ''' <remarks></remarks>
        Friend Sub SetTable(ByVal table As ObjectTable)
            Me._table = table
        End Sub

    End Class

End Namespace