Support diagram profile activity store/restore in model export/import
[simantics/platform.git] / bundles / org.simantics.diagram.profile / src / org / simantics / diagram / profile / request / ReferencedProfileEntries.java
1 package org.simantics.diagram.profile.request;
2
3 import java.util.Collection;
4 import java.util.HashSet;
5
6 import org.simantics.db.ReadGraph;
7 import org.simantics.db.Resource;
8 import org.simantics.db.common.request.ResourceRead;
9 import org.simantics.db.exception.DatabaseException;
10 import org.simantics.diagram.stubs.DiagramResource;
11 import org.simantics.scenegraph.profile.ProfileUtils;
12
13 public class ReferencedProfileEntries extends ResourceRead<Collection<Resource>> {
14
15         public ReferencedProfileEntries(Resource part) {
16                 super(part);
17         }
18
19         public HashSet<Resource> process(ReadGraph graph, Resource resource, HashSet<Resource> result) throws DatabaseException {
20
21                 DiagramResource DIA = DiagramResource.getInstance(graph);
22                 
23         if(graph.isInstanceOf(resource, DIA.Profile)) {
24
25                 for(Resource child : ProfileUtils.getProfileChildren(graph, resource)) {
26                         process(graph, child, result);
27                 }
28                 
29         } else if(graph.isInstanceOf(resource, DIA.ProfileEntry)) {
30                 
31                 result.add(resource);
32
33                 }
34         
35         return result;
36         
37         }
38         
39         @Override
40         public Collection<Resource> perform(ReadGraph graph) throws DatabaseException {
41                 return process(graph, resource, new HashSet<Resource>());
42         }
43         
44 }