/**
 * Project      : AMDA-NG
 * Name         : PlotTreeNode.js
 * @class   amdaPlotObj.PlotTreeNode
 * @extends Ext.data.Model
 * @brief   Plot Tree Node Definition 
 * @author  Benjamin Renard
 * @version $Id: PlotTreeNode.js benjamin $
 ******************************************************************************
 *    FT Id     :   Date   : Name - Description
 ******************************************************************************
 *	:           :23/07/2015: BRE  - file creation
 */

Ext.define('amdaPlotObj.PlotTreeNode', {
	extend: 'Ext.data.Model', 	
	
	//Node type
	type: '',
	
	//Node text
	text: '',
	
	//Node icon class
	iconCls: '',
	
	//Node leaf
	leaf: false,
	
	//Node expanded
	expanded : true,
	
	//Node can be removed by user
	removable : false,
	
	//Link to the object associated to this node 
	object: null,
	
	//Additional information about a node to show in the tree view
	getAdditionalText : null,
	
	getNodeStateKey : null,
	
	getNodeState : function()
	{
		if (!this.getNodeStateKey || !this.object)
			return;
		return this.object.get(this.getNodeStateKey());
	},
	
	setNodeState : function(state)
	{
		if (!this.getNodeStateKey || !this.object)
			return;
		this.object.set(this.getNodeStateKey(), state);
	},
	
	constructor : function(config)
    {
		this.callParent(arguments);
		this.set('text',this.text);
		this.set('iconCls',this.iconCls);
		this.set('leaf',this.leaf);
		this.set('type',this.type);
		this.set('removable',this.removable);
		if (config && config.object) {
			this.object = config.object;
			this.set('qtip', config.object.get('info'));
		}
		if (this.getNodeState() != 2)
			this.set('expanded',(this.getNodeState() == 1));
		else {
			this.set('expanded',this.expanded);
			this.setNodeState(this.expanded ? 1 : 0);
		}
		
    }	
}, function () {
    Ext.data.NodeInterface.decorate(this);
});

Ext.define('amdaPlotObj.PlotPageTreeNode', {
	extend: 'amdaPlotObj.PlotTreeNode',
	
	iconCls: 'icon-plot-page',
	
	text: 'Page',
	
	type: 'page',
	
	getNodeStateKey: function()
	{
		return 'page-node-state';
	},
	
	getAdditionalText: function()
	{
		return ' ('+this.object.getPageShortInfo()+')';
	}
});

Ext.define('amdaPlotObj.PlotLayoutTreeNode', {
	extend: 'amdaPlotObj.PlotTreeNode',
	
	leaf: true,
	
	iconCls: 'icon-plot-layout',
	
	text: 'Layout',
	
	type: 'layout',
	
	getAdditionalText: function()
	{
		return ' ('+this.object.getLayoutShortInfo()+')';
	}
});

Ext.define('amdaPlotObj.PlotPanelsTreeNode', {
	extend: 'amdaPlotObj.PlotTreeNode',
	
	iconCls: 'icon-plot-panels',
	
	text: 'Panels list',
	
	type: 'panels',
	
	getNodeStateKey: function()
	{
		return 'panels-node-state';
	}
});

Ext.define('amdaPlotObj.PlotPanelTreeNode', {
	extend: 'amdaPlotObj.PlotTreeNode',
	
	iconCls: 'icon-plot-panel',
	
	text: 'Panel',
	
	type: 'panel',
	
	removable: true,
	
	getNodeStateKey: function()
	{
		return 'panel-node-state';
	},
	
	getAdditionalText: function()
	{
		return ' ('+this.object.getPanelShortInfo()+')';
	}
});

Ext.define('amdaPlotObj.PlotAxesTreeNode', {
	extend: 'amdaPlotObj.PlotTreeNode',
	
	expanded: false,
	
	iconCls: 'icon-plot-axes',
	
	text: 'Axes',
	
	type: 'axes',
	
	getNodeStateKey: function()
	{
		return 'axes-node-state';
	}
});

Ext.define('amdaPlotObj.PlotTimeAxisTreeNode', {
	extend: 'amdaPlotObj.PlotTreeNode',
	
	leaf: true,
	
	iconCls: 'icon-plot-axis-t',
	
	text: 'Time Axis',
	
	type: 'time-axis'
});

Ext.define('amdaPlotObj.PlotEpochAxisTreeNode', {
	extend: 'amdaPlotObj.PlotTreeNode',
	
	leaf: true,
	
	iconCls: 'icon-plot-axis-e',
	
	text: 'Epoch Axis',
	
	type: 'epoch-axis'
});

Ext.define('amdaPlotObj.PlotXAxisTreeNode', {
	extend: 'amdaPlotObj.PlotTreeNode',
	
	leaf: true,
	
	iconCls: 'icon-plot-axis-x',
	
	text: 'X Axis',
	
	type: 'x-axis'
});

Ext.define('amdaPlotObj.PlotYLeftAxisTreeNode', {
	extend: 'amdaPlotObj.PlotTreeNode',
	
	leaf: true,
	
	iconCls: 'icon-plot-axis-y-left',
	
	text: 'Y Left Axis',
	
	type: 'y-left-axis'
});

Ext.define('amdaPlotObj.PlotYRightAxisTreeNode', {
	extend: 'amdaPlotObj.PlotTreeNode',
	
	leaf: true,
	
	iconCls: 'icon-plot-axis-y-right',
	
	text: 'Y Right Axis',
	
	type: 'y-right-axis'
});

Ext.define('amdaPlotObj.PlotColorAxisTreeNode', {
	extend: 'amdaPlotObj.PlotTreeNode',
	
	leaf: true,
	
	iconCls: 'icon-plot-axis-color',
	
	text: 'Color Axis',
	
	type: 'color-axis'
});

Ext.define('amdaPlotObj.PlotParamsTreeNode', {
	extend: 'amdaPlotObj.PlotTreeNode',
	
	iconCls: 'icon-plot-params',
	
	text: 'Params',
	
	type: 'params',
	
	getNodeStateKey: function()
	{
		return 'params-node-state';
	}
});

Ext.define('amdaPlotObj.PlotParamTreeNode', {
	extend: 'amdaPlotObj.PlotTreeNode',
	
	leaf: true,
	
	//iconCls: 'icon-plot-params',
	
	text: '',
	
	type: 'param',
	
	removable: true,

	panelObject: null,
	
	getAdditionalText: function()
	{
		var parentNode = this.parentNode;
		var plotType = parentNode.object.get('panel-plot-type');
		return this.object.getShortInfo(plotType);
	}
});

Ext.define('amdaPlotObj.PlotAdditionalObjectsTreeNode', {
	extend: 'amdaPlotObj.PlotTreeNode',
	
	expanded: false,
	
	iconCls: 'icon-plot-add-objs',
	
	text: 'Additional Objects',
	
	type: 'objects',
	
	getNodeStateKey: function()
	{
		return 'add-objects-node-state';
	}
});

Ext.define('amdaPlotObj.PlotLegendsTreeNode', {
	extend: 'amdaPlotObj.PlotTreeNode',
	
	iconCls: 'icon-plot-add-legends',
	
	text: 'Legends',
	
	type: 'legends',
	
	getNodeStateKey: function()
	{
		return 'legends-node-state';
	}
});

Ext.define('amdaPlotObj.PlotSeriesLegendTreeNode', {
	extend: 'amdaPlotObj.PlotTreeNode',
	
	leaf: true,
	
	iconCls: 'icon-plot-add-legend-series',
	
	text: 'Series Legend',
	
	type: 'series-legend',
	
	getAdditionalText: function()
	{
		if (this.object.get('panel-legend-series'))
			return ' ('+this.object.get('panel-legend-series').getShortInfo()+')';
		return '';
	}
});

Ext.define('amdaPlotObj.PlotTextLegendsTreeNode', {
	extend: 'amdaPlotObj.PlotTreeNode',
	
	iconCls: 'icon-plot-add-legends-text',
	
	text: 'Text Legends',
	
	type: 'text-legends',
	
	getNodeStateKey: function()
	{
		return 'text-legends-node-state';
	}
});

Ext.define('amdaPlotObj.PlotTextLegendTreeNode', {
	extend: 'amdaPlotObj.PlotTreeNode',
	
	leaf: true,
	
	iconCls: 'icon-plot-add-legend-text',
	
	text: 'Text Legend',
	
	type: 'text-legend',
	
	removable: true,
	
	getAdditionalText: function()
	{
		return ' ('+this.object.getShortInfo()+')';
	}
});

Ext.define('amdaPlotObj.PlotDrawingObjectsTreeNode', {
	extend: 'amdaPlotObj.PlotTreeNode',
	
	iconCls: 'icon-plot-add-drawing-objs',
	
	text: 'Drawing objects',
	
	type: 'drawing-objects',
	
	getNodeStateKey: function()
	{
		return 'drawing-objects-node-state';
	}
});

Ext.define('amdaPlotObj.PlotConstantTreeNode', {
	extend: 'amdaPlotObj.PlotTreeNode',
	
	leaf: true,
	
	iconCls: 'icon-plot-add-drawing-constant',
	
	text: 'Constant',
	
	type: 'constant',
	
	removable: true,
	
	getAdditionalText: function()
	{
		return ' ('+this.object.getShortInfo()+')';
	}
});

Ext.define('amdaPlotObj.PlotTextTreeNode', {
	extend: 'amdaPlotObj.PlotTreeNode',
	
	leaf: true,
	
	iconCls: 'icon-plot-add-drawing-text',
	
	text: 'Text',
	
	type: 'text-obj',
	
	removable: true
});

Ext.define('amdaPlotObj.PlotCurveTreeNode', {
	extend: 'amdaPlotObj.PlotTreeNode',
	
	leaf: true,
	
	iconCls: 'icon-plot-add-drawing-curve',
	
	text: 'Curve',
	
	type: 'curve',
	
	removable: true
});

Ext.define('amdaPlotObj.PlotFillsTreeNode', {
	extend: 'amdaPlotObj.PlotTreeNode',
	
	iconCls: 'icon-plot-add-fills',
	
	text: 'Fills',
	
	type: 'fills',
	
	getNodeStateKey: function()
	{
		return 'fills-node-state';
	}
});

Ext.define('amdaPlotObj.PlotFillTreeNode', {
	extend: 'amdaPlotObj.PlotTreeNode',
	
	leaf: true,
	
	iconCls: 'icon-plot-add-fill',
	
	text: 'Fill',
	
	type: 'fill',
		
	removable: true,
	
	getAdditionalText: function()
	{
		return ' ('+this.object.getShortInfo()+')';
	}
});