X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.modeling%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2FLifeCycleProcesses.java;h=ae7cdfd2bc4512411b51ea7cb96cba132c2c73d0;hb=b055bfb36cca301ceed0591028d245e152c8c32d;hp=c597a9289db05b1bdb27dfd12ceef4cc9f2d5e7b;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git 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 c597a9289..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,80 +1,76 @@ -package org.simantics.modeling; - -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.util.Layer0Utils; -import org.simantics.db.layer0.variable.Variable; -import org.simantics.db.layer0.variable.Variables; -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; - -public class LifeCycleProcesses extends AbstractProjectFeature { - - Set contexts = new HashSet(); - - @Override - public void configure() throws ProjectException { - - try { - - Simantics.getSession().syncRequest(new ReadRequest() { - - @Override - public void run(ReadGraph graph) throws DatabaseException { - - 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)); - Function1 load = null; - Function1 unload = null; - Variable loadProperty = Variables.tryGetProperty(graph, lcp, MOD.LifeCycleProcess_load); - if (loadProperty != null) { - load = loadProperty.getPossibleValue(graph); - } - Variable unloadProperty = Variables.tryGetProperty(graph, lcp, MOD.LifeCycleProcess_unload); - if (unloadProperty != null) { - unload = unloadProperty.getPossibleValue(graph); - } - - LifeCycleContext lcc = new LifeCycleContext(lcp, load, unload); - contexts.add(lcc); - - } - } - - } - - }); - - } 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(); - } - - } - -} +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.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 { + + private static final Logger LOGGER = LoggerFactory.getLogger(LifeCycleProcesses.class); + + Set contexts = Collections.emptySet(); + + @Override + public void configure() throws ProjectException { + try { + this.contexts = Simantics.getSession().syncRequest(new Read>() { + + @Override + 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 : 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); + if (loadProperty != null) { + load = loadProperty.getPossibleValue(graph); + } + Variable unloadProperty = Variables.tryGetProperty(graph, lcp, MOD.LifeCycleProcess_unload); + if (unloadProperty != null) { + unload = unloadProperty.getPossibleValue(graph); + } + + LifeCycleContext lcc = new LifeCycleContext(lcp, load, unload); + contexts.add(lcc); + + } + } + + return contexts; + } + }); + + contexts.forEach(LifeCycleContext::load); + + } catch (DatabaseException e) { + throw new ProjectException(e); + } + } + + @Override + public void deconfigure() throws ProjectException { + contexts.forEach(LifeCycleContext::unload); + } + +}