1 package org.simantics.modeling;
3 import java.util.ArrayList;
5 import org.simantics.db.ReadGraph;
6 import org.simantics.db.common.request.ParametrizedPrimitiveRead;
7 import org.simantics.db.procedure.Listener;
8 import org.simantics.scl.compiler.environment.specification.EnvironmentSpecification;
9 import org.simantics.scl.compiler.module.repository.ImportFailureException;
10 import org.simantics.scl.compiler.module.repository.UpdateListener;
11 import org.simantics.scl.compiler.runtime.RuntimeEnvironment;
12 import org.simantics.scl.osgi.SCLOsgi;
13 import org.simantics.scl.runtime.SCLContext;
15 public class ComponentTypeScriptRuntimeEnvironmentRequest extends ParametrizedPrimitiveRead<EnvironmentSpecification, RuntimeEnvironment> {
17 // This array list is only needed to keep strong references to update listeners preventing their garbage collection.
18 ArrayList<UpdateListener> listeners;
20 public ComponentTypeScriptRuntimeEnvironmentRequest(EnvironmentSpecification parameter) {
25 public void register(ReadGraph graph, Listener<RuntimeEnvironment> procedure) {
26 UpdateListener listener = null;
27 if(!procedure.isDisposed()) {
28 listener = new UpdateListener() {
30 public void notifyAboutUpdate() {
31 createRuntimeEnvironment(graph, procedure, this);
35 listeners = new ArrayList<UpdateListener>(2);
36 listeners.add(listener);
38 createRuntimeEnvironment(graph, procedure, listener);
41 private void createRuntimeEnvironment(ReadGraph graph, Listener<RuntimeEnvironment> procedure, UpdateListener listener) {
42 SCLContext context = SCLContext.getCurrent();
43 Object oldGraph = context.put("graph", graph);
45 procedure.execute(SCLOsgi.MODULE_REPOSITORY.createRuntimeEnvironment(parameter, ComponentTypeScriptRuntimeEnvironmentRequest.class.getClassLoader(), listener));
47 catch (ImportFailureException e) {
48 procedure.exception(e);
51 context.put("graph", oldGraph);