]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling/src/org/simantics/modeling/LifeCycleProcesses.java
Disable SCL Issue provider by default
[simantics/platform.git] / bundles / org.simantics.modeling / src / org / simantics / modeling / LifeCycleProcesses.java
1 package org.simantics.modeling;
2
3 import java.util.Collections;
4 import java.util.HashSet;
5 import java.util.Set;
6
7 import org.simantics.Simantics;
8 import org.simantics.db.ReadGraph;
9 import org.simantics.db.Resource;
10 import org.simantics.db.exception.DatabaseException;
11 import org.simantics.db.layer0.QueryIndexUtils;
12 import org.simantics.db.layer0.util.Layer0Utils;
13 import org.simantics.db.layer0.variable.Variable;
14 import org.simantics.db.layer0.variable.Variables;
15 import org.simantics.db.request.Read;
16 import org.simantics.project.exception.ProjectException;
17 import org.simantics.project.features.AbstractProjectFeature;
18 import org.simantics.scl.runtime.function.Function1;
19 import org.simantics.scl.runtime.tuple.Tuple0;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23 public class LifeCycleProcesses extends AbstractProjectFeature {
24
25         private static final Logger LOGGER = LoggerFactory.getLogger(LifeCycleProcesses.class);
26
27         Set<LifeCycleContext> contexts = Collections.emptySet();
28
29         @Override
30         public void configure() throws ProjectException {
31                 try {
32                         this.contexts = Simantics.getSession().syncRequest(new Read<Set<LifeCycleContext>>() {
33
34                                 @Override
35                                 public Set<LifeCycleContext> perform(ReadGraph graph) throws DatabaseException {
36                                         Set<LifeCycleContext> contexts = new HashSet<>();
37
38                                         ModelingResources MOD = ModelingResources.getInstance(graph);
39                                         for(Resource indexRoot : Layer0Utils.listIndexRoots(graph)) {
40                                                 for(Resource lcp : QueryIndexUtils.searchByTypeShallow(graph, indexRoot, MOD.LifeCycleProcess)) {
41
42                                                         LOGGER.trace("Loading life cycle process " + graph.getURI(lcp));
43                                                         Function1<LifeCycleContext,Tuple0> load = null; 
44                                                         Function1<LifeCycleContext,Tuple0> unload = null;
45                                                 Variable loadProperty = Variables.tryGetProperty(graph, lcp, MOD.LifeCycleProcess_load);
46                                                 if (loadProperty != null) {
47                                                     load = loadProperty.getPossibleValue(graph);
48                                                 }
49                                                 Variable unloadProperty = Variables.tryGetProperty(graph, lcp, MOD.LifeCycleProcess_unload);
50                                                 if (unloadProperty != null) {
51                                                     unload = unloadProperty.getPossibleValue(graph);
52                                                 }
53
54                                                         LifeCycleContext lcc = new LifeCycleContext(lcp, load, unload);
55                                                         contexts.add(lcc);
56
57                                                 }
58                                         }
59
60                                         return contexts;
61                                 }
62                         });
63
64                         contexts.forEach(LifeCycleContext::load);
65
66                 } catch (DatabaseException e) {
67                         throw new ProjectException(e);
68                 }
69         }
70
71         @Override
72         public void deconfigure() throws ProjectException {
73                 contexts.forEach(LifeCycleContext::unload);
74         }
75
76 }