Blame view

js/app/views/PlotComponents/PlotTree.js 31.1 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
	//Link to the combo box to define the use of the simplified view
	simplifiedViewCombo : null,
	
17433635   Benjamin Renard   Add series and sp...
21
	
437c4dbc   Benjamin Renard   First implementat...
22
23
	//Link to the Plot Element Panel
    plotElementPanel: null,
27b2a53e   Benjamin Renard   Link tab plot to ...
24
25
26
    
    //Link to the Plot Tab Content Panel
    plotTabContent : null,
437c4dbc   Benjamin Renard   First implementat...
27
28
	
	//Tab object
abe09878   Benjamin Renard   Add panels and ax...
29
30
31
32
    tabObject: null,
	
	//Panels list node
	panelsNode: null,
437c4dbc   Benjamin Renard   First implementat...
33
34
35
36
37
38
	
	constructor: function(config) {
		this.init(config);	    
		this.callParent(arguments);
	},
	
e84ed2cf   Benjamin Renard   Add Interval Tick...
39
40
41
42
	refresh: function() {
		this.getView().refresh();
	},
	
437c4dbc   Benjamin Renard   First implementat...
43
	buildTree: function(tabObject) {
abe09878   Benjamin Renard   Add panels and ax...
44
45
46
47
		if (this.store.getRootNode().hasChildNodes())
			this.store.getRootNode().removeAll();
		
		this.tabObject = tabObject;
74967644   Elena.Budnik   avoid tree node d...
48
49
			
		if (this.tabObject.get('tree-full-view') && this.simplifiedViewCombo.getValue())
17433635   Benjamin Renard   Add series and sp...
50
51
52
		{
			//Page Node
			var pageNode = this.store.getRootNode().appendChild(new amdaPlotObj.PlotPageTreeNode({object : tabObject}));
17433635   Benjamin Renard   Add series and sp...
53
			//Layout node
003ba315   Benjamin Renard   Add Epoch Plot an...
54
			pageNode.appendChild(new amdaPlotObj.PlotLayoutTreeNode({object : tabObject}));
437c4dbc   Benjamin Renard   First implementat...
55
		
17433635   Benjamin Renard   Add series and sp...
56
			//Panels node
2a0b8d2c   Benjamin Renard   Restore node stat...
57
			this.panelsNode = pageNode.appendChild(new amdaPlotObj.PlotPanelsTreeNode({object : tabObject}));
17433635   Benjamin Renard   Add series and sp...
58
59
60
		}
		else
			this.panelsNode = this.store.getRootNode();
4e4da7d3   Elena.Budnik   resume/suspend La...
61
62

		this.suspendLayouts();
17433635   Benjamin Renard   Add series and sp...
63
		this.buildPanelsNode();
74967644   Elena.Budnik   avoid tree node d...
64
		this.simplifiedViewCombo.setValue(this.tabObject.get('tree-full-view'));
c1beab2e   Elena.Budnik   resume(true!!)
65
		this.resumeLayouts(true);
17433635   Benjamin Renard   Add series and sp...
66
67
	},
	
bb6e93d9   Benjamin Renard   Implement templat...
68
	buildPanelsNode: function(paramNodeToSelect) {
17433635   Benjamin Renard   Add series and sp...
69
70
		if (this.panelsNode.hasChildNodes())
			this.panelsNode.removeAll();
abe09878   Benjamin Renard   Add panels and ax...
71
72
		
		var me = this;
509bf9fa   Benjamin Renard   Replace panel ID ...
73
		this.tabObject.updatePanelIndex();
abe09878   Benjamin Renard   Add panels and ax...
74
		this.tabObject.panels().each(function (panelObject) {
bb6e93d9   Benjamin Renard   Implement templat...
75
			me.addPanelNode(panelObject, paramNodeToSelect);
abe09878   Benjamin Renard   Add panels and ax...
76
77
78
		});
	},
	
abe09878   Benjamin Renard   Add panels and ax...
79
80
81
82
83
84
85
86
87
88
89
	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...
90
					axesNode = panelNode.appendChild(new amdaPlotObj.PlotAxesTreeNode({object : panelObject}));
abe09878   Benjamin Renard   Add panels and ax...
91
92
93
				return;
			}
		});
437c4dbc   Benjamin Renard   First implementat...
94
		
abe09878   Benjamin Renard   Add panels and ax...
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
123
124
125
		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...
126
127
	},
	
003ba315   Benjamin Renard   Add Epoch Plot an...
128
129
130
	buildPanelParamsNode: function(panelObject, selectedParamId) {
		selectedParamId = (typeof selectedParamId !== 'undefined') ? selectedParamId : '';
		
17433635   Benjamin Renard   Add series and sp...
131
132
133
134
135
136
137
		var paramsNode = null;
		
		var me = this;
		this.panelsNode.eachChild(function (panelNode) {
			//Retrieve corresponding panel node
			if (panelNode.object == panelObject)
			{
8816e270   Elena.Budnik   simplified vies c...
138
				if (me.tabObject.get('tree-full-view'))
17433635   Benjamin Renard   Add series and sp...
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
				{
					//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...
159
		var selectedParamNode = null;
17433635   Benjamin Renard   Add series and sp...
160
		panelObject.params().each(function (paramObject) {
a0bf9157   Benjamin Renard   Add tick plot and...
161
162
163
			var paramNode = paramsNode.appendChild(new amdaPlotObj.PlotParamTreeNode({object : paramObject}));
			if (paramObject.get('id') == selectedParamId)
				selectedParamNode = paramNode;
17433635   Benjamin Renard   Add series and sp...
164
165
		});
		this.getView().refresh();
a0bf9157   Benjamin Renard   Add tick plot and...
166
167
168
		
		if (selectedParamNode)
			this.getSelectionModel().select(selectedParamNode);
17433635   Benjamin Renard   Add series and sp...
169
170
	},
	
fd5552a4   Benjamin Renard   Info for plot ele...
171
172
	buildPanelAdditionalObjectsNode: function(panelObject, selectedObject) {
		selectedObject = (typeof selectedObject !== 'undefined') ? selectedObject : null;
339866c4   Benjamin Renard   Add text legend d...
173
		
94abdb37   Benjamin Renard   Add params legend...
174
175
176
177
178
179
180
181
182
183
184
185
186
		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...
187
188
189
190
191
192
193
194
				}
				return;
			}
		});
		
		if (objectsNode == null)
			return;
		
339866c4   Benjamin Renard   Add text legend d...
195
196
197
198
		//Remove old objects nodes
		objectsNode.removeAll();
		
		//create legends node
fd5552a4   Benjamin Renard   Info for plot ele...
199
		this.buildPanelLegendsNode(panelObject, objectsNode, selectedObject);
829160b3   Benjamin Renard   Add constants def...
200
201
		
		//create drawing objects node
fd5552a4   Benjamin Renard   Info for plot ele...
202
		this.buildDrawingObjectsNode(panelObject, objectsNode, selectedObject);
486cc3c7   Benjamin Renard   Add fill elements...
203
204
205
		
		//create fills node
		this.buildFillsNode(panelObject, objectsNode, selectedObject);
94abdb37   Benjamin Renard   Add params legend...
206
207
	},
	
fd5552a4   Benjamin Renard   Info for plot ele...
208
	buildPanelLegendsNode: function(panelObject, objectsNode, selectedObject) {
94abdb37   Benjamin Renard   Add params legend...
209
210
211
212
		var legendsNode = objectsNode.appendChild(new amdaPlotObj.PlotLegendsTreeNode({object : panelObject}));
		
		legendsNode.appendChild(new amdaPlotObj.PlotSeriesLegendTreeNode({object : panelObject}));
		
339866c4   Benjamin Renard   Add text legend d...
213
214
215
216
217
		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...
218
			if (legendObject == selectedObject)
339866c4   Benjamin Renard   Add text legend d...
219
220
221
222
223
224
				selectedTextLegendNode = textLegendNode;
		});
		
		this.getView().refresh();
		if (selectedTextLegendNode)
			this.getSelectionModel().select(selectedTextLegendNode);
94abdb37   Benjamin Renard   Add params legend...
225
226
	},
	
fd5552a4   Benjamin Renard   Info for plot ele...
227
	buildDrawingObjectsNode: function(panelObject, objectsNode, selectedObject) {
829160b3   Benjamin Renard   Add constants def...
228
229
		var drawingObjectsNode = objectsNode.appendChild(new amdaPlotObj.PlotDrawingObjectsTreeNode({object : panelObject}));
		
a8c54fb9   Benjamin Renard   Add text object p...
230
		//Constants
829160b3   Benjamin Renard   Add constants def...
231
232
233
		var selectedConstantNode = null;
		panelObject.constants().each(function (constantObject) {
			var constantNode = drawingObjectsNode.appendChild(new amdaPlotObj.PlotConstantTreeNode({object : constantObject}));
fd5552a4   Benjamin Renard   Info for plot ele...
234
			if (constantObject == selectedObject)
829160b3   Benjamin Renard   Add constants def...
235
236
237
				selectedConstantNode = constantNode;
		});
		
a8c54fb9   Benjamin Renard   Add text object p...
238
239
240
241
		//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...
242
			if (textObject == selectedObject)
a8c54fb9   Benjamin Renard   Add text object p...
243
244
245
				selectedTextNode = textNode;
		});
		
dbb7bcbe   Benjamin Renard   Add curves defint...
246
247
248
249
		//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...
250
			if (curveObject == selectedObject)
dbb7bcbe   Benjamin Renard   Add curves defint...
251
252
253
254
				selectedCurveNode = curveNode;
		});
		
		
a8c54fb9   Benjamin Renard   Add text object p...
255
		//Refresh & selection
829160b3   Benjamin Renard   Add constants def...
256
257
258
		this.getView().refresh();
		if (selectedConstantNode)
			this.getSelectionModel().select(selectedConstantNode);
a8c54fb9   Benjamin Renard   Add text object p...
259
260
261
		
		if (selectedTextNode)
			this.getSelectionModel().select(selectedTextNode);
dbb7bcbe   Benjamin Renard   Add curves defint...
262
263
264
		
		if (selectedCurveNode)
			this.getSelectionModel().select(selectedCurveNode);
829160b3   Benjamin Renard   Add constants def...
265
266
	},
	
486cc3c7   Benjamin Renard   Add fill elements...
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
	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);
	},
	
bb6e93d9   Benjamin Renard   Implement templat...
282
	addPanelNode: function(panelObject, paramNodeToSelect) {
17433635   Benjamin Renard   Add series and sp...
283
		var panelNode = this.panelsNode.appendChild(new amdaPlotObj.PlotPanelTreeNode({object : panelObject}));
8816e270   Elena.Budnik   simplified vies c...
284
		if (this.tabObject.get('tree-full-view'))
94abdb37   Benjamin Renard   Add params legend...
285
		{
17433635   Benjamin Renard   Add series and sp...
286
287
			//Axes node
			this.buildPanelAxesNode(panelObject);
94abdb37   Benjamin Renard   Add params legend...
288
289
290
			//Additional objects
			this.buildPanelAdditionalObjectsNode(panelObject);
		}
17433635   Benjamin Renard   Add series and sp...
291
		//Params node
bb6e93d9   Benjamin Renard   Implement templat...
292
		this.buildPanelParamsNode(panelObject, paramNodeToSelect);
17433635   Benjamin Renard   Add series and sp...
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
326
327
328
		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...
329
330
	moveParam : function(record,targetNode,position)
	{
88fa6068   Benjamin Renard   Fix a bug with dr...
331
		if ((record.$className != 'amdaPlotObj.PlotParamTreeNode') || (targetNode == null))
7cf5fd16   Benjamin Renard   Move param in plo...
332
333
334
335
336
337
			return false;
		
		var fromIndex = record.parentNode.indexOf(record);
		var toIndex   = targetNode.parentNode.indexOf(targetNode);
		
		var fromPanelObject = null;
8816e270   Elena.Budnik   simplified vies c...
338
 		if (this.tabObject.get('tree-full-view'))
7cf5fd16   Benjamin Renard   Move param in plo...
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
		{
			fromPanelObject = record.parentNode.parentNode.object;
		}
		else
			fromPanelObject = record.parentNode.object;
 		if (fromPanelObject == null)
 			return false;
 		
 		switch (targetNode.$className)
 		{
 		case 'amdaPlotObj.PlotPanelTreeNode' :
 		case 'amdaPlotObj.PlotParamsTreeNode' :
 			var toPanelObject = targetNode.object;
 			if (toPanelObject.get('panel-plot-type') != fromPanelObject.get('panel-plot-type'))
 				return false;
 			if (toPanelObject == fromPanelObject)
 			{
 				//Move param on the same panel
 				fromPanelObject.params().data.removeAt(fromIndex);
				toPanelObject.params().data.add(record.object);
				this.buildPanelParamsNode(toPanelObject, record.object.get('id'));
 			}
 			else
 			{
 				//Move param on another panel
 				var clonedObject = record.object.copy();
 	 			fromPanelObject.params().remove(record.object);
 	 			toPanelObject.set('last-param-id', toPanelObject.get('last-param-id')+1);
 	 			clonedObject.set('id', toPanelObject.get('last-param-id'));
 	 			toPanelObject.params().add(clonedObject);
 	 			this.buildPanelParamsNode(fromPanelObject);
 	 			this.buildPanelParamsNode(toPanelObject, clonedObject.get('id'));
 			}
 			return true;
 		case 'amdaPlotObj.PlotParamTreeNode' :
 			var toPanelObject = null;
8816e270   Elena.Budnik   simplified vies c...
375
 			if (this.tabObject.get('tree-full-view'))
7cf5fd16   Benjamin Renard   Move param in plo...
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
			{
 				toPanelObject = targetNode.parentNode.parentNode.object;
			}
			else
				toPanelObject = targetNode.parentNode.object;
 			targetNode.object;
 			if (toPanelObject.get('panel-plot-type') != fromPanelObject.get('panel-plot-type'))
 				return false;
 			
 			if (toPanelObject == fromPanelObject)
 			{
 				//Move param on the same panel
 				var insertIndex = -1;
 	 			switch (position)
 	 			{
 	 			case 'before' :
 	 				insertIndex = (fromIndex > toIndex) ? toIndex : toIndex - 1;
 	 				break;
 	 			case 'after' :
 	 			default :
 	 				insertIndex = (fromIndex > toIndex) ? toIndex + 1 : toIndex;
 	 				break;
 	 			}
 	 			fromPanelObject.params().data.removeAt(fromIndex);
				toPanelObject.params().data.insert(insertIndex, record.object);
				this.buildPanelParamsNode(toPanelObject, record.object.get('id'));
 			}
 			else
 			{
 				//move param on another panel
 				var insertIndex = -1;
 	 			switch (position)
 	 			{
 	 			case 'before' :
 	 				insertIndex = (toIndex == 0) ? 0: toIndex - 1;
 	 				break;
 	 			case 'after' :
 	 			default :
 	 				insertIndex = toIndex + 1;
 	 				break;
 	 			}
 	 			var clonedObject = record.object.copy();
 	 			fromPanelObject.params().remove(record.object);
 	 			toPanelObject.set('last-param-id', toPanelObject.get('last-param-id')+1);
 	 			clonedObject.set('id', toPanelObject.get('last-param-id'));
 	 			toPanelObject.params().insert(insertIndex, clonedObject);
 	 			this.buildPanelParamsNode(fromPanelObject);
 	 			this.buildPanelParamsNode(toPanelObject, clonedObject.get('id'));
 			}
 			return true;
 		}
 		return false;
17433635   Benjamin Renard   Add series and sp...
428
429
	},
	
a0bf9157   Benjamin Renard   Add tick plot and...
430
431
432
	onNodeSelect: function(tree, record, index, eOpts) {
		if (index == -1)
			return;
437c4dbc   Benjamin Renard   First implementat...
433
		if (this.plotElementPanel != null)
abe09878   Benjamin Renard   Add panels and ax...
434
			this.plotElementPanel.setElement(record.type, record.object, this);
437c4dbc   Benjamin Renard   First implementat...
435
436
	},
	
a0bf9157   Benjamin Renard   Add tick plot and...
437
438
439
440
441
	onNodeDeselect: function(tree, record, index, eOpts) {
		if (this.plotElementPanel != null)
			this.plotElementPanel.resetElement();
	},
	
17433635   Benjamin Renard   Add series and sp...
442
443
444
	onCellClick: function(tree, td, cellIndex, record, tr, rowIndex, e, eOpts) {
		if ((cellIndex === 1) && record.get('removable'))
		{
a0bf9157   Benjamin Renard   Add tick plot and...
445
			this.getSelectionModel().deselectAll();
17433635   Benjamin Renard   Add series and sp...
446
447
448
449
450
451
452
453
			switch (record.get('type'))
			{
			case 'panel' :
				if (this.tabObject.removePanelById(record.object.get('id')))
					this.buildPanelsNode();
				break;
			case 'param' :
				var panelObject = null;
8816e270   Elena.Budnik   simplified vies c...
454
				if (this.tabObject.get('tree-full-view'))
17433635   Benjamin Renard   Add series and sp...
455
456
457
458
459
460
461
					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...
462
463
			case 'text-legend' :
				var panelObject = null;
8816e270   Elena.Budnik   simplified vies c...
464
				if (this.tabObject.get('tree-full-view'))
339866c4   Benjamin Renard   Add text legend d...
465
466
467
468
469
470
					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...
471
472
			case 'constant' :
				var panelObject = null;
8816e270   Elena.Budnik   simplified vies c...
473
				if (this.tabObject.get('tree-full-view'))
486cc3c7   Benjamin Renard   Add fill elements...
474
475
476
477
478
479
480
481
					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;
8816e270   Elena.Budnik   simplified vies c...
482
				if (this.tabObject.get('tree-full-view'))
486cc3c7   Benjamin Renard   Add fill elements...
483
484
485
486
487
488
489
490
					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;
8816e270   Elena.Budnik   simplified vies c...
491
				if (this.tabObject.get('tree-full-view'))
486cc3c7   Benjamin Renard   Add fill elements...
492
493
494
495
496
497
498
499
					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;
8816e270   Elena.Budnik   simplified vies c...
500
				if (this.tabObject.get('tree-full-view'))
486cc3c7   Benjamin Renard   Add fill elements...
501
502
503
504
505
506
507
					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...
508
509
510
		}
	},
	
2a0b8d2c   Benjamin Renard   Restore node stat...
511
512
513
514
515
516
517
518
	onNodeCollapse: function(node) {
		node.setNodeState(0);
	},
	
	onNodeExpand: function(node) {
		node.setNodeState(1);
	},
	
437c4dbc   Benjamin Renard   First implementat...
519
520
521
522
523
524
525
	getSelectedNode: function() {
		var selection = this.getSelectionModel().getSelection();
		if ((selection == null) || (selection.length == 0))
			return null;
		return selection[0];
	},
	
dbb7bcbe   Benjamin Renard   Add curves defint...
526
	getSelectedPanelObject: function() {
17433635   Benjamin Renard   Add series and sp...
527
528
		var selectedNode = this.getSelectedNode();
		if (selectedNode == null)
dbb7bcbe   Benjamin Renard   Add curves defint...
529
			return null;
17433635   Benjamin Renard   Add series and sp...
530
531
532
		var crtNode = selectedNode;
		do {
			if (crtNode.get('type') == 'panel')
dbb7bcbe   Benjamin Renard   Add curves defint...
533
				return crtNode.object;
17433635   Benjamin Renard   Add series and sp...
534
535
			crtNode = crtNode.parentNode;
		} while(crtNode != null);
dbb7bcbe   Benjamin Renard   Add curves defint...
536
537
538
539
540
541
542
543
544
		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...
545
546
547
548
549
	},
	
	isValidToDrop : function(record,targetNode,position)
	{
		switch (record.$className)
bf776dc8   Benjamin Renard   working
550
                
17433635   Benjamin Renard   Add series and sp...
551
        {
ea69a33c   Benjamin Renard   Allow drag&drop o...
552
553
554
555
556
		case 'amdaModel.sharedTimeTableNode' :
		case 'amdaModel.sharedCatalogNode' :
		case 'amdaModel.TimeTableNode' :
		case 'amdaModel.CatalogNode' :
			return record.get('leaf');
b0f72ee0   Erdogan Furkan   #10557 For now
557
558
559
560
561
562
563
564
565
566
567
568
569
570
		case 'amdaModel.LocalParamNode'   :
		case 'amdaModel.RemoteParamNode'  :
		case 'amdaModel.RemoteSimuParamNode'  :    
			return record.get('isParameter') && ! record.get('disable');
		
		case 'amdaModel.DerivedParamNode' : 
		case 'amdaModel.DerivedParamComponentNode':
								return record.get('isParameter') ;
		case 'amdaModel.AliasNode'        :
		case 'amdaModel.SpecialParamNode':
		case 'amdaModel.MyDataParamNode'  :
		case 'amdaModel.MyDataParamComponentNode':
			return record.get('isParameter') ;
		case 'amdaPlotObj.PlotParamTreeNode' :
7cf5fd16   Benjamin Renard   Move param in plo...
571
    	 		var fromPanelObject = null;
8816e270   Elena.Budnik   simplified vies c...
572
    	 		if (this.tabObject.get('tree-full-view'))
7cf5fd16   Benjamin Renard   Move param in plo...
573
574
575
576
577
				{
					fromPanelObject = record.parentNode.parentNode.object;
				}
				else
					fromPanelObject = record.parentNode.object;
88fa6068   Benjamin Renard   Fix a bug with dr...
578
    	 		if ((fromPanelObject == null) || (targetNode == null))
7cf5fd16   Benjamin Renard   Move param in plo...
579
580
581
582
583
584
585
586
587
588
    	 			return false;
    	 		
    	 		var toPanelObject = null;
    	 		switch (targetNode.$className)
    	 		{
    	 		case 'amdaPlotObj.PlotPanelTreeNode' :
    	 		case 'amdaPlotObj.PlotParamsTreeNode' :
    	 			toPanelObject = targetNode.object;
    	 			break;
    	 		case 'amdaPlotObj.PlotParamTreeNode' :
8816e270   Elena.Budnik   simplified vies c...
589
    	 			if (this.tabObject.get('tree-full-view'))
7cf5fd16   Benjamin Renard   Move param in plo...
590
591
592
593
594
595
596
597
598
599
    				{
    	 				toPanelObject = targetNode.parentNode.parentNode.object;
    				}
    				else
    					toPanelObject = targetNode.parentNode.object;
    	 			break;
    	 		}
    	 		if (toPanelObject == null)
    	 			return false;
    	 		return (fromPanelObject.get('panel-plot-type') == toPanelObject.get('panel-plot-type'));
bf776dc8   Benjamin Renard   working
600
    	 	                    case 'amdaPlotObj.PlotPanelTreeNode' :	
17433635   Benjamin Renard   Add series and sp...
601
602
603
604
605
606
607
608
609
610
611
612
613
    	 		switch (position)
    	 		{
    	 			case 'append' :
    	 				return false;
    	 			case 'before' :
    	 				return (targetNode.$className == 'amdaPlotObj.PlotPanelTreeNode');
    	 			case 'after'  :
    	 				return ((targetNode.$className == 'amdaPlotObj.PlotPanelTreeNode') && targetNode.isLast());
    	 		}
        }
		return false;
	},
	
7f23e0f7   Erdogan Furkan   #5119 -Done. Adde...
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
	dropParamToCreate: function (targetNode, position, paramId, data)
	{
		var panelObject = null;
		if (targetNode == null)
		{
			//create new panel
			panelObject = this.tabObject.createNewPanel();
		} 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();
			}
		}
17433635   Benjamin Renard   Add series and sp...
644

7f23e0f7   Erdogan Furkan   #5119 -Done. Adde...
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
		//Create param object
		var me = this;
		if ((typeof data !== "undefined") && (typeof data.predefinedArgs !== "undefined") && data.predefinedArgs) {
			var plotModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.plot.id);
			plotModule.parseTemplatedParam(paramId, function(param_info) {
				data.template_args = param_info.template_args;
				panelObject.createNewParam(param_info.paramid, data, function (newParamObject) {
					//Rebuild params node
					me.buildPanelsNode(newParamObject.getId());
				}); 
				//downModule.addParam(param_info.paramid, true, true, components, param_info.template_args);
			});
		}
		else {
			panelObject.createNewParam(paramId, data, function (newParamObject) {
					//Rebuild params node
					me.buildPanelsNode(newParamObject.getId());
					//BRE newParamObject
			});
		}
	},
0cefcae2   Benjamin Renard   il reste click droit
666

7f23e0f7   Erdogan Furkan   #5119 -Done. Adde...
667
668
669
	dropRecord: function (record, targetNode, position)
	{
		var selModel = this.getSelectionModel();
0cefcae2   Benjamin Renard   il reste click droit
670

7f23e0f7   Erdogan Furkan   #5119 -Done. Adde...
671
672
673
674
675
		//select the target node if defined
		if (targetNode)
			selModel.select(targetNode);
		else
			selModel.deselectAll();
0cefcae2   Benjamin Renard   il reste click droit
676

7f23e0f7   Erdogan Furkan   #5119 -Done. Adde...
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
		switch (record.$className)
		{
			case 'amdaModel.sharedTimeTableNode' :
			case 'amdaModel.sharedCatalogNode' :
			case 'amdaModel.TimeTableNode' :
			case 'amdaModel.CatalogNode' :
				if (!record.get('leaf'))
					return false;
				this.dropParamToCreate(targetNode, position, record.get('id'), {'isTTCat': true, 'name': record.get('text'), 'info':record.data.info});
				return true;
			case 'amdaModel.LocalParamNode'   :
			case 'amdaModel.RemoteParamNode'  :
			case 'amdaModel.RemoteSimuParamNode'  :
				if (!record.get('isParameter') || record.get('disable'))
					return false;
0cefcae2   Benjamin Renard   il reste click droit
692

7f23e0f7   Erdogan Furkan   #5119 -Done. Adde...
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
				if (record.get('alias') != "")
					this.dropParamToCreate(targetNode, position, "#" + record.get('alias'));
				else {
					var isVector = record.get('iconCls') == 'icon-vector';
					var component_info = record.get('component_info');
					var param_id = record.get('id');
					var plot_only = record.get('notyet');
					var param_info = record.data.info;
					var components = null;
					var predefinedArgs = record.get('predefinedArgs');
					if (component_info && component_info.parentId) {
						//It's a component
						param_id = component_info.parentId;
						components = [];
						if (component_info.index1)
							components['index1'] = component_info.index1;
						if (component_info.index2)
							components['index2'] = component_info.index2;
51713556   Benjamin Renard   Templated paramet...
711
						predefinedArgs = record.parentNode.get('predefinedArgs');
7f23e0f7   Erdogan Furkan   #5119 -Done. Adde...
712
713
714
715
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
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
					}
					this.dropParamToCreate(targetNode, position, param_id, {'components': components, 'isVector': isVector, 'plotOnly': plot_only, 'predefinedArgs': predefinedArgs, 'info':param_info});
				}
				return true;
			case 'amdaModel.AliasNode'        :
				if (!record.isLeaf())
					return false;
				this.dropParamToCreate(targetNode, position, "#" + record.get('text'));
				return true;
			case 'amdaModel.DerivedParamNode' :
					if (!record.get('isParameter'))
					return false;
				//targetNode, position, paramId, paramComponents, isVector, plotOnly
				var isVector = record.get('iconCls') == 'icon-vector';
				var components = null;
				var dim1=record.get("dim_1");
				var dim2=record.get("dim_2");
				if(dim1>3 && dim2==1)
				{
					components = [];
					components['index2'] ="0"
				}else if(dim1==1 && dim2>1)
				{
					components = [];
					components['index1'] ="0"
				}
				this.dropParamToCreate(targetNode, position, "ws_" + record.get('text'), {'components': components, 'isVector': isVector, 'info':record.data.info});
				return true;
			case 'amdaModel.DerivedParamComponentNode':
				if (!record.get('isParameter'))
					return false;
				//targetNode, position, paramId, paramComponents, isVector, plotOnly
					paramId=record.get('text');
					var parentId = paramId.substr(0, paramId.length - 3);
				idToSent = "ws_" + parentId;
				var regExp = /\(([\d]+)\)/;
						var component_index = regExp.exec(paramId);
						if (component_index)
						{
							components = [];
							components['index1'] = component_index[1];
						}
				this.dropParamToCreate(targetNode, position,idToSent, {'components': components});
				return true;
				case 'amdaModel.MyDataParamComponentNode':
				if (!record.get('isParameter'))
					return false;
				//targetNode, position, paramId, paramComponents, isVector, plotOnly
					paramId=record.get('text');
					var parentId = paramId.substr(0, paramId.length - 3);
				idToSent = "wsd_" + parentId;
				var regExp = /\(([\d]+)\)/;
						var component_index = regExp.exec(paramId);
						if (component_index)
						{
							components = [];
							components['index1'] = component_index[1];
						}
				this.dropParamToCreate(targetNode, position,idToSent, {'components': components});
				return true;
			case 'amdaModel.MyDataParamNode' :
				if (!record.get('isParameter'))
					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);
			case 'amdaModel.SpecialParamNode' :
				if (!record.get('isParameter'))
						return false;
					this.dropParamToCreate(targetNode, position, record.get('id'));
					return true;
			default :
				return false;
17433635   Benjamin Renard   Add series and sp...
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
    	}
    	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];
17433635   Benjamin Renard   Add series and sp...
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
                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
          			});
      			}
			}
        }
	},
	
437c4dbc   Benjamin Renard   First implementat...
892
893
	init : function(config) {
		var me = this;
74967644   Elena.Budnik   avoid tree node d...
894
	 
437c4dbc   Benjamin Renard   First implementat...
895
896
897
898
899
900
901
902
		this.plotElementPanel = config.plotElementPanel;
		
		var store = Ext.create('Ext.data.TreeStore', {
			root: {
				expanded: true
		    }
		});
		
74967644   Elena.Budnik   avoid tree node d...
903
	//	this.plotElementPanel = config.plotElementPanel;
437c4dbc   Benjamin Renard   First implementat...
904
		
27b2a53e   Benjamin Renard   Link tab plot to ...
905
906
		this.simplifiedViewCombo = Ext.create('Ext.form.field.Checkbox', {
			xtype: 'checkbox',
5a7720c8   Elena.Budnik   title modif
907
			boxLabel: 'Extended Plot Options',
27b2a53e   Benjamin Renard   Link tab plot to ...
908
			listeners: {
8816e270   Elena.Budnik   simplified vies c...
909
910
911
912
913
914
// 				 render: function(c) {
// 					Ext.create('Ext.tip.ToolTip', {
// 						target: c.getEl(),
// 						html: "SOME TEXT" 
// 					});
// 				},
27b2a53e   Benjamin Renard   Link tab plot to ...
915
916
				change: function(combo, newValue, oldValue, eOpts) {
					if (this.tabObject)
8816e270   Elena.Budnik   simplified vies c...
917
			        	this.tabObject.set('tree-full-view', newValue);
74967644   Elena.Budnik   avoid tree node d...
918
					 
27b2a53e   Benjamin Renard   Link tab plot to ...
919
920
921
922
923
924
925
					if (newValue != oldValue)
						this.buildTree(this.tabObject);
				},
			    scope: this
			}
		});
		
437c4dbc   Benjamin Renard   First implementat...
926
927
928
		var myConf = {
				store: store,
				rootVisible: false,
17433635   Benjamin Renard   Add series and sp...
929
930
				hideHeaders: true,
				viewConfig:{
e84ed2cf   Benjamin Renard   Add Interval Tick...
931
932
	                plugins: this.getDragAndDropPluginConfig(),
	                preserveScrollOnRefresh: true
17433635   Benjamin Renard   Add series and sp...
933
	            },
437c4dbc   Benjamin Renard   First implementat...
934
935
				listeners: {
			        select: me.onNodeSelect,
a0bf9157   Benjamin Renard   Add tick plot and...
936
			        deselect: me.onNodeDeselect,
17433635   Benjamin Renard   Add series and sp...
937
			        cellclick: me.onCellClick,
2a0b8d2c   Benjamin Renard   Restore node stat...
938
939
			        itemcollapse: me.onNodeCollapse,
			        itemexpand: me.onNodeExpand,
437c4dbc   Benjamin Renard   First implementat...
940
			        scope: me
abe09878   Benjamin Renard   Add panels and ax...
941
942
943
944
945
946
947
948
949
950
951
952
953
			    },
			    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...
954
955
956
957
958
959
960
961
962
963
964
			              },
			              {
			            	  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...
965
966
967
968
969
970
			              }
			    ],
			    tbar: [
			           {
			        	   xtype: 'button',
			        	   text: 'Add panel',
17433635   Benjamin Renard   Add series and sp...
971
			        	   iconCls: 'icon-add',
abe09878   Benjamin Renard   Add panels and ax...
972
			        	   handler: function() {
17433635   Benjamin Renard   Add series and sp...
973
974
			        		   var newPabelNode = this.addPanelNode(this.tabObject.createNewPanel());
			        		   this.getSelectionModel().select(newPabelNode);
abe09878   Benjamin Renard   Add panels and ax...
975
976
			        	   },
			        	   scope: this
17433635   Benjamin Renard   Add series and sp...
977
			           },
8816e270   Elena.Budnik   simplified vies c...
978
			           '-', '->',
27b2a53e   Benjamin Renard   Link tab plot to ...
979
			           this.simplifiedViewCombo
abe09878   Benjamin Renard   Add panels and ax...
980
			    ]
437c4dbc   Benjamin Renard   First implementat...
981
982
		};
		
8816e270   Elena.Budnik   simplified vies c...
983
		Ext.apply(this,Ext.apply(arguments, myConf));
437c4dbc   Benjamin Renard   First implementat...
984
	}
edd44876   Hacene SI HADJ MOHAND   fixing conflicts
985
});