Imports DevExpress.XtraEditors
Imports DevExpress.XtraLayout
Imports DigitalData.Modules.Logging
Imports DigitalData.Modules.ZooFlow
Imports DigitalData.Modules.Database
Imports DigitalData.Controls.LookupGrid
Imports DevExpress.XtraGrid
Imports System.Windows.Forms
Imports DevExpress.XtraGrid.Views.Grid

Public Class PropertyControls
    Private _LogConfig As LogConfig
    Private _Logger As Logger
    Private _Db As MSSQLServer

    Public Sub New(LogConfig As LogConfig, Database As MSSQLServer)
        _LogConfig = LogConfig
        _Logger = LogConfig.GetLogger()
        _Db = Database
    End Sub

    Public Function GetControlForAttribute(pAttribute As Attribute, pIsReadOnly As Boolean) As Control
        Dim oControl As Control

        Select Case pAttribute.TypeName
            Case Attribute.TYPE_BIT
                Dim oCheckboxEdit As New CheckEdit With {
                    .Name = pAttribute.ID,
                    .Text = pAttribute.Title,
                    .[ReadOnly] = pIsReadOnly
                }
                oControl = oCheckboxEdit

            Case Attribute.TYPE_DATE
                Dim oDateEdit As New DateEdit With {
                    .Name = pAttribute.ID,
                    .[ReadOnly] = pIsReadOnly
                }
                oControl = oDateEdit

            Case Attribute.TYPE_BIG_INTEGER
                Dim oTextEdit As New TextEdit With {
                    .Name = pAttribute.ID,
                    .[ReadOnly] = pIsReadOnly
                }
                oControl = oTextEdit

            Case Attribute.TYPE_DECIMAL
                Dim oTextEdit As New TextEdit With {
                    .Name = pAttribute.ID,
                    .[ReadOnly] = pIsReadOnly
                }
                oControl = oTextEdit

            Case Attribute.TYPE_FLOAT
                Dim oTextEdit As New TextEdit With {
                    .Name = pAttribute.ID,
                    .[ReadOnly] = pIsReadOnly
                }
                oControl = oTextEdit

            Case Attribute.TYPE_VECTOR_STRING
                ' Minimum size is picked up by the LayoutControl to determine the grids size
                Dim oGrid As New GridControl With {
                    .Name = pAttribute.ID,
                    .MinimumSize = New System.Drawing.Size(0, 100)
                }

                oGrid.ForceInitialize()

                Dim oView = DirectCast(oGrid.DefaultView, GridView)
                oView.OptionsView.ShowGroupPanel = False
                oView.OptionsView.ShowColumnHeaders = False
                oView.OptionsView.ShowIndicator = False
                oView.OptionsBehavior.ReadOnly = True
                oView.OptionsBehavior.Editable = False
                oControl = oGrid

            Case Else
                Dim oTextEdit As New TextEdit With {
                    .Name = pAttribute.ID,
                    .[ReadOnly] = pIsReadOnly
                }
                oControl = oTextEdit

        End Select

        Return oControl
    End Function
End Class
