]> gerrit.simantics Code Review - simantics/district.git/blob
c2b473c5a50163668ad50af2c38a897c17f27cce
[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.layer0.Layer0;
15
16 /**
17  * @author Jani Simomaa
18  */
19 public class DynamicVisualisationsRequest extends ResourceRead<Collection<NamedResource>> {
20
21     public DynamicVisualisationsRequest(Resource parent) {
22         super(parent);
23     }
24
25     @Override
26     public Collection<NamedResource> perform(ReadGraph graph) throws DatabaseException {
27         DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
28         List<NamedResource> results = new ArrayList<>();
29         Resource visualisationFolder = DistrictNetworkUtil.getVisualisationFolder(graph, resource);
30         if (visualisationFolder != null) {
31             Collection<Resource> visualisationResources = graph.getObjects(visualisationFolder, DN.Diagram_hasVisualisation);
32             if (visualisationResources != null && !visualisationResources.isEmpty()) {
33                 for (Resource visualisationResource : visualisationResources) {
34                     String name = graph.getRelatedValue(visualisationResource, Layer0.getInstance(graph).HasName);
35                     results.add(new NamedResource(name, visualisationResource));
36                 }
37             }
38         }
39         return results;
40     }
41
42 }