]> gerrit.simantics Code Review - simantics/district.git/blob
f8f4b9aa34ee2e85b18309048160ec6ed881b9ca
[simantics/district.git] /
1 package org.simantics.district.network.profile;
2
3 import java.util.Collection;
4 import java.util.Map;
5 import java.util.stream.Collectors;
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.district.network.DistrictNetworkUtil;
12 import org.simantics.district.network.ontology.DistrictNetworkResource;
13 import org.simantics.district.network.visualisations.DynamicVisualisationsContributions;
14 import org.simantics.district.network.visualisations.DynamicVisualisationsContributions.DynamicColoringObject;
15 import org.simantics.district.network.visualisations.DynamicVisualisationsContributions.DynamicSizingObject;
16 import org.simantics.district.network.visualisations.model.ColorBarOptions;
17 import org.simantics.district.network.visualisations.model.DynamicColorContribution;
18 import org.simantics.district.network.visualisations.model.DynamicSizeContribution;
19 import org.simantics.district.network.visualisations.model.DynamicVisualisation;
20 import org.simantics.district.network.visualisations.model.SizeBarOptions;
21 import org.simantics.layer0.Layer0;
22
23 /**
24  * @author Jani Simomaa
25  */
26 public class ActiveDynamicVisualisationsRequest extends ResourceRead<DynamicVisualisation> {
27
28     public ActiveDynamicVisualisationsRequest(Resource parent) {
29         super(parent);
30     }
31
32     @Override
33     public DynamicVisualisation perform(ReadGraph graph) throws DatabaseException {
34         DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
35         Resource visualisationFolder = DistrictNetworkUtil.getVisualisationFolder(graph, resource);
36         if (visualisationFolder != null) {
37             Resource visualisationResource = graph.getPossibleObject(visualisationFolder, DN.Diagram_hasActiveVisualisation);
38             if (visualisationResource != null) {
39                 String name = graph.getRelatedValue(visualisationResource, Layer0.getInstance(graph).HasName);
40                 
41                 Collection<DynamicColoringObject> dynamicColoringObjects = DynamicVisualisationsContributions.dynamicColoringObjects(graph);
42                 Map<String, DynamicColoringObject> defaultColoringObjects = dynamicColoringObjects.stream().collect(Collectors.toMap(dcc -> dcc.getColoringObject().getName(), dcc -> dcc));
43                 
44                 Collection<DynamicSizingObject> dynamicSizingObjects = DynamicVisualisationsContributions.dynamicSizingObjects(graph);
45                 Map<String, DynamicSizingObject> defaultSizingObjects = dynamicSizingObjects.stream().collect(Collectors.toMap(dcc -> dcc.getSizingObject().getName(), dcc -> dcc));
46                 
47                 Map<String, DynamicColorContribution> colorContributions = DistrictNetworkUtil.colorContributions(graph, visualisationResource);
48                 ColorBarOptions colorBarOptions = DistrictNetworkUtil.colorBarOptions(graph, visualisationResource);
49                 Map<String, DynamicSizeContribution> sizeContributions = DistrictNetworkUtil.sizeContributions(graph, visualisationResource);
50                 SizeBarOptions sizeBarOptions = DistrictNetworkUtil.sizeBarOptions(graph, visualisationResource);
51                 DynamicVisualisation visualisation = new DynamicVisualisation(name, visualisationResource, colorContributions, defaultColoringObjects, colorBarOptions, sizeContributions, defaultSizingObjects, sizeBarOptions);
52                 return visualisation; 
53             }
54         }
55         return null;
56     }
57
58 }