]> gerrit.simantics Code Review - simantics/district.git/blob
0387029ffdf98fefaabce12d2fc4e4c6b86e6a99
[simantics/district.git] /
1 package org.simantics.district.network.profile;
2
3 import java.util.ArrayList;
4 import java.util.Collection;
5 import java.util.List;
6
7 import org.simantics.db.ReadGraph;
8 import org.simantics.db.Resource;
9 import org.simantics.db.common.NamedResource;
10 import org.simantics.db.common.request.ResourceRead;
11 import org.simantics.db.exception.DatabaseException;
12 import org.simantics.district.network.DistrictNetworkUtil;
13 import org.simantics.district.network.ontology.DistrictNetworkResource;
14 import org.simantics.district.network.visualisations.DynamicVisualisations;
15 import org.simantics.layer0.Layer0;
16
17 /**
18  * @author Jani Simomaa
19  */
20 public class DynamicVisualisationsRequest extends ResourceRead<Collection<NamedResource>> {
21
22     public DynamicVisualisationsRequest(Resource parent) {
23         super(parent);
24     }
25
26     @Override
27     public Collection<NamedResource> perform(ReadGraph graph) throws DatabaseException {
28         DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
29         List<NamedResource> results = new ArrayList<>();
30         Resource visualisationFolder = DynamicVisualisations.getVisualisationFolder(graph, resource);
31         if (visualisationFolder != null) {
32             Collection<Resource> visualisationResources = graph.getObjects(visualisationFolder, DN.Diagram_hasVisualisation);
33             if (visualisationResources != null && !visualisationResources.isEmpty()) {
34                 for (Resource visualisationResource : visualisationResources) {
35                     String name = graph.getRelatedValue(visualisationResource, Layer0.getInstance(graph).HasName);
36                     results.add(new NamedResource(name, visualisationResource));
37                 }
38             }
39         }
40         return results;
41     }
42
43 }