1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package Torello.Browser.JsonAST;

import Torello.Java.UnreachableError;
import Torello.Java.Additional.Ret2;
import Torello.Java.StrIndent;

/**
 * Generates the HTML for the elements of the {@code "types"} array, which is a sub-property 
 * of a {@code "domain"} object.
 */
@Torello.JavaDoc.Annotations.StaticFunctional
@Torello.JavaDoc.Annotations.JDHeaderBackgroundImg(EmbedTagFileID="TOHTML_JDHBI")
public class HTML$TypeNode
{
    private HTML$TypeNode() { }

    static String run(final TypeNode typeNode)
    {
        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
        // FLAGS HTML, Possible 'Redirect' Note
        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

        final Ret2<String, String> r2 = HTML$TCE.flagsAndRedirectNote(typeNode, null);
        final String flagsStr = r2.a;
        final String rNote    = r2.b;


        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
        // The 'type' column (not present in Commands or Events, Just Types)
        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

        // The 'types' column MAY OR MAY NOT not exist
        final String typeCol;

        if (typeNode.enumValsStr != null) typeCol =
            "    <TD><DIV CLASS=tooltip><SPAN CLASS=tooltiptext>" +
            typeNode.enumValsStr + "</SPAN>String<BR />[Hover] Enum</DIV></TD>";

        else if (typeNode.arrItemsTypeProp != null) typeCol =
            "    <TD>" +
            "\"type\": \"array\"" +
            "<BR />\"items\":<BR />{ " + typeNode.arrItemsTypeProp.toString() + " }" +
            "</TD>\n";

        else if (typeNode.typeProp != null)
        {
            // Has Warnings: Domain: [Network], Section [types] [7]
            // Has Warnings: Domain: [Tracing], Section [types] [0]

            if ((typeNode.typeProp == TypeProp.OBJECT) && (typeNode.properties == null))
                typeCol = "    <TD>OBJECT<BR />as JsonValue</TD>\n";
            else 
                typeCol = "    <TD>" + typeNode.typeProp.toString() + "</TD>\n";
        }

        else throw new UnreachableError();


        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
        // HTML Inner-Tables: 'Properties'
        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

        final StringBuilder sb = new StringBuilder();

        if (typeNode.properties != null)
            HTML$TCE.appendPPRs(sb, typeNode.properties, "PROPERTIES");

        final String innerTablesRow;

        if (sb.length() == 0) innerTablesRow = "";

        else innerTablesRow =
            "<TR><TD COLSPAN=3>\n" + 
            StrIndent.indent(sb.toString(), 4) +
            "</TD></TR>\n";


        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
        // Return the HTML
        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

        final String descStr = typeNode.description.replace("<", "&lt;").replace(">", "&gt;");

        return 
            // Note, there is a CSS ID included with TypeNode's.  This is not present inside of
            // CommandNode's and EventNode's.  There are "back  links" to TypeNode's.

            "<TR ID=" + typeNode.name + ">\n" +
            "    <TD CLASS=MAINNAME>" +
                "<SPAN CLASS=MAINNAME>" + typeNode.name + "</SPAN>" +
                rNote + "</TD>\n" +

                 typeCol +
            "    <TD>" + descStr + "</TD>\n" +
            "    <TD>" + flagsStr + "</TD>\n" +
            "</TR>\n" +
            innerTablesRow;
    }
}