Blame view

js/app/views/PlotComponents/PlotTree.js 24.9 KB
437c4dbc   Benjamin Renard   First implementat...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/**
 * 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'
	],
	
27b2a53e   Benjamin Renard   Link tab plot to ...
18
19
20
21
	//Link to the combo box to define the use of the simplified view
	simplifiedViewCombo : null,
	
	//Link to the combo to attach the tab to the multi plot mode
17433635   Benjamin Renard   Add series and sp...
22
	
437c4dbc   Benjamin Renard   First implementat...
23
24
	//Link to the Plot Element Panel
    plotElementPanel: null,
27b2a53e   Benjamin Renard   Link tab plot to ...
25
26
27
    
    //Link to the Plot Tab Content Panel
    plotTabContent : null,
437c4dbc   Benjamin Renard   First implementat...
28
29
	
	//Tab object
abe09878   Benjamin Renard   Add panels and ax...
30
31
32
33
    tabObject: null,
	
	//Panels list node
	panelsNode: null,
437c4dbc   Benjamin Renard   First implementat...
34
35
36
37
38
39
	
	constructor: function(config) {
		this.init(config);	    
		this.callParent(arguments);
	},
	
437c4dbc   Benjamin Renard   First implementat...
40
	buildTree: function(tabObject) {
abe09878   Benjamin Renard   Add panels and ax...
41
42
43
44
		if (this.store.getRootNode().hasChildNodes())
			this.store.getRootNode().removeAll();
		
		this.tabObject = tabObject;
437c4dbc   Benjamin Renard   First implementat...
45
		
27b2a53e   Benjamin Renard   Link tab plot to ...
46
47
48
49
		this.simplifiedViewCombo.setValue(this.tabObject.get('tree-simplified-view'));
		this.linkToMultiPlotCombo.setValue(this.tabObject.get('multi-plot-linked'));
		
		if (!this.tabObject.get('tree-simplified-view'))
17433635   Benjamin Renard   Add series and sp...
50
51
52
		{
			//Page Node
			var pageNode = this.store.getRootNode().appendChild(new amdaPlotObj.PlotPageTreeNode({object : tabObject}));
437c4dbc   Benjamin Renard   First implementat...
53
		
17433635   Benjamin Renard   Add series and sp...
54
			//Layout node
003ba315   Benjamin Renard   Add Epoch Plot an...
55
			pageNode.appendChild(new amdaPlotObj.PlotLayoutTreeNode({object : tabObject}));
437c4dbc   Benjamin Renard   First implementat...
56
		
17433635   Benjamin Renard   Add series and sp...
57
58
59
60
61
62
63
64
65
66
67
68
			//Panels node
			this.panelsNode = pageNode.appendChild(new amdaPlotObj.PlotPanelsTreeNode());
		}
		else
			this.panelsNode = this.store.getRootNode();
		
		this.buildPanelsNode();
	},
	
	buildPanelsNode: function() {
		if (this.panelsNode.hasChildNodes())
			this.panelsNode.removeAll();
abe09878   Benjamin Renard   Add panels and ax...
69
70
71
		
		var me = this;
		this.tabObject.panels().each(function (panelObject) {
17433635   Benjamin Renard   Add series and sp...
72
			me.addPanelNode(panelObject);
abe09878   Benjamin Renard   Add panels and ax...
73
74
75
		});
	},
	
abe09878   Benjamin Renard   Add panels and ax...
76
77
78
79
80
81
82
83
84
85
86
	buildPanelAxesNode: function(panelObject) {
		var axesNode = null;
		
		this.panelsNode.eachChild(function (panelNode) {
			//Retrieve corresponding panel node
			if (panelNode.object == panelObject)
			{
				//Retrieve axes node
				axesNode = panelNode.findChild('type', 'axes');
				if (!axesNode)
					//create axes node
17433635   Benjamin Renard   Add series and sp...
87
					axesNode = panelNode.appendChild(new amdaPlotObj.PlotAxesTreeNode({object : panelObject}));
abe09878   Benjamin Renard   Add panels and ax...
88
89
90
				return;
			}
		});
437c4dbc   Benjamin Renard   First implementat...
91
		
abe09878   Benjamin Renard   Add panels and ax...
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
		if (axesNode == null)
			return;
		
		//Remove old axis nodes
		axesNode.removeAll();
		
		//Add axis nodes
		panelObject.axes().each(function (axisObject) {
			switch (axisObject.get('axis-type'))
			{
			case 'time' :
				axesNode.appendChild(new amdaPlotObj.PlotTimeAxisTreeNode({object : axisObject}));
				break;
			case 'epoch' :
				axesNode.appendChild(new amdaPlotObj.PlotEpochAxisTreeNode({object : axisObject}));
				break;
			case 'x' :
				axesNode.appendChild(new amdaPlotObj.PlotXAxisTreeNode({object : axisObject}));
				break;
			case 'y-left' :
				axesNode.appendChild(new amdaPlotObj.PlotYLeftAxisTreeNode({object : axisObject}));
				break;
			case 'y-right' :
				axesNode.appendChild(new amdaPlotObj.PlotYRightAxisTreeNode({object : axisObject}));
				break;
			case 'color' :
				axesNode.appendChild(new amdaPlotObj.PlotColorAxisTreeNode({object : axisObject}));
				break;
			}
		});
		this.getView().refresh();
437c4dbc   Benjamin Renard   First implementat...
123
124
	},
	
003ba315   Benjamin Renard   Add Epoch Plot an...
125
126
127
	buildPanelParamsNode: function(panelObject, selectedParamId) {
		selectedParamId = (typeof selectedParamId !== 'undefined') ? selectedParamId : '';
		
17433635   Benjamin Renard   Add series and sp...
128
129
130
131
132
133
134
		var paramsNode = null;
		
		var me = this;
		this.panelsNode.eachChild(function (panelNode) {
			//Retrieve corresponding panel node
			if (panelNode.object == panelObject)
			{
27b2a53e   Benjamin Renard   Link tab plot to ...
135
				if (!me.tabObject.get('tree-simplified-view'))
17433635   Benjamin Renard   Add series and sp...
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
				{
					//Retrieve params node
					paramsNode = panelNode.findChild('type', 'params');
					if (!paramsNode)
						//create axes node
						paramsNode = panelNode.appendChild(new amdaPlotObj.PlotParamsTreeNode({object : panelObject}));
				}
				else
					paramsNode = panelNode;
				return;
			}
		});
		
		if (paramsNode == null)
			return;
		
		//Remove old param nodes
		paramsNode.removeAll();
		
		//Add param nodes
a0bf9157   Benjamin Renard   Add tick plot and...
156
		var selectedParamNode = null;
17433635   Benjamin Renard   Add series and sp...
157
		panelObject.params().each(function (paramObject) {
a0bf9157   Benjamin Renard   Add tick plot and...
158
159
160
			var paramNode = paramsNode.appendChild(new amdaPlotObj.PlotParamTreeNode({object : paramObject}));
			if (paramObject.get('id') == selectedParamId)
				selectedParamNode = paramNode;
17433635   Benjamin Renard   Add series and sp...
161
162
		});
		this.getView().refresh();
a0bf9157   Benjamin Renard   Add tick plot and...
163
164
165
		
		if (selectedParamNode)
			this.getSelectionModel().select(selectedParamNode);
17433635   Benjamin Renard   Add series and sp...
166
167
	},
	
fd5552a4   Benjamin Renard   Info for plot ele...
168
169
	buildPanelAdditionalObjectsNode: function(panelObject, selectedObject) {
		selectedObject = (typeof selectedObject !== 'undefined') ? selectedObject : null;
339866c4   Benjamin Renard   Add text legend d...
170
		
94abdb37   Benjamin Renard   Add params legend...
171
172
173
174
175
176
177
178
179
180
181
182
183
		var objectsNode = null;
		
		var me = this;
		this.panelsNode.eachChild(function (panelNode) {
			//Retrieve corresponding panel node
			if (panelNode.object == panelObject)
			{
				//Retrieve additional objects node
				objectsNode = panelNode.findChild('type', 'objects');
				if (!objectsNode)
				{
					//create additional objects node
					objectsNode = panelNode.appendChild(new amdaPlotObj.PlotAdditionalObjectsTreeNode({object : panelObject}));
94abdb37   Benjamin Renard   Add params legend...
184
185
186
187
188
189
190
191
				}
				return;
			}
		});
		
		if (objectsNode == null)
			return;
		
339866c4   Benjamin Renard   Add text legend d...
192
193
194
195
		//Remove old objects nodes
		objectsNode.removeAll();
		
		//create legends node
fd5552a4   Benjamin Renard   Info for plot ele...
196
		this.buildPanelLegendsNode(panelObject, objectsNode, selectedObject);
829160b3   Benjamin Renard   Add constants def...
197
198
		
		//create drawing objects node
fd5552a4   Benjamin Renard   Info for plot ele...
199
		this.buildDrawingObjectsNode(panelObject, objectsNode, selectedObject);
486cc3c7   Benjamin Renard   Add fill elements...
200
201
202
		
		//create fills node
		this.buildFillsNode(panelObject, objectsNode, selectedObject);
94abdb37   Benjamin Renard   Add params legend...
203
204
	},
	
fd5552a4   Benjamin Renard   Info for plot ele...
205
	buildPanelLegendsNode: function(panelObject, objectsNode, selectedObject) {
94abdb37   Benjamin Renard   Add params legend...
206
207
208
209
		var legendsNode = objectsNode.appendChild(new amdaPlotObj.PlotLegendsTreeNode({object : panelObject}));
		
		legendsNode.appendChild(new amdaPlotObj.PlotSeriesLegendTreeNode({object : panelObject}));
		
339866c4   Benjamin Renard   Add text legend d...
210
211
212
213
214
		var textLegendsNode = legendsNode.appendChild(new amdaPlotObj.PlotTextLegendsTreeNode({object : panelObject}));
		
		var selectedTextLegendNode = null;
		panelObject.textLegends().each(function (legendObject) {
			var textLegendNode = textLegendsNode.appendChild(new amdaPlotObj.PlotTextLegendTreeNode({object : legendObject}));
fd5552a4   Benjamin Renard   Info for plot ele...
215
			if (legendObject == selectedObject)
339866c4   Benjamin Renard   Add text legend d...
216
217
218
219
220
221
				selectedTextLegendNode = textLegendNode;
		});
		
		this.getView().refresh();
		if (selectedTextLegendNode)
			this.getSelectionModel().select(selectedTextLegendNode);
94abdb37   Benjamin Renard   Add params legend...
222
223
	},
	
fd5552a4   Benjamin Renard   Info for plot ele...
224
	buildDrawingObjectsNode: function(panelObject, objectsNode, selectedObject) {
829160b3   Benjamin Renard   Add constants def...
225
226
		var drawingObjectsNode = objectsNode.appendChild(new amdaPlotObj.PlotDrawingObjectsTreeNode({object : panelObject}));
		
a8c54fb9   Benjamin Renard   Add text object p...
227
		//Constants
829160b3   Benjamin Renard   Add constants def...
228
229
230
		var selectedConstantNode = null;
		panelObject.constants().each(function (constantObject) {
			var constantNode = drawingObjectsNode.appendChild(new amdaPlotObj.PlotConstantTreeNode({object : constantObject}));
fd5552a4   Benjamin Renard   Info for plot ele...
231
			if (constantObject == selectedObject)
829160b3   Benjamin Renard   Add constants def...
232
233
234
				selectedConstantNode = constantNode;
		});
		
a8c54fb9   Benjamin Renard   Add text object p...
235
236
237
238
		//Texts
		var selectedTextNode = null;
		panelObject.textObjs().each(function (textObject) {
			var textNode = drawingObjectsNode.appendChild(new amdaPlotObj.PlotTextTreeNode({object : textObject}));
fd5552a4   Benjamin Renard   Info for plot ele...
239
			if (textObject == selectedObject)
a8c54fb9   Benjamin Renard   Add text object p...
240
241
242
				selectedTextNode = textNode;
		});
		
dbb7bcbe   Benjamin Renard   Add curves defint...
243
244
245
246
		//Curves
		var selectedCurveNode = null;
		panelObject.curves().each(function (curveObject) {
			var curveNode = drawingObjectsNode.appendChild(new amdaPlotObj.PlotCurveTreeNode({object : curveObject}));
fd5552a4   Benjamin Renard   Info for plot ele...
247
			if (curveObject == selectedObject)
dbb7bcbe   Benjamin Renard   Add curves defint...
248
249
250
251
				selectedCurveNode = curveNode;
		});
		
		
a8c54fb9   Benjamin Renard   Add text object p...
252
		//Refresh & selection
829160b3   Benjamin Renard   Add constants def...
253
254
255
		this.getView().refresh();
		if (selectedConstantNode)
			this.getSelectionModel().select(selectedConstantNode);
a8c54fb9   Benjamin Renard   Add text object p...
256
257
258
		
		if (selectedTextNode)
			this.getSelectionModel().select(selectedTextNode);
dbb7bcbe   Benjamin Renard   Add curves defint...
259
260
261
		
		if (selectedCurveNode)
			this.getSelectionModel().select(selectedCurveNode);
829160b3   Benjamin Renard   Add constants def...
262
263
	},
	
486cc3c7   Benjamin Renard   Add fill elements...
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
	buildFillsNode: function(panelObject, objectsNode, selectedObject) {
		var fillsNode = objectsNode.appendChild(new amdaPlotObj.PlotFillsTreeNode({object : panelObject}));
		
		var selectedFillNode = null;
		panelObject.fills().each(function (fillObject) {
			var fillNode = fillsNode.appendChild(new amdaPlotObj.PlotFillTreeNode({object : fillObject}));
			if (fillObject == selectedObject)
				selectedFillNode = fillNode;
		});
		
		this.getView().refresh();
		if (selectedFillNode)
			this.getSelectionModel().select(selectedFillNode);
	},
	
17433635   Benjamin Renard   Add series and sp...
279
280
	addPanelNode: function(panelObject) {
		var panelNode = this.panelsNode.appendChild(new amdaPlotObj.PlotPanelTreeNode({object : panelObject}));
27b2a53e   Benjamin Renard   Link tab plot to ...
281
		if (!this.tabObject.get('tree-simplified-view'))
94abdb37   Benjamin Renard   Add params legend...
282
		{
17433635   Benjamin Renard   Add series and sp...
283
284
			//Axes node
			this.buildPanelAxesNode(panelObject);
94abdb37   Benjamin Renard   Add params legend...
285
286
287
			//Additional objects
			this.buildPanelAdditionalObjectsNode(panelObject);
		}
17433635   Benjamin Renard   Add series and sp...
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
		//Params node
		this.buildPanelParamsNode(panelObject);
		return panelNode;
	},
	
	movePanel : function(record,targetNode,position)
	{
		var fromIndex = targetNode.parentNode.indexOf(record);
		var toIndex   = targetNode.parentNode.indexOf(targetNode);
		
		var fromRecord = this.tabObject.panels().getAt(fromIndex);
		if (!fromRecord)
			return false;
		
		switch (position)
		{
			case 'before' :
				this.tabObject.panels().data.removeAt(fromIndex);
				var insertIndex = (fromIndex > toIndex) ? toIndex : toIndex - 1;
				this.tabObject.panels().data.insert(insertIndex, fromRecord);
				this.buildPanelsNode();
				this.getSelectionModel().select(this.panelsNode.getChildAt(insertIndex));
				return true;
			case 'after' :
				this.tabObject.panels().data.removeAt(fromIndex);
				var insertIndex = (fromIndex > toIndex) ? toIndex + 1 : toIndex;
				this.tabObject.panels().data.insert(insertIndex, fromRecord);
				this.buildPanelsNode();
				this.getSelectionModel().select(this.panelsNode.getChildAt(insertIndex));
				return true;
				break;
			default :
				return false;
		}
		
		return true;
	},
	
17433635   Benjamin Renard   Add series and sp...
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
	moveParam : function(record,targetNode,position)
	{
		/*var fromIndex = targetNode.parentNode.indexOf(record);
		var toIndex   = targetNode.parentNode.indexOf(targetNode);
		
		var fromRecord = this.tabObject.panels().getAt(fromIndex);
		if (!fromRecord)
			return false;
		
		switch (position)
		{
			case 'before' :
				this.tabObject.panels().data.removeAt(fromIndex);
				var insertIndex = (fromIndex > toIndex) ? toIndex : toIndex - 1;
				this.tabObject.panels().data.insert(insertIndex, fromRecord);
				this.buildPanelsNode();
				this.getSelectionModel().select(this.panelsNode.getChildAt(insertIndex));
				return true;
			case 'after' :
				this.tabObject.panels().data.removeAt(fromIndex);
				var insertIndex = (fromIndex > toIndex) ? toIndex + 1 : toIndex;
				this.tabObject.panels().data.insert(insertIndex, fromRecord);
				this.buildPanelsNode();
				this.getSelectionModel().select(this.panelsNode.getChildAt(insertIndex));
				return true;
				break;
			default :
				return false;
		}*/
		
		console.log('ToDo move param');
		
		return true;
	},
	
a0bf9157   Benjamin Renard   Add tick plot and...
361
362
363
	onNodeSelect: function(tree, record, index, eOpts) {
		if (index == -1)
			return;
437c4dbc   Benjamin Renard   First implementat...
364
		if (this.plotElementPanel != null)
abe09878   Benjamin Renard   Add panels and ax...
365
			this.plotElementPanel.setElement(record.type, record.object, this);
437c4dbc   Benjamin Renard   First implementat...
366
367
	},
	
a0bf9157   Benjamin Renard   Add tick plot and...
368
369
370
371
372
	onNodeDeselect: function(tree, record, index, eOpts) {
		if (this.plotElementPanel != null)
			this.plotElementPanel.resetElement();
	},
	
17433635   Benjamin Renard   Add series and sp...
373
374
375
	onCellClick: function(tree, td, cellIndex, record, tr, rowIndex, e, eOpts) {
		if ((cellIndex === 1) && record.get('removable'))
		{
a0bf9157   Benjamin Renard   Add tick plot and...
376
			this.getSelectionModel().deselectAll();
17433635   Benjamin Renard   Add series and sp...
377
378
379
380
381
382
383
384
			switch (record.get('type'))
			{
			case 'panel' :
				if (this.tabObject.removePanelById(record.object.get('id')))
					this.buildPanelsNode();
				break;
			case 'param' :
				var panelObject = null;
27b2a53e   Benjamin Renard   Link tab plot to ...
385
				if (!this.tabObject.get('tree-simplified-view'))
17433635   Benjamin Renard   Add series and sp...
386
387
388
389
390
391
392
					panelObject = record.parentNode.parentNode.object;
				else
					panelObject = record.parentNode.object;
				//removeParamById
				if (panelObject.removeParamById(record.object.get('id')))
					this.buildPanelsNode();
				break;
339866c4   Benjamin Renard   Add text legend d...
393
394
			case 'text-legend' :
				var panelObject = null;
27b2a53e   Benjamin Renard   Link tab plot to ...
395
				if (!this.tabObject.get('tree-simplified-view'))
339866c4   Benjamin Renard   Add text legend d...
396
397
398
399
400
401
					panelObject = record.parentNode.parentNode.object;
				else
					panelObject = record.parentNode.object;
				if (panelObject.removeTextLegendById(record.object.get('id')))
					this.buildPanelAdditionalObjectsNode(panelObject);
				break;
486cc3c7   Benjamin Renard   Add fill elements...
402
403
			case 'constant' :
				var panelObject = null;
27b2a53e   Benjamin Renard   Link tab plot to ...
404
				if (!this.tabObject.get('tree-simplified-view'))
486cc3c7   Benjamin Renard   Add fill elements...
405
406
407
408
409
410
411
412
					panelObject = record.parentNode.parentNode.object;
				else
					panelObject = record.parentNode.object;
				if (panelObject.removeConstantById(record.object.get('id')))
					this.buildPanelAdditionalObjectsNode(panelObject);
				break;
			case 'text-obj' :
				var panelObject = null;
27b2a53e   Benjamin Renard   Link tab plot to ...
413
				if (!this.tabObject.get('tree-simplified-view'))
486cc3c7   Benjamin Renard   Add fill elements...
414
415
416
417
418
419
420
421
					panelObject = record.parentNode.parentNode.object;
				else
					panelObject = record.parentNode.object;
				if (panelObject.removeTextObjectById(record.object.get('id')))
					this.buildPanelAdditionalObjectsNode(panelObject);
				break;
			case 'curve' :
				var panelObject = null;
27b2a53e   Benjamin Renard   Link tab plot to ...
422
				if (!this.tabObject.get('tree-simplified-view'))
486cc3c7   Benjamin Renard   Add fill elements...
423
424
425
426
427
428
429
430
					panelObject = record.parentNode.parentNode.object;
				else
					panelObject = record.parentNode.object;
				if (panelObject.removeCurveById(record.object.get('id')))
					this.buildPanelAdditionalObjectsNode(panelObject);
				break;
			case 'fill' :
				var panelObject = null;
27b2a53e   Benjamin Renard   Link tab plot to ...
431
				if (!this.tabObject.get('tree-simplified-view'))
486cc3c7   Benjamin Renard   Add fill elements...
432
433
434
435
436
437
438
					panelObject = record.parentNode.parentNode.object;
				else
					panelObject = record.parentNode.object;
				if (panelObject.removeFillById(record.object.get('id')))
					this.buildPanelAdditionalObjectsNode(panelObject);
				break;
 			}
17433635   Benjamin Renard   Add series and sp...
439
440
441
		}
	},
	
437c4dbc   Benjamin Renard   First implementat...
442
443
444
445
446
447
448
	getSelectedNode: function() {
		var selection = this.getSelectionModel().getSelection();
		if ((selection == null) || (selection.length == 0))
			return null;
		return selection[0];
	},
	
dbb7bcbe   Benjamin Renard   Add curves defint...
449
	getSelectedPanelObject: function() {
17433635   Benjamin Renard   Add series and sp...
450
451
		var selectedNode = this.getSelectedNode();
		if (selectedNode == null)
dbb7bcbe   Benjamin Renard   Add curves defint...
452
			return null;
17433635   Benjamin Renard   Add series and sp...
453
454
455
		var crtNode = selectedNode;
		do {
			if (crtNode.get('type') == 'panel')
dbb7bcbe   Benjamin Renard   Add curves defint...
456
				return crtNode.object;
17433635   Benjamin Renard   Add series and sp...
457
458
			crtNode = crtNode.parentNode;
		} while(crtNode != null);
dbb7bcbe   Benjamin Renard   Add curves defint...
459
460
461
462
463
464
465
466
467
		return null;
	},
	
	getSelectedPlotType: function() {
		var crtPanelObject = this.getSelectedPanelObject();
		if (crtPanelObject == null)
			return 'none';
		
		return crtPanelObject.get('panel-plot-type');
17433635   Benjamin Renard   Add series and sp...
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
	},
	
	isValidToDrop : function(record,targetNode,position)
	{
		switch (record.$className)
        {
        	case 'amdaModel.LocalParamNode'   :
    	 	case 'amdaModel.RemoteParamNode'  :
    	 	case 'amdaModel.RemoteSimuParamNode'  :    
    	 		return record.get('isParameter') && ! record.get('disable');
    	 	case 'amdaModel.AliasNode'        :
    	 	case 'amdaModel.DerivedParamNode' :
    	 	case 'amdaModel.MyDataParamNode'  :
    	 		return record.isLeaf(); 
    	 	case 'amdaPlotObj.PlotParamTreeNode' :
    	 		return true;
    	 	case 'amdaPlotObj.PlotPanelTreeNode' :	
    	 		switch (position)
    	 		{
    	 			case 'append' :
    	 				return false;
    	 			case 'before' :
    	 				return (targetNode.$className == 'amdaPlotObj.PlotPanelTreeNode');
    	 			case 'after'  :
    	 				return ((targetNode.$className == 'amdaPlotObj.PlotPanelTreeNode') && targetNode.isLast());
    	 		}
        }
		return false;
	},
	
	dropParamToCreate : function(targetNode, position, paramId, needsArgs, plotOnly)
	{
		var panelObject = null;
		if (targetNode == null)
		{
			//create new panel
			panelObject = this.tabObject.createNewPanel();
a0bf9157   Benjamin Renard   Add tick plot and...
505
506
			//Rebuild params node
			this.buildPanelsNode();
17433635   Benjamin Renard   Add series and sp...
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
		}
		else
		{
			switch (targetNode.$className)
	        {
			case 'amdaPlotObj.PlotParamsTreeNode' :
			case 'amdaPlotObj.PlotPanelTreeNode' :
			case 'amdaPlotObj.PlotAxesTreeNode' :
				panelObject = targetNode.object;
				break;
			case 'amdaPlotObj.PlotTimeAxisTreeNode' :
			case 'amdaPlotObj.PlotEpochAxisTreeNode' :
			case 'amdaPlotObj.PlotXAxisTreeNode' :
			case 'amdaPlotObj.PlotYLeftAxisTreeNode' :
			case 'amdaPlotObj.PlotYRightAxisTreeNode' :
			case 'amdaPlotObj.PlotColorAxisTreeNode' :
			case 'amdaPlotObj.PlotParamTreeNode' :
				panelObject = targetNode.parentNode.object;
				break;
			default:
				//create new panel
				panelObject = this.tabObject.createNewPanel();
a0bf9157   Benjamin Renard   Add tick plot and...
529
530
				//Rebuild params node
				this.buildPanelsNode();
17433635   Benjamin Renard   Add series and sp...
531
532
533
534
535
536
537
	        }
		}

		//Create param object
		var newParamObject = panelObject.createNewParam();
		newParamObject.set('param-id', paramId);
		
a0bf9157   Benjamin Renard   Add tick plot and...
538
		this.buildPanelParamsNode(panelObject, newParamObject.get('id'));		
17433635   Benjamin Renard   Add series and sp...
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
	},
	
	dropRecord : function(record,targetNode,position)
    {
    	var selModel = this.getSelectionModel();
		
    	//select the target node if defined
    	if (targetNode)
    		selModel.select(targetNode);
    	else
    		selModel.deselectAll();
    	
    	switch (record.$className)
    	{
    	 	case 'amdaModel.LocalParamNode'   :	  
    	 	case 'amdaModel.RemoteParamNode'  :
    	 	case 'amdaModel.RemoteSimuParamNode'  :    
    	 		if (!record.get('isParameter') || record.get('disable'))
    	 			return false;
                        
    	 		var needsArgs = false;

                if (record.$className == 'amdaModel.RemoteSimuParamNode') {
                	needsArgs = record.get('needsArgs');
                }
                else if (record.$className == 'amdaModel.LocalParamNode') {
                	needsArgs = record.get('needsArgs') && !record.get('isSpectra');
                }

                if (record.get('alias') != "" )
                	this.dropParamToCreate(targetNode, position, "#"+record.get('alias'), needsArgs);
                else
                	this.dropParamToCreate(targetNode, position, record.get('id'), needsArgs, record.get('notyet'));                 
                return true;
    	 	case 'amdaModel.AliasNode'        :
    	 		if (!record.isLeaf())
    	 			return false;
    	 		this.dropParamToCreate(targetNode, position, "#"+record.get('text'));
    	 		return true;
    	 	case 'amdaModel.DerivedParamNode' :
    	 		if (!record.isLeaf())
				    return false;
    	 		this.dropParamToCreate(targetNode, position, "ws_"+record.get('text'));
			    return true;
			case 'amdaModel.MyDataParamNode' :
				if (!record.isLeaf())
				    return false;
				this.dropParamToCreate(targetNode, position, "wsd_"+record.get('text'));
			    return true;
		 	case 'amdaPlotObj.PlotParamTreeNode' :
			    return this.moveParam(record,targetNode,position);
		 	case 'amdaPlotObj.PlotPanelTreeNode' :
		 		return this.movePanel(record,targetNode,position);
		    default :
			    return false;
    	}
    	return false;
	},
	
	getDragAndDropPluginConfig : function() {
		var me = this;
		
		return {
			ptype:'treeviewdragdrop',
			ddGroup:'explorerTree',
            enableDrag:true,
            enableDrop:true,
            appendOnly : false,
            allowContainerDrops : true,
            containerScroll : true,
            isValidDropPoint : function (node, position, dragZone, e, data) 
            {       
            	if (!node || !data.item) {
            		return false;
            	}           	    
                
                var view = this.view,
                targetNode = view.getRecord(node),
                draggedRecords = data.records,
                dataLength = draggedRecords.length,
                ln = draggedRecords.length,
                i, record;        		
                // No drop position, or dragged records: invalid drop point
                if (!(targetNode && position && dataLength)) {
                    return false;
                }
                             
                // If the targetNode is within the folder we are dragging
                for (i = 0; i < ln; i++) {
                    record = draggedRecords[i];
                    if (record.isNode && record.contains(targetNode)) {
                        return false;
                    }
                }
                
                // Respect the allowDrop field on Tree nodes
                if (position === 'append' && targetNode.get('allowDrop') === false) {
                    return false;
                }
                
                // If the target record is in the dragged dataset, then invalid drop
                if (Ext.Array.contains(draggedRecords, targetNode)) {
                     return false;
                }
                         
                if (dataLength > 1)
                	return false;
                var draggedRecord = draggedRecords[0];
                
                return me.isValidToDrop(draggedRecord,targetNode,position);
            },
            onPlotContainerDrop : function(dd, e, data){
            	if (data.records.length != 1)
            		return false;
            	return me.dropRecord(data.records[0],null,null);
            },
            onPlotNodeDrop : function(n, dd, e, data){
            	if (data.records.length != 1)
            		return false;
            	return me.dropRecord(data.records[0],this.view.getRecord(n),this.getPosition(e,n));
            }, 
            onPlotContainerOver : function(dd, e, data) {
            	if (data.records.length != 1)
            		return false;
            	var draggedRecord = data.records[0];
                return me.isValidToDrop(draggedRecord,null,'append') ? this.dropAllowed : this.dropNotAllowed;
            },
            onViewRender : function(view) {
				var me = this;

      			if (me.enableDrag) {
          			me.dragZone = Ext.create('Ext.tree.ViewDragZone', {
              			view: view,
              			ddGroup: me.dragGroup || me.ddGroup,
              			dragText: me.dragText,
              			repairHighlightColor: me.nodeHighlightColor,
              			repairHighlight: me.nodeHighlightOnRepair
          			});
      			}

      			if (me.enableDrop) {
          			me.dropZone = Ext.create('Ext.tree.ViewDropZone', {
              			view: view,
              			ddGroup: me.dropGroup || me.ddGroup,
              			allowContainerDrops: me.allowContainerDrops,
              			appendOnly: me.appendOnly,
              			allowParentInserts: me.allowParentInserts,
              			expandDelay: me.expandDelay,
              			dropHighlightColor: me.nodeHighlightColor,
              			dropHighlight: me.nodeHighlightOnDrop,
              			isValidDropPoint : me.isValidDropPoint,
              			onContainerDrop : me.onPlotContainerDrop,
              			onNodeDrop      : me.onPlotNodeDrop,
              			onContainerOver : me.onPlotContainerOver
          			});
      			}
			}
        }
	},
	
27b2a53e   Benjamin Renard   Link tab plot to ...
699
700
701
702
	updateLinkedToMultiPlotMode : function() {
		this.plotTabContent.updateLinkedToMultiPlotMode(this.tabObject.get('multi-plot-linked'));
	},
	
437c4dbc   Benjamin Renard   First implementat...
703
704
705
706
707
708
709
710
711
712
713
714
715
	init : function(config) {
		var me = this;
		
		this.plotElementPanel = config.plotElementPanel;
		
		var store = Ext.create('Ext.data.TreeStore', {
			root: {
				expanded: true
		    }
		});
		
		this.plotElementPanel = config.plotElementPanel;
		
27b2a53e   Benjamin Renard   Link tab plot to ...
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
		this.simplifiedViewCombo = Ext.create('Ext.form.field.Checkbox', {
			xtype: 'checkbox',
			boxLabel: 'Simplified View',
			listeners: {
				change: function(combo, newValue, oldValue, eOpts) {
					if (this.tabObject)
			        	this.tabObject.set('tree-simplified-view', newValue);
					if (newValue != oldValue)
						this.buildTree(this.tabObject);
				},
			    scope: this
			}
		});
		
		this.linkToMultiPlotCombo = Ext.create('Ext.form.field.Checkbox', {
			xtype: 'checkbox',
			boxLabel: 'Link to MultiPlot',
			listeners: {
				change: function(combo, newValue, oldValue, eOpts) {
					if (this.tabObject)
					{
			        	this.tabObject.set('multi-plot-linked', newValue);
			        	this.updateLinkedToMultiPlotMode();
					}
				},
			    scope: this
			}
		});
		
437c4dbc   Benjamin Renard   First implementat...
745
746
747
		var myConf = {
				store: store,
				rootVisible: false,
17433635   Benjamin Renard   Add series and sp...
748
749
750
751
				hideHeaders: true,
				viewConfig:{
	                plugins: this.getDragAndDropPluginConfig()
	            },
437c4dbc   Benjamin Renard   First implementat...
752
753
				listeners: {
			        select: me.onNodeSelect,
a0bf9157   Benjamin Renard   Add tick plot and...
754
			        deselect: me.onNodeDeselect,
17433635   Benjamin Renard   Add series and sp...
755
			        cellclick: me.onCellClick,
437c4dbc   Benjamin Renard   First implementat...
756
			        scope: me
abe09878   Benjamin Renard   Add panels and ax...
757
758
759
760
761
762
763
764
765
766
767
768
769
			    },
			    columns: [
			              {
			            	  xtype: 'treecolumn',
			                  text: 'Plot Element',
			                  flex: 1,
			                  dataIndex: 'text',
			                  renderer: function (val, meta, rec) {
			                	  var fullVal = val;
			                	  if (rec.getAdditionalText)
			                	    fullVal += rec.getAdditionalText();
			                	  return fullVal;
			                  }
17433635   Benjamin Renard   Add series and sp...
770
771
772
773
774
775
776
777
778
779
780
			              },
			              {
			            	  menuDisabled: true, 
			            	  align: 'center',
			            	  width: 24, 
			            	  renderer: function(v,m,record){
			            		  if (record.get('removable'))
			            			  return'<div class="icon-small-remover" style="width: 16px; height: 16px; vertical-align: middle;"></div>';
			            		  else
			            			  return '';
			            	  }
abe09878   Benjamin Renard   Add panels and ax...
781
782
783
784
785
786
			              }
			    ],
			    tbar: [
			           {
			        	   xtype: 'button',
			        	   text: 'Add panel',
17433635   Benjamin Renard   Add series and sp...
787
			        	   iconCls: 'icon-add',
abe09878   Benjamin Renard   Add panels and ax...
788
			        	   handler: function() {
17433635   Benjamin Renard   Add series and sp...
789
790
			        		   var newPabelNode = this.addPanelNode(this.tabObject.createNewPanel());
			        		   this.getSelectionModel().select(newPabelNode);
abe09878   Benjamin Renard   Add panels and ax...
791
792
			        	   },
			        	   scope: this
17433635   Benjamin Renard   Add series and sp...
793
794
			           },
			           '->',
27b2a53e   Benjamin Renard   Link tab plot to ...
795
796
797
			           this.linkToMultiPlotCombo,
			           ' ',
			           this.simplifiedViewCombo
abe09878   Benjamin Renard   Add panels and ax...
798
			    ]
437c4dbc   Benjamin Renard   First implementat...
799
800
801
802
803
		};
		
		Ext.apply (this , Ext.apply (arguments, myConf));
	}
});