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