diff --git a/platform/commonUI/general/res/templates/subtree.html b/platform/commonUI/general/res/templates/subtree.html index d9d7481d59..1290d17f8a 100644 --- a/platform/commonUI/general/res/templates/subtree.html +++ b/platform/commonUI/general/res/templates/subtree.html @@ -19,6 +19,9 @@ this source code distribution or the Licensing information page available at runtime from the About dialog for additional information. --> - + diff --git a/platform/commonUI/general/src/directives/MCTTree.js b/platform/commonUI/general/src/directives/MCTTree.js index 3b08691125..cae72d497b 100644 --- a/platform/commonUI/general/src/directives/MCTTree.js +++ b/platform/commonUI/general/src/directives/MCTTree.js @@ -26,25 +26,54 @@ define([ ], function (angular, TreeView) { function MCTTree(gestureService) { function link(scope, element) { - var treeView = new TreeView(gestureService), - unobserve = treeView.observe(function (domainObject) { - if (scope.mctModel !== domainObject) { - scope.mctModel = domainObject; - scope.$apply(); - } - }); + if (!scope.allowSelection) { + scope.allowSelection = function () { + return true; + } + } + if (!scope.onSelection) { + scope.onSelection = function () {}; + } + var currentSelection = scope.selectedObject; + var treeView = new TreeView(gestureService); + + function setSelection(domainObject, event) { + if (currentSelection === domainObject) { + return; + } + if (!scope.allowSelection(domainObject)) { + treeView.value(currentSelection); + return; + } + currentSelection = domainObject; + scope.onSelection(domainObject); + scope.selectedObject = domainObject; + if (event && event instanceof MouseEvent) { + scope.$apply(); + } + } + + var unobserve = treeView.observe(setSelection); element.append(angular.element(treeView.elements())); - scope.$watch('mctModel', treeView.value.bind(treeView)); - scope.$watch('mctObject', treeView.model.bind(treeView)); + scope.$watch('selectedObject', function (object) { + currentSelection = object; + treeView.value(object); + }); + scope.$watch('rootObject', treeView.model.bind(treeView)); scope.$on('$destroy', unobserve); } return { restrict: "E", link: link, - scope: { mctObject: "=", mctModel: "=" } + scope: { + rootObject: "=", + selectedObject: "=", + onSelection: "=?", + allowSelection: "=?" + } }; } diff --git a/platform/commonUI/general/src/ui/TreeNodeView.js b/platform/commonUI/general/src/ui/TreeNodeView.js index 41430e5aa1..993316c4da 100644 --- a/platform/commonUI/general/src/ui/TreeNodeView.js +++ b/platform/commonUI/general/src/ui/TreeNodeView.js @@ -49,8 +49,8 @@ define([ this.labelView = new TreeLabelView(gestureService); - $(this.labelView.elements()).on('click', function () { - selectFn(this.activeObject); + $(this.labelView.elements()).on('click', function (event) { + selectFn(this.activeObject, event); }.bind(this)); this.li.append($(nodeTemplate)); diff --git a/platform/commonUI/general/src/ui/TreeView.js b/platform/commonUI/general/src/ui/TreeView.js index 92719d6113..f0cb0b16ad 100644 --- a/platform/commonUI/general/src/ui/TreeView.js +++ b/platform/commonUI/general/src/ui/TreeView.js @@ -109,11 +109,11 @@ define([ }.bind(this)); }; - TreeView.prototype.value = function (domainObject) { + TreeView.prototype.value = function (domainObject, event) { this.selectedObject = domainObject; this.updateNodeViewSelection(); this.callbacks.forEach(function (callback) { - callback(domainObject); + callback(domainObject, event); }); };