InteractiveNode.js 27 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
/**
 * Project  : AMDA-NG4
 * Name     : InteractiveNode.js
 * @class   amdaModel.InteractiveNode
 * @extends amdaModel.AmdaNode
 * @brief   Generic Model of Interactive Node
 * @author  CDA
 * @version $Id: InteractiveNode.js 2683 2014-12-02 10:58:53Z elena $
 */

/* global amdaUI, AmdaAction, myDesktopApp, amdaPlotObj, amdaModel*/

Ext.define('amdaModel.InteractiveNode', {
  extend: 'amdaModel.AmdaNode',

  requires: ['amdaPlotObj.PlotRequestObject'],
  
  fields: [
    {
      name: 'contextNode',
      type: 'amdaModel.AmdaNode',
      persist: false
    },
    {
      name: 'objectDataModel',
      type: 'string',
      persist: false
    },
    {
      name: 'object',
      type: 'object',
      persist: false
    },
    {
      name: 'moduleId',
      type: 'string',
      persist: false
    },
    {
      name: 'filtered',
      type: 'boolean',
      defaultValue: false,
      persist: false
    },
    {
      name: 'disable',
      type: 'boolean',
      defaultValue: false,
      persist: false
    }
  ],

  statics: {
    preloadNodes: function (node, onready) {
      var nodesToLoad;

      nodesToLoad = [];
      nodesToLoad.push(node);
      this.preloadTreeNode(node, nodesToLoad, function () {
        var isFinish = true;
        nodesToLoad.forEach(function (element) {
          if (!element.isLoaded()) {
            isFinish = false;
          }
        });
        if (isFinish && onready) {
          onready.call();
        }
      });
    },

    preloadTreeNode: function (node, nodesToLoad, onloaded) {
      var me = this;

      if (node.isLoaded()) {
        node.eachChild(function (n) {
          if (!n.isLoaded() && !n.isLeaf()) {
            nodesToLoad.push(n);
            me.preloadTreeNode(n, nodesToLoad, onloaded);
          }
        });

        if (onloaded) {
          onloaded.call(me, node);
        }
        return;
      }

      node.store.load({
        node: node,
        callback: function (records) {
          records.forEach(function (record) {
            if (!record.isLoaded() && !record.isLeaf()) {
              nodesToLoad.push(record);
              me.preloadTreeNode(record, nodesToLoad, onloaded);
            }
          });
          if (onloaded) {
            onloaded.call(me, node);
          }
        }
      });
    }
  },

  onReady: null,

  constructor: function (config) {
    var suffix;
    this.callParent(arguments);
    this.set('nodeType', this.self.nodeType);
    this.set('ownerTreeId', amdaUI.ExplorerUI.RESRC_TAB.TREE_ID);
    // TODO why sometimes (delete in remote interoper tree) this.get('id') = undefined ?
    if (this.get('id')) {
      // If id of this node have root category suffix
      suffix = amdaUI.ExplorerUI.CAT_SUFFIX;
      if (Ext.util.Format.substr(this.get('id'), -suffix.length, this.get('id').length) === suffix) {
        // Set the expanded property to true
        this.set('expanded', true);
      }
    }
  },

  /**
   * This method is overriden into ExecutableNode to return true
   * @returns {boolean} true if node is executable
   */
  isExecutable: function () {
    return false;
  },

  /**
   * Open Module with THIS NODE
   * @param {object} contextNode Context node
   * @param {function} onReady onRady callback function
   * @returns {void}
   */
  editInModule: function (contextNode, onReady) {
    var me = this;
    // Set the contextNode of this node
    this.set('contextNode', contextNode);
    // Parameter module
    myDesktopApp.getLoadedModule(this.get('moduleId'), true, function (module) {
      // If the node to edit is not already linked to this module
      if (module.getLinkedNode() != me) {
        // Set relative node into parameter Module
        module.setLinkedNode(me);
        if (contextNode == null) {
          // Set the root node as contextNode
          contextNode = me.getRootNode();
        }
        module.setContextNode(contextNode);

      } else if (module.getLinkedNode() != null) {

        /*
         * TODO the node to edit is already edited
         * myDesktopApp.warningMsg('This object is  being edited');
         * Sol1: msg alert: "warning this node is already edited! If you want to get the original,
         *       please press the 'reset' button"->'OK'
         * Sol2: msg with user choice: "warning this node is already edited! Would you confirm this action and lost your
         *       modification?"->'Confirm','Cancel'
         */
      }
      // Opening parameter window
      module.createWindow(onReady);
    });
  },

  /**
   * Method to rename the workspace node
   * @param {string} value The new name
   * @param {function} callBackFn Callback function
   * @returns {void}
   */
  rename: function (value, callBackFn) {
    var dataToSend = {
      id: this.get('id'),
      old_name: this.modified.text,
      name: value,
      parent: this.data.parentId,
      leaf: this.isLeaf(),
      nodeType: this.get('nodeType')
    };
    AmdaAction.renameObject(dataToSend, callBackFn);
  },

  /**
   * Method to rename the workspace node when D&D
   * @param {string} parentId The parent ID
   * @param {function} callBackFn callback function
   * @returns {void}
   */
  renameDD: function (parentId, callBackFn) {
    var dataToSend = {
      id: this.get('id'),
      old_name: this.get('name'),
      name: this.get('name'),
      parent: parentId,
      leaf: this.isLeaf(),
      nodeType: this.get('nodeType')
    };
    AmdaAction.renameObject(dataToSend, callBackFn);
  },

  /**
   * Validation method on name (used in module forms)
   * @param {string} name the name to validate
   * @param {function} callBackFn Callback function
   * @returns {void}
   */
  isValidName: function (name, callBackFn) {
    var dataToSend = {
      name: name,
      nodeType: this.get('nodeType'),
      leaf: this.isLeaf()
    };
    AmdaAction.validNameObject(dataToSend, callBackFn);
  },

  /**
   * Method to persist modifications of an AmdaObject by Server side and update the workspace node linked to a Module
   * @param {object} opt ...
   * @returns {void}
   */
  update: function (opt) {
    AmdaAction.modifyObject(this.get('object').getJsonValues(true), function (res, e) {

      if (e.status) {
        if (res.id) {
          if (!this.get('contextNode')) {
            // Set the root node of 'Derived Parameters' tree as contextNode
            this.set('contextNode', this.getRootNode());
          }
          this.get('contextNode').expand(false, false);
          this.myGetOwnerTree().getSelectionModel().select(this);

          if (opt && opt.callback) {
            opt.callback.call(opt.scope ? opt.scope : this, 'update');
          }

          Ext.Msg.alert('Complete', 'Object ' + this.get('object').get('name') + ' has been modified');
          // Fix the modifications for object
          this.get('object').commit();

          if (res.info) {
            this.set('info', res.info);
          }

          if (this.get('nodeType') == 'myDataParam') {
            if (res.isSpectra) {
              this.set('iconCls', 'icon-spectra');
            } else if (res.size > 1) {
              this.set('iconCls', 'icon-unknowntype');
            }
          }

          // Update my data on possibble mask change
          if (res.updateMyData) {
            this.updateMyData();
            this.updateMask(res.mask);
          }
          // Reload object into the view of corresponding Module
          var me = this;
          myDesktopApp.getLoadedModule(this.get('moduleId'), true, function (module) {
            module.getUiContent().setObject(me.get('object'));
          });
        } else {

          /*
           *TODO proper error message handling
           * error code from server; but e.status==true
           * revert all modifications since last load or commit
           */
          this.get('object').reject();
          myDesktopApp.errorMsg(res.error);
        }
      } else {
        // Revert all modifications since last load or commit
        this.get('object').reject();
        myDesktopApp.errorMsg(e.message);
      }
    }, this);
  },

  /**
   * Method to create a new AmdaObject by server side and create the workspace node linked to a Module under its
   * contextNode or the root node corresponding to this nodeType category.
   * @param {object} opt ...
   * @returns {void}
   */
  create: function (opt) {
    var contextId;
    if (!this.get('contextNode') || this.get('contextNode').data.id == 'sharedtimeTable-treeRootNode' ||
        this.get('contextNode').data.id == 'sharedcatalog-treeRootNode') {
      // Set the root node of 'Derived Parameters' tree as contextNode
      this.set('contextNode', this.getRootNode());
    }
    // Call the Ext.Direct method to create parameter
    contextId = this.get('contextNode').get('id');
    AmdaAction.createObject(this.get('object').getJsonValues(false), contextId, function (res, e) {
      var myRoot, updateNode;
      // Success
      if (e.status) {
        // If correct response received
        if (res.id) {
          // If (res.id || res.error == 'NAME_EXISTS') {
          if (this.toRename) {
            // 'save as' case ; delete old node if it exists
            this.toRename = false;
            myRoot = this.getRootNode();
            // Search the same named node to override
            updateNode = myRoot.findChild('text', this.get('object').get('name'), true);
            // Destroy the overrided node
            updateNode.parentNode.removeChild(updateNode);
            // TODO ??if destroy==true => too many recursions....
            updateNode.destroy();
          }
          // Set text of this node
          this.set('text', this.get('object').get('name'));
          // Set id of this node
          this.set('id', res.id);
          this.internalId = res.id;
          // Set id of node's object
          this.get('object').set('id', res.id);

          if (res.created) {
            // Set the created date
            this.get('object').set('created', res.created);
          }

          if (res.info) {
            // Set the tooltip
            this.set('info', res.info);
            // Set globalStart & global Stop to be used for time selection
            if (this.get('nodeType') == 'myDataParam') {
              var startStop = res.info.split('<br/>');
              this.set('globalStart', startStop[1].substr(0, 19));
              this.set('globalStop', startStop[1].substr(20));

              if (res.mask) {
                this.set('linkedMask', res.mask);
              }
              if (res.size) {
                this.set('size', res.size);
              }

              if (res.isSpectra) {
                this.set('iconCls', 'icon-spectra');
              } else if (res.size > 1) {
                this.set('iconCls', 'icon-unknowntype');
              }
            }
          }

          /*
           *TODO do we need this commission ???
           * fix the modifications for object
           */
          this.get('object').commit();
          // If ownerTree panel is not active
          if (this.myGetOwnerTree().ownerCt.getActiveTab() !== this.myGetOwnerTree()) {
            // Set ownerTree panel as the active tab - to enable selection of this node his ownerTree must have a view
            this.myGetOwnerTree().ownerCt.setActiveTab(this.myGetOwnerTree());
          }

          Ext.Msg.alert('Complete', 'New object ' + this.get('object').get('name') + ' has been created');
          // Expand the contextNode
          this.get('contextNode').expand(false, function () {
            if (!this.get('contextNode').findChild('text', this.get('text'))) {
              // Create node in tree as child of contextNode
              this.get('contextNode').appendChild(this);
            }
            // Select the new node
            this.myGetOwnerTree().getSelectionModel().select(this);
            if (opt && opt.callback) {
              opt.callback.call(opt.scope ? opt.scope : this, 'create');
            }
          }, this);

          /*
           * MyDataParamNode - update MyData subtree
           *TODO put this in mydataparamnode
           */
          if (res.updateMyData) {
            this.updateMyData();
            this.updateMask(res.mask);
          }

        }
        // Error code from server; but e.status==true
        else {
          myDesktopApp.errorMsg(res.error);
          // Revert all modifications since last load or commit
          this.get('object').reject();
        }
      }
      // Failure: e.status == false
      else {
        // Revert all modifications since last load or commit
        this.get('object').reject();
        // TODO: this.destroy();
        myDesktopApp.errorMsg(e.message);
      }
    }, this);
  },

  /**
   * Generic part of Context Menu
   * @returns {*[]|*} Menu items
   */
  allMenuItems: function () {
    var menuItems, src;

    src = this.self.objectName;
    menuItems = [
      {
        fnId: 'root-createLeaf',
        text: 'Create ' + src
      },
      {
        fnId: 'root-createDir',
        text: 'Create Folder'
      },
      {
        fnId: 'dire-createLeaf',
        text: 'Create ' + src
      },
      {
        fnId: 'dire-createDir',
        text: 'Create Folder'
      },
      {
        fnId: 'dire-renameNode',
        text: 'Rename Folder'
      },
      {
        fnId: 'dire-deleteNode',
        text: 'Delete Folder'
      },
      {
        fnId: 'leaf-editLeaf',
        text: 'Edit ' + src
      },
      {
        fnId: 'leaf-renameNode',
        text: 'Rename ' + src
      },
      {
        fnId: 'leaf-deleteNode',
        text: 'Delete ' + src
      }
    ];
    return menuItems;
  },

  allMenuMultiItems: function () {
    return [
      {
        fnId: 'mult-deleteMulti',
        text: 'Delete selected ' + this.self.objectName + 's'
      }
    ];
  },

  getAllContextMenuItems: function () {
    return this.allMenuItems();
  },

  getMultiContextMenuItems: function () {
    return this.allMenuMultiItems();
  },

  // FIXME: duplicate declaration ↓ ↑

  /**
   * Default implementation: no menu display if there's no override of this function
   * @returns {null} Items
   */
  getMultiContextMenuItems: function () {
    return null;
  },

  /**
   * Context Menu Actions
   * @param {object} menu The menu
   * @param {object} item the item
   * @returns {void}
   */
  onMenuItemClick: function (menu, item) {
    // FnId parsing :
    var fnId = Ext.util.Format.substr(item.fnId, 5, item.fnId.length);

    switch (fnId) {
      case 'deleteNode':
        this.deleteNode();
        break;
      case 'createDir':
        this.createDir();
        break;
      case 'createLeaf':
        this.createLeaf(this);
        break;
      case 'renameNode':
        this.renameNode(false);
        break;
      case 'editLeaf':
        this.editLeaf();
        break;
      case 'deleteMulti':
        this.deleteMulti();
        break;
      case 'plotParam':
        this.createPlot(this);
        break;
      case 'downParam':
        this.createDownload(this);
        break;
      default:
        break;
    }
  },

  getTimeFromNode: function (node) {
    var startDate, stopDate, timeObj;
    startDate = new Date(String(node.get('globalStart')).replace(/-/g, '/').replace(/[T|Z]/g, ' '));
    stopDate = new Date(String(node.get('globalStop')).replace(/-/g, '/').replace(/[T|Z]/g, ' '));

    if (stopDate - startDate > 86400000) {
      // 'timeObj = {start: Ext.Date.format(startTime, 'Y/m/d H:i:s'), stop: Ext.Date.format(stopDate, 'Y/m/d H:i:s')};
      timeObj = {
        start: Ext.Date.format(Ext.Date.add(stopDate, Ext.Date.DAY, -1), 'Y/m/d'),
        stop: Ext.Date.format(stopDate, 'Y/m/d')
      };
    } else {
      timeObj = {
        start: node.get('globalStart'),
        stop: node.get('globalStop')
      };
    }
    return timeObj;
  },

  createPlot: function (node) {
    if (node.get('disable')) {
      return;
    }
    myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.plot.id, true, function (module) {
      if (!myDesktopApp.desktop.getWindow(myDesktopApp.dynamicModules.plot.id)) {
        var request = Ext.create(amdaPlotObj.PlotRequestObject.$className);
        var newNode = Ext.create(amdaModel.PlotNode.$className, {object: request});
        // Edit newNode into Plot Module with node as contextNode
        newNode.editInModule();
        if (node.get('globalStart') != null && node.get('globalStop') != null &&
            node.get('globalStart') != 'depending on mission' && node.get('isParameter')) {
          module.getUiContent().setTimeFromData(node.getTimeFromNode(node));
        }
      }
      module.getUiContent().addParameter(node);
    });
  },

  createDownload: function (node) {
    if (node.get('disable')) {
      return;
    }

    if (node.get('notyet')) {
      myDesktopApp.warningMsg('Sorry! access to this parameter is restricted.');
      return;
    }

    myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.download.id, true, function (module) {
      var paramName, request;
      if (!myDesktopApp.desktop.getWindow(myDesktopApp.dynamicModules.download.id)) {
        request = Ext.create(amdaModel.Download.$className);
        amdaModel.DownloadNode.set('object', request);
        // Singleton!
        amdaModel.DownloadNode.editInModule();
        if (node.get('globalStart') != null && node.get('globalStop') != null &&
            node.get('globalStart') != 'depending on mission' && node.get('isParameter')) {
          module.getUiContent().setTimeFromData(node.getTimeFromNode(node));
        }
      }
      switch (node.$className) {
        case 'amdaModel.AliasNode':
          paramName = '#' + node.get('text');
          break;
        case 'amdaModel.DerivedParamNode':
          paramName = 'ws_' + node.get('text');
          break;
        case 'amdaModel.MyDataParamNode':
          paramName = 'wsd_' + node.get('text');
          break;
        default:
          if (node.get('alias') != '') {
            paramName = '#' + node.get('alias');
          } else {
            paramName = node.get('id');
          }
      }

      /*
       * Var component_info = node.get('component_info');
       * If (component_info && component_info.parentId) {
       *   // It's a component
       *   ParamName = component_info.parentId;
       *   Components = [];
       *   If (component_info.index1)
       *     Components['index1'] = component_info.index1;
       *   If (component_info.index2)
       *     Components['index2'] = component_info.index2;
       * }
       */
      module.addParam(paramName, true, node.get('needsArgs'), null);
    });
  },

  deleteNode: function () {
    // If the target is a directory
    if (this.isLeaf()) {
      // No confirmation prompt for leaves
      this.confirmDirectoryDeletion(false);
    } else {
      // Determine if this directory is empty before launching the delete confirmation method
      this.isNotEmptyDir(this.confirmDirectoryDeletion);
      // Else (the target is a leaf)
    }
  },

  /**
   * This method return if node has Childs even if it was not already loaded
   * @param {function} callbackFn Callback function
   * @returns {void}
   */
  isNotEmptyDir: function (callbackFn) {
    // If node not already loaded
    if (this.isLoaded()) {
      callbackFn.call(this, this.hasChildNodes());
    } else {
      // Call directFunction to load this node
      AmdaAction.getTree({
        node: this.get('id'),
        nodeType: this.get('nodeType')
      }, function (res) {
        callbackFn.call(this, res.length > 0);
      }, this);
    }
  },

  /**
   * This method is used to display a confirmation message
   * @param {boolean} isNotEmptyDir true if the directory is not empty.
   * @returns {void}
   */
  confirmDirectoryDeletion: function (isNotEmptyDir) {
    var ConfirmMsg = 'The target is a non-empty directory!<br>Do you want to continue and also delete its content?';
    // If this is a non-empty directory
    if (isNotEmptyDir) {
      // Prompt to the user if he also wants to delete its content
      Ext.Msg.confirm('non-empty directory', ConfirmMsg, function (btn, text) {
        if (btn == 'yes') {
          // Do delete
          this.realDelete();
        }
      }, this);
    } else {
      this.realDelete();
    }
  },

  /*
   *    Call the extDirect method to delete parameter
   *    Callback method needed to execute node deletion in tree if id in result or to show error msg
   */
  realDelete: function () {
    AmdaAction.deleteObject({
      id: this.get('id'),
      leaf: this.isLeaf(),
      nodeType: this.get('nodeType')
    }, function (res, e) {
      var me, moduleId;
      me = this;

      // Node deletion in tree - TODO proper errors handling

      // If success
      if (res) {
        if (res.id) {

          /*
           * Ext.Msg.show({
           *   title:'Warning',
           *   msg: 'Requests with parameter '+node.data.text+' are deleted',
           *   icon: Ext.MessageBox.ERROR,
           *   buttons: Ext.Msg.OK
           * });
           */
          if (this.parentNode) {
            if (this.isLeaf()) {
              moduleId = this.get('moduleId');
              // If really interactive node
              if (moduleId) {
                myDesktopApp.getLoadedModule(moduleId, true, function (module) {
                  var editedNode, isThisFile, linkedNodes, newNode, tabPanel;
                  editedNode = module.getLinkedNode();
                  // File node is not linked directly to the module
                  isThisFile = false;

                  if (editedNode && editedNode.$className == 'amdaModel.MyDataParamNode') {
                    if (editedNode.get('fileObject').get('fileName') == me.get('text')) {
                      isThisFile = true;
                    }
                  }

                  if (me.$className == 'amdaModel.DerivedParamNode') {
                    AmdaAction.compilParamDelete({paramId: 'ws_' + me.get('text')});
                  }

                  if (editedNode === me || isThisFile) {
                    newNode = Ext.ModelManager.create({leaf: true}, me.$className);
                    // Several tabs could be connected to one node
                    if (moduleId === myDesktopApp.dynamicModules.plot.id) {
                      linkedNodes = module.linkedNodes;

                      if (linkedNodes) {
                        linkedNodes.each(function (key, value) {
                          if (value === me) {
                            linkedNodes.replace(key, newNode);
                            tabPanel = module.getUiContent().tabPanel.items.getByKey(key);
                            tabPanel.setObject(Ext.create(amdaModel.Plot.$className, {}));
                          }
                        }, me);
                      }
                    }
                    newNode.editInModule();
                  }
                });
              }
            }
            // Update mask info in myData
            if (res.maskDesc && !res.maskDeleted) {
              this.parentNode.set('info', res.maskDesc);
              this.updateMyDataParam(res.mask, res.maskDesc);
            }
            this.remove();
          }

          /*
           *TODO Several special node-dependent actions - to move to node functions..
           * nodes of another nodeType to be deleted as they depend on deleted node
           */
          if (res.params) {
            this.deleteDependence(res.params);
            // TODO reset
          }
          // Mask was deleted or updated - to update mydata tree
          if (res.maskDeleted) {
            this.updateMyData();
          }
        } else {
          myDesktopApp.warningMsg(res.error);
        }
      } else {
        myDesktopApp.errorMsg(e.message);
      }
    }, this);
  },

  /**
   * Delete multi selection
   * @returns {void}
   */
  deleteMulti: function () {
    var selection = this.myGetOwnerTree().getSelectionModel().selected.items;
    Ext.alert(selection.length + ' to delete!');
    Ext.Array.each(selection, function (item, index, allItems) {
      item.deleteNode();
    });
  },

  /**
   * Create Folder
   * @returns {void}
   */
  createDir: function () {
    var me = this;
    amdaModel.InteractiveNode.preloadNodes(this.getRootNode(), function () {
      var newNode = Ext.create(me.$className,
        {
          leaf: false,
          nodeType: me.get('nodeType'),
          text: amdaModel.AmdaNode.NEW_DIR_NAME,
          children: [],
          parentId: me.get('id')
        });

      // Insert the new node as a child of node
      me.insertChild(0, newNode);
      // Start text edition on this new directory node
      me.expand(false);
      newNode.expand(false);

      // Select the new node
      me.myGetOwnerTree().getSelectionModel().select(newNode);
      // Call the renameNode method for this new node
      newNode.renameNode(true);
    });
  },

  /*
   *
   */
  createLeaf: function (contextNode) {
    // Create new node with the same type than the contextNode
    var newNode = Ext.create(contextNode.$className, {leaf: true});

    // Load the rootNode and recursively all its child nodes
    amdaModel.InteractiveNode.preloadNodes(contextNode.getRootNode(), function () {
      // Edit newNode into Parameter Module with node as contextNode
      newNode.editInModule(contextNode);
    });
  },

  renameNode: function (deleteOnFailure) {
    var item, me;
    me = this;
    if (this.myGetOwnerTree()) {
      // Load the rootNode and recursively all its child nodes if not already loaded
      amdaModel.InteractiveNode.preloadNodes(this.getRootNode(), function () {
        // Fire the edition event on tree
        item = me.myGetOwnerTree().getSelectionModel().selected.items[0];
        item.deleteOnFailure = deleteOnFailure;
        me.myGetOwnerTree().fireEvent('edition', me.myGetOwnerTree().view, item);
      });
    } else {
      myDesktopApp.errorMsg('tree is undefined');
    }
  },

  /**
   * Load the rootNode and recursively all its child nodes to know all names of DerivedParameters
   * @param {function} onReady On ready callback function
   * @returns {void}
   */
  editLeaf: function (onReady) {
    var me = this;
    amdaModel.InteractiveNode.preloadNodes(this.getRootNode(), function () {
      if (me.get('object')) {
        // Launch edition of parameter into parameter module
        me.editInModule(null, onReady);
      } else {

        /*
         * Call the ext method to get the details of parameter
         * the edition of real parameter is done into callback method getObjectCallback
         */
        if (onReady) {
          me.onReady = onReady;
        }

        AmdaAction.getObject(me.get('id'), me.get('nodeType'), me.getObjectCallback, me);
      }
    });
  },

  /**
   * Get object callback
   * @param {object} result The result
   * @param {object} remoteEvent ...
   * @returns {void}
   */
  getObjectCallback: function (result, remoteEvent) {
    var t = remoteEvent.getTransaction();

    if (result) {
      var paramObj = Ext.create(this.get('objectDataModel'), result);
      // Set parameter into node
      this.set('object', paramObj);
      // Edition of parameter into parameter Module
      this.editInModule(null, this.onReady);
    } else {
      // EXCEPTION : parameter not found !?
      myDesktopApp.errorMsg(t.action + '.' + t.method + ' : No parameter \'' +
        this.get('name') + '\' found!');
    }
  }
});