-/*******************************************************************************\r
- * Copyright (c) 2016 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * THTH ry - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.debug.browser.sections;\r
-\r
-import java.io.PrintWriter;\r
-\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.debug.browser.utils.ResourceInfo;\r
-\r
-public class TypeHierarchySection implements ResourceBrowserSection {\r
-\r
- public static class Node {\r
- public final String relation;\r
- public final ResourceInfo type;\r
- public final Node[] superTypes;\r
- public final int height;\r
- public final int width;\r
- \r
- public Node(String relation, ResourceInfo type, Node[] superTypes) {\r
- this.relation = relation;\r
- this.type = type;\r
- this.superTypes = superTypes;\r
- this.height = sumHeights(superTypes);\r
- this.width = maxWidths(superTypes);\r
- }\r
- }\r
- \r
- Node root;\r
- \r
- public TypeHierarchySection(Node root) {\r
- this.root = root;\r
- }\r
-\r
- private static int sumHeights(Node[] nodes) {\r
- int sum = 0;\r
- for(Node node : nodes)\r
- sum += node.height;\r
- if(sum == 0)\r
- sum = 1;\r
- return sum;\r
- }\r
- \r
- private static int maxWidths(Node[] nodes) {\r
- int max = 0;\r
- for(Node node : nodes)\r
- if(node.width > max)\r
- max = node.width;\r
- return max+1;\r
- }\r
- \r
- @Override\r
- public double getPriority() {\r
- return 1;\r
- }\r
-\r
- @Override\r
- public void toHtml(ReadGraph graph, PrintWriter out)\r
- throws DatabaseException {\r
- Node[][] table = new Node[root.height][root.width-1];\r
- fillTable(table, root, 0, 0);\r
- \r
- if (root.width - 1 > 0) {\r
- out.println("<div id=\"typeHierarchyContent\">");\r
- out.println("<table>");\r
- for(int j=0;j<root.height;++j) {\r
- out.println("\t<tr>");\r
- for(int i=0;i<root.width-1;++i) {\r
- Node node = table[j][i];\r
- if(node != null) {\r
- out.print("\t\t<td rowspan=\""+node.height+"\">");\r
- out.print(node.relation + " " + node.type);\r
- out.println("</td>");\r
- }\r
- }\r
- out.println("\t</tr>");\r
- }\r
- out.println("</table>");\r
- out.println("</div>");\r
- }\r
- }\r
-\r
- private static void fillTable(Node[][] table, Node node, int i, int j) {\r
- for(Node child : node.superTypes) {\r
- table[j][i] = child;\r
- fillTable(table, child, i+1, j);\r
- j += child.height;\r
- }\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2016 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * THTH ry - initial API and implementation
+ *******************************************************************************/
+package org.simantics.debug.browser.sections;
+
+import java.io.PrintWriter;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.debug.browser.utils.ResourceInfo;
+
+public class TypeHierarchySection implements ResourceBrowserSection {
+
+ public static class Node {
+ public final String relation;
+ public final ResourceInfo type;
+ public final Node[] superTypes;
+ public final int height;
+ public final int width;
+
+ public Node(String relation, ResourceInfo type, Node[] superTypes) {
+ this.relation = relation;
+ this.type = type;
+ this.superTypes = superTypes;
+ this.height = sumHeights(superTypes);
+ this.width = maxWidths(superTypes);
+ }
+ }
+
+ Node root;
+
+ public TypeHierarchySection(Node root) {
+ this.root = root;
+ }
+
+ private static int sumHeights(Node[] nodes) {
+ int sum = 0;
+ for(Node node : nodes)
+ sum += node.height;
+ if(sum == 0)
+ sum = 1;
+ return sum;
+ }
+
+ private static int maxWidths(Node[] nodes) {
+ int max = 0;
+ for(Node node : nodes)
+ if(node.width > max)
+ max = node.width;
+ return max+1;
+ }
+
+ @Override
+ public double getPriority() {
+ return 1;
+ }
+
+ @Override
+ public void toHtml(ReadGraph graph, PrintWriter out)
+ throws DatabaseException {
+ Node[][] table = new Node[root.height][root.width-1];
+ fillTable(table, root, 0, 0);
+
+ if (root.width - 1 > 0) {
+ out.println("<div id=\"typeHierarchyContent\">");
+ out.println("<table>");
+ for(int j=0;j<root.height;++j) {
+ out.println("\t<tr>");
+ for(int i=0;i<root.width-1;++i) {
+ Node node = table[j][i];
+ if(node != null) {
+ out.print("\t\t<td rowspan=\""+node.height+"\">");
+ out.print(node.relation + " " + node.type);
+ out.println("</td>");
+ }
+ }
+ out.println("\t</tr>");
+ }
+ out.println("</table>");
+ out.println("</div>");
+ }
+ }
+
+ private static void fillTable(Node[][] table, Node node, int i, int j) {
+ for(Node child : node.superTypes) {
+ table[j][i] = child;
+ fillTable(table, child, i+1, j);
+ j += child.height;
+ }
+ }
+
+}