/* ************************************************************************ qooxdoo - the new era of web development http://qooxdoo.org Copyright: 2007 Derrell Lipman License: LGPL: http://www.gnu.org/licenses/lgpl.html EPL: http://www.eclipse.org/org/documents/epl-v10.php See the LICENSE file in the project's top-level directory for details. Authors: * Derrell Lipman (derrell) ************************************************************************ */ /* ************************************************************************ #module(treevirtual) #embed(qx.icontheme/16/status/folder-open.png) #embed(qx.icontheme/16/places/folder.png) #embed(qx.icontheme/16/actions/document-open.png) #embed(qx.icontheme/16/actions/document-new.png) #embed(qx.widgettheme/tree/*) #embed(qx.static/blank.gif) ************************************************************************ */ /** * A data cell renderer for the tree column of a simple tree */ qx.OO.defineClass("qx.ui.treevirtual.SimpleTreeDataCellRenderer", qx.ui.table.AbstractDataCellRenderer, function() { qx.ui.table.AbstractDataCellRenderer.call(this); // Base URL used for indent images var Am = qx.manager.object.AliasManager; this.WIDGET_TREE_URI = Am.getInstance().resolvePath("widget/tree/"); this.STATIC_IMAGE_URI = Am.getInstance().resolvePath("static/image/") }); /** * Set whether lines linking tree children shall be drawn on the tree. */ qx.OO.addProperty({ name : "useTreeLines", type : "boolean", defaultValue : true, getAlias : "useTreeLines" }); /* * When true, exclude only the first-level tree lines, creating, effectively, * multiple unrelated root nodes. */ qx.OO.addProperty({ name : "excludeFirstLevelTreeLines", type : "boolean", defaultValue : false }); /** * Set whether the open/close button should be displayed on a branch, even if * the branch has no children. */ qx.OO.addProperty({ name : "alwaysShowOpenCloseSymbol", type : "boolean", defaultValue : false }); // overridden qx.Proto._getCellStyle = function(cellInfo) { var node = cellInfo.value; // Return the style for the div for the cell. If there's cell-specific // style information provided, append it. var html = cellInfo.style + qx.ui.treevirtual.SimpleTreeDataCellRenderer.MAIN_DIV_STYLE + (node.cellStyle ? node.cellStyle + ";" : ""); return html; }; // overridden qx.Proto._getContentHtml = function(cellInfo) { var html = ""; var node = cellInfo.value; var imageUrl; var _this = this; var Stdcr = qx.ui.treevirtual.SimpleTreeDataCellRenderer; function addImage(urlAndToolTip) { var html = Stdcr.IMG_START; var Am = qx.manager.object.AliasManager; if (qx.core.Client.getInstance().isMshtml() && /\.png$/i.test(urlAndToolTip.url)) { html += this.STATIC_IMAGE_URI + "blank.gif" + '" style="filter:' + "progid:DXImageTransform.Microsoft.AlphaImageLoader(" + " src='" + Am.getInstance().resolvePath(urlAndToolTip.url) + "',sizingMethod='scale')"; } else { var imageUrl = Am.getInstance().resolvePath(urlAndToolTip.url); html += imageUrl + '" style="'; } if (urlAndToolTip.imageWidth && urlAndToolTip.imageHeight) { html += ';width:' + urlAndToolTip.imageWidth + 'px' + ';height:' + urlAndToolTip.imageHeight + 'px'; } var tooltip = urlAndToolTip.tooltip; if (tooltip != null) { html += Stdcr.IMG_TITLE_START + tooltip; } html += Stdcr.IMG_END; return html; } // Generate the indentation. Obtain icon determination values once rather // than each time through the loop. var bUseTreeLines = this.getUseTreeLines(); var bExcludeFirstLevelTreeLines = this.getExcludeFirstLevelTreeLines(); var bAlwaysShowOpenCloseSymbol = this.getAlwaysShowOpenCloseSymbol(); for (var i = 0; i < node.level; i++) { imageUrl = this._getIndentSymbol(i, node, bUseTreeLines, bAlwaysShowOpenCloseSymbol, bExcludeFirstLevelTreeLines); html += addImage({ url : imageUrl, imageWidth : 19, imageHeight : 16 }); } // Add the node's icon imageUrl = (node.bSelected ? node.iconSelected : node.icon); if (! imageUrl) { if (node.type == qx.ui.treevirtual.SimpleTreeDataModel.Type.LEAF) { imageUrl = (node.bSelected ? "icon/16/actions/document-open.png" : "icon/16/actions/document-new.png"); } else { imageUrl = (node.bSelected ? "icon/16/status/folder-open.png" : "icon/16/places/folder.png"); } } html += addImage({ url : imageUrl, imageWidth : 16, imageHeight : 16 }); // Add the node's label. We calculate the "left" property with: each tree // line (indentation) icon is 19 pixels wide; the folder icon is 16 pixels // wide, there are two pixels of padding at the left, and we want 2 pixels // between the folder icon and the label html += '