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%2Futils%2FResourceInfo.java;h=009623f4b8bcecc35c1ca2f33359886de8a70a83;hp=655ef935e488de0cbd409b938693372a3883944c;hb=refs%2Fchanges%2F38%2F238%2F2;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.debug.browser/src/org/simantics/debug/browser/utils/ResourceInfo.java b/bundles/org.simantics.debug.browser/src/org/simantics/debug/browser/utils/ResourceInfo.java index 655ef935e..009623f4b 100644 --- a/bundles/org.simantics.debug.browser/src/org/simantics/debug/browser/utils/ResourceInfo.java +++ b/bundles/org.simantics.debug.browser/src/org/simantics/debug/browser/utils/ResourceInfo.java @@ -1,92 +1,92 @@ -/******************************************************************************* - * 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 org.simantics.databoard.Bindings; -import org.simantics.databoard.binding.Binding; -import org.simantics.databoard.binding.error.BindingException; -import org.simantics.databoard.type.Datatype; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.exception.DatabaseException; -import org.simantics.layer0.Layer0; -import org.simantics.utils.strings.AlphanumComparator; - -public class ResourceInfo implements Comparable { - public final String label; - public final String uri; - public final long resourceId; - public final Resource resource; - - public ResourceInfo(ReadGraph graph, Resource resource) throws DatabaseException { - this.label = getLabel(graph, resource); - this.uri = graph.getPossibleURI(resource); - this.resourceId = resource.getResourceId(); - this.resource = resource; - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(80); - sb.append("") - .append(Escapes.html(label)) - .append(""); - - return sb.toString(); - } - - public static String getLabel(ReadGraph graph, Resource resource) throws DatabaseException { - Layer0 L0 = Layer0.getInstance(graph); - String name = graph.getPossibleRelatedValue(resource, L0.HasName); - if(name != null) { - if(name.equals("Inverse")) { - Resource inverse = graph.getPossibleInverse(resource); - Resource parent = graph.getPossibleObject(resource, L0.PartOf); - if(inverse != null && inverse.equals(parent)) { - String parentName = graph.getPossibleRelatedValue(parent, L0.HasName); - if(parentName != null) - return parentName + "/Inverse"; - } - } - return name; - } - - if(graph.hasValue(resource)) { - Datatype datatype = graph.getDataType(resource); - Binding binding = Bindings.getBinding(datatype); - Object value = graph.getValue(resource, binding); - try { - String valueString = binding.toString(value, true); - if(valueString.length() < 100) - return valueString; - else - return valueString.substring(0, 100) + "..."; - } catch (BindingException e) { - e.printStackTrace(); - } - } - - return "$" + resource.getResourceId(); - } - - @Override - public int compareTo(ResourceInfo o) { - return AlphanumComparator.CASE_INSENSITIVE_COMPARATOR.compare(label, o.label); - } -} +/******************************************************************************* + * 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 org.simantics.databoard.Bindings; +import org.simantics.databoard.binding.Binding; +import org.simantics.databoard.binding.error.BindingException; +import org.simantics.databoard.type.Datatype; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.layer0.Layer0; +import org.simantics.utils.strings.AlphanumComparator; + +public class ResourceInfo implements Comparable { + public final String label; + public final String uri; + public final long resourceId; + public final Resource resource; + + public ResourceInfo(ReadGraph graph, Resource resource) throws DatabaseException { + this.label = getLabel(graph, resource); + this.uri = graph.getPossibleURI(resource); + this.resourceId = resource.getResourceId(); + this.resource = resource; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(80); + sb.append("") + .append(Escapes.html(label)) + .append(""); + + return sb.toString(); + } + + public static String getLabel(ReadGraph graph, Resource resource) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + String name = graph.getPossibleRelatedValue(resource, L0.HasName); + if(name != null) { + if(name.equals("Inverse")) { + Resource inverse = graph.getPossibleInverse(resource); + Resource parent = graph.getPossibleObject(resource, L0.PartOf); + if(inverse != null && inverse.equals(parent)) { + String parentName = graph.getPossibleRelatedValue(parent, L0.HasName); + if(parentName != null) + return parentName + "/Inverse"; + } + } + return name; + } + + if(graph.hasValue(resource)) { + Datatype datatype = graph.getDataType(resource); + Binding binding = Bindings.getBinding(datatype); + Object value = graph.getValue(resource, binding); + try { + String valueString = binding.toString(value, true); + if(valueString.length() < 100) + return valueString; + else + return valueString.substring(0, 100) + "..."; + } catch (BindingException e) { + e.printStackTrace(); + } + } + + return "$" + resource.getResourceId(); + } + + @Override + public int compareTo(ResourceInfo o) { + return AlphanumComparator.CASE_INSENSITIVE_COMPARATOR.compare(label, o.label); + } +}