| 1 |
// Copyright 2007 The Closure Library Authors. All Rights Reserved. |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
// you may not use this file except in compliance with the License. |
| 5 |
// You may obtain a copy of the License at |
| 6 |
// |
| 7 |
// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
// |
| 9 |
// Unless required by applicable law or agreed to in writing, software |
| 10 |
// distributed under the License is distributed on an "AS-IS" BASIS, |
| 11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
// See the License for the specific language governing permissions and |
| 13 |
// limitations under the License. |
| 14 |
|
| 15 |
/** |
| 16 |
* @fileoverview Definition of the goog.ui.tree.TreeNode class. |
| 17 |
* |
| 18 |
* @author [email protected] (Erik Arvidsson) |
| 19 |
* @author [email protected] (Emil A Eklund) |
| 20 |
* |
| 21 |
* This is a based on the webfx tree control. See file comment in |
| 22 |
* treecontrol.js. |
| 23 |
*/ |
| 24 |
|
| 25 |
goog.provide('goog.ui.tree.TreeNode'); |
| 26 |
|
| 27 |
goog.require('goog.ui.tree.BaseNode'); |
| 28 |
|
| 29 |
goog.forwardDeclare('goog.ui.tree.TreeControl'); // circular |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
/** |
| 34 |
* A single node in the tree. |
| 35 |
* @param {string|!goog.html.SafeHtml} content The content of the node label. |
| 36 |
* Strings are treated as plain-text and will be HTML escaped. |
| 37 |
* @param {Object=} opt_config The configuration for the tree. See |
| 38 |
* goog.ui.tree.TreeControl.defaultConfig. If not specified, a default config |
| 39 |
* will be used. |
| 40 |
* @param {goog.dom.DomHelper=} opt_domHelper Optional DOM helper. |
| 41 |
* @constructor |
| 42 |
* @extends {goog.ui.tree.BaseNode} |
| 43 |
*/ |
| 44 |
goog.ui.tree.TreeNode = function(content, opt_config, opt_domHelper) { |
| 45 |
goog.ui.tree.BaseNode.call(this, content, opt_config, opt_domHelper); |
| 46 |
}; |
| 47 |
goog.inherits(goog.ui.tree.TreeNode, goog.ui.tree.BaseNode); |
| 48 |
|
| 49 |
|
| 50 |
/** |
| 51 |
* Returns the tree. |
| 52 |
* @return {?goog.ui.tree.TreeControl} The tree. |
| 53 |
* @override |
| 54 |
*/ |
| 55 |
goog.ui.tree.TreeNode.prototype.getTree = function() { |
| 56 |
if (this.tree) { |
| 57 |
return this.tree; |
| 58 |
} |
| 59 |
var parent = this.getParent(); |
| 60 |
if (parent) { |
| 61 |
var tree = parent.getTree(); |
| 62 |
if (tree) { |
| 63 |
this.setTreeInternal(tree); |
| 64 |
return tree; |
| 65 |
} |
| 66 |
} |
| 67 |
return null; |
| 68 |
}; |
| 69 |
|
| 70 |
|
| 71 |
/** |
| 72 |
* Returns the source for the icon. |
| 73 |
* @return {string} Src for the icon. |
| 74 |
* @override |
| 75 |
*/ |
| 76 |
goog.ui.tree.TreeNode.prototype.getCalculatedIconClass = function() { |
| 77 |
var expanded = this.getExpanded(); |
| 78 |
var expandedIconClass = this.getExpandedIconClass(); |
| 79 |
if (expanded && expandedIconClass) { |
| 80 |
return expandedIconClass; |
| 81 |
} |
| 82 |
var iconClass = this.getIconClass(); |
| 83 |
if (!expanded && iconClass) { |
| 84 |
return iconClass; |
| 85 |
} |
| 86 |
|
| 87 |
// fall back on default icons |
| 88 |
var config = this.getConfig(); |
| 89 |
if (this.hasChildren()) { |
| 90 |
if (expanded && config.cssExpandedFolderIcon) { |
| 91 |
return config.cssTreeIcon + ' ' + config.cssExpandedFolderIcon; |
| 92 |
} else if (!expanded && config.cssCollapsedFolderIcon) { |
| 93 |
return config.cssTreeIcon + ' ' + config.cssCollapsedFolderIcon; |
| 94 |
} |
| 95 |
} else { |
| 96 |
if (config.cssFileIcon) { |
| 97 |
return config.cssTreeIcon + ' ' + config.cssFileIcon; |
| 98 |
} |
| 99 |
} |
| 100 |
return ''; |
| 101 |
}; |