ExplorerUI.js 29.1 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 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 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 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 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 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 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 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 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 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 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 699 700 701 702 703 704 705 706 707 708 709 710 711 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 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 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 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083
/**
 * Project      : AMDA-NG4
 * Name         : ExplorerUI.js
 * @class   amdaUI.ExplorerUI 
 * @extends Ext.tab.Panel
 * @class   amdaUI.TreeToolColumn
 * @extends Ext.tree.Column
 * @class   MyTreeEditor
 * @extends Ext.grid.plugin.CellEditing
 * @brief   Explorer View
 * @author  CDA
 */

Ext.define('amdaUI.TreeToolColumn', {
	extend: 'Ext.tree.Column',
	alias: 'widget.treetoolcolumn',

	/**
	* Add more tools here.  These will be on the prototype for all TreeToolColumns
	*/
	tools: {
		'info': 'js/resources/images/16x16/info_mini.png'
	},

	initComponent: function()
	{
		var me = this;
		me.addEvents('toolclick');
		me.callParent();
		me.on('toolclick', me.toolHandler, me);
	},

	renderer: function(value, metaData, record, rowIdx, colIdx, store, view)
	{
		var toolCol = view.getHeaderAtIndex(colIdx);

		if (!toolCol.toolIsVisible(record)) return value;

		var toolId  = 'tool-' + rowIdx + '-' + colIdx,
			toolImg = toolCol.tools[toolCol.tool],
			imgHtml = Ext.DomHelper.markup({
					id      : toolId,
					tag     : 'img',
					tooltype: toolCol.tool,
					src     : toolImg,
					style   : 'cursor:hand;'
			});

		return value + ' ' + imgHtml;
	},

	processEvent: function(type, view, cell, recordIndex, cellIndex, e)
	{
		if(type === "click" && e.target.tagName === "IMG")
		{
			var tooltype = e.target.getAttribute("tooltype");
			if(tooltype)
					return this.fireEvent("toolclick", view, cell, recordIndex, cellIndex, e);
		}
		return this.fireEvent.apply(this, arguments);
	},

	/**
	* Override this when you add columns to the tree... see example below
	*/
//    toolHandler: function() {
//        alert("override this");
//    },

	toolIsVisible : function(record) {
		return false;
	}
});


// ExplorerUI
Ext.define('amdaUI.ExplorerUI', {
	extend: 'Ext.tab.Panel',
	alias : 'widget.panelExplorer',

	statics:
	{
		RESRC_TAB : {
			TREE_ID:'resourcesTree',
			TREE_TYPE:'resources'
		},
		OPE_TAB : {
			TREE_ID:'operationsTree',
			TREE_TYPE:'operations'
		},
		JOB_TAB : {
			TREE_ID:'jobsTree',
			TREE_TYPE:'jobs'
		},

		CAT_SUFFIX: '-treeBase',
		ROOT_SUFFIX: '-treeRootNode',
		SUB_ROOT_SUFFIX : 'RootNode',
		
		ITEM_KIND_BASE : 'base',
		ITEM_KIND_ROOT : 'root',
		ITEM_KIND_LEAF : 'leaf',
		ITEM_KIND_DIRE : 'dire',
		ITEM_KIND_PARA : 'para',
		ITEM_KIND_MISS : 'miss'
	},

	initComponent : function (config) 
	{
		var explorerModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.explorer.id);

		var myConf = {
			split	: true,
			width	: '100%',
			height      : '100%',
			autoScroll  : true,
			border      : true,
			header	: false,
			defaults	: {
				// applied to each contained panel
				containerScroll	: true
			},
			stateful: true,
			//stateId: 'tp1',
			stateEvents: ['tabchange'],
			getState: function() {
				return {
					activeTab: this.items.findIndex('id',this.getActiveTab().id)
				};
			},
			applyState: function(s) {
					this.setActiveTab(s.activeTab);
			},
			items: [
					this.initTree(amdaUI.ExplorerUI.RESRC_TAB.TREE_TYPE),
					this.initTree(amdaUI.ExplorerUI.OPE_TAB.TREE_TYPE),
					this.initTree(amdaUI.ExplorerUI.JOB_TAB.TREE_TYPE)
			],
			tbar : [
				{
					xtype : 'combo',
					fieldLabel: 'Filter',
					labelWidth: 25,
					width: 140,
					store: explorerModule.filtersStore,
					queryMode: 'local',
					displayField: 'name',
					valueField: 'id',
					listeners : {
						scope : this,
						select: function(combo, records) {
							AmdaAction.setCrtFilterId({id : records[0].get('id')},
									function (result, e)
									{
										var t = e.getTransaction();
										if (e.status)
										{
											if (result)
											{
												var explorerModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.explorer.id);
												if (explorerModule)
														explorerModule.setCrtFilter();
											}
											else
												Ext.Msg.show( {
														title : 'Filter',
														msg : 'Cannot apply filter',
														modal : true,
														icon : Ext.Msg.ERROR,
														buttons : Ext.Msg.OK
												});
										}
										else
										{
											// FAILURE
											Ext.Msg.show({title:'Error System', msg: e.message, icon: Ext.MessageBox.ERROR, buttons: Ext.Msg.OK});
										}
								},this);
							}
					}
				},
				{
					text: '',
					iconCls : 'icon-parameters',
					tooltip: { text: 'Edit Filter', align: 'bl-tl' },
					handler: function(t){
						myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.filters.id, true, function (module) {
							module.createWindow();
						});
					}
				},
				{
					text: '',
					iconCls : 'icon-remover',
					tooltip: { text: 'Reset Filter', align: 'bl-tl' },
					handler: function(t){
						var explorerModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.explorer.id);
						explorerModule.resetFilter();
					}
				}, '-',
				{
					xtype: 'displayfield',
					fieldLabel: 'SortBy',
					width: 40
				},
				{
					text: 'Name',
					scope : this,
					tooltip: { text: 'Sort out AMDA DataBase Data by Mission Name', align: 'bl-tl' },
					pressed: true,
					enableToggle : true,
					toggleGroup: 'sorting',
					handler: function(){
						var tree = Ext.getCmp(amdaUI.ExplorerUI.RESRC_TAB.TREE_ID);
						tree.getStore().sort([
								{  sorterFn: function(o1, o2){
										if (o1.get('nodeType') !== 'localParam' || o1.get('isParameter'))
											return;

										return o1.get('text').toUpperCase()  < o2.get('text').toUpperCase() ? -1 : 1;
									} 
								}]);
						this.updateFilter();
					}
				},
				{
					text: 'Target',
					scope : this,
					tooltip: {text: 'Sort out AMDA DataBase Data by Mission Main Target', align: 'bl-tl'},
					enableToggle : true,
					toggleGroup: 'sorting',
					handler: function(){
							var tree = Ext.getCmp(amdaUI.ExplorerUI.RESRC_TAB.TREE_ID);
							tree.getStore().sort('rank');
							this.updateFilter();
					}
				}]
		};
		Ext.apply (this , Ext.apply (arguments, myConf));
		this.callParent(arguments);
	},

	initTree : function(treeType)
	{
		switch (treeType) 
		{
			case amdaUI.ExplorerUI.RESRC_TAB.TREE_TYPE:
					treeId = amdaUI.ExplorerUI.RESRC_TAB.TREE_ID;
					break;
			case amdaUI.ExplorerUI.OPE_TAB.TREE_TYPE:
					treeId = amdaUI.ExplorerUI.OPE_TAB.TREE_ID;
					break;
			case amdaUI.ExplorerUI.JOB_TAB.TREE_TYPE:
					treeId = amdaUI.ExplorerUI.JOB_TAB.TREE_ID;
					break;
			default:
					treeId = amdaUI.ExplorerUI.RESRC_TAB.TREE_ID;
					break;
		}

		var store = Ext.create('Ext.data.TreeStore', {
			root: {
					expanded: true,
					nodeType : treeType
				},
			model: 'amdaModel.AmdaNode',
			sorters:[{ direction: 'ASC' ,
						sorterFn: function(o1, o2){
							
								if ((o1.get('nodeType') == 'localParam' && !o1.get('isParameter')) || o1.get('nodeType') == 'myData') {
									return o1.get('text').toUpperCase()  < o2.get('text').toUpperCase() ? -1 : 1;
								}
								
								return;
							} 
						}],
			listeners: {
				beforeload: function(store, operation){
					store.proxy.extraParams = {
							nodeType: operation.node.get('nodeType')
					};
				}
			}
		});

		var menu = new Ext.menu.Menu();

		var tree = Ext.create('Ext.tree.Panel', {
			id : treeId,
			title: treeType,
			store: store,
			rootVisible: false,
			animate: false,
			hideHeaders : true,
			selModel: Ext.create('Ext.selection.TreeModel', {
		//   	ignoreRightMouseSelection: true,
				mode: 'MULTI'
			}),
			viewConfig:
			{
				plugins:
				{
					ptype: 'treeviewdragdrop',
					enableDrag:true,
					enableDrop:true,
					//TODO - BRE - Wait a fix for drag&drop issue
					ddGroup:'explorerTree',
					pluginId : 'ddplugin',
					
					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;
						}
						else if (position != 'append' && targetNode.parentNode.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];
						//
						switch (targetNode.data.nodeType)
						{
							case 'localParam' :
							case 'remoteParam' :
							case 'remoteSimuParam' :
							case 'myData' :
                                                                                                                                            case 'sharedcatalog':
                                                                                                                                            case ' sharedtimeTable':
								return false;
							default :
								if (draggedRecord.data.id == targetNode.data.nodeType+'-treeRootNode')
									return false;
								if ((position == 'before') && (targetNode.data.id == targetNode.data.nodeType+'-treeRootNode'))
									return false;
								return (draggedRecord.data.nodeType == targetNode.data.nodeType);
						}
						return false;
					},
					onViewRender : function(view)
					{
						var me = this;

						view.on('itemupdate', function(record,index,node,opts)
						{
							var forceHide = false;
							var crtRec = record.parentNode;
							while (crtRec && !forceHide)
							{
								if (crtRec.get('filtered'))
										forceHide = crtRec.get('filtered');
								crtRec = crtRec.parentNode;
							}
							tree.setNodesVisibility(record,forceHide);
							tree.applyDisableToNode(record);
						});

						view.on('itemadd', function(records,index,node,opts)
						{
							Ext.each(records,function (rec)
							{
								tree.applyFilterToNode(rec);
								tree.applyDisableToNode(rec);
							});
						});

						view.on('afteritemexpand', function(record,index,node,opts)
						{
							var forceHide = false;
							var crtRec = record.parentNode;
							while (crtRec && !forceHide)
							{
								if (crtRec.get('filtered'))
											forceHide = crtRec.get('filtered');
								crtRec = crtRec.parentNode;

							}
							tree.setNodesVisibility(record,forceHide);
							tree.applyDisableToNode(record);
						});

						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
							});
						}
					}
				},
				listeners :
				{
					beforedrop : function(node, data, overModel, dropPosition)
					{
						var parentId;
						switch(dropPosition)
						{
							case 'append' :
									if (overModel.isLeaf())
										parentId = overModel.parentNode.get('id');
									else
										parentId = overModel.get('id');

										if(!overModel.isExpanded() && overModel.isExpandable()) {
													myDesktopApp.warningMsg('Please open the folder before node adding');
													return false;
										}
									break;
							case 'before' :
							case 'after' :
									parentId = overModel.parentNode.get('id');
									break;
						}

						Ext.each(data.records, function(rec)
						{
							rec.renameDD(parentId,function(result)
							{
								if (result)
								{
									if (!result.id)
									{
										Ext.Msg.show({
													title : 'Drop is impossible',
													msg : result.error,
													buttons : Ext.Msg.OK,
													icon : Ext.MessageBox.WARNING
										});

										return false;
									}
								}
								else
								{
									Ext.Msg.show({
														title : 'Drop is impossible',
														msg : 'Cannot connect to the server',
														buttons : Ext.Msg.OK,
														icon : Ext.MessageBox.WARNING
												});

									return false;
								}

								return true;
							});
						});
					}
				}
			},
			listeners: 
			{
				itemmouseenter: function(view, record, item){
					if(record.get('isParameter')){
						var el = Ext.get(item),
						td = el.down('td > div');
						td.setStyle('cursor', 'crosshair');
					}
					else
					{
						var el = Ext.get(item),
						td = el.down('td > div');
						td.setStyle('cursor', 'pointer');
					}
				},

				itemcontextmenu: function(view, rec, item, index, e){
					// Add record to selection model
					view.ownerCt.getSelectionModel().select(rec);

					// block other events
					e.stopEvent();

					// clear menu items
					menu.removeAll();
					var menuItems;

					// if it's a single selection
					if (view.ownerCt.getSelectionModel().selected.length === 1) {
						// get items menu corresponding to right clicked record
						menuItems = rec.getContextMenuItems(this);

					} else if (view.ownerCt.getSelectionModel().selected.length > 1) {
						// get items menu corresponding to right clicked record
						menuItems = rec.getContextMenuMultiItems(this);
					}
								// if there's at least one item menu
					if (menuItems && menuItems.length){
						// add the items
						menu.add(menuItems);
						// add listener on right clicked record
						var onRecordClick = function (menu, item, e, eOpts)
							{
								if (this.myGetOwnerTree().getSelectionModel().isSelected(this)) {
									//Dispatch click event to the record
									this.onMenuItemClick(menu,item,e);
								}
								//Remove old click listener
								menu.removeListener('click',onRecordClick,this);
							};

						menu.addListener('click',onRecordClick,rec);
						// then show menu
						menu.showAt(e.getXY());
					}
				},

				itemdblclick: function(view, record, item, index, event){
					event.stopEvent();
					// first check if it is for SAVE-START-STOP plugin...
					if (Ext.PluginManager.getCount() > 0 &&
						record.get('nodeType') == amdaModel.TimeTableNode.nodeType && record.isLeaf()) {
						var zmgr = myDesktopApp.desktop.getDesktopZIndexManager();
						var winActive = zmgr.getActive();
						var winId =  winActive.getId();
						if (winId == 'explorer-win') {
							zmgr.eachTopDown(function(win) {
								var id = win.getId();
								if (id !==  'explorer-win') {
									winId = id;
									return false;
								}
							});
						}
					}

					if (record.get('nodeType') == 'remoteParam' && !record.isLeaf()
										&& !record.get('isParameter')) {
						myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.interop.id, true, function (module) {
							module.createWindow(record.getBaseId());
						});
					}

					if (record.isLeaf() || record.data.isParameter)                                                                                                                                     
						switch (record.get('nodeType'))
						{
							case 'myData' :
							case 'myDataParam' :
							case 'derivedParam' :
							case 'timeTable' :
							case 'sharedtimeTable' :
							case 'sharedcatalog' :
							case 'catalog' :
							case 'request' :
							case 'condition' :
								record.editLeaf();
								break;
							case 'localParam' :
							case 'remoteParam':
							case 'remoteSimuParam':
								record.createPlot(record);
								break;
							case 'bkgWorks' :
								if (!record.get('object')) {
									AmdaAction.getObject(record.get('id'), record.get('nodeType'), record.getObjectCallback, record);
								}
								else {
									if (record.get('status') == 'done') {
										var isInteractive = false;
										var isNewTab = true;
										record.editNode(isNewTab, isInteractive);
									}
									else {
										myDesktopApp.infoMsg('Job Status: ' + record.get('status'));
									}
								}
								break;
						}
					},
					
					beforeselect: function(view,node,index,options){
						// if there's at least one node already selected
						if(view.selected.length
							//AND (the node which is beeing selected has a different nodeType than the first selected node OR the first selected node isn't a leaf
							&& ( node.get('nodeType')!== view.selected.items[0].get('nodeType') ||  !view.selected.items[0].isLeaf())
							// OR the node which is beeing selected has no nodeType OR it isn't a leaf OR
							|| !node.get('nodeType') || !node.isLeaf()
						){
							// clear old selection
							view.deselectAll();
						}
					},

					afterrender: function(comp){
						var view = comp.getView();
						view.tip = Ext.create('Ext.tip.ToolTip', {
							// The overall target element.
							target: view.el,
							// Each grid row causes its own seperate show and hide.
							delegate: view.itemSelector,
							dismissDelay : 0,
							//    showDelay: 100,
							//  anchor: 'left',
							// Moving within the row should not hide the tip.
							trackMouse: true,
							autoRender: true,
							listeners: {
								// Change content dynamically depending on which element triggered the show.
								beforeshow: function updateTipBody(tip) {
									if (view.getRecord(tip.triggerElement)) {
										var info = view.getRecord(tip.triggerElement).get('info');
										if (!info || info == '') {
											tip.addCls('hide');
										}
										else {
											tip.removeCls('hide');
											tip.update(info);
										}
									}
								}
							}
						});
					},
					// if remote base is empty - open interoperability module
					itemexpand: function(node) {
						if ( node.get('nodeType') == amdaModel.RemoteParamNode.nodeType
						&& node.getDepth() == 3 && !node.hasChildNodes()) {
							node.addData();
						}
					},
					scope: this
				},

				hideHeaders: true,
            // must define a column with a field to enable editor
				columns: [{
						xtype    : 'treetoolcolumn',
						text     : 'Name',
						flex     : 1,
						dataIndex: 'text',
						tool: 'info', // this references the "tools" object on the prototype
						toolHandler: function(view, cell, recordIndex, cellIndex, e) {
							var tooltype = e.target.getAttribute("tooltype");
							var record = view.store.getAt(recordIndex);
							switch (tooltype)
							{
							case 'info' :
								myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.info.id, true, function (module) {
									module.createWindow(record.get('help'), record.get('text'));
								});
								break;
							}
						},
						toolIsVisible : function(record) {

							switch (record.get('nodeType'))
							{
								case 'localParam' :
								case 'remoteParam' :
								case 'remoteSimuParam' :

								return record.get('help') != '';
							}
							return false;
						},
						field: {
							validFlag: true,
							listeners: {
								change : function( field, newValue, oldValue, eOpts )
								{
									var explModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.explorer.id);
									var explUI = explModule.getUiContent();
									var activeTreePanel = explUI.getActiveTab();

										var editedNode = activeTreePanel.getSelectionModel().selected.items[0];
										if (editedNode) {
											editedNode.isValidName(newValue, function (res) {
                        var validFlag = true;
                        if(newValue === amdaModel.AmdaNode.NEW_DIR_NAME) {
                          validFlag = 'Field is not modified'
                        } else if (!res) {
                          validFlag = 'Error during object validation';
												} else if (!res.valid) {
													if (res.error) {
                            validFlag = res.error;
													} else {
                            validFlag = 'Invalid object name';
													}
												}
                        if (validFlag !== true) {
                        	field.markInvalid(validFlag);
												}
                        field.validFlag = validFlag;
											});
										}
								}
							},
							scope: this
						}
					}],
					// Add our custom editor plugin
					plugins: [
						new MyTreeEditor({
							pluginId: 'treeEditor',
							listeners: {
								beforeedit: function (editor, e) {
									e.column.field.fireEvent('change', e.column.field, e.value, '');
								},
								validateedit: function (editor, e) {
									if (e.column.field.validFlag !== true) {
										if (e.record.deleteOnFailure) {
											e.record.remove(true);
										} else {
											return false;
										}
									}
									return true;
								}
							},
							scope: this
						})
					],

					setNodesVisibility : function(node,forceHide)
					{
						var isFiltered = node.get('filtered');

						for (var i = 0; i < node.childNodes.length; i++)
							this.setNodesVisibility(node.childNodes[i],forceHide || isFiltered);

						this.setNodeVisibility(node,!(forceHide || isFiltered));
					},

					setNodeVisibility : function(node,isVisible)
					{
						var record = store.getNodeById(node.internalId);
						var viewNode = Ext.fly(tree.getView().getNode(record));
						if (viewNode)
						{
							viewNode.setVisibilityMode(Ext.Element.DISPLAY);
							if (isVisible)
							{
								viewNode.show();
								this.applyDisableToNode(record);
							}
							else
								viewNode.hide();
						}
					},

					applyFilterToNode : function(node)
					{
						if (!node)
							return;

						var filter = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.explorer.id).filter;

						switch (node.get('nodeType'))
						{
							case 'localParam' :
								if (!filter || !filter['param'])
								{
									//no filter applied
									node.set('filtered',false);
									return;
								}
								var pos = node.get('depth') - 3; //depth from local param root node
								if (pos < 0 || pos > 2)
								{
									node.set('filtered',false);
									return;
								}
								var isFiltered = true;
								for (var i = 0; i < filter['param'].length; i++)
								{
									s = filter['param'][i].split(';');
									if (node.get('id') == s[pos])
									{
										isFiltered = false;
										break;
									}
								}
								node.set('filtered',isFiltered);
								break;
								
							case 'remoteSimuParam' :
								if (!filter || !filter['simu'] )
								{
									//no filter applied
									node.set('filtered',false);
									return;
								}
								var pos = node.get('depth') - 3; //depth from remote param root node

								if (pos < 0 || pos > 5)
								{
									node.set('filtered',false);
									return;
								}
								var isFiltered = true;

								for (var i = 0; i < filter['simu'].length; i++)
								{
									s = filter['simu'][i].split(';');

									if (node.get('id') == s[pos])
									{
										isFiltered = false;
										break;
									}
								}
								node.set('filtered',isFiltered);
								break;
							/*case 'alias' :
								if (!this.localParamFilter.result || this.localParamFilter.id == "" ||
									!node.isLeaf())
								{
									//no filter applied
									node.set('filtered',false);
									return;
								}
								var crtParam = node.get('id');
								crtParam = crtParam.replace('alias_','');
								crtParam = crtParam.replace(/_/g,':');
								var isFiltered = true;
								for (var i = 0; i < this.localParamFilter.result.length; i++)
								{
									s = this.localParamFilter.result[i].split(';');
									console.log(s[2]);
								if (crtParam == s[2])
								{
									isFiltered = false;
									break;
								}
								}
								node.set('filtered',isFiltered);
								break;*/
							default :
								return;
						}
					},

					applyFilterToNodes : function(node)
					{
						node.eachChild(function (child){
							tree.applyFilterToNodes(child);
						});
						tree.applyFilterToNode(node);
					},

					applyDisableToNode : function(node)
					{
						var crtNode = node;
						var disable = false;

						do
						{
							if (crtNode.get('disable'))
							{
								disable = true;
								break;
							}
							crtNode = crtNode.parentNode;
						} while (crtNode);


						var viewNode = Ext.fly(tree.getView().getNode(node));
						if (disable)
						{
							node.set('disable',true);
							viewNode.setStyle('opacity',0.5);
						}
					}
				});

				tree.addEvents('edition');

				return tree;
			},

			updateFilter : function()
			{
				var filter = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.explorer.id).filter;

				var keys = [];
				for (var f in filter) {
						if (hasOwnProperty.call(filter, f))
							keys.push(f);
				}

				var tree = this.query('#'+amdaUI.ExplorerUI.RESRC_TAB.TREE_ID)[0];
				tree.getView().refresh();

				for (var i = 0; i < keys.length; i++)
				{
					if (keys[i] == "_empty_")
						continue;

					switch (keys[i])
					{
						case 'param' :
								//apply filter to local datasets
								var localNode = tree.getRootNode().findChild('id','myLocalData-treeRootNode',true);
								tree.applyFilterToNodes(localNode);
								tree.setNodesVisibility(localNode,false);
								tree.applyDisableToNode(localNode);

								//apply filter to aliases
// 								var aliasNode = tree.getRootNode().findChild('id','alias-treeRootNode',true);
// 								tree.applyFilterToNodes(aliasNode);
// 								tree.setNodesVisibility(aliasNode,false);
// 								tree.applyDisableToNode(aliasNode);
								break;

						case 'simu' :
								//apply filter to simulation datasets (in remote data)
								var remoteNode = tree.getRootNode().findChild('id','myRemoteSimuData-treeRootNode',true);
								tree.applyFilterToNodes(remoteNode);
								tree.setNodesVisibility(remoteNode,false);
								tree.applyDisableToNode(remoteNode);
								break;
					}
				}

				this.dockedItems.getAt(1).items.items[0].select(filter['name']);
			}
});

// MyTreeEditor
Ext.define( 'MyTreeEditor', {
	extend: 'Ext.grid.plugin.CellEditing',
	alias: 'editing.treeeditor',

	// initialization method of plugin
	init: function(cmp) {
		var me = this;
		me.hostCmp = cmp;
		// on parent event
		me.hostCmp.on({
			// on edition event
			edition : {
					delay: 50,
					fn : function(view, record, item, index, e){
						// view.getHeaderAtIndex(0).field.validFlag = 'Not modified';
						// call the start edition method
						me.startEdit(record, view.getHeaderAtIndex(0));
					},
					scope: me
			}
		});
		me.callParent(arguments);
	},

	/**
	* Cancel any active editing.
	*/
	cancelEdit: function() {
		var me = this,
		activeEd = me.getActiveEditor(),
		viewEl = me.grid.getView().getEl(me.getActiveColumn());

		me.setActiveEditor(null);
		me.setActiveColumn(null);
		me.setActiveRecord(null);
		if (activeEd) {
			activeEd.cancelEdit();
			viewEl.focus();
			this.fireEvent('canceledit', activeEd, me.context);
		}
	},

	/**
	* overwrite the initEditTriggers to disable edition on click/dblclick
	* and to add custom
	*/
	initEditTriggers: function() 
	{
		var me = this,
		view = me.view;

		me.on({
			edit: function(editor,event){
					// if there is a modification
					if (event.originalValue !== event.value) {
						// delegate rename action on model
						event.record.rename(event.value,function(result){
							// if a result has been returned : success
							if(result) {
									// delegate commit action to delete modification flag
									event.record.commit();
									var rec = event.record.data;
									// in case of directory
									if (!rec.leaf){
										// set folder's ID returned by server
										rec.id = result.id;
									}
							} else { // in case of transaction error
									// reset originalValue
									event.record.value = event.originalValue;
									event.record.set('text', event.originalValue);
									event.record.commit();
							}
						});
					}
			}
		});

		// enable Enter key and Esc Key
		view.on('render', function() {
			me.keyNav = Ext.create('Ext.util.KeyNav', view.el, {
					enter: me.onEnterKey,
					esc: me.onEscKey,
					scope: me
			});
		}, me, { single: true });
	},
	//overwrite the getEditing context because we do not need the rowId
	getEditingContext: function(record, columnHeader) {
		var me = this,
		grid = me.grid,
		store = grid.store,
		colIdx,
		view = grid.getView(),
		value;

		// getting colIdx and real columnHeader
		if (Ext.isNumber(columnHeader)) {
			colIdx = columnHeader;
			columnHeader = grid.headerCt.getHeaderAtIndex(colIdx);
		} else {
			colIdx = columnHeader.getIndex();
		}
		// getting current value
		value = record.get(columnHeader.dataIndex);

		// return editing context
		return {
			grid: grid,
			record: record,
			field: columnHeader.dataIndex,
			value: value,
			column: columnHeader,
			colIdx: colIdx,
			view: columnHeader.getOwnerHeaderCt().view
		};
	}
});