X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.document.linking.ui%2Fsrc%2Forg%2Fsimantics%2Fdocument%2Flinking%2Freport%2Ftemplates%2FSourceParentHierarchyWithPropComparator.java;fp=bundles%2Forg.simantics.document.linking.ui%2Fsrc%2Forg%2Fsimantics%2Fdocument%2Flinking%2Freport%2Ftemplates%2FSourceParentHierarchyWithPropComparator.java;h=0e958872b28d16ae45b5317637f61c8160bdde37;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.document.linking.ui/src/org/simantics/document/linking/report/templates/SourceParentHierarchyWithPropComparator.java b/bundles/org.simantics.document.linking.ui/src/org/simantics/document/linking/report/templates/SourceParentHierarchyWithPropComparator.java new file mode 100644 index 000000000..0e958872b --- /dev/null +++ b/bundles/org.simantics.document.linking.ui/src/org/simantics/document/linking/report/templates/SourceParentHierarchyWithPropComparator.java @@ -0,0 +1,51 @@ +package org.simantics.document.linking.report.templates; + +import java.util.List; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.document.linking.ontology.DocumentLink; + +class SourceParentHierarchyWithPropComparator extends ResourceNameComparator { + DocumentLink sl; + + public SourceParentHierarchyWithPropComparator(ReadGraph graph, Resource model) { + super(graph,model); + sl = DocumentLink.getInstance(graph); + } + @Override + public int compare(Resource o1, Resource o2) { + try { + Resource r1 = graph.getSingleObject(o1, sl.hasSource_Inverse); + Resource r2 = graph.getSingleObject(o2, sl.hasSource_Inverse); + List path1 = getPath(r1); + List path2 = getPath(r2); + int count = Math.min(path1.size(), path2.size()); + int i = 0; + int comp = 0; + for (; i < count; i++) { + comp = super.compare(path1.get(i), path2.get(i)); + if (comp != 0) + return comp; + } + if (path1.size() < path2.size()) + return -1; + else if (path2.size() > path1.size()) + return 1; + + Resource rel1 = graph.getPossibleObject(o1, sl.consernsRelation); + Resource rel2 = graph.getPossibleObject(o2, sl.consernsRelation); + if (rel1 != null) { + if (rel2 != null) + return super.compare(rel1,rel2); + return 1; + } else if (rel2 != null) + return -1; + return 0; + + } catch (Exception e) { + return 0; + } + + } +} \ No newline at end of file