PlotTree.js 1.99 KB
/**
 * Project   : AMDA-NG
 * Name      : PlotTree.js
 * @class   amdaPlotComp.PlotTree
 * @extends Ext.tree.Panel
 * @brief   Tree to define all elements of a plot
 * @author  Benjamin Renard
 * @version $Id: PlotTree.js benjamin $
 */

Ext.define('amdaPlotComp.PlotTree', {
	extend: 'Ext.tree.Panel',
	
	requires: [
	           'amdaPlotObj.PlotTreeNode'
	],
	
	//Link to the Plot Element Panel
    plotElementPanel: null,
	
	//Tab object
	object: null,
	
	constructor: function(config) {
		this.init(config);	    
		this.callParent(arguments);
	},
	
	buildTree: function(tabObject) {
		this.object = tabObject;
		
		//Page Node
		var pageNode = this.store.getRootNode().appendChild(new amdaPlotObj.PlotPageTreeNode({object : tabObject}));
		
		//Layout node
		pageNode.appendChild(new amdaPlotObj.PlotLayoutTreeNode());
		
		//Panels node
		var panelsNode = pageNode.appendChild(new amdaPlotObj.PlotPanelsTreeNode());
		
		//Panel for test
		var panelNode = panelsNode.appendChild(new amdaPlotObj.PlotPanelTreeNode());
		var axisNode = panelNode.appendChild(new amdaPlotObj.PlotAxisTreeNode());
		axisNode.appendChild(new amdaPlotObj.PlotTimeAxisTreeNode());
		panelNode.appendChild(new amdaPlotObj.PlotLegendsTreeNode());
	},
	
	onNodeSelect: function(tree,record, index, eOpts) {
		if (this.plotElementPanel != null)
			this.plotElementPanel.setElement(record.type, record.object);
	},
	
	getSelectedNode: function() {
		var selection = this.getSelectionModel().getSelection();
		if ((selection == null) || (selection.length == 0))
			return null;
		return selection[0];
	},
	
	init : function(config) {
		var me = this;
		
		this.plotElementPanel = config.plotElementPanel;
		
		var store = Ext.create('Ext.data.TreeStore', {
			root: {
				expanded: true
		    }
		});
		
		this.plotElementPanel = config.plotElementPanel;
		
		var myConf = {
				store: store,
				rootVisible: false,
				listeners: {
			        select: me.onNodeSelect,
			        scope: me
			    }
		};
		
		Ext.apply (this , Ext.apply (arguments, myConf));
	}
});