<commit_before>/*
 * Copyright (c) 2008-2012 The Open Source Geospatial Foundation
 *
 * Published under the BSD license.
 * See https://github.com/geoext/geoext2/blob/master/license.txt for the full text
 * of the license.
 */

/*
 * @include GeoExt/tree/LayerNode.js
 */

/**
 * A loader that will load layers from a GeoExt.data.LayerStore.
 * By default, only layers that have displayInLayerSwitcher set to true will be
 * included. The childrens' iconCls defaults to "gx-tree-layer-icon".
 */
Ext.define('GeoExt.tree.LayerLoader', {
    extend: 'Ext.util.Observable',
    requires: [
        'GeoExt.tree.LayerNode'
    ],

    /**
     * Triggered before loading children. Return false to avoid
     * loading children.
     * @event beforeload
     * @param {GeoExt.tree.LayerLoader} this loader
     * @param {Ext.data.NodeInterface} the node that this loader is configured
     *     with
     */

    /**
     * Triggered after children were loaded.
     * @event load
     * @param {GeoExt.tree.LayerLoader} this loader
     * @param {Ext.data.NodeInterface} the node that this loader is configured
     *     with
     */

    /**
     * @cfg {GeoExt.data.LayerStore} store
     * The layer store containing layers to be added by this loader.
     */
    /**
     * @property {GeoExt.data.LayerStore} store
     * The layer store containing layers to be added by this loader.
     */
     store: null,
    
    /**
     * @property {Function} filter
     * A function, called in the scope of this loader, with a layer record
     * as argument. Is expected to return true for layers to be loaded, false
     * otherwise. By default, the filter checks for displayInLayerSwitcher:
     *  
     * @example
     * filter: function(record) {
     *     return record.getLayer().displayInLayerSwitcher === true
     * }
     */
    filter: function(record) {
        return record.getLayer().displayInLayerSwitcher === true;
    },
    
    /**
     * @cfg
     * An object containing attributes to be added to all nodes created by
     * this loader.
     */
    baseAttrs: null,
    
    /**
     * @param {GeoExt.data.LayerTreeModel} node The node to add children to.
     * @private
     */
    load: function(node) {
        if (this.fireEvent("beforeload", this, node)) {
            this.removeStoreHandlers();
            while (node.firstChild) {
                node.removeChild(node.firstChild);
            }
            
            if (!this.store) {
                this.store = GeoExt.MapPanel.guess().layers;
            }
            this.store.each(function(record) {
                this.addLayerNode(node, record);
            }, this);
            this.addStoreHandlers(node);
    
            this.fireEvent("load", this, node);
        }
    },
    
    /**
     * Listener for the store's add event.
     *
     * @param {Ext.data.Store} store
     * @param {Ext.data.Record[]} records
     * @param {Number} index
     * @param {GeoExt.data.LayerTreeModel} node
     *  
     * @private
     */
    onStoreAdd: function(store, records, index, node) {
        if (!this._reordering) {
            var nodeIndex = node.get('container')
                .recordIndexToNodeIndex(index+records.length-1, node);
            for (var i=0, ii=records.length; i<ii; ++i) {
                this.addLayerNode(node, records[i], nodeIndex);
            }
        }
    },
    
    /**
     * Listener for the store's remove event.
     *
     * @param {Ext.data.Store} store
     * @param {Ext.data.Record} record
     * @param {Integer} index
     * @param {GeoExt.data.LayerTreeModel} node
     *
     * @private
     */
    onStoreRemove: function(layerRecord, node) {
        if (!this._reordering) {
            this.removeLayerNode(node, layerRecord);
        }
    },

    /**
     * Adds a child node representing a layer of the map
     *
     * @param {GeoExt.data.LayerTreeModel} node The node that the layer node
     *     will be added to as child.
     * @param {GeoExt.data.LayerModel} layerRecord The layer record containing
     *     the layer to be added.
     * @param {Integer} index Optional index for the new layer.  Default is 0.
     *
     * @private
     */
    addLayerNode: function(node, layerRecord, index) {
        index = index || 0;
        if (this.filter(layerRecord) === true) {
            var layer = layerRecord.getLayer();
            var child = this.createNode({
                plugins: [{
                    ptype: 'gx_layer'
                }],
                layer: layer,
                text: layer.name,
                listeners: {
                    move: this.onChildMove,
                    scope: this
                }
            });
            if (index !== undefined) {
                node.insertChild(index, child);
            } else {
                node.appendChild(child);
            }
            node.getChildAt(index).on("move", this.onChildMove, this);
        }
    },

    /**
     * Removes a child node representing a layer of the map
     * @param {GeoExt.data.LayerTreeModel} node The node that the layer node
     *     will be removed from as child.
     * @param {GeoExt.data.LayerModel} layerRecord The layer record containing
     *     the layer to be removed.
     *
     * @private
     */
    removeLayerNode: function(node, layerRecord) {
        if (this.filter(layerRecord) === true) {
            var child = node.findChildBy(function(node) {
                return node.get('layer') == layerRecord.getLayer();
            });
            if (child) {
                child.un("move", this.onChildMove, this);
                child.remove();
            }
        }
    },
    
    /**
     * Listener for child node "move" events.  This updates the order of
     * records in the store based on new node order if the node has not
     * changed parents.
     *
     * @param {GeoExt.data.LayerTreeModel} node
     * @param {GeoExt.data.LayerTreeModel} oldParent
     * @param {GeoExt.data.LayerTreeModel} newParent
     * @param {Integer} index
     *
     * @private
     */
    onChildMove: function(node, oldParent, newParent, index) {
        var me = this,
            record = me.store.getByLayer(node.get('layer')),<commit_msg>More api doc improvements.<commit_after>/*
 * Copyright (c) 2008-2012 The Open Source Geospatial Foundation
 *
 * Published under the BSD license.
 * See https://github.com/geoext/geoext2/blob/master/license.txt for the full text
 * of the license.
 */

/*
 * @include GeoExt/tree/LayerNode.js
 */

/**
 * A loader that will load layers from a GeoExt.data.LayerStore.
 * By default, only layers that have displayInLayerSwitcher set to true will be
 * included. The childrens' iconCls defaults to "gx-tree-layer-icon".
 */
Ext.define('GeoExt.tree.LayerLoader', {
    extend: 'Ext.util.Observable',
    requires: [
        'GeoExt.tree.LayerNode'
    ],

    /**
     * Triggered before loading children. Return false to avoid
     * loading children.
     * @event beforeload
     * @param {GeoExt.tree.LayerLoader} this This loader.
     * @param {Ext.data.NodeInterface} node The node that this loader is
     * configured with.
     */

    /**
     * Triggered after children were loaded.
     * @event load
     * @param {GeoExt.tree.LayerLoader} loader This loader.
     * @param {Ext.data.NodeInterface} node The node that this loader is
     * configured with.
     */

    /**
     * @cfg {GeoExt.data.LayerStore} store
     * The layer store containing layers to be added by this loader.
     */
    /**
     * @property {GeoExt.data.LayerStore} store
     * The layer store containing layers to be added by this loader.
     */
     store: null,
    
    /**
     * @property {Function} filter
     * A function, called in the scope of this loader, with a layer record
     * as argument. Is expected to return true for layers to be loaded, false
     * otherwise. By default, the filter checks for displayInLayerSwitcher:
     *  
     *     filter: function(record) {
     *         return record.getLayer().displayInLayerSwitcher === true
     *     }
     */
    filter: function(record) {
        return record.getLayer().displayInLayerSwitcher === true;
    },
    
    /**
     * @cfg
     * An object containing attributes to be added to all nodes created by
     * this loader.
     */
    baseAttrs: null,
    
    /**
     * @param {GeoExt.data.LayerTreeModel} node The node to add children to.
     * @private
     */
    load: function(node) {
        if (this.fireEvent("beforeload", this, node)) {
            this.removeStoreHandlers();
            while (node.firstChild) {
                node.removeChild(node.firstChild);
            }
            
            if (!this.store) {
                this.store = GeoExt.MapPanel.guess().layers;
            }
            this.store.each(function(record) {
                this.addLayerNode(node, record);
            }, this);
            this.addStoreHandlers(node);
    
            this.fireEvent("load", this, node);
        }
    },
    
    /**
     * Listener for the store's add event.
     *
     * @param {Ext.data.Store} store
     * @param {Ext.data.Record[]} records
     * @param {Number} index
     * @param {GeoExt.data.LayerTreeModel} node
     *  
     * @private
     */
    onStoreAdd: function(store, records, index, node) {
        if (!this._reordering) {
            var nodeIndex = node.get('container')
                .recordIndexToNodeIndex(index+records.length-1, node);
            for (var i=0, ii=records.length; i<ii; ++i) {
                this.addLayerNode(node, records[i], nodeIndex);
            }
        }
    },
    
    /**
     * Listener for the store's remove event.
     *
     * @param {Ext.data.Store} store
     * @param {Ext.data.Record} record
     * @param {Integer} index
     * @param {GeoExt.data.LayerTreeModel} node
     *
     * @private
     */
    onStoreRemove: function(layerRecord, node) {
        if (!this._reordering) {
            this.removeLayerNode(node, layerRecord);
        }
    },

    /**
     * Adds a child node representing a layer of the map
     *
     * @param {GeoExt.data.LayerTreeModel} node The node that the layer node
     * will be added to as child.
     * @param {GeoExt.data.LayerModel} layerRecord The layer record containing
     * the layer to be added.
     * @param {Integer} index Optional index for the new layer.  Default is 0.
     *
     * @private
     */
    addLayerNode: function(node, layerRecord, index) {
        index = index || 0;
        if (this.filter(layerRecord) === true) {
            var layer = layerRecord.getLayer();
            var child = this.createNode({
                plugins: [{
                    ptype: 'gx_layer'
                }],
                layer: layer,
                text: layer.name,
                listeners: {
                    move: this.onChildMove,
                    scope: this
                }
            });
            if (index !== undefined) {
                node.insertChild(index, child);
            } else {
                node.appendChild(child);
            }
            node.getChildAt(index).on("move", this.onChildMove, this);
        }
    },

    /**
     * Removes a child node representing a layer of the map
     * @param {GeoExt.data.LayerTreeModel} node The node that the layer node
     * will be removed from as child.
     * @param {GeoExt.data.LayerModel} layerRecord The layer record containing
     * the layer to be removed.
     *
     * @private
     */
    removeLayerNode: function(node, layerRecord) {
        if (this.filter(layerRecord) === true) {
            var child = node.findChildBy(function(node) {
                return node.get('layer') == layerRecord.getLayer();
            });
            if (child) {
                child.un("move", this.onChildMove, this);
                child.remove();
            }
        }
    },
    
    /**
     * Listener for child node "move" events.  This updates the order of
     * records in the store based on new node order if the node has not
     * changed parents.
     *
     * @param {GeoExt.data.LayerTreeModel} node
     * @param {GeoExt.data.LayerTreeModel} oldParent
     * @param {GeoExt.data.LayerTreeModel} newParent
     * @param {Integer} index
     *
     * @private
     */
    onChildMove: function(node, oldParent, newParent, index) {
        var me = this,
            record = me.store.getByLayer(node.get('layer')),
{'fraction_non_alphanumeric': 0.11102230037566942, 'fraction_numerical': 0.0020781712093357846, 'mean_word_length': 1.8527131782945736, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '793592', 'n_tokens_mistral': 3631, 'n_tokens_neox': 3558, 'n_words': 989}