]> gerrit.simantics Code Review - simantics/platform.git/blob
806cc47fb336d952faa7bbb14dc3f46658d14860
[simantics/platform.git] /
1 package org.simantics.document.linking.report.templates;
2
3 import java.util.ArrayList;
4 import java.util.Collection;
5 import java.util.Collections;
6 import java.util.List;
7
8 import org.simantics.db.ReadGraph;
9 import org.simantics.db.Resource;
10 import org.simantics.db.layer0.adapter.Instances;
11 import org.simantics.document.linking.utils.SourceLinkUtil;
12 import org.simantics.utils.datastructures.MapList;
13
14
15 public class DiagramStructureWithDependenciesWriter extends DiagramStructureWriter{
16         
17         @Override
18         public String getName() {
19                 return "Diagram structure with dependencies";
20         }
21         
22         @Override
23         public List<Resource> getReportItems(ReadGraph graph) throws Exception {
24                 Instances instancesQuery = graph.adapt(sl.Source, Instances.class);
25         Collection<Resource> found = instancesQuery.find(graph, model);
26         List<Resource> list = new ArrayList<Resource>();
27         MapList<Resource, Resource> diagramToReference = new MapList<Resource, Resource>();
28         for (Resource source : found) {
29                 Resource parent = graph.getSingleObject(source, sl.hasSource_Inverse);
30                 List<Resource> path = SourceLinkUtil.getPath(graph, model, parent);
31                 for (Resource r : path) {
32                         if (graph.hasStatement(r, mod.CompositeToDiagram)){
33                                 Resource doc = SourceLinkUtil.getReferredDocument(graph, source);
34                                 if (doc != null && !diagramToReference.contains(r, doc)) {
35                                         diagramToReference.add(r,doc);
36                                         list.add(source);
37                                 }
38                         }
39                 }
40         }
41         Collections.sort(list, diagramDocumentComparator);
42         return list;
43         }
44
45 }