Imports Stax.ComponentModel

Namespace ComponentModel
    <AttributeUsage(AttributeTargets.Property)> _
    Public Class ListEditorPropertiesAttribute
        Inherits Attribute

        Public Sub New(ByVal itemType As Type, ByVal title As String)
            Me.ItemType = itemType
            Me.Title = title
        End Sub

        Private ItemTypeValue As Type

        Public Property ItemType() As Type
            Get
                Return ItemTypeValue
            End Get
            Set(ByVal Value As Type)
                ItemTypeValue = Value
            End Set
        End Property

        Private TitleValue As String

        Public Property Title() As String
            Get
                Return TitleValue
            End Get
            Set(ByVal Value As String)
                TitleValue = Value
            End Set
        End Property
    End Class

    <AttributeUsage(AttributeTargets.Class)> _
    Public Class ListItemEditorAttribute
        Inherits Attribute

        Public Sub New(ByVal editorType As Type)
            Me.EditorType = editorType
        End Sub

        Private EditorTypeValue As Type

        Public Property EditorType() As Type
            Get
                Return EditorTypeValue
            End Get
            Set(ByVal Value As Type)
                EditorTypeValue = Value
            End Set
        End Property
    End Class

    Public Interface IEditor
        Sub SetSelectedObjects(ByVal objects As Object())
        Event ValueChanged()
    End Interface

    Public Interface IEditorControl
        Event ValueChanged()
        Property Value() As Object
    End Interface

    <AttributeUsage(AttributeTargets.Property)> _
    Public Class DefaultValuesAttribute
        Inherits Attribute

        Public DefaultValues As String

        Public Sub New(ByVal defaultValues As String)
            Me.DefaultValues = defaultValues
        End Sub
    End Class

    Public Class PropertyCheckBox
        Inherits CheckBox
        Implements IEditorControl

        Private Block As Boolean

        Public Event ValueChanged() Implements IEditorControl.ValueChanged

        Private Sub PropertyCheckBox_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.CheckedChanged
            If Not Block Then
                RaiseEvent ValueChanged()
            End If
        End Sub

        Public Property Value() As Object Implements IEditorControl.Value
            Get
                Return Checked
            End Get
            Set(ByVal Value As Object)
                Block = True
                Checked = DirectCast(Value, Boolean)
                Block = False
            End Set
        End Property
    End Class
End Namespace