Imports DevExpress.ExpressApp.Model
Imports DevExpress.ExpressApp.Model.Core
Imports DevExpress.ExpressApp.Model.NodeGenerators

Public Class ModelListViewLinqColumnsNodesGeneratorUpdater
    Inherits ModelNodesGeneratorUpdater(Of ModelListViewColumnsNodesGenerator)
    Public Overrides Sub UpdateNode(ByVal node As ModelNode)
        Dim linqViewInfo As IModelListViewLinq = TryCast(node.Parent, IModelListViewLinq)
        If linqViewInfo IsNot Nothing AndAlso (Not String.IsNullOrEmpty(linqViewInfo.XPQueryMethod)) Then
            Dim listViewInfo As IModelListView = CType(linqViewInfo, IModelListView)
            Dim columns() As String = LinqCollectionSourceHelper.GetDisplayableProperties(listViewInfo.ModelClass.TypeInfo.Type, linqViewInfo.XPQueryMethod)
            If columns IsNot Nothing Then
                If listViewInfo.Columns Is Nothing Then
                    listViewInfo.AddNode(Of IModelColumns)("Columns")
                End If
                Dim i As Integer = listViewInfo.Columns.Count
                Do While i > 0
                    i -= 1
                    Dim col As IModelColumn = listViewInfo.Columns.Item(i)
                    If Array.IndexOf(columns, col.Id) < 0 Then
                        'listViewInfo.Columns.Remove(col)
                    End If
                Loop
                For Each column As String In columns
                    Dim col As IModelColumn = listViewInfo.Columns.GetNode(column)
                    If col Is Nothing Then
                        col = listViewInfo.Columns.AddNode(Of IModelColumn)(column)
                        col.PropertyName = column
                    End If
                Next column
            End If
        End If
    End Sub
End Class
