' Developer Express Code Central Example:
' How to show filter dialog before showing ListView
' 
' When the ListView contains a large amount of data, it is useful to provide a
' capability for the end-user to set a filter for this View before loading it. To
' accomplish this task, I've performed the following actions in this example:
' 1.
' Extended the Application Model with the AdditionalCriteria attribute for the
' ListView node via the WinSampleModule.GetSchema overridden method. This
' attribute should store the filter, selected by the user.
' 2. Implemented the
' ViewFilterContainer class, whose DetailView is used as a filter dialog.
' 3.
' Implemented the ViewFilterObject class, which is used to store filters.
' 4.
' Implemented a ShowFilterDialogController, which shows the DetailView of the
' ViewFilterContainer object before showing ListView, and then shows the filtered
' ListView.
' 5. Implemented the ViewFilterContainerModificationsController, which
' sets the ObjectType property of the ViewFilterObject class, created by the
' lookup's New action.
' 
' See Also:
' How to: Use Criteria Property Editors
' (ms-help://DevExpress.Xaf/CustomDocument3014.htm)
' How to: Extend the
' Application Model and Schema
' (ms-help://DevExpress.Xaf/CustomDocument2785.htm)
' ShowNavigationItemController
' Class
' (ms-help://DevExpress.Xaf/clsDevExpressExpressAppSystemModuleShowNavigationItemControllertopic.htm)
' Dialog
' Controller
' (ms-help://DevExpress.Xaf/clsDevExpressExpressAppSystemModuleDialogControllertopic.htm)
' 
' You can find sample updates and versions for different programming languages here:
' http://www.devexpress.com/example=E1554

Imports Microsoft.VisualBasic
Imports DevExpress.ExpressApp.DC
Imports System
Imports DevExpress.ExpressApp
Imports DevExpress.ExpressApp.SystemModule
Imports DevExpress.ExpressApp.Actions
Imports DevExpress.ExpressApp.Editors
Imports DevExpress.Data.Filtering



Public Class ShowFilterDialogController
    Inherits WindowController
    Private dialogCotnroller As DialogController
    Public Sub New()
        TargetWindowType = WindowType.Main
    End Sub
    Protected Overrides Sub OnActivated()
        MyBase.OnActivated()
        AddHandler Frame.GetController(Of ShowNavigationItemController)().ShowNavigationItemAction.Execute, AddressOf ShowNavigationItemAction_Execute
    End Sub
    Private oldListView As View
    Private Sub ShowNavigationItemAction_Execute(ByVal sender As Object, ByVal e As SingleChoiceActionExecuteEventArgs)
        Dim showViewParameters As ShowViewParameters = e.ShowViewParameters
        If TypeOf showViewParameters.CreatedView Is ListView Then

            oldListView = showViewParameters.CreatedView
            If (CType(oldListView.Model, IModelListViewExtender)).RequireCriteriaBeforeView = True Then
                Dim objectSpace As IObjectSpace = Application.CreateObjectSpace()
                Dim newViewFilterContainer As ViewFilterContainer = objectSpace.CreateObject(Of ViewFilterContainer)()
                newViewFilterContainer.ObjectType = oldListView.ObjectTypeInfo.Type
                newViewFilterContainer.ViewID = oldListView.Id
                If (CType(oldListView.Model, IModelListViewExtender)).RequireCriteriaBeforeViewCriteria <> "" And (CType(oldListView.Model, IModelListViewExtender)).AdditionalCriteria = "" Then
                    newViewFilterContainer.Criteria = (CType(oldListView.Model, IModelListViewExtender)).RequireCriteriaBeforeViewCriteria
                Else
                    newViewFilterContainer.Criteria = (CType(oldListView.Model, IModelListViewExtender)).AdditionalCriteria
                End If

                showViewParameters.CreatedView = Application.CreateDetailView(objectSpace, newViewFilterContainer)
                showViewParameters.CreatedView.Caption = String.Format((CType(oldListView.Model, IModelListViewExtender)).RequireCriteriaBeforeViewCaption, oldListView.Caption)
                showViewParameters.TargetWindow = TargetWindow.Current

                dialogCotnroller = Application.CreateController(Of DialogController)()
                AddHandler dialogCotnroller.AcceptAction.Execute, AddressOf AcceptAction_Execute
                showViewParameters.Controllers.Add(dialogCotnroller)
            End If
        End If
    End Sub
    Private Sub AcceptAction_Execute(ByVal sender As Object, ByVal e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs)
        Try
        Dim currentViewFilterContainer As ViewFilterContainer = CType(e.CurrentObject, ViewFilterContainer)
        CType(oldListView, ListView).CollectionSource.BeginUpdateCriteria()
        CType(oldListView, ListView).CollectionSource.Criteria("ByViewFilterObject") = CriteriaEditorHelper.GetCriteriaOperator(currentViewFilterContainer.Criteria, currentViewFilterContainer.ObjectType, oldListView.ObjectSpace)
        CType(oldListView, ListView).CollectionSource.EndUpdateCriteria()

        CType(oldListView.Model, IModelListViewExtender).AdditionalCriteria = currentViewFilterContainer.Criteria


            e.ShowViewParameters.CreatedView = Application.CreateListView(oldListView.Id, CType(oldListView, ListView).CollectionSource, False)
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.OkOnly, "Hiba")
        End Try
    End Sub
End Class

