X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.modeling%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Fadapters%2FActiveExperiment.java;fp=bundles%2Forg.simantics.modeling%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Fadapters%2FActiveExperiment.java;h=187d56e49cba433877286cad4001d06c8c03a643;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/adapters/ActiveExperiment.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/adapters/ActiveExperiment.java new file mode 100644 index 000000000..187d56e49 --- /dev/null +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/adapters/ActiveExperiment.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2012 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.modeling.adapters; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.utils.Logger; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.request.PossibleActiveExperimentPath; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.db.layer0.variable.Variables; +import org.simantics.scl.runtime.function.FunctionImpl2; + +/** + * f: (ReadGraph, Resource model) -> Variable activeExperiment + * + * @author Tuukka Lehtonen + */ +public class ActiveExperiment extends FunctionImpl2 { + + @Override + public Variable apply(ReadGraph p0, Resource p1) { + try { + ReadGraph graph = (ReadGraph) p0; + Resource model = (Resource) p1; + + String activeExperimentPath = graph.syncRequest(new PossibleActiveExperimentPath(model)); + if (activeExperimentPath == null) + return null; + + Variable var = Variables.getPossibleVariable(graph, model); + if (var == null) + return null; + Variable run = var.browsePossible(graph, activeExperimentPath); + return run; + } catch (DatabaseException e) { + Logger.defaultLogError(e); + return null; + } + } + +}