From 626bb8efb0c825f332c937ffaaadc9b402079539 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Wed, 3 Jan 2007 20:17:37 +0000 Subject: r20517: re-add cleaned-up webapps (This used to be commit 5a3d6ad0b7cf0ecf8b57b4088b19f7d4291c990b) --- .../frontend/api/source/class/api/ClassViewer.js | 1589 ++++++++++++++++++++ .../frontend/api/source/class/api/InfoViewer.js | 35 + .../frontend/api/source/class/api/TreeUtil.js | 356 +++++ .../frontend/api/source/class/api/Viewer.js | 386 +++++ 4 files changed, 2366 insertions(+) create mode 100755 webapps/qooxdoo-0.6.3-sdk/frontend/api/source/class/api/ClassViewer.js create mode 100644 webapps/qooxdoo-0.6.3-sdk/frontend/api/source/class/api/InfoViewer.js create mode 100755 webapps/qooxdoo-0.6.3-sdk/frontend/api/source/class/api/TreeUtil.js create mode 100755 webapps/qooxdoo-0.6.3-sdk/frontend/api/source/class/api/Viewer.js (limited to 'webapps/qooxdoo-0.6.3-sdk/frontend/api/source/class') diff --git a/webapps/qooxdoo-0.6.3-sdk/frontend/api/source/class/api/ClassViewer.js b/webapps/qooxdoo-0.6.3-sdk/frontend/api/source/class/api/ClassViewer.js new file mode 100755 index 0000000000..20e110b117 --- /dev/null +++ b/webapps/qooxdoo-0.6.3-sdk/frontend/api/source/class/api/ClassViewer.js @@ -0,0 +1,1589 @@ +/* +#module(api) +*/ + +/** + * Shows the class details. + */ +qx.OO.defineClass("api.ClassViewer", qx.ui.embed.HtmlEmbed, +function() { + qx.ui.embed.HtmlEmbed.call(this); + + this.setOverflow("auto"); + this.setPadding(20); + this.setEdge(0); + this.setHtmlProperty("id", "ClassViewer"); + this.setVisibility(false); + + api.ClassViewer.instance = this; +}); + + +qx.Proto._fixLinks = function(el) +{ + var a = el.getElementsByTagName("a"); + for (var i=0; itrue + * when a item has details. + * @param addInheritedCheckBox {boolean} whether to add a "show inherited ..." + * checkbox. + * @param isOpen {boolean} whether the info panel is open by default. + * @return {string} the HTML for the info panel. + */ +qx.Proto._createInfoPanel = function(nodeType, listName, labelText, infoFactory, + hasDetailDecider, addInheritedCheckBox, isOpen) +{ + var uppercaseLabelText = labelText.charAt(0).toUpperCase() + labelText.substring(1); + + typeInfo = { listName:listName, labelText:labelText, infoFactory:infoFactory, + hasDetailDecider:hasDetailDecider, isOpen:isOpen, + hasInheritedCheckBox:addInheritedCheckBox } + this._infoPanelHash[nodeType] = typeInfo; + + var html = '

'; + + if (addInheritedCheckBox) { + html += '' + + ''; + } + + html += ' " + + '" + + uppercaseLabelText + + ''; + + html += '

'; + + return html; +} + + +/** + * Shows the information about a class. + * + * @param classNode {Map} the doc node of the class to show. + */ +qx.Proto.showClass = function(classNode) { + if (this._currentClassDocNode == classNode) { + // Nothing to do + return; + } + + this._currentClassDocNode = classNode; + + if (!this._titleElem) { + // _initContentDocument was not called yet + // -> Do nothing, the class will be shown in _initContentDocument. + return; + } + + var ClassViewer = api.ClassViewer; + + var titleHtml = ""; + + titleHtml += '
' + classNode.attributes.packageName + '
'; + + titleHtml += ''; + + if (classNode.attributes.isAbstract) { + titleHtml += "Abstract "; + } else if (classNode.attributes.isStatic) { + titleHtml += "Static "; + } + + titleHtml += "Class "; + titleHtml += ''; + titleHtml += classNode.attributes.name; + + this._titleElem.innerHTML = titleHtml; + + var classHtml = ""; + + // Add the class description + var ctorList = api.TreeUtil.getChild(classNode, "constructor"); + if (ctorList) { + var desc = this._createDescHtml(ctorList.children[0], classNode, true); + + if (desc != "") + { + classHtml += '
' + desc + '
'; + classHtml += "
"; + } + } + + // Create the class hierarchy + classHtml += ClassViewer.DIV_START_DETAIL_HEADLINE + "Inheritance hierarchy:" + ClassViewer.DIV_END; + + var classHierarchy = []; + var currClass = classNode; + while (currClass != null) { + classHierarchy.push(currClass); + currClass = this._getClassDocNode(currClass.attributes.superClass); + } + this._currentClassHierarchy = classHierarchy; + + // Add the class hierarchy + classHtml += ClassViewer.createImageHtml("api/class18.gif") + "Object
"; + var indent = 0; + for (var i = classHierarchy.length - 1; i >= 0; i--) { + classHtml += ClassViewer.createImageHtml("api/nextlevel.gif", null, "margin-left:" + indent + "px") + + ClassViewer.createImageHtml(api.TreeUtil.getIconUrl(classHierarchy[i])); + if (i != 0) { + classHtml += this._createItemLinkHtml(classHierarchy[i].attributes.fullName, null, false); + } else { + classHtml += classHierarchy[i].attributes.fullName; + } + classHtml += "
"; + indent += 18; + } + + classHtml += '
'; + + // Add child classes + if (classNode.attributes.childClasses) { + classHtml += ClassViewer.DIV_START_DETAIL_HEADLINE + "Direct subclasses:" + ClassViewer.DIV_END + + ClassViewer.DIV_START_DETAIL_TEXT; + + var classNameArr = classNode.attributes.childClasses.split(","); + for (var i = 0; i < classNameArr.length; i++) { + if (i != 0) { + classHtml += ", "; + } + classHtml += this._createItemLinkHtml(classNameArr[i], null, true, false); + } + + classHtml += ClassViewer.DIV_END; + classHtml += '
'; + } + + // Add @see attributes + if (ctorList) { + classHtml += this._createSeeAlsoHtml(ctorList.children[0], classNode); + classHtml += '
'; + } + + this._classDescElem.innerHTML = classHtml; + this._fixLinks(this._classDescElem); + + // Refresh the info viewers + for (var nodeType in this._infoPanelHash) { + this._updateInfoPanel(parseInt(nodeType)); + } + + // Scroll to top + this.getElement().scrollTop = 0; +} + +qx.Proto.showInfo = function(classNode) { + if (this._currentClassDocNode == classNode) { + // Nothing to do + return; + } + + this._currentClassDocNode = classNode; + + if (!this._titleElem) { + // _initContentDocument was not called yet + // -> Do nothing, the class will be shown in _initContentDocument. + return; + } + + var ClassViewer = api.ClassViewer; + + this._titleElem.innerHTML = "Info View"; + this._classDescElem.innerHTML = ""; + + // Scroll to top + this.getElement().scrollTop = 0; +} + +/** + * Highlights an item (property, method or constant) and scrolls it visible. + * + * @param itemName {string} the name of the item to highlight. + */ +qx.Proto.showItem = function(itemName) { + var itemNode = api.TreeUtil.getItemDocNode(this._currentClassDocNode, itemName); + if (! itemNode) { + alert("Item '" + itemName + "' not found"); + } + + var nodeType = this._getTypeForItemNode(itemNode); + var elem = this._getItemElement(nodeType, itemNode.attributes.name).parentNode.parentNode; + + // Handle mark + if (this._markedElement) { + this._markedElement.className = ""; + } + + elem.className = "marked"; + this._markedElement = elem; + + // Scroll the element visible + var top = qx.dom.Location.getPageBoxTop(elem); + var height = elem.offsetHeight; + + var doc = this.getElement(); + var scrollTop = doc.scrollTop; + var clientHeight = doc.offsetHeight; + + if (scrollTop > top) { + doc.scrollTop = top; + } else if (scrollTop < top + height - clientHeight) { + doc.scrollTop = top + height - clientHeight; + } +} + + +/** + * Updates an info panel. + * + * @param nodeType {int} the node type of which to update the info panel. + */ +qx.Proto._updateInfoPanel = function(nodeType) { + var ClassViewer = api.ClassViewer; + + var typeInfo = this._infoPanelHash[nodeType]; + + // Get the nodes to show + var nodeArr = null; + var fromClassHash = null; + if (typeInfo.isOpen && this._currentClassDocNode) { + if (typeInfo.showInherited) { + nodeArr = []; + fromClassArr = []; + fromClassHash = {}; + var currClassNode = this._currentClassDocNode; + while (currClassNode != null) { + var currParentNode = api.TreeUtil.getChild(currClassNode, typeInfo.listName); + var currNodeArr = currParentNode ? currParentNode.children : null; + if (currNodeArr) { + // Add the nodes from this class + for (var i = 0; i < currNodeArr.length; i++) { + var name = currNodeArr[i].attributes.name; + if (fromClassHash[name] == null) { + fromClassHash[name] = currClassNode; + nodeArr.push(currNodeArr[i]); + } + } + } + + var superClassName = currClassNode.attributes.superClass; + currClassNode = superClassName ? this._getClassDocNode(superClassName) : null; + } + + // Sort the nodeArr by name + nodeArr.sort(function(obj1, obj2) { + return (obj1.attributes.name.toLowerCase() < obj2.attributes.name.toLowerCase()) ? -1 : 1; + }); + } else { + var parentNode = api.TreeUtil.getChild(this._currentClassDocNode, typeInfo.listName); + nodeArr = parentNode ? parentNode.children : null; + } + } + + // Show the nodes + if (nodeArr && nodeArr.length != 0) + { + var html = ''; + + for (var i = 0; i < nodeArr.length; i++) + { + var node = nodeArr[i]; + var fromClassNode = fromClassHash ? fromClassHash[node.attributes.name] : null; + if (fromClassNode == null) { + fromClassNode = this._currentClassDocNode; + } + + var info = typeInfo.infoFactory.call(this, node, nodeType, fromClassNode, false); + var inherited = fromClassNode && (fromClassNode != this._currentClassDocNode); + var iconUrl = api.TreeUtil.getIconUrl(node, inherited); + + // Create the title row + html += ''; + + html += ''; + html += ''; + + html += ''; + + html += ''; + html += ''; + } + + html += '
' + ClassViewer.createImageHtml(iconUrl) + '' + ((info.typeHtml.length != 0) ? (info.typeHtml + " ") : "") + ''; + if (typeInfo.hasDetailDecider.call(this, node, nodeType, fromClassNode)) + { + // This node has details -> Show the detail button + html += '"; + } + else + { + html += " "; + } + html += ''; + + // Create headline + html += '"; + } + else + { + html += '>'; + } + + html += info.titleHtml; + html += ''; + + // Create content area + html += '
'; + html += info.textHtml; + html += '
'; + + html += '
'; + + typeInfo.infoBodyElem.innerHTML = html; + this._fixLinks(typeInfo.infoBodyElem); + typeInfo.infoBodyElem.style.display = ""; + } + else + { + if (typeInfo.isOpen) + { + typeInfo.infoBodyElem.innerHTML = '
This class has no ' + typeInfo.labelText + '
'; + typeInfo.infoBodyElem.style.display = ""; + } + else + { + typeInfo.infoBodyElem.style.display = "none"; + } + } +} + + +/** + * Event handler. Called when the user clicked a button for showing/hiding the + * details of an item. + * + * @param nodeType {int} the node type of the item to show/hide the details. + * @param name {string} the name of the item. + * @param fromClassName {string} the name of the class the item the item was + * defined in. + */ +qx.Proto._onShowItemDetailClicked = function(nodeType, name, fromClassName) { + try { + var typeInfo = this._infoPanelHash[nodeType]; + var textDiv = this._getItemElement(nodeType, name); + + if (!textDiv) { + throw Error("Element for name '" + name + "' not found!"); + } + + var showDetails = textDiv._showDetails ? !textDiv._showDetails : true; + textDiv._showDetails = showDetails; + + var fromClassNode = this._currentClassDocNode; + if (fromClassName) { + fromClassNode = this._getClassDocNode(fromClassName); + } + + var listNode = api.TreeUtil.getChild(fromClassNode, typeInfo.listName); + var node; + if (nodeType == api.ClassViewer.NODE_TYPE_CONSTRUCTOR) { + node = listNode.children[0]; + } else { + node = api.TreeUtil.getChildByAttribute(listNode, "name", name); + } + + // Update the close/open image + var opencloseImgElem = textDiv.parentNode.previousSibling.firstChild; + opencloseImgElem.src = qx.manager.object.AliasManager.getInstance().resolvePath(showDetails ? 'api/close.gif' : 'api/open.gif'); + + // Update content + var info = typeInfo.infoFactory.call(this, node, nodeType, fromClassNode, showDetails); + textDiv.innerHTML = info.textHtml; + this._fixLinks(textDiv); + } catch (exc) { + this.error("Toggling item details failed", exc); + } +} + + +/** + * Event handler. Called when the user clicked on a "show inherited ..." + * checkbox. + * + * @param nodeType {int} the node type of which the inherited-checkbox was + * clicked. + */ +qx.Proto._onInheritedCheckBoxClick = function(nodeType) { + try { + var typeInfo = this._infoPanelHash[nodeType]; + var checkboxElem = typeInfo.infoTitleElem.getElementsByTagName("input")[0]; + + typeInfo.showInherited = checkboxElem.checked; + + this._updateInfoPanel(nodeType); + } catch (exc) { + this.error("Handling inherited checkbox click failed", exc); + } +} + + +/** + * Event handler. Called when the user clicked a button for showing/hiding the + * body of an info panel. + * + * @param nodeType {int} the node type of which the show/hide-body-button was + * clicked. + */ +qx.Proto._onShowInfoPanelBodyClicked = function(nodeType) { + try { + var typeInfo = this._infoPanelHash[nodeType]; + typeInfo.isOpen = !typeInfo.isOpen; + + var imgElem = typeInfo.infoTitleElem.getElementsByTagName("img")[0]; + imgElem.src = qx.manager.object.AliasManager.getInstance().resolvePath(typeInfo.isOpen ? 'api/close.gif' : 'api/open.gif'); + + this._updateInfoPanel(nodeType); + } catch (exc) { + this.error("Toggling info body failed", exc); + } +} + + +/** + * Gets the HTML element showing the details of an item. + * + * @param nodeType {int} the node type of the item. + * @param name {string} the item's name. + * @return {Element} the HTML element showing the details of the item. + */ +qx.Proto._getItemElement = function(nodeType, name) { + var typeInfo = this._infoPanelHash[nodeType]; + var elemArr = typeInfo.infoBodyElem.getElementsByTagName("TBODY")[0].childNodes; + + for (var i = 0; i < elemArr.length; i++) { + // ARRG, should be implemented in a more fault-tolerant way + // iterate over tr's, look inside the third "td" and there the second element + if (elemArr[i].childNodes[3].childNodes[1].getAttribute("_itemName") == name) { + return elemArr[i].childNodes[3].childNodes[1]; + } + } +} + + +/** + * Selects an item. + * + * @param itemName {string} the name of the item. + * @see ApiViewer#selectItem + */ +qx.Proto._selectItem = function(itemName) { + try { + api.Viewer.instance.selectItem(itemName); + qx.ui.core.Widget.flushGlobalQueues(); + } catch (exc) { + this.error("Selecting item '" + itemName + "' failed", exc); + } +} + + +/** + * Gets the doc node of a class. + * + * @param className {string} the name of the class. + * @return {Map} the doc node of the class. + */ +qx.Proto._getClassDocNode = function(className) { + if (className) { + return api.TreeUtil.getClassDocNode(api.Viewer.instance.getDocTree(), className); + } else { + return null; + } +} + + +/** + * Creates the HTML showing the information about a property. + * + * @param node {Map} the doc node of the property. + * @param nodeType {int} the node type of the property. + * @param fromClassNode {Map} the doc node of the class the property was defined. + * @param showDetails {boolean} whether to show the details. + * @return {string} the HTML showing the information about the property. + */ +qx.Proto._createPropertyInfo = function(node, nodeType, fromClassNode, showDetails) { + var ClassViewer = api.ClassViewer; + + var info = {} + + var typeInfo = this._infoPanelHash[nodeType]; + + // Get the property node that holds the documentation + var docClassNode = fromClassNode; + var docNode = node; + if (node.attributes.docFrom) { + docClassNode = this._getClassDocNode(node.attributes.docFrom); + var listNode = api.TreeUtil.getChild(docClassNode, typeInfo.listName); + docNode = api.TreeUtil.getChildByAttribute(listNode, "name", node.attributes.name); + } + + // Add the title + info.typeHtml = this._createTypeHtml(node, fromClassNode, "var"); + info.titleHtml = node.attributes.name; + + // Add the description + info.textHtml = this._createDescHtml(docNode, fromClassNode, showDetails); + + if (showDetails) { + // Add allowed values + var allowedValue = null; + if (node.attributes.possibleValues) { + allowedValue = node.attributes.possibleValues; + } else if (node.attributes.classname) { + allowedValue = "instances of " + node.attributes.classname; + } else if (node.attributes.instance) { + allowedValue = "instances of " + node.attributes.instance + " or sub classes"; + } else if (node.attributes.unitDetection) { + allowedValue = "units: " + node.attributes.unitDetection; + } else if (node.attributes.type) { + allowedValue = "any " + node.attributes.type; + } + + if (allowedValue) { + info.textHtml += ClassViewer.DIV_START_DETAIL_HEADLINE + "Allowed values:" + ClassViewer.DIV_END + + ClassViewer.DIV_START_DETAIL_TEXT; + + if (node.attributes.allowNull != "false") { + info.textHtml += "null, "; + } + info.textHtml += allowedValue + ClassViewer.DIV_END; + } + + // Add default value + info.textHtml += ClassViewer.DIV_START_DETAIL_HEADLINE + "Default value:" + ClassViewer.DIV_END + + ClassViewer.DIV_START_DETAIL_TEXT + + (node.attributes.defaultValue ? node.attributes.defaultValue : "null") + + ClassViewer.DIV_END; + + // Add get alias + if (node.attributes.getAlias) { + info.textHtml += ClassViewer.DIV_START_DETAIL_HEADLINE + "Get alias:" + ClassViewer.DIV_END + + ClassViewer.DIV_START_DETAIL_TEXT + node.attributes.getAlias + ClassViewer.DIV_END; + } + + // Add set alias + if (node.attributes.setAlias) { + info.textHtml += ClassViewer.DIV_START_DETAIL_HEADLINE + "Set alias:" + ClassViewer.DIV_END + + ClassViewer.DIV_START_DETAIL_TEXT + node.attributes.setAlias + ClassViewer.DIV_END; + } + + // Add inherited from or overridden from + if (fromClassNode && fromClassNode != this._currentClassDocNode) { + info.textHtml += ClassViewer.DIV_START_DETAIL_HEADLINE + "Inherited from:" + ClassViewer.DIV_END + + ClassViewer.DIV_START_DETAIL_TEXT + + this._createItemLinkHtml(fromClassNode.attributes.fullName) + + ClassViewer.DIV_END; + } else if (node.attributes.overriddenFrom) { + info.textHtml += ClassViewer.DIV_START_DETAIL_HEADLINE + "Overridden from:" + ClassViewer.DIV_END + + ClassViewer.DIV_START_DETAIL_TEXT + + this._createItemLinkHtml(node.attributes.overriddenFrom) + + ClassViewer.DIV_END; + } + + // Add @see attributes + info.textHtml += this._createSeeAlsoHtml(docNode, docClassNode); + + // Add documentation errors + info.textHtml += this._createErrorHtml(docNode, docClassNode); + } + + return info; +} + + +/** + * Checks whether an event has details. + * + * @param node {Map} the doc node of the event. + * @param nodeType {int} the node type of the event. + * @param fromClassNode {Map} the doc node of the class the event was defined. + * @return {boolean} whether the event has details. + */ +qx.Proto._eventHasDetails = function(node, nodeType, fromClassNode) { + return (fromClassNode != this._currentClassDocNode) // event is inherited + || this._hasSeeAlsoHtml(node) + || this._hasErrorHtml(node) + || this._descHasDetails(node); +}; + + +/** + * Creates the HTML showing the information about an event. + * + * @param node {Map} the doc node of the event. + * @param nodeType {int} the node type of the event. + * @param fromClassNode {Map} the doc node of the class the event was defined. + * @param showDetails {boolean} whether to show the details. + * @return {string} the HTML showing the information about the event. + */ +qx.Proto._createEventInfo = function(node, nodeType, fromClassNode, showDetails) { + var ClassViewer = api.ClassViewer; + + var info = {} + + var typeInfo = this._infoPanelHash[nodeType]; + + // Add the title + info.typeHtml = this._createTypeHtml(node, fromClassNode, "var"); + info.titleHtml = node.attributes.name; + + // Add the description + info.textHtml = this._createDescHtml(node, fromClassNode, showDetails); + + if (showDetails) { + // Add inherited from or overridden from + if (fromClassNode && fromClassNode != this._currentClassDocNode) { + info.textHtml += ClassViewer.DIV_START_DETAIL_HEADLINE + "Inherited from:" + ClassViewer.DIV_END + + ClassViewer.DIV_START_DETAIL_TEXT + + this._createItemLinkHtml(fromClassNode.attributes.fullName) + + ClassViewer.DIV_END; + } + + // Add @see attributes + info.textHtml += this._createSeeAlsoHtml(node, fromClassNode); + + // Add documentation errors + info.textHtml += this._createErrorHtml(node, fromClassNode); + } + + return info; +}; + + +/** + * Checks whether a method has details. + * + * @param node {Map} the doc node of the method. + * @param nodeType {int} the node type of the method. + * @param fromClassNode {Map} the doc node of the class the method was defined. + * @return {boolean} whether the method has details. + */ +qx.Proto._methodHasDetails = function(node, nodeType, fromClassNode) { + var TreeUtil = api.TreeUtil; + + var typeInfo = this._infoPanelHash[nodeType]; + + // Get the method node that holds the documentation + var docClassNode = fromClassNode; + var docNode = node; + if (node.attributes.docFrom) { + docClassNode = this._getClassDocNode(node.attributes.docFrom); + var listNode = TreeUtil.getChild(docClassNode, typeInfo.listName); + docNode = TreeUtil.getChildByAttribute(listNode, "name", node.attributes.name); + } + + // Check whether there are details + var hasParams = TreeUtil.getChild(docNode, "params") != null; + var hasReturn = TreeUtil.getChild(docNode, "return") != null; + var isOverridden = fromClassNode != this._currentClassDocNode; + + return (fromClassNode != this._currentClassDocNode) // method is inherited + || (node.attributes.overriddenFrom != null) // method is overridden + || (TreeUtil.getChild(docNode, "params") != null) // method has params + || (TreeUtil.getChild(docNode, "return") != null) // method has return value + || this._hasSeeAlsoHtml(docNode) + || this._hasErrorHtml(docNode) + || this._descHasDetails(docNode); +} + + +/** + * Creates the HTML showing the information about a method. + * + * @param node {Map} the doc node of the method. + * @param nodeType {int} the node type of the method. + * @param fromClassNode {Map} the doc node of the class the method was defined. + * @param showDetails {boolean} whether to show the details. + * @return {string} the HTML showing the information about the method. + */ +qx.Proto._createMethodInfo = function(node, nodeType, fromClassNode, showDetails) { + var ClassViewer = api.ClassViewer; + var TreeUtil = api.TreeUtil; + + var info = {} + + var typeInfo = this._infoPanelHash[nodeType]; + + // Get the method node that holds the documentation + var docClassNode = fromClassNode; + var docNode = node; + if (node.attributes.docFrom) { + docClassNode = this._getClassDocNode(node.attributes.docFrom); + var listNode = TreeUtil.getChild(docClassNode, typeInfo.listName); + docNode = TreeUtil.getChildByAttribute(listNode, "name", node.attributes.name); + } + + if (node.attributes.isAbstract) { + info.typeHtml = "abstract "; + } else { + info.typeHtml = ""; + } + + // Get name, icon and return type + var returnNode = TreeUtil.getChild(docNode, "return"); + if (node.attributes.isCtor) { + info.titleHtml = fromClassNode.attributes.name; + } else { + info.titleHtml = node.attributes.name; + info.typeHtml += this._createTypeHtml(returnNode, fromClassNode, "void"); + } + + // Add the title (the method signature) + info.titleHtml += ' ('; + var paramsNode = TreeUtil.getChild(docNode, "params"); + if (paramsNode) { + for (var i = 0; i < paramsNode.children.length; i++) { + var param = paramsNode.children[i]; + if (i != 0) { + info.titleHtml += ', '; + } + info.titleHtml += '' + this._createTypeHtml(param, fromClassNode, "var") + " " + + param.attributes.name; + if (param.attributes.defaultValue) { + info.titleHtml += "?"; + } + } + } + info.titleHtml += ')'; + + // Add the description + if (node.attributes.isCtor) { + info.textHtml = "Creates a new instance of " + fromClassNode.attributes.name + "."; + } else { + info.textHtml = this._createDescHtml(docNode, docClassNode, showDetails); + } + + + if (showDetails) { + // Add Parameters + var paramsNode = TreeUtil.getChild(docNode, "params"); + if (paramsNode) { + info.textHtml += ClassViewer.DIV_START_DETAIL_HEADLINE + "Parameters:" + ClassViewer.DIV_END; + for (var i = 0; i < paramsNode.children.length; i++) { + var param = paramsNode.children[i]; + var paramType = param.attributes.type ? param.attributes.type : "var"; + var dims = param.attributes.arrayDimensions; + if (dims) { + for (var i = 0; i < dims; i++) { + paramType += "[]"; + } + } + var defaultValue = param.attributes.defaultValue; + + info.textHtml += ClassViewer.DIV_START_DETAIL_TEXT; + if (defaultValue) { + info.textHtml += ClassViewer.SPAN_START_OPTIONAL; + } + info.textHtml += ClassViewer.SPAN_START_PARAM_NAME + param.attributes.name + ClassViewer.SPAN_END; + if (defaultValue) { + info.textHtml += " (default: " + defaultValue + ") " + ClassViewer.SPAN_END; + } + + var paramDescNode = TreeUtil.getChild(param, "desc"); + if (paramDescNode) { + info.textHtml += " " + this._createDescriptionHtml(paramDescNode.attributes.text, docClassNode); + } + info.textHtml += ClassViewer.DIV_END; + } + } + + // Add return value + if (returnNode) { + var returnDescNode = TreeUtil.getChild(returnNode, "desc"); + if (returnDescNode) { + info.textHtml += ClassViewer.DIV_START_DETAIL_HEADLINE + "Returns:" + ClassViewer.DIV_END + + ClassViewer.DIV_START_DETAIL_TEXT + + this._createDescriptionHtml(returnDescNode.attributes.text, docClassNode) + + ClassViewer.DIV_END; + } + } + + // Add inherited from or overridden from + if (fromClassNode && fromClassNode != this._currentClassDocNode) { + info.textHtml += ClassViewer.DIV_START_DETAIL_HEADLINE + "Inherited from:" + ClassViewer.DIV_END + + ClassViewer.DIV_START_DETAIL_TEXT + + this._createItemLinkHtml(fromClassNode.attributes.fullName) + + ClassViewer.DIV_END; + } else if (node.attributes.overriddenFrom) { + info.textHtml += ClassViewer.DIV_START_DETAIL_HEADLINE + "Overridden from:" + ClassViewer.DIV_END + + ClassViewer.DIV_START_DETAIL_TEXT + + this._createItemLinkHtml(node.attributes.overriddenFrom) + + ClassViewer.DIV_END; + } + + // Add @see attributes + info.textHtml += this._createSeeAlsoHtml(docNode, docClassNode); + + // Add documentation errors + info.textHtml += this._createErrorHtml(docNode, docClassNode); + } + + return info; +} + + +/** + * Checks whether a constant has details. + * + * @param node {Map} the doc node of the constant. + * @param nodeType {int} the node type of the constant. + * @param fromClassNode {Map} the doc node of the class the constant was defined. + * @return {boolean} whether the constant has details. + */ +qx.Proto._constantHasDetails = function(node, nodeType, fromClassNode) { + return this._hasSeeAlsoHtml(node) || this._hasErrorHtml(node) || this._descHasDetails(node); +} + + +/** + * Creates the HTML showing the information about a constant. + * + * @param node {Map} the doc node of the constant. + * @param nodeType {int} the node type of the constant. + * @param fromClassNode {Map} the doc node of the class the constant was defined. + * @param showDetails {boolean} whether to show the details. + * @return {string} the HTML showing the information about the constant. + */ +qx.Proto._createConstantInfo = function(node, nodeType, fromClassNode, showDetails) { + var info = {} + + // Add the title + info.typeHtml = this._createTypeHtml(node, fromClassNode, "var"); + info.titleHtml = node.attributes.name; + + // Add the description + info.textHtml = this._createDescHtml(node, fromClassNode, showDetails); + + if (showDetails) { + // Add @see attributes + info.textHtml += this._createSeeAlsoHtml(node, fromClassNode); + + // Add documentation errors + info.textHtml += this._createErrorHtml(node, fromClassNode); + } + + return info; +} + + +/** + * Returns whether the description of an item has details (has more than one + * sentence). + * + * @param node {Map} the doc node of the item. + * @return {boolean} whether the description of an item has details. + */ +qx.Proto._descHasDetails = function(node) { + var descNode = api.TreeUtil.getChild(node, "desc"); + if (descNode) { + var desc = descNode.attributes.text; + return this._extractFirstSentence(desc) != desc; + } else { + return false; + } +} + + +/** + * Creates the HTML showing the description of an item. + * + * @param node {Map} the doc node of the item. + * @param fromClassNode {Map} the doc node of the class the item was defined. + * @param showDetails {boolean} whether to show details. If false + * only the first sentence of the description will be shown. + * @return {string} the HTML showing the description. + */ +qx.Proto._createDescHtml = function(node, fromClassNode, showDetails) { + var descNode = api.TreeUtil.getChild(node, "desc"); + if (descNode) { + var desc = descNode.attributes.text; + if (!showDetails) { + desc = this._extractFirstSentence(desc); + } + return api.ClassViewer.DIV_START_DESC + + this._createDescriptionHtml(desc, fromClassNode) + + api.ClassViewer.DIV_END; + } else { + return ""; + } +} + + +/** + * Extracts the first sentence from a text. + * + * @param text {string} the text. + * @return {string} the first sentence from the text. + */ +qx.Proto._extractFirstSentence = function(text) +{ + var ret = text; + + // Extract first block + var pos = ret.indexOf("

"); + if (pos != -1) + { + ret = ret.substr(0, pos+4); + + var hit = api.ClassViewer.SENTENCE_END_REGEX.exec(ret); + if (hit != null) { + ret = text.substring(0, hit.index + hit[0].length - 1) + "

"; + } + } + + return ret; +} + + +/** + * Checks whether a item has @see attributes. + * + * @param node {Map} the doc node of the item. + * @return {boolean} whether the item has @see attributes. + */ +qx.Proto._hasSeeAlsoHtml = function(node) { + var TreeUtil = api.TreeUtil; + + var descNode = TreeUtil.getChild(node, "desc"); + if (descNode) { + var attributesNode = TreeUtil.getChild(descNode, "attributes"); + if (attributesNode) { + var seeAttribNode = TreeUtil.getChildByAttribute(attributesNode, "name", "see"); + if (seeAttribNode) { + return true; + } + } + } + + // There is no @see attribute + return false; +} + + +/** + * Creates the HTML showing the @see attributes of an item. + * + * @param node {Map} the doc node of the item. + * @param fromClassNode {Map} the doc node of the class the item was defined. + * @return {string} the HTML showing the @see attributes. + */ +qx.Proto._createSeeAlsoHtml = function(node, fromClassNode) { + var ClassViewer = api.ClassViewer; + + var descNode = api.TreeUtil.getChild(node, "desc"); + if (descNode) { + var attributesNode = api.TreeUtil.getChild(descNode, "attributes"); + if (attributesNode) { + var seeAlsoHtml = ""; + for (var i = 0; i < attributesNode.children.length; i++) { + var attribNode = attributesNode.children[i]; + if (attribNode.attributes.name == "see") { + // This is a @see attribute + if (seeAlsoHtml.length != 0) { + seeAlsoHtml += ", "; + } + seeAlsoHtml += this._createItemLinkHtml(attribNode.attributes.text, fromClassNode); + } + } + + if (seeAlsoHtml.length != 0) { + // We had @see attributes + return ClassViewer.DIV_START_DETAIL_HEADLINE + "See also:" + ClassViewer.DIV_END + + ClassViewer.DIV_START_DETAIL_TEXT + seeAlsoHtml + ClassViewer.DIV_END; + } + } + } + + // Nothing found + return ""; +} + + +/** + * Checks whether a item has documentation errors. + * + * @param node {Map} the doc node of the item. + * @return {boolean} whether the item has documentation errors. + */ +qx.Proto._hasErrorHtml = function(node) { + var errorNode = api.TreeUtil.getChild(node, "errors"); + return (errorNode != null); +} + + +/** + * Creates the HTML showing the documentation errors of an item. + * + * @param node {Map} the doc node of the item. + * @param fromClassNode {Map} the doc node of the class the item was defined. + * @return {string} the HTML showing the documentation errors. + */ +qx.Proto._createErrorHtml = function(node, fromClassNode) { + var ClassViewer = api.ClassViewer; + + var errorNode = api.TreeUtil.getChild(node, "errors"); + if (errorNode) { + var html = ClassViewer.DIV_START_ERROR_HEADLINE + "Documentation errors:" + ClassViewer.DIV_END; + var errArr = errorNode.children; + for (var i = 0; i < errArr.length; i++) { + html += ClassViewer.DIV_START_DETAIL_TEXT + errArr[i].attributes.msg + "
"; + html += "(" + if (fromClassNode && fromClassNode != this._currentClassDocNode) { + html += fromClassNode.attributes.fullName + "; "; + } + html += "Line: " + errArr[i].attributes.line + ", Column:" + errArr[i].attributes.column + ")" + ClassViewer.DIV_END; + } + return html; + } else { + return ""; + } +} + + +/** + * Creates the HTML showing the type of a doc node. + * + * @param typeNode {Map} the doc node to show the type for. + * @param packageBaseClass {Map} the doc node of the class typeNode + * belongs to. + * @param defaultType {string} the type name to use if typeNode is + * null or defines no type. + * @param useShortName {boolean,true} whether to use short class names + * (without package). + * @return {string} the HTML showing the type. + */ +qx.Proto._createTypeHtml = function(typeNode, packageBaseClass, defaultType, useShortName) { + if (useShortName == null) { + useShortName = true; + } + + var types = []; + var typeHtml, typeDimensions, typeName, linkText, dims; + + if (typeNode) + { + // read in children + if (typeNode.children && api.TreeUtil.getChild(typeNode, "types")) + { + for (var i=0, a=api.TreeUtil.getChild(typeNode, "types").children, l=a.length; i 0) { + types.push({ "type" : typeName, "dimensions" : dims }); + } else { + types.push({ "type" : typeName }); + } + } + } + } + + if (types.length == 0) + { + typeHtml = defaultType; + } + else + { + typeHtml = ""; + + if (types.length > 1) { + typeHtml += "(" + } + + for (var j=0; j0) { + typeHtml += " | "; + } + + typeName = types[j].type; + typeDimensions = types[j].dimensions; + + if (api.ClassViewer.PRIMITIVES[typeName]) + { + typeHtml += typeName; + } + else + { + linkText = typeName; + if (useShortName) + { + var lastDot = typeName.lastIndexOf("."); + if (lastDot != -1) { + linkText += " " + typeName.substring(lastDot + 1); + } + } + typeHtml += this._createItemLinkHtml(linkText, packageBaseClass, false, true); + } + + if (typeDimensions) + { + for (var i = 0; i < parseInt(typeDimensions); i++) { + typeHtml += "[]"; + } + } + } + + if (types.length > 1) { + typeHtml += ")" + } + } + + return typeHtml; +} + + +/** + * Creates HTML that replaces all @link-attributes with links. + * + * @param description {string} the description. + * @param packageBaseClass {Map,null} the doc node of the class to use for + * auto-adding packages. + */ +qx.Proto._createDescriptionHtml = function(description, packageBaseClass) { + var linkRegex = /\{@link([^\}]*)\}/mg; + + var html = ""; + var hit; + var lastPos = 0; + while ((hit = linkRegex.exec(description)) != null) { + // Add the text before the link + html += description.substring(lastPos, hit.index) + + this._createItemLinkHtml(hit[1], packageBaseClass); + + lastPos = hit.index + hit[0].length; + } + + // Add the text after the last hit + html += description.substring(lastPos, description.length); + + return html; +} + + +/** + * Creates the HTML for a link to an item. + * + * @param linkText {string} the link text + * (e.g. "mypackage.MyClass#myMethod alt text") + * @param packageBaseClass {Map,null} the doc node of the class to use when + * auto-adding the package to a class name having no package specified. + * If null, no automatic package addition is done. + * @param useIcon {boolean,true} whether to add an icon to the link. + * @param useShortName {boolean,false} whether to use the short name. + */ +qx.Proto._createItemLinkHtml = function(linkText, packageBaseClass, useIcon, + useShortName) +{ + if (useIcon == null) { + useIcon = true; + } + + linkText = qx.lang.String.trim(linkText); + + if (linkText.charAt(0) == '"' || linkText.charAt(0) == '<') { + // This is a String or a link to a URL -> Just use it as it is + return linkText; + } else { + // This is a link to another class or method -> Create an item link + + // Separate item name from label + var hit = api.ClassViewer.ITEM_SPEC_REGEX.exec(linkText); + if (hit == null) { + // Malformed item name + return linkText; + } else { + var className = hit[2]; + var itemName = hit[3]; + var label = hit[6]; + + // Make the item name absolute + if (className == null || className.length == 0) { + // This is a relative link to a method -> Add the current class + className = packageBaseClass.attributes.fullName; + } else if (packageBaseClass && className.indexOf(".") == -1) { + // The class name has no package -> Use the same package as the current class + var name = packageBaseClass.attributes.name; + var fullName = packageBaseClass.attributes.fullName; + var packageName = fullName.substring(0, fullName.length - name.length); + className = packageName + className; + } + + // Get the node info + if (label == null || label.length == 0) { + // We have no label -> Use the item name as label + label = hit[1]; + } + + // Add the right icon + if (useIcon) { + var classNode = this._getClassDocNode(className); + if (classNode) { + var itemNode; + if (itemName) { + // The links points to a item of the class + var cleanItemName = itemName.substring(1); + var parenPos = cleanItemName.indexOf("("); + if (parenPos != -1) { + cleanItemName = qx.lang.String.trim(cleanItemName.substring(0, parenPos)); + } + itemNode = api.TreeUtil.getItemDocNode(classNode, cleanItemName); + } else { + // The links points to the class + itemNode = classNode; + } + if (itemNode) { + var iconUrl = api.TreeUtil.getIconUrl(itemNode); + var iconCode = api.ClassViewer.createImageHtml(iconUrl); + } + } + } + + // Create a real bookmarkable link + // NOTE: The onclick-handler must be added by HTML code. If it + // is added using the DOM element then the href is followed. + var fullItemName = className + (itemName ? itemName : ""); + return (typeof iconCode != "undefined" ? iconCode : "") + + '' + label + ''; + } + } +} + + +/** + * Gets the node type for a doc node. + * + * @param itemNode {Map} the doc node of the item. + * @return {int} the item's node type. + */ +qx.Proto._getTypeForItemNode = function(itemNode) { + var ClassViewer = api.ClassViewer; + + if (itemNode.type == "constant") { + return ClassViewer.NODE_TYPE_CONSTANT; + } else if (itemNode.type == "property") { + return ClassViewer.NODE_TYPE_PROPERTY; + } else if (itemNode.type == "event") { + return ClassViewer.NODE_TYPE_EVENT; + } else if (itemNode.type == "method") { + var name = itemNode.attributes.name; + if (name == null) { + return ClassViewer.NODE_TYPE_CONSTRUCTOR; + } else if (name.charAt(0) == "_") { + if (itemNode.attributes.isStatic) { + return ClassViewer.NODE_TYPE_METHOD_STATIC_PROTECTED; + } else { + return ClassViewer.NODE_TYPE_METHOD_PROTECTED; + } + } else { + if (itemNode.attributes.isStatic) { + return ClassViewer.NODE_TYPE_METHOD_STATIC_PUBLIC; + } else { + return ClassViewer.NODE_TYPE_METHOD_PUBLIC; + } + } + } +} + + +// overridden +qx.Proto.dispose = function() { + if (this.getDisposed()) { + return; + } + + this._titleElem = null; + this._classDescElem = null; + this._markedElement = null; + + for (var nodeType in this._infoPanelHash) { + this._infoPanelHash[nodeType].infoElem = null; + this._infoPanelHash[nodeType].infoTitleElem = null; + this._infoPanelHash[nodeType].infoBodyElem = null; + } + + document._detailViewer = null; + + return qx.ui.embed.HtmlEmbed.prototype.dispose.call(this); +} + + +/** {Map} The primitive types. These types will not be shown with links. */ +qx.Class.PRIMITIVES = { "boolean":true, "string":true, "float":true, + "number":true, "int":true, "double":true, "var":true, "void":true, + "RegExp":true, "Array":true, "Map":true, "Date":true, "Element":true, + "Node":true, "Function":true, "Object":true, "Event":true }; + +/** + * {regexp} The regexp for parsing a item name + * (e.g. "mypackage.MyClass#MY_CONSTANT alternative text"). + */ +qx.Class.ITEM_SPEC_REGEX = /^(([\w\.]+)?(#\w+(\([^\)]*\))?)?)(\s+(.*))?$/; + +/** {regexp} The regexp that finds the end of a sentence. */ +qx.Class.SENTENCE_END_REGEX = /[^\.].\.(\s|<)/; + + +/** {int} The node type of a constructor. */ +qx.Class.NODE_TYPE_CONSTRUCTOR = 1; +/** {int} The node type of a property. */ +qx.Class.NODE_TYPE_PROPERTY = 2; +/** {int} The node type of an event. */ +qx.Class.NODE_TYPE_EVENT = 3; +/** {int} The node type of a public method. */ +qx.Class.NODE_TYPE_METHOD_PUBLIC = 4; +/** {int} The node type of a protected method. */ +qx.Class.NODE_TYPE_METHOD_PROTECTED = 5; +/** {int} The node type of a static public method. */ +qx.Class.NODE_TYPE_METHOD_STATIC_PUBLIC = 6; +/** {int} The node type of a static protected method. */ +qx.Class.NODE_TYPE_METHOD_STATIC_PROTECTED = 7; +/** {int} The node type of a constant. */ +qx.Class.NODE_TYPE_CONSTANT = 8; + +/** {string} The start tag of a div. */ +qx.Class.DIV_START = '
'; +/** {string} The start tag of a div containing an item description. */ +qx.Class.DIV_START_DESC = '
'; +/** {string} The start tag of a div containing the headline of an item detail. */ +qx.Class.DIV_START_DETAIL_HEADLINE = '
'; +/** {string} The start tag of a div containing the text of an item detail. */ +qx.Class.DIV_START_DETAIL_TEXT = '
'; +/** {string} The start tag of a div containing the headline of an item error. */ +qx.Class.DIV_START_ERROR_HEADLINE = '
'; +/** {string} The end tag of a div. */ +qx.Class.DIV_END = '
'; + +/** {string} The start tag of a span containing an optional detail. */ +qx.Class.SPAN_START_OPTIONAL = ''; +/** {string} The start tag of a span containing a parameter name. */ +qx.Class.SPAN_START_PARAM_NAME = ''; +/** {string} The end tag of a span. */ +qx.Class.SPAN_END = ''; + + +/** + * Creates the HTML showing an image. + * + * @param imgUrl {var} the URL of the image. May be a string or an array of + * strings (for overlay images). + * @param tooltip {string} the tooltip to show. + * @param styleAttributes {string} the style attributes to add to the image. + */ +qx.Class.createImageHtml = function(imgUrl, tooltip, styleAttributes) { + if (typeof imgUrl == "string") { + return ''; + } else { + if (styleAttributes) { + styleAttributes += ";vertical-align:top"; + } else { + styleAttributes = "vertical-align:top"; + } + return api.ClassViewer.createOverlayImageHtml(18, 18, imgUrl, tooltip, styleAttributes); + } +} + + +/** + * Creates HTML that shows an overlay image (several images on top of each other). + * The resulting HTML will behave inline. + * + * @param width {int} the width of the images. + * @param height {int} the height of the images. + * @param imgUrlArr {string[]} the URLs of the images. The last image will be + * painted on top. + * @param toolTip {string,null} the tooltip of the icon. + * @param styleAttributes {string,null} custom CSS style attributes. + * @return {string} the HTML with the overlay image. + */ +qx.Class.createOverlayImageHtml + = function(width, height, imgUrlArr, toolTip, styleAttributes) +{ + var html = '
'; + + for (var i = 0; i < imgUrlArr.length; i++) { + html += ''; + } + + html += '
'; + + /* + // NOTE: See testOverlay.html + var html = '' + + '
'; + for (var i = 0; i < imgUrlArr.length; i++) { + html += ''; + } + html += '
'; + */ + + return html; +} \ No newline at end of file diff --git a/webapps/qooxdoo-0.6.3-sdk/frontend/api/source/class/api/InfoViewer.js b/webapps/qooxdoo-0.6.3-sdk/frontend/api/source/class/api/InfoViewer.js new file mode 100644 index 0000000000..f65d1e82b1 --- /dev/null +++ b/webapps/qooxdoo-0.6.3-sdk/frontend/api/source/class/api/InfoViewer.js @@ -0,0 +1,35 @@ +/* +#module(api) +*/ + +/** + * Shows the class details. + */ +qx.OO.defineClass("api.InfoViewer", qx.ui.embed.HtmlEmbed, +function() { + qx.ui.embed.HtmlEmbed.call(this); + + this.setOverflow("auto"); + this.setPadding(20); + this.setEdge(0); + this.setHtmlProperty("id", "InfoViewer"); + this.setVisibility(false); + + api.InfoViewer.instance = this; +}); + +qx.Proto.showInfo = function(classNode) +{ + var vHtml = ""; + + // Title + vHtml += '

'; + vHtml += '
package
'; + vHtml += classNode.attributes.fullName; + vHtml += '

'; + + // TODO: Overview of classes in this package + + // Apply HTML + this.setHtml(vHtml); +} diff --git a/webapps/qooxdoo-0.6.3-sdk/frontend/api/source/class/api/TreeUtil.js b/webapps/qooxdoo-0.6.3-sdk/frontend/api/source/class/api/TreeUtil.js new file mode 100755 index 0000000000..bb90bfd6ef --- /dev/null +++ b/webapps/qooxdoo-0.6.3-sdk/frontend/api/source/class/api/TreeUtil.js @@ -0,0 +1,356 @@ +/* +#module(api) +*/ + +/** + * A util class for handling the documentation tree. + */ +qx.OO.defineClass("api.TreeUtil", qx.core.Object, +function () { + qx.core.Object.call(this); +}); + + +/** + * Gets the child of a doc node having a certain type. + * + * @param docNode {Map} the doc node to get the child of. + * @param childType {string} the type of the child to get. + * @return {Map} the wanted child or null if docNode + * is null or has no such child. + */ +qx.Class.getChild = function(docNode, childType) { + if (docNode != null && docNode.children != null) { + for (var i = 0; i < docNode.children.length; i++) { + if (docNode.children[i].type == childType) { + return docNode.children[i]; + } + } + } + + return null; +} + + +/** + * Gets the child of a doc node having a certain attribute value. + * + * @param docNode {Map} the doc node to get the child of. + * @param attributeName {string} the name of the attribute the wanted child must have. + * @param attributeValue {string} the value of the attribute the wanted child must have. + * @return {Map} the wanted child or code if there is no such child. + */ +qx.Class.getChildByAttribute = function(docNode, attributeName, attributeValue) { + if (docNode.children != null) { + for (var i = 0; i < docNode.children.length; i++) { + var node = docNode.children[i]; + if (node.attributes && node.attributes[attributeName] == attributeValue) { + return node; + } + } + } + + return null; +} + + +/** + * Searches the doc node of a item. Only use this method if you don't know the + * type of the item. + * + * @param classNode {Map} the class node the item belongs to. + * @param itemName {string} the name of the item to search. + * @return {Map} the doc node of the item or null if the class has + * no such item. + */ +qx.Class.getItemDocNode = function(classNode, itemName) { + var TreeUtil = api.TreeUtil; + + // Go through the item lists and check whether one contains the wanted item + for (var i = 0; i < TreeUtil.ITEM_LIST_ARR.length; i++) { + var listNode = TreeUtil.getChild(classNode, TreeUtil.ITEM_LIST_ARR[i]); + if (listNode) { + var itemNode = TreeUtil.getChildByAttribute(listNode, "name", itemName); + if (itemNode) { + return itemNode; + } + } + } + + // Nothing found + return null; +} + + +/** + * Gets the doc node of a class. + * + * @param docTree {Map} the documentation tree. + * @param className {string} the name of the class. + * @return {Map} the doc node of the class. + */ +qx.Class.getClassDocNode = function(docTree, className) { + var splits = className.split("."); + var currNode = docTree; + for (var i = 0; i < splits.length && currNode != null; i++) { + if (i < splits.length - 1) { + // The current name is a package name + var packages = this.getChild(currNode, "packages"); + currNode = packages ? this.getChildByAttribute(packages, "name", splits[i]) : null; + } else { + // The current name is a class name + var classes = this.getChild(currNode, "classes"); + currNode = classes ? this.getChildByAttribute(classes, "name", splits[i]) : null; + } + } + + return currNode; +} + + +/** + * Gets the icon URL of a doc node. + * + * @param node {Map} the node to get the icon for. + * @param inherited {boolean,false} whether the node was inherited. + * @return {var} the URL of the icon. May be a string or an array of string + * (in case of an overlay icon). + */ +qx.Class.getIconUrl = function(node, inherited) { + var constName; + switch (node.type) { + case "package": + constName = "ICON_PACKAGE"; + break; + case "class": + constName = "ICON_CLASS"; + + if (node.attributes.isStatic) { + constName += "_STATIC"; + } else if (node.attributes.isAbstract) { + constName += "_ABSTRACT"; + } + + break; + case "property": + constName = "ICON_PROPERTY"; + break; + case "event": + constName = "ICON_EVENT"; + break; + case "method": + var isCtor = node.attributes.name == null; + var isPublic = isCtor || (node.attributes.name.charAt(0) != "_"); + + constName = "ICON_METHOD" + (isPublic ? "_PUB" : "_PROT"); + + if (isCtor) { + constName += "_CTOR"; + } else if (node.attributes.isStatic) { + constName += "_STATIC"; + } else if (node.attributes.isAbstract) { + constName += "_ABSTRACT"; + } + + break; + case "constant": + constName = "ICON_CONSTANT"; + break; + default: throw new Error("Unknown node type: " + node.type); + } + + if (inherited) { + constName += "_INHERITED"; + } else if (node.attributes.overriddenFrom) { + constName += "_OVERRIDDEN"; + } + + if (node.attributes.hasError) { + constName += "_ERROR"; + } else if (node.attributes.hasWarning) { + constName += "_WARN"; + } + + var iconUrl = api.TreeUtil[constName]; + if (iconUrl == null) { + throw new Error("Unknown img constant: " + constName); + } + return iconUrl; +} + + +/** {string[]} The names of lists containing items. */ +qx.Class.ITEM_LIST_ARR = [ "constants", "properties", "methods-pub", "methods-pub", + "methods-static-prot", "methods-static-prot" ]; + + +/** {string} The URL of the overlay "abstract". */ +qx.Class.OVERLAY_ABSTRACT = "api/overlay_abstract18.gif"; +/** {string} The URL of the overlay "error". */ +qx.Class.OVERLAY_ERROR = "api/overlay_error18.gif"; +/** {string} The URL of the overlay "inherited". */ +qx.Class.OVERLAY_INHERITED = "api/overlay_inherited18.gif"; +/** {string} The URL of the overlay "overridden". */ +qx.Class.OVERLAY_OVERRIDDEN = "api/overlay_overridden18.gif"; +/** {string} The URL of the overlay "static". */ +qx.Class.OVERLAY_STATIC = "api/overlay_static18.gif"; +/** {string} The URL of the overlay "warning". */ +qx.Class.OVERLAY_WARN = "api/overlay_warning18.gif"; + + +/** {string} The icon URL of a package. */ +qx.Class.ICON_PACKAGE = "api/package18.gif"; +/** {string} The icon URL of a package with warning. */ +qx.Class.ICON_PACKAGE_WARN = "api/package_warning18.gif"; + + +/** {string} The icon URL of a class. */ +qx.Class.ICON_CLASS = "api/class18.gif"; +/** {string} The icon URL of a class with warning. */ +qx.Class.ICON_CLASS_WARN = "api/class_warning18.gif"; +/** {string} The icon URL of a class with error. */ +qx.Class.ICON_CLASS_ERROR = "api/class_warning18.gif"; + +/** {string} The icon URL of a static class. */ +qx.Class.ICON_CLASS_STATIC = "api/class_static18.gif"; +/** {string} The icon URL of a static class with warning. */ +qx.Class.ICON_CLASS_STATIC_WARN = "api/class_static_warning18.gif"; +/** {string} The icon URL of a static class with error. */ +qx.Class.ICON_CLASS_STATIC_ERROR = "api/class_static_warning18.gif"; + +/** {string} The icon URL of an abstract class. */ +qx.Class.ICON_CLASS_ABSTRACT = "api/class_abstract18.gif"; +/** {string} The icon URL of an abstract class with warning. */ +qx.Class.ICON_CLASS_ABSTRACT_WARN = "api/class_abstract_warning18.gif"; +/** {string} The icon URL of an abstract class with error. */ +qx.Class.ICON_CLASS_ABSTRACT_ERROR = "api/class_abstract_warning18.gif"; + + +/** {string} The icon URL of a property. */ +qx.Class.ICON_PROPERTY = "api/property18.gif"; +/** {string[]} The icon URL of a property with warning. */ +qx.Class.ICON_PROPERTY_WARN = [ qx.Class.ICON_PROPERTY, qx.Class.OVERLAY_WARN ]; +/** {string[]} The icon URL of a property with error. */ +qx.Class.ICON_PROPERTY_ERROR = [ qx.Class.ICON_PROPERTY, qx.Class.OVERLAY_ERROR ]; + +/** {string[]} The icon URL of an inherited property. */ +qx.Class.ICON_PROPERTY_INHERITED = [ qx.Class.ICON_PROPERTY, qx.Class.OVERLAY_INHERITED ]; +/** {string[]} The icon URL of an inherited property with warning. */ +qx.Class.ICON_PROPERTY_INHERITED_WARN = [ qx.Class.ICON_PROPERTY, qx.Class.OVERLAY_INHERITED, qx.Class.OVERLAY_WARN ]; +/** {string[]} The icon URL of an inherited property with error. */ +qx.Class.ICON_PROPERTY_INHERITED_ERROR = [ qx.Class.ICON_PROPERTY, qx.Class.OVERLAY_INHERITED, qx.Class.OVERLAY_ERROR ]; + +/** {string[]} The icon URL of an overridden property. */ +qx.Class.ICON_PROPERTY_OVERRIDDEN = [ qx.Class.ICON_PROPERTY, qx.Class.OVERLAY_OVERRIDDEN ]; +/** {string[]} The icon URL of an overridden property with warning. */ +qx.Class.ICON_PROPERTY_OVERRIDDEN_WARN = [ qx.Class.ICON_PROPERTY, qx.Class.OVERLAY_OVERRIDDEN, qx.Class.OVERLAY_WARN ]; +/** {string[]} The icon URL of an overridden property with error. */ +qx.Class.ICON_PROPERTY_OVERRIDDEN_ERROR = [ qx.Class.ICON_PROPERTY, qx.Class.OVERLAY_OVERRIDDEN, qx.Class.OVERLAY_ERROR ]; + + +/** {string} The icon URL of an event. */ +qx.Class.ICON_EVENT = "api/event18.gif"; + +/** {string[]} The icon URL of an inherited event. */ +qx.Class.ICON_EVENT_INHERITED = [ qx.Class.ICON_EVENT, qx.Class.OVERLAY_INHERITED ]; + + +/** {string} The icon URL of a public method. */ +qx.Class.ICON_METHOD_PUB = "api/method_public18.gif"; +/** {string[]} The icon URL of a public method with warning. */ +qx.Class.ICON_METHOD_PUB_WARN = [ qx.Class.ICON_METHOD_PUB, qx.Class.OVERLAY_ERROR ]; +/** {string[]} The icon URL of a public method with error. */ +qx.Class.ICON_METHOD_PUB_ERROR = [ qx.Class.ICON_METHOD_PUB, qx.Class.OVERLAY_ERROR ]; + +/** {string[]} The icon URL of an inherited public method. */ +qx.Class.ICON_METHOD_PUB_INHERITED = [ qx.Class.ICON_METHOD_PUB, qx.Class.OVERLAY_INHERITED ]; +/** {string[]} The icon URL of an inherited public method with warning. */ +qx.Class.ICON_METHOD_PUB_INHERITED_WARN = [ qx.Class.ICON_METHOD_PUB, qx.Class.OVERLAY_INHERITED, qx.Class.OVERLAY_WARN ]; +/** {string[]} The icon URL of an inherited public method with error. */ +qx.Class.ICON_METHOD_PUB_INHERITED_ERROR = [ qx.Class.ICON_METHOD_PUB, qx.Class.OVERLAY_INHERITED, qx.Class.OVERLAY_ERROR ]; + +/** {string[]} The icon URL of an overridden public method. */ +qx.Class.ICON_METHOD_PUB_OVERRIDDEN = [ qx.Class.ICON_METHOD_PUB, qx.Class.OVERLAY_OVERRIDDEN ]; +/** {string[]} The icon URL of an overridden public method with warning. */ +qx.Class.ICON_METHOD_PUB_OVERRIDDEN_WARN = [ qx.Class.ICON_METHOD_PUB, qx.Class.OVERLAY_OVERRIDDEN, qx.Class.OVERLAY_WARN ]; +/** {string[]} The icon URL of an overridden public method with error. */ +qx.Class.ICON_METHOD_PUB_OVERRIDDEN_ERROR = [ qx.Class.ICON_METHOD_PUB, qx.Class.OVERLAY_OVERRIDDEN, qx.Class.OVERLAY_ERROR ]; + +/** {string[]} The icon URL of a public static method. */ +qx.Class.ICON_METHOD_PUB_STATIC = [ qx.Class.ICON_METHOD_PUB, qx.Class.OVERLAY_STATIC ]; +/** {string[]} The icon URL of a public static method with error. */ +qx.Class.ICON_METHOD_PUB_STATIC_ERROR = [ qx.Class.ICON_METHOD_PUB, qx.Class.OVERLAY_STATIC, qx.Class.OVERLAY_ERROR ]; + +/** {string[]} The icon URL of a public abstract method. */ +qx.Class.ICON_METHOD_PUB_ABSTRACT = [ qx.Class.ICON_METHOD_PUB, qx.Class.OVERLAY_ABSTRACT ]; +/** {string[]} The icon URL of a public abstract method with warning. */ +qx.Class.ICON_METHOD_PUB_ABSTRACT_WARN = [ qx.Class.ICON_METHOD_PUB, qx.Class.OVERLAY_ABSTRACT, qx.Class.OVERLAY_WARN ]; +/** {string[]} The icon URL of a public abstract method with error. */ +qx.Class.ICON_METHOD_PUB_ABSTRACT_ERROR = [ qx.Class.ICON_METHOD_PUB, qx.Class.OVERLAY_ABSTRACT, qx.Class.OVERLAY_ERROR ]; + +/** {string[]} The icon URL of an overridden public abstract method. */ +qx.Class.ICON_METHOD_PUB_ABSTRACT_OVERRIDDEN = [ qx.Class.ICON_METHOD_PUB, qx.Class.OVERLAY_ABSTRACT, qx.Class.OVERLAY_OVERRIDDEN ]; +/** {string[]} The icon URL of an overridden public abstract method with warning. */ +qx.Class.ICON_METHOD_PUB_ABSTRACT_OVERRIDDEN_WARN = [ qx.Class.ICON_METHOD_PUB, qx.Class.OVERLAY_ABSTRACT, qx.Class.OVERLAY_OVERRIDDEN, qx.Class.OVERLAY_WARN ]; +/** {string[]} The icon URL of an overridden public abstract method with error. */ +qx.Class.ICON_METHOD_PUB_ABSTRACT_OVERRIDDEN_ERROR = [ qx.Class.ICON_METHOD_PUB, qx.Class.OVERLAY_ABSTRACT, qx.Class.OVERLAY_OVERRIDDEN, qx.Class.OVERLAY_ERROR ]; + +/** {string[]} The icon URL of an inherited public abstract method. */ +qx.Class.ICON_METHOD_PUB_ABSTRACT_INHERITED = [ qx.Class.ICON_METHOD_PUB, qx.Class.OVERLAY_ABSTRACT, qx.Class.OVERLAY_INHERITED ]; +/** {string[]} The icon URL of an inherited public abstract method with warning. */ +qx.Class.ICON_METHOD_PUB_ABSTRACT_INHERITED_WARN = [ qx.Class.ICON_METHOD_PUB, qx.Class.OVERLAY_ABSTRACT, qx.Class.OVERLAY_INHERITED, qx.Class.OVERLAY_WARN ]; +/** {string[]} The icon URL of an inherited public abstract method with error. */ +qx.Class.ICON_METHOD_PUB_ABSTRACT_INHERITED_ERROR = [ qx.Class.ICON_METHOD_PUB, qx.Class.OVERLAY_ABSTRACT, qx.Class.OVERLAY_INHERITED, qx.Class.OVERLAY_ERROR ]; + + +/** {string} The icon URL of a constructor. */ +qx.Class.ICON_METHOD_PUB_CTOR = "api/constructor18.gif"; +/** {string[]} The icon URL of a constructor with error. */ +qx.Class.ICON_METHOD_PUB_CTOR_ERROR = [ qx.Class.ICON_METHOD_PUB_CTOR, qx.Class.OVERLAY_ERROR ]; + + +/** {string} The icon URL of a protected method. */ +qx.Class.ICON_METHOD_PROT = "api/method_protected18.gif"; +/** {string[]} The icon URL of a protected method with warning. */ +qx.Class.ICON_METHOD_PROT_WARN = [ qx.Class.ICON_METHOD_PROT, qx.Class.OVERLAY_ERROR ]; +/** {string[]} The icon URL of a protected method with error. */ +qx.Class.ICON_METHOD_PROT_ERROR = [ qx.Class.ICON_METHOD_PROT, qx.Class.OVERLAY_ERROR ]; + +/** {string[]} The icon URL of an inherited protected method. */ +qx.Class.ICON_METHOD_PROT_INHERITED = [ qx.Class.ICON_METHOD_PROT, qx.Class.OVERLAY_INHERITED ]; +/** {string[]} The icon URL of an inherited protected method with warning. */ +qx.Class.ICON_METHOD_PROT_INHERITED_WARN = [ qx.Class.ICON_METHOD_PROT, qx.Class.OVERLAY_INHERITED, qx.Class.OVERLAY_WARN ]; +/** {string[]} The icon URL of an inherited protected method with error. */ +qx.Class.ICON_METHOD_PROT_INHERITED_ERROR = [ qx.Class.ICON_METHOD_PROT, qx.Class.OVERLAY_INHERITED, qx.Class.OVERLAY_ERROR ]; + +/** {string[]} The icon URL of an overridden protected method. */ +qx.Class.ICON_METHOD_PROT_OVERRIDDEN = [ qx.Class.ICON_METHOD_PROT, qx.Class.OVERLAY_OVERRIDDEN ]; +/** {string[]} The icon URL of an overridden protected method with warning. */ +qx.Class.ICON_METHOD_PROT_OVERRIDDEN_WARN = [ qx.Class.ICON_METHOD_PROT, qx.Class.OVERLAY_OVERRIDDEN, qx.Class.OVERLAY_WARN ]; +/** {string[]} The icon URL of an overridden protected method with error. */ +qx.Class.ICON_METHOD_PROT_OVERRIDDEN_ERROR = [ qx.Class.ICON_METHOD_PROT, qx.Class.OVERLAY_OVERRIDDEN, qx.Class.OVERLAY_ERROR ]; + +/** {string[]} The icon URL of a protected static method. */ +qx.Class.ICON_METHOD_PROT_STATIC = [ qx.Class.ICON_METHOD_PROT, qx.Class.OVERLAY_STATIC ]; +/** {string[]} The icon URL of a protected static method with error. */ +qx.Class.ICON_METHOD_PROT_STATIC_ERROR = [ qx.Class.ICON_METHOD_PROT, qx.Class.OVERLAY_STATIC, qx.Class.OVERLAY_ERROR ]; + +/** {string[]} The icon URL of an abstract protected method. */ +qx.Class.ICON_METHOD_PROT_ABSTRACT = [ qx.Class.ICON_METHOD_PROT, qx.Class.OVERLAY_ABSTRACT ]; +/** {string[]} The icon URL of an abstract protected method with warning. */ +qx.Class.ICON_METHOD_PROT_ABSTRACT_WARN = [ qx.Class.ICON_METHOD_PROT, qx.Class.OVERLAY_ABSTRACT, qx.Class.OVERLAY_WARN ]; +/** {string[]} The icon URL of an abstract protected method with error. */ +qx.Class.ICON_METHOD_PROT_ABSTRACT_ERROR = [ qx.Class.ICON_METHOD_PROT, qx.Class.OVERLAY_ABSTRACT, qx.Class.OVERLAY_ERROR ]; + +/** {string[]} The icon URL of an inherited abstract protected method. */ +qx.Class.ICON_METHOD_PROT_ABSTRACT_INHERITED = [ qx.Class.ICON_METHOD_PROT, qx.Class.OVERLAY_ABSTRACT, qx.Class.OVERLAY_INHERITED ]; +/** {string[]} The icon URL of an inherited abstract protected method with warning. */ +qx.Class.ICON_METHOD_PROT_ABSTRACT_INHERITED_WARN = [ qx.Class.ICON_METHOD_PROT, qx.Class.OVERLAY_ABSTRACT, qx.Class.OVERLAY_INHERITED, qx.Class.OVERLAY_WARN ]; +/** {string[]} The icon URL of an inherited abstract protected method with error. */ +qx.Class.ICON_METHOD_PROT_ABSTRACT_INHERITED_ERROR = [ qx.Class.ICON_METHOD_PROT, qx.Class.OVERLAY_ABSTRACT, qx.Class.OVERLAY_INHERITED, qx.Class.OVERLAY_ERROR ]; + + +/** {string} The icon URL of a constant. */ +qx.Class.ICON_CONSTANT = "api/constant18.gif"; +/** {string[]} The icon URL of a constant with error. */ +qx.Class.ICON_CONSTANT_ERROR = [ qx.Class.ICON_CONSTANT, qx.Class.OVERLAY_ERROR ]; diff --git a/webapps/qooxdoo-0.6.3-sdk/frontend/api/source/class/api/Viewer.js b/webapps/qooxdoo-0.6.3-sdk/frontend/api/source/class/api/Viewer.js new file mode 100755 index 0000000000..f633c0d50e --- /dev/null +++ b/webapps/qooxdoo-0.6.3-sdk/frontend/api/source/class/api/Viewer.js @@ -0,0 +1,386 @@ +/* +#module(api) +#resource(css:css) +#resource(images:image) +*/ + +/** + * The API viewer. Shows the API documentation. + */ +qx.OO.defineClass("api.Viewer", qx.ui.layout.HorizontalBoxLayout, +function () { + qx.ui.layout.HorizontalBoxLayout.call(this); + + this.setEdge(0); + + this._titlePrefix = this.getSetting("title") + " API Documentation"; + document.title = this._titlePrefix; + + this._tree = new qx.ui.tree.Tree("API Documentation"); + this._tree.set({ + backgroundColor: "white", + overflow: "scroll", + width: "22%", + minWidth : 150, + maxWidth : 300 + }); + this._tree.getManager().addEventListener("changeSelection", this._onTreeSelectionChange, this); + this.add(this._tree); + + this._detailFrame = new qx.ui.layout.CanvasLayout; + this._detailFrame.setWidth("1*"); + this._detailFrame.setBorder(qx.renderer.border.BorderPresets.horizontalDivider); + this._detailFrame.setBackgroundColor("white"); + this._detailFrame.setHtmlProperty("id", "DetailFrame"); + this.add(this._detailFrame); + + this._detailLoader = new qx.ui.embed.HtmlEmbed('

please wait
Loading data...

'); + this._detailLoader.setHtmlProperty("id", "DetailLoader"); + this._detailLoader.setMarginLeft(20); + this._detailLoader.setMarginTop(20); + this._detailFrame.add(this._detailLoader); + + this._classViewer = new api.ClassViewer; + this._detailFrame.add(this._classViewer); + + this._infoViewer = new api.InfoViewer; + this._detailFrame.add(this._infoViewer); + + this._currentTreeType = api.Viewer.PACKAGE_TREE; + + // Workaround: Since navigating in qx.ui.tree.Tree doesn't work, we've to + // maintain a hash that keeps the tree nodes for class names + this._classTreeNodeHash = {}; + this._classTreeNodeHash[api.Viewer.PACKAGE_TREE] = {}; + this._classTreeNodeHash[api.Viewer.INHERITENCE_TREE] = {}; + + api.Viewer.instance = this; + + qx.client.History.getInstance().init(); + qx.client.History.getInstance().addEventListener("request", this._onHistoryRequest, this); +}); + + +/** The documentation tree to show. */ +qx.OO.addProperty({ name:"docTree", type:"object" }); + + +qx.Settings.setDefault("title", "qooxdoo"); +qx.Settings.setDefault("initialTreeDepth", 1); + + +// property checker +qx.Proto._modifyDocTree = function(propValue, propOldValue, propData) { + this._updateTree(propValue); + return true; +} + + +/** + * Loads the API doc tree from a URL. The URL must point to a JSON encoded + * doc tree. + * + * @param url {string} the URL. + */ +qx.Proto.load = function(url) +{ + var req = new qx.io.remote.Request(url); + + req.setTimeout(180000); + + req.addEventListener("completed", function(evt) + { + var content = evt.getData().getContent(); + this.setDocTree(eval("(" + content + ")")); + + qx.ui.core.Widget.flushGlobalQueues(); + + // Handle bookmarks + if (window.location.hash) { + var self = this; + window.setTimeout(function() { + self.selectItem(window.location.hash.substring(1)); + }, 0); + } + + this._detailLoader.setHtml('

' + this.getSetting("title") + + '
API Documentation

'); + + }, this); + + req.addEventListener("failed", function(evt) + { + this.error("Couldn't load file: " + url); + }, this); + + req.send(); +} + + +/** + * Updates the tree on the left. + * + * @param docTree {Map} the documentation tree to use for updating. + */ +qx.Proto._updateTree = function(docTree) { + var inheritenceNode = new qx.ui.tree.TreeFolder("Inheritence hierarchy"); + var packagesNode = new qx.ui.tree.TreeFolder("Packages"); + + this._tree.removeAll(); + this._tree.add(inheritenceNode, packagesNode); + + // Fille the packages tree (and fill the _topLevelClassNodeArr) + this._topLevelClassNodeArr = []; + this._fillPackageNode(packagesNode, docTree, 0); + + // Sort the _topLevelClassNodeArr + this._topLevelClassNodeArr.sort(function (node1, node2) { + return (node1.attributes.fullName < node2.attributes.fullName) ? -1 : 1; + }); + + // Fill the inheritence tree + for (var i = 0; i < this._topLevelClassNodeArr.length; i++) { + this._createInheritanceNode(inheritenceNode, this._topLevelClassNodeArr[i], docTree); + } + + packagesNode.open(); + + if (this._wantedClassName) { + this.showClassByName(this._wantedClassName); + this._wantedClassName = null; + } +} + + +/** + * Fills a package tree node with tree nodes for the sub packages and classes. + * + * @param treeNode {qx.ui.tree.TreeFolder} the package tree node. + * @param docNode {Map} the documentation node of the package. + */ +qx.Proto._fillPackageNode = function(treeNode, docNode, depth) { + var ApiViewer = api.Viewer; + var TreeUtil = api.TreeUtil; + + var packagesDocNode = TreeUtil.getChild(docNode, "packages"); + if (packagesDocNode && packagesDocNode.children) { + for (var i = 0; i < packagesDocNode.children.length; i++) { + var packageDocNode = packagesDocNode.children[i]; + var iconUrl = TreeUtil.getIconUrl(packageDocNode); + var packageTreeNode = new qx.ui.tree.TreeFolder(packageDocNode.attributes.name, iconUrl); + packageTreeNode.docNode = packageDocNode; + treeNode.add(packageTreeNode); + + this._fillPackageNode(packageTreeNode, packageDocNode, depth+1); + + // Open the package node if it has child packages + if (depth < this.getSetting("initialTreeDepth") && TreeUtil.getChild(packageDocNode, "packages")) { + packageTreeNode.open(); + } + + // Register the tree node + this._classTreeNodeHash[ApiViewer.PACKAGE_TREE][packageDocNode.attributes.fullName] = packageTreeNode; + } + } + + var classesDocNode = TreeUtil.getChild(docNode, "classes"); + if (classesDocNode && classesDocNode.children) { + for (var i = 0; i < classesDocNode.children.length; i++) { + var classDocNode = classesDocNode.children[i]; + var iconUrl = TreeUtil.getIconUrl(classDocNode); + var classTreeNode = new qx.ui.tree.TreeFolder(classDocNode.attributes.name, iconUrl); + classTreeNode.docNode = classDocNode; + classTreeNode.treeType = ApiViewer.PACKAGE_TREE; + treeNode.add(classTreeNode); + + // Register the tree node + this._classTreeNodeHash[ApiViewer.PACKAGE_TREE][classDocNode.attributes.fullName] = classTreeNode; + + // Check whether this is a top-level-class + if (classDocNode.attributes.superClass == null) { + this._topLevelClassNodeArr.push(classDocNode); + } + } + } +} + + +/** + * Creates the tree node for a class containing class nodes for all its child + * classes. + * + * @param classDocNode {Map} the documentation node of the class. + * @param docTree {Map} the documentation tree. + */ +qx.Proto._createInheritanceNode = function(parentTreeNode, classDocNode, docTree) { + var ApiViewer = api.Viewer; + var TreeUtil = api.TreeUtil; + + // Create the tree node + var iconUrl = TreeUtil.getIconUrl(classDocNode); + var classTreeNode = new qx.ui.tree.TreeFolder(classDocNode.attributes.fullName, iconUrl); + classTreeNode.docNode = classDocNode; + classTreeNode.treeType = ApiViewer.INHERITENCE_TREE; + parentTreeNode.add(classTreeNode); + + // Register the tree node + this._classTreeNodeHash[ApiViewer.INHERITENCE_TREE][classDocNode.attributes.fullName] = classTreeNode; + + // Add all child classes + var childClassNameCsv = classDocNode.attributes.childClasses; + if (childClassNameCsv) { + var childClassNameArr = childClassNameCsv.split(","); + for (var i = 0; i < childClassNameArr.length; i++) { + var childClassDocNode = TreeUtil.getClassDocNode(docTree, childClassNameArr[i]); + this._createInheritanceNode(classTreeNode, childClassDocNode, docTree); + } + } +} + + +/** + * Event handler. Called when the tree selection has changed. + * + * @param evt {Map} the event. + */ +qx.Proto._onTreeSelectionChange = function(evt) +{ + var treeNode = evt.getData()[0]; + + if (treeNode && treeNode.docNode) + { + var newTitle = this._titlePrefix + " - class " + treeNode.docNode.attributes.fullName; + + qx.client.History.getInstance().addToHistory(treeNode.docNode.attributes.fullName, newTitle); + + this._currentTreeType = treeNode.treeType; + + this._selectTreeNode(treeNode); + + window.location.hash = "#" + treeNode.docNode.attributes.fullName; + } +} + + +qx.Proto._onHistoryRequest = function(evt) +{ + this.showClassByName(evt.getData()); +} + +qx.Proto._selectTreeNode = function(vTreeNode) +{ + if (!(vTreeNode && vTreeNode.docNode)) { + this.error("Invalid tree node: " + vTreeNode); + } + + var vDoc = vTreeNode.docNode; + + this._detailLoader.setVisibility(false); + + if (vDoc.type == "class") + { + this._infoViewer.setVisibility(false); + this._classViewer.showClass(vDoc); + this._classViewer.setVisibility(true); + } + else + { + this._classViewer.setVisibility(false); + this._infoViewer.showInfo(vDoc); + this._infoViewer.setVisibility(true); + } +} + + +/** + * Selects an item (class, property, method or constant). + * + * @param fullItemName {string} the full name of the item to select. + * (e.g. "qx.mypackage.MyClass" or "qx.mypackage.MyClass#myProperty") + */ +qx.Proto.selectItem = function(fullItemName) { + var className = fullItemName; + var itemName = null; + var hashPos = fullItemName.indexOf("#"); + if (hashPos != -1) { + className = fullItemName.substring(0, hashPos); + itemName = fullItemName.substring(hashPos + 1); + + var parenPos = itemName.indexOf("("); + if (parenPos != -1) { + itemName = qx.lang.String.trim(itemName.substring(0, parenPos)); + } + } + + this.showClassByName(className); + if (itemName) { + this._classViewer.showItem(itemName); + } +} + + +/** + * Shows a certain class. + * + * @param className {string} the name of the class to show. + */ +qx.Proto.showClassByName = function(className) { + var treeNode = this._classTreeNodeHash[this._currentTreeType][className]; + + if (treeNode) { + treeNode.setSelected(true); + } else if (this.getDocTree() == null) { + // The doc tree has not been loaded yet + // -> Remeber the wanted class and show when loading is done + this._wantedClassName = className; + } else { + this.error("Unknown class: " + className); + } +} + + +qx.Class.PACKAGE_TREE = 1; +qx.Class.INHERITENCE_TREE = 2; + + + +qx.Proto.dispose = function() +{ + if (this.getDisposed()) { + return; + } + + if (this._tree) + { + this._tree.dispose(); + this._tree = null; + } + + if (this._detailFrame) + { + this._detailFrame.dispose(); + this._detailFrame = null; + } + + if (this._detailLoader) + { + this._detailLoader.dispose(); + this._detailLoader = null; + } + + if (this._classViewer) + { + this._classViewer.dispose(); + this._classViewer = null; + } + + if (this._infoViewer) + { + this._infoViewer.dispose(); + this._infoViewer = null; + } + + this._classTreeNodeHash = null; + + return qx.ui.layout.HorizontalBoxLayout.prototype.dispose.call(this); +} -- cgit