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