/// class ProspectDirector.Web.UI.FeatureSets.EditorDefinition

/**
[NEEDS DOCUMENTATION]
@class EditorDefinition
@namespace Web.UI.FeatureSets
@constructor
**/
ProspectDirector.Web.UI.FeatureSets.EditorDefinition = Class.extend({

    //==============================
    // FIELDS
    //==============================

    _options: null,
    _name: null,
    _featureName: null,

    //==============================
    // CONSTRUCTOR
    //==============================

    init: function (options) {
        this._options = options;
        this._setName();
        this._setFeatureName();
    },

    //==============================
    // PROPERTIES
    //==============================

    /**
    @public
    @property get_data
    @type {Object}
    **/
    get_data: function () {
        return this.get_options().data;
    },

    /**
    @public
    @property get_options
    @type {Object}
    **/
    get_options: function () {
        return this._options;
    },

    /**
    @public
    @property get_script
    @type {String}
    **/
    get_script: function () {
        return this.get_data().script;
    },

    /**
    @public
    @property get_type
    @type {String}
    **/
    get_type: function () {
        return this.get_data().type;
    },

    /**
    @public
    @property get_eventBus
    @type {Web.UI.EventBus}
    **/
    get_eventBus: function () {
        return this.get_options().eventBus;
    },

    /**
    @public
    @property get_feature
    @type {Web.UI.FeatureSets.Feature}
    **/
    get_feature: function () {
        return this.get_options().feature;
    },

    /**
    @public
    @property get_featureName
    @type {String}
    **/
    get_featureName: function () {
        return this._featureName;
    },

    /**
    @public
    @property get_name
    @type {String}
    **/
    get_name: function () {
        return this._name;
    },

    /**
    @public
    @property get_groupId
    @type {String}
    **/
    get_groupId: function () {
        return this.get_options().groupId;
    },

    /**
    @public
    @property get_initializer
    @type {Object}
    **/
    get_initializer: function () {
        return this.get_options().initializer;
    },

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

    /**
    Creates and returns an instance of an {{#crossLink "Web.UI.FeatureSets.EditorBase"}}Editor{{/crossLink}} configured as per this editor definition.
    @public
    @method activate
    @return {Web.UI.FeatureSets.EditorBase}
    **/
    activate: function () {

        var result = null,
            instance = ProspectDirector.RUNTIME.type(this.get_script());

        if (instance) {

            result = new instance({
                data: this.get_feature(),
                init: this.get_initializer(),
                definition: this,
                eventBus: this.get_eventBus(),
                additonalData: null
            });

        }

        return result;

    },

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

    _setName: function () {
        this._name = this.get_data().name ? this.get_data().name : null;
    },

    _setFeatureName: function () {

        var index = this.get_type().lastIndexOf(".") + 1,
            name = this.get_type().substr(index);

        this._featureName = name.substr(0, 1).toLowerCase() + name.substr(1);

    }

});