X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.modeling%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2FLifeCycleProcesses.java;h=ae7cdfd2bc4512411b51ea7cb96cba132c2c73d0;hp=e8e32796d83421c3cc381050114fae226a06b626;hb=bd6a9e185eb6ba6b5f739f54b48c9607dd784ba9;hpb=78d831a19c254d829e45d04c5ec6a3057680b7d7 diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/LifeCycleProcesses.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/LifeCycleProcesses.java index e8e32796d..ae7cdfd2b 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/LifeCycleProcesses.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/LifeCycleProcesses.java @@ -1,40 +1,45 @@ package org.simantics.modeling; +import java.util.Collections; import java.util.HashSet; import java.util.Set; import org.simantics.Simantics; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; -import org.simantics.db.common.request.ReadRequest; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.QueryIndexUtils; import org.simantics.db.layer0.util.Layer0Utils; import org.simantics.db.layer0.variable.Variable; import org.simantics.db.layer0.variable.Variables; +import org.simantics.db.request.Read; import org.simantics.project.exception.ProjectException; import org.simantics.project.features.AbstractProjectFeature; import org.simantics.scl.runtime.function.Function1; import org.simantics.scl.runtime.tuple.Tuple0; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class LifeCycleProcesses extends AbstractProjectFeature { - - Set contexts = new HashSet(); + + private static final Logger LOGGER = LoggerFactory.getLogger(LifeCycleProcesses.class); + + Set contexts = Collections.emptySet(); @Override public void configure() throws ProjectException { - try { - - Simantics.getSession().syncRequest(new ReadRequest() { + this.contexts = Simantics.getSession().syncRequest(new Read>() { @Override - public void run(ReadGraph graph) throws DatabaseException { + public Set perform(ReadGraph graph) throws DatabaseException { + Set contexts = new HashSet<>(); ModelingResources MOD = ModelingResources.getInstance(graph); for(Resource indexRoot : Layer0Utils.listIndexRoots(graph)) { - for(Resource lcp : ModelingUtils.searchByTypeShallow(graph, indexRoot, MOD.LifeCycleProcess)) { - -// System.err.println("Loading life cycle process " + graph.getURI(lcp)); + for(Resource lcp : QueryIndexUtils.searchByTypeShallow(graph, indexRoot, MOD.LifeCycleProcess)) { + + LOGGER.trace("Loading life cycle process " + graph.getURI(lcp)); Function1 load = null; Function1 unload = null; Variable loadProperty = Variables.tryGetProperty(graph, lcp, MOD.LifeCycleProcess_load); @@ -48,33 +53,24 @@ public class LifeCycleProcesses extends AbstractProjectFeature { LifeCycleContext lcc = new LifeCycleContext(lcp, load, unload); contexts.add(lcc); - + } } - + + return contexts; } - }); - + + contexts.forEach(LifeCycleContext::load); + } catch (DatabaseException e) { - throw new ProjectException(e); - } - - for(LifeCycleContext context : contexts) { - context.load(); - } - } @Override public void deconfigure() throws ProjectException { - - for(LifeCycleContext context : contexts) { - context.unload(); - } - + contexts.forEach(LifeCycleContext::unload); } - + }