/// class PD.Web.UI.Controls.TreeViewContextMenuModule
/// using PD.Web.UI.Controls.TreeViewModule

PD.Web.UI.Controls.TreeViewContextMenuModule =
PD.Web.UI.Controls.TreeViewModule.extend({

    //===================================
    // PUBLIC METHODS
    //===================================

    start: function () {
        
        var contextMenu = new PD.Web.UI.Controls.ContextMenu({
            target: this.get_kendo().element,
            filter: "LI.k-item[role=treeitem]",
            segments: this._getSegments(),
            animation: false
        });

        this.get_tree().get_children().add(contextMenu);

    },

    //===================================
    // PRIVATE METHODS
    //===================================

    _getSegments: function () {

        var segments = this.getOption("contextMenu", []);
    
        if (!$.isArray(segments)) {
            segments = [segments];
        }

        segments = this._transformSegments(segments);

        return segments;

    },

    _transformSegments: function (segments) {

        var that = this,
            result = new PD.BCL.List(segments);

        result = result.transform(function (item) {
            var type = PD.Type.getType(item.type);
            return new type($.proxy(item.context, that.get_tree()));
        });

        return result.toArray();

    }

});