Support diagram profile activity store/restore in model export/import
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / profile / TopLevelProfiles.java
1 package org.simantics.diagram.profile;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 import org.simantics.databoard.Bindings;
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.db.layer0.adapter.Instances;
13 import org.simantics.diagram.synchronization.graph.BasicResources;
14
15 /**
16  * @author Tuukka Lehtonen
17  * @since 1.32.0
18  */
19 public class TopLevelProfiles extends ResourceRead<List<NamedResource>> {
20
21         protected TopLevelProfiles(Resource root) {
22                 super(root);
23         }
24
25         @Override
26         public List<NamedResource> perform(ReadGraph graph) throws DatabaseException {
27                 BasicResources BR = BasicResources.getInstance(graph);
28                 ArrayList<NamedResource> result = new ArrayList<>();
29
30                 Instances query = graph.adapt(BR.DIA.Profile, Instances.class);
31                 for (Resource profile : query.find(graph, resource)) {
32                         if (!graph.hasStatement(profile, BR.L0.Abstract)) {
33                                 String name = graph.getPossibleRelatedValue(profile, BR.L0.HasName, Bindings.STRING);
34                                 if (name != null) {
35                                         result.add(new NamedResource(name, profile));
36                                 }
37                         }
38                 }
39
40                 return result;
41         }
42
43 }