]> gerrit.simantics Code Review - simantics/platform.git/blob
4c3cd57b7e1e21efc297650bcba579368e2cc648
[simantics/platform.git] /
1 package org.simantics.scenegraph.profile.request;
2
3 import java.util.ArrayList;
4 import java.util.Collection;
5 import java.util.Collections;
6
7 import org.simantics.db.ReadGraph;
8 import org.simantics.db.Resource;
9 import org.simantics.db.common.request.ResourceRead;
10 import org.simantics.db.exception.DatabaseException;
11 import org.simantics.db.layer0.adapter.Instances;
12 import org.simantics.diagram.stubs.DiagramResource;
13
14 public class ProfileEntryContributions extends ResourceRead<Collection<Resource>>{
15
16         protected ProfileEntryContributions(Resource runtimeDiagram) {
17                 super(runtimeDiagram);
18         }
19
20         @Override
21         public Collection<Resource> perform(ReadGraph graph) throws DatabaseException {
22
23                 DiagramResource DIA = DiagramResource.getInstance(graph);
24
25                 String indexURI = graph.getPossibleRelatedValue(resource, DIA.RuntimeDiagram_HasModelURI);
26                 if (indexURI == null)
27                         return Collections.emptyList();
28
29                 Resource index = graph.getPossibleResource(indexURI);
30                 if (index == null)
31                         return Collections.emptyList();
32
33                 Instances query = graph.adapt(DIA.ProfileEntryContribution, Instances.class);
34
35                 ArrayList<Resource> result = new ArrayList<>();
36                 for(Resource contribution : query.find(graph, index)) {
37                         result.add(graph.getSingleObject(contribution, DIA.ProfileEntryContribution_HasEntry));
38                 }
39
40                 return result;
41
42         }
43
44 }