001package Torello.Browser.JsonAST;
002
003import Torello.Java.UnreachableError;
004import Torello.Java.Additional.Ret2;
005import Torello.Java.StrIndent;
006
007/**
008 * Generates the HTML for the elements of the {@code "types"} array, which is a sub-property 
009 * of a {@code "domain"} object.
010 */
011@Torello.JavaDoc.Annotations.StaticFunctional
012@Torello.JavaDoc.Annotations.JDHeaderBackgroundImg(EmbedTagFileID="TOHTML_JDHBI")
013public class HTML$TypeNode
014{
015    private HTML$TypeNode() { }
016
017    static String run(final TypeNode typeNode)
018    {
019        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
020        // FLAGS HTML, Possible 'Redirect' Note
021        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
022
023        final Ret2<String, String> r2 = HTML$TCE.flagsAndRedirectNote(typeNode, null);
024        final String flagsStr = r2.a;
025        final String rNote    = r2.b;
026
027
028        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
029        // The 'type' column (not present in Commands or Events, Just Types)
030        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
031
032        // The 'types' column MAY OR MAY NOT not exist
033        final String typeCol;
034
035        if (typeNode.enumValsStr != null) typeCol =
036            "    <TD><DIV CLASS=tooltip><SPAN CLASS=tooltiptext>" +
037            typeNode.enumValsStr + "</SPAN>String<BR />[Hover] Enum</DIV></TD>";
038
039        else if (typeNode.arrItemsTypeProp != null) typeCol =
040            "    <TD>" +
041            "\"type\": \"array\"" +
042            "<BR />\"items\":<BR />{ " + typeNode.arrItemsTypeProp.toString() + " }" +
043            "</TD>\n";
044
045        else if (typeNode.typeProp != null)
046        {
047            // Has Warnings: Domain: [Network], Section [types] [7]
048            // Has Warnings: Domain: [Tracing], Section [types] [0]
049
050            if ((typeNode.typeProp == TypeProp.OBJECT) && (typeNode.properties == null))
051                typeCol = "    <TD>OBJECT<BR />as JsonValue</TD>\n";
052            else 
053                typeCol = "    <TD>" + typeNode.typeProp.toString() + "</TD>\n";
054        }
055
056        else throw new UnreachableError();
057
058
059        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
060        // HTML Inner-Tables: 'Properties'
061        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
062
063        final StringBuilder sb = new StringBuilder();
064
065        if (typeNode.properties != null)
066            HTML$TCE.appendPPRs(sb, typeNode.properties, "PROPERTIES");
067
068        final String innerTablesRow;
069
070        if (sb.length() == 0) innerTablesRow = "";
071
072        else innerTablesRow =
073            "<TR><TD COLSPAN=3>\n" + 
074            StrIndent.indent(sb.toString(), 4) +
075            "</TD></TR>\n";
076
077
078        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
079        // Return the HTML
080        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
081
082        final String descStr = typeNode.description.replace("<", "&lt;").replace(">", "&gt;");
083
084        return 
085            // Note, there is a CSS ID included with TypeNode's.  This is not present inside of
086            // CommandNode's and EventNode's.  There are "back  links" to TypeNode's.
087
088            "<TR ID=" + typeNode.name + ">\n" +
089            "    <TD CLASS=MAINNAME>" +
090                "<SPAN CLASS=MAINNAME>" + typeNode.name + "</SPAN>" +
091                rNote + "</TD>\n" +
092
093                 typeCol +
094            "    <TD>" + descStr + "</TD>\n" +
095            "    <TD>" + flagsStr + "</TD>\n" +
096            "</TR>\n" +
097            innerTablesRow;
098    }
099}