-KDView           = require './../../core/view.coffee'
-KDViewController = require './../../core/viewcontroller.coffee'
-KDScrollView     = require './../scrollview/scrollview.coffee'
-KDListView       = require './../list/listview.coffee'
-KDLoaderView     = require './../loader/loaderview.coffee'
+KDView             = require './../../core/view.coffee'
+KDViewController   = require './../../core/viewcontroller.coffee'
+KDCustomScrollView = require './../scrollview/customscrollview.coffee'
+KDListView         = require './../list/listview.coffee'
+KDLoaderView       = require './../loader/loaderview.coffee'
 
 module.exports = class KDListViewController extends KDViewController
 

    if options.keyNav
      listView.on 'KeyDownOnList', (event)=> @keyDownPerformed listView, event

  loadView:(mainView)->

    options = @getOptions()
    if options.scrollView
      mainView.addSubView @scrollView
      @scrollView.addSubView @getListView()
      if options.startWithLazyLoader
        @showLazyLoader no
      @scrollView.on 'LazyLoadThresholdReached', @bound "showLazyLoader"

    if options.noItemFoundWidget
      @putNoItemView()

    @instantiateListItems(@getData()?.items or [])
    KD.getSingleton("windowController").on "ReceivedMouseUpElsewhere", (event)=> @mouseUpHappened event

  instantiateListItems:(items)->
    newItems = for itemData in items

      @setListView listView = new KDListView viewOptions

    if options.scrollView
      @customScrollView = new KDCustomScrollView
        lazyLoadThreshold : options.lazyLoadThreshold
        ownScrollBars     : options.ownScrollBars
      @scrollView = @customScrollView.wrapper

    options.view = if options.wrapper
    then new KDView cssClass : "listview-wrapper"
