X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.debug.browser%2Fsrc%2Forg%2Fsimantics%2Fdebug%2Fbrowser%2Finternal%2Frewriters%2FTypeHierarchyCreator.java;h=c0cd27550315d56b2090e778cd352e29ae7bbbaf;hp=5e6df9ea403981c78e557fbe61dc7461d32bcf35;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.debug.browser/src/org/simantics/debug/browser/internal/rewriters/TypeHierarchyCreator.java b/bundles/org.simantics.debug.browser/src/org/simantics/debug/browser/internal/rewriters/TypeHierarchyCreator.java index 5e6df9ea4..c0cd27550 100644 --- a/bundles/org.simantics.debug.browser/src/org/simantics/debug/browser/internal/rewriters/TypeHierarchyCreator.java +++ b/bundles/org.simantics.debug.browser/src/org/simantics/debug/browser/internal/rewriters/TypeHierarchyCreator.java @@ -1,68 +1,68 @@ -/******************************************************************************* - * 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.internal.rewriters; - -import java.util.ArrayList; - -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.exception.DatabaseException; -import org.simantics.debug.browser.content.ResourceBrowserContent; -import org.simantics.debug.browser.content.ResourceBrowserRewriter; -import org.simantics.debug.browser.sections.RawStatementsSection; -import org.simantics.debug.browser.sections.TypeHierarchySection; -import org.simantics.debug.browser.sections.TypeHierarchySection.Node; -import org.simantics.debug.browser.utils.ResourceInfo; -import org.simantics.layer0.Layer0; - -public enum TypeHierarchyCreator implements ResourceBrowserRewriter { - INSTANCE; - - @Override - public void rewrite(ReadGraph graph, ResourceBrowserContent content) - throws DatabaseException { - content.putSection(TypeHierarchySection.class, - new TypeHierarchySection( - new Node(null, null, getSuper(graph, content.resource)) - )); - - // Remove raw statements that this section already shows - Layer0 L0 = Layer0.getInstance(graph); - RawStatementsSection rawStatementsSection = content.getSection(RawStatementsSection.class); - rawStatementsSection.statementsByPredicates.remove(L0.InstanceOf); - rawStatementsSection.statementsByPredicates.remove(L0.SubrelationOf); - rawStatementsSection.statementsByPredicates.remove(L0.Inherits); - } - - public Node[] getSuper(ReadGraph graph, Resource resource) throws DatabaseException { - ArrayList nodes = new ArrayList(); - Layer0 L0 = Layer0.getInstance(graph); - for(Resource s : graph.getObjects(resource, L0.InstanceOf)) - nodes.add(new Node(":", new ResourceInfo(graph, s), getSuper(graph, s))); - for(Resource s : graph.getObjects(resource, L0.Inherits)) { - if(s.equals(L0.Entity)) - continue; - nodes.add(new Node("<T", new ResourceInfo(graph, s), getSuper(graph, s))); - } - for(Resource s : graph.getObjects(resource, L0.SubrelationOf)) { - if(s.equals(L0.IsWeaklyRelatedTo)) - continue; - nodes.add(new Node("<R", new ResourceInfo(graph, s), getSuper(graph, s))); - } - return nodes.toArray(new Node[nodes.size()]); - } - - @Override - public double getPriority() { - return 1; - } -} +/******************************************************************************* + * 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.internal.rewriters; + +import java.util.ArrayList; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.debug.browser.content.ResourceBrowserContent; +import org.simantics.debug.browser.content.ResourceBrowserRewriter; +import org.simantics.debug.browser.sections.RawStatementsSection; +import org.simantics.debug.browser.sections.TypeHierarchySection; +import org.simantics.debug.browser.sections.TypeHierarchySection.Node; +import org.simantics.debug.browser.utils.ResourceInfo; +import org.simantics.layer0.Layer0; + +public enum TypeHierarchyCreator implements ResourceBrowserRewriter { + INSTANCE; + + @Override + public void rewrite(ReadGraph graph, ResourceBrowserContent content) + throws DatabaseException { + content.putSection(TypeHierarchySection.class, + new TypeHierarchySection( + new Node(null, null, getSuper(graph, content.resource)) + )); + + // Remove raw statements that this section already shows + Layer0 L0 = Layer0.getInstance(graph); + RawStatementsSection rawStatementsSection = content.getSection(RawStatementsSection.class); + rawStatementsSection.statementsByPredicates.remove(L0.InstanceOf); + rawStatementsSection.statementsByPredicates.remove(L0.SubrelationOf); + rawStatementsSection.statementsByPredicates.remove(L0.Inherits); + } + + public Node[] getSuper(ReadGraph graph, Resource resource) throws DatabaseException { + ArrayList nodes = new ArrayList(); + Layer0 L0 = Layer0.getInstance(graph); + for(Resource s : graph.getObjects(resource, L0.InstanceOf)) + nodes.add(new Node(":", new ResourceInfo(graph, s), getSuper(graph, s))); + for(Resource s : graph.getObjects(resource, L0.Inherits)) { + if(s.equals(L0.Entity)) + continue; + nodes.add(new Node("<T", new ResourceInfo(graph, s), getSuper(graph, s))); + } + for(Resource s : graph.getObjects(resource, L0.SubrelationOf)) { + if(s.equals(L0.IsWeaklyRelatedTo)) + continue; + nodes.add(new Node("<R", new ResourceInfo(graph, s), getSuper(graph, s))); + } + return nodes.toArray(new Node[nodes.size()]); + } + + @Override + public double getPriority() { + return 1; + } +}