X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.debug.browser%2Fsrc%2Forg%2Fsimantics%2Fdebug%2Fbrowser%2Futils%2FStatementInfo.java;h=6853803b88ee66619d802b7c721b3cb59daf107c;hb=cf9bdb9c3223ccee2b0a264d72dcc84091718043;hp=606a6048f3dc627d4eff3b2ba3207873a613b7a9;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.debug.browser/src/org/simantics/debug/browser/utils/StatementInfo.java b/bundles/org.simantics.debug.browser/src/org/simantics/debug/browser/utils/StatementInfo.java index 606a6048f..6853803b8 100644 --- a/bundles/org.simantics.debug.browser/src/org/simantics/debug/browser/utils/StatementInfo.java +++ b/bundles/org.simantics.debug.browser/src/org/simantics/debug/browser/utils/StatementInfo.java @@ -1,72 +1,72 @@ -/******************************************************************************* - * 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.utils; - -import java.util.Arrays; -import java.util.Collection; - -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.Statement; -import org.simantics.db.VirtualGraph; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.service.VirtualGraphSupport; - -public class StatementInfo implements Comparable { - public final ResourceInfo subject; // null, if not asserted - public final ResourceInfo object; - public final ResourceInfo[] objectTypes; - public final String graph; // null, if in DB - - public StatementInfo(ReadGraph graph, Resource defaultSubject, Statement statement) throws DatabaseException { - Resource subject = statement.getSubject(); - Resource predicate = statement.getPredicate(); - Resource object = statement.getObject(); - Collection objectTypes = graph.getPrincipalTypes(object); - - if(subject.equalsResource(defaultSubject)) - this.subject = null; - else - this.subject = new ResourceInfo(graph, subject); - this.object = new ResourceInfo(graph, object); - if(objectTypes.isEmpty()) - this.objectTypes = null; - else - this.objectTypes = mapTypes(graph, objectTypes); - this.graph = getGraphName(graph, subject, predicate, object); - } - - - private static ResourceInfo[] mapTypes(ReadGraph graph, Collection types) throws DatabaseException { - ResourceInfo[] result = new ResourceInfo[types.size()]; - int i=0; - for(Resource type : types) - result[i++] = new ResourceInfo(graph, type); - Arrays.sort(result); - return result; - } - - - public static String getGraphName(ReadGraph graph, Resource s, Resource p, Resource o) throws DatabaseException { - VirtualGraphSupport vgs = graph.getService(VirtualGraphSupport.class); - VirtualGraph vg = vgs.getGraph(graph, s, p, o); - if(vg != null) - return vg.toString(); - else - return null; - } - - @Override - public int compareTo(StatementInfo o) { - return object.compareTo(o.object); - } -} +/******************************************************************************* + * 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.utils; + +import java.util.Arrays; +import java.util.Collection; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Statement; +import org.simantics.db.VirtualGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.VirtualGraphSupport; + +public class StatementInfo implements Comparable { + public final ResourceInfo subject; // null, if not asserted + public final ResourceInfo object; + public final ResourceInfo[] objectTypes; + public final String graph; // null, if in DB + + public StatementInfo(ReadGraph graph, Resource defaultSubject, Statement statement) throws DatabaseException { + Resource subject = statement.getSubject(); + Resource predicate = statement.getPredicate(); + Resource object = statement.getObject(); + Collection objectTypes = graph.getPrincipalTypes(object); + + if(subject.equalsResource(defaultSubject)) + this.subject = null; + else + this.subject = new ResourceInfo(graph, subject); + this.object = new ResourceInfo(graph, object); + if(objectTypes.isEmpty()) + this.objectTypes = null; + else + this.objectTypes = mapTypes(graph, objectTypes); + this.graph = getGraphName(graph, subject, predicate, object); + } + + + private static ResourceInfo[] mapTypes(ReadGraph graph, Collection types) throws DatabaseException { + ResourceInfo[] result = new ResourceInfo[types.size()]; + int i=0; + for(Resource type : types) + result[i++] = new ResourceInfo(graph, type); + Arrays.sort(result); + return result; + } + + + public static String getGraphName(ReadGraph graph, Resource s, Resource p, Resource o) throws DatabaseException { + VirtualGraphSupport vgs = graph.getService(VirtualGraphSupport.class); + VirtualGraph vg = vgs.getGraph(graph, s, p, o); + if(vg != null) + return vg.toString(); + else + return null; + } + + @Override + public int compareTo(StatementInfo o) { + return object.compareTo(o.object); + } +}