1 /*******************************************************************************
2 * Copyright (c) 2016 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * THTH ry - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.debug.browser.sections;
14 import java.io.PrintWriter;
16 import org.simantics.db.ReadGraph;
17 import org.simantics.db.exception.DatabaseException;
18 import org.simantics.debug.browser.utils.ResourceInfo;
20 public class TypeHierarchySection implements ResourceBrowserSection {
22 public static class Node {
23 public final String relation;
24 public final ResourceInfo type;
25 public final Node[] superTypes;
26 public final int height;
27 public final int width;
29 public Node(String relation, ResourceInfo type, Node[] superTypes) {
30 this.relation = relation;
32 this.superTypes = superTypes;
33 this.height = sumHeights(superTypes);
34 this.width = maxWidths(superTypes);
40 public TypeHierarchySection(Node root) {
44 private static int sumHeights(Node[] nodes) {
46 for(Node node : nodes)
53 private static int maxWidths(Node[] nodes) {
55 for(Node node : nodes)
62 public double getPriority() {
67 public void toHtml(ReadGraph graph, PrintWriter out)
68 throws DatabaseException {
69 Node[][] table = new Node[root.height][root.width-1];
70 fillTable(table, root, 0, 0);
72 if (root.width - 1 > 0) {
73 out.println("<div id=\"typeHierarchyContent\">");
74 out.println("<table>");
75 for(int j=0;j<root.height;++j) {
76 out.println("\t<tr>");
77 for(int i=0;i<root.width-1;++i) {
78 Node node = table[j][i];
80 out.print("\t\t<td rowspan=\""+node.height+"\">");
81 out.print(node.relation + " " + node.type);
85 out.println("\t</tr>");
87 out.println("</table>");
88 out.println("</div>");
92 private static void fillTable(Node[][] table, Node node, int i, int j) {
93 for(Node child : node.superTypes) {
95 fillTable(table, child, i+1, j);