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.internal.rewriters;
14 import java.util.ArrayList;
16 import org.simantics.db.ReadGraph;
17 import org.simantics.db.Resource;
18 import org.simantics.db.exception.DatabaseException;
19 import org.simantics.debug.browser.content.ResourceBrowserContent;
20 import org.simantics.debug.browser.content.ResourceBrowserRewriter;
21 import org.simantics.debug.browser.sections.RawStatementsSection;
22 import org.simantics.debug.browser.sections.TypeHierarchySection;
23 import org.simantics.debug.browser.sections.TypeHierarchySection.Node;
24 import org.simantics.debug.browser.utils.ResourceInfo;
25 import org.simantics.layer0.Layer0;
27 public enum TypeHierarchyCreator implements ResourceBrowserRewriter {
31 public void rewrite(ReadGraph graph, ResourceBrowserContent content)
32 throws DatabaseException {
33 content.putSection(TypeHierarchySection.class,
34 new TypeHierarchySection(
35 new Node(null, null, getSuper(graph, content.resource))
38 // Remove raw statements that this section already shows
39 Layer0 L0 = Layer0.getInstance(graph);
40 RawStatementsSection rawStatementsSection = content.getSection(RawStatementsSection.class);
41 rawStatementsSection.statementsByPredicates.remove(L0.InstanceOf);
42 rawStatementsSection.statementsByPredicates.remove(L0.SubrelationOf);
43 rawStatementsSection.statementsByPredicates.remove(L0.Inherits);
46 public Node[] getSuper(ReadGraph graph, Resource resource) throws DatabaseException {
47 ArrayList<Node> nodes = new ArrayList<Node>();
48 Layer0 L0 = Layer0.getInstance(graph);
49 for(Resource s : graph.getObjects(resource, L0.InstanceOf))
50 nodes.add(new Node(":", new ResourceInfo(graph, s), getSuper(graph, s)));
51 for(Resource s : graph.getObjects(resource, L0.Inherits)) {
52 if(s.equals(L0.Entity))
54 nodes.add(new Node("<T", new ResourceInfo(graph, s), getSuper(graph, s)));
56 for(Resource s : graph.getObjects(resource, L0.SubrelationOf)) {
57 if(s.equals(L0.IsWeaklyRelatedTo))
59 nodes.add(new Node("<R", new ResourceInfo(graph, s), getSuper(graph, s)));
61 return nodes.toArray(new Node[nodes.size()]);
65 public double getPriority() {