]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.document.linking.ui/src/org/simantics/document/linking/report/templates/SourceParentComparator.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.document.linking.ui / src / org / simantics / document / linking / report / templates / SourceParentComparator.java
1 package org.simantics.document.linking.report.templates;
2
3 import org.simantics.db.ReadGraph;
4 import org.simantics.db.Resource;
5 import org.simantics.document.linking.ontology.DocumentLink;
6
7 class SourceParentComparator extends ResourceNameComparator {
8         DocumentLink sl;
9         public SourceParentComparator(ReadGraph graph, Resource model) {
10                 super(graph,model);
11                 sl = DocumentLink.getInstance(graph);
12         }
13         
14         @Override
15         public int compare(Resource o1, Resource o2) {
16                 try {
17                         Resource r1 = graph.getSingleObject(o1, sl.hasSource_Inverse);
18                         Resource r2 = graph.getSingleObject(o2, sl.hasSource_Inverse);
19                         int comp = super.compare(r1,r2);
20                         if (comp == 0) {
21                                 Resource rel1 = graph.getPossibleObject(o1, sl.consernsRelation);
22                                 Resource rel2 = graph.getPossibleObject(o2, sl.consernsRelation);
23                                 if (rel1 != null) {
24                                         if (rel2 != null)
25                                                 return super.compare(rel1,rel2);
26                                         return 1;
27                                 } else if (rel2 != null)
28                                         return -1;
29                                 return 0;
30                         } else {
31                                 return comp;
32                         }
33                 } catch (Exception e) {
34                         return 0;
35                 }
36                 
37         }
38 }