1 package org.simantics.modeling;
3 import java.util.HashSet;
6 import org.simantics.Simantics;
7 import org.simantics.db.ReadGraph;
8 import org.simantics.db.Resource;
9 import org.simantics.db.common.request.ReadRequest;
10 import org.simantics.db.exception.DatabaseException;
11 import org.simantics.db.layer0.util.Layer0Utils;
12 import org.simantics.db.layer0.variable.Variable;
13 import org.simantics.db.layer0.variable.Variables;
14 import org.simantics.project.exception.ProjectException;
15 import org.simantics.project.features.AbstractProjectFeature;
16 import org.simantics.scl.runtime.function.Function1;
17 import org.simantics.scl.runtime.tuple.Tuple0;
19 public class LifeCycleProcesses extends AbstractProjectFeature {
21 Set<LifeCycleContext> contexts = new HashSet<LifeCycleContext>();
24 public void configure() throws ProjectException {
28 Simantics.getSession().syncRequest(new ReadRequest() {
31 public void run(ReadGraph graph) throws DatabaseException {
33 ModelingResources MOD = ModelingResources.getInstance(graph);
34 for(Resource indexRoot : Layer0Utils.listIndexRoots(graph)) {
35 for(Resource lcp : ModelingUtils.searchByTypeShallow(graph, indexRoot, MOD.LifeCycleProcess)) {
37 // System.err.println("Loading life cycle process " + graph.getURI(lcp));
38 Function1<LifeCycleContext,Tuple0> load = null;
39 Function1<LifeCycleContext,Tuple0> unload = null;
40 Variable loadProperty = Variables.tryGetProperty(graph, lcp, MOD.LifeCycleProcess_load);
41 if (loadProperty != null) {
42 load = loadProperty.getPossibleValue(graph);
44 Variable unloadProperty = Variables.tryGetProperty(graph, lcp, MOD.LifeCycleProcess_unload);
45 if (unloadProperty != null) {
46 unload = unloadProperty.getPossibleValue(graph);
49 LifeCycleContext lcc = new LifeCycleContext(lcp, load, unload);
59 } catch (DatabaseException e) {
61 throw new ProjectException(e);
65 for(LifeCycleContext context : contexts) {
72 public void deconfigure() throws ProjectException {
74 for(LifeCycleContext context : contexts) {