]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling/src/org/simantics/modeling/adapters/ActiveExperiment.java
Find SCL references in SCLModuleEditor with Ctrl+Shift+G
[simantics/platform.git] / bundles / org.simantics.modeling / src / org / simantics / modeling / adapters / ActiveExperiment.java
1 /*******************************************************************************
2  * Copyright (c) 2012 Association for Decentralized Information Management in
3  * Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.modeling.adapters;
13
14 import org.simantics.db.ReadGraph;
15 import org.simantics.db.Resource;
16 import org.simantics.db.common.utils.Logger;
17 import org.simantics.db.exception.DatabaseException;
18 import org.simantics.db.layer0.request.PossibleActiveExperimentPath;
19 import org.simantics.db.layer0.variable.Variable;
20 import org.simantics.db.layer0.variable.Variables;
21 import org.simantics.scl.runtime.function.FunctionImpl2;
22
23 /**
24  * f: (ReadGraph, Resource model) -> Variable activeExperiment
25  * 
26  * @author Tuukka Lehtonen
27  */
28 public class ActiveExperiment extends FunctionImpl2<ReadGraph, Resource, Variable> {
29
30     @Override
31     public Variable apply(ReadGraph p0, Resource p1) {
32         try {
33             ReadGraph graph = (ReadGraph) p0;
34             Resource model = (Resource) p1;
35
36             String activeExperimentPath = graph.syncRequest(new PossibleActiveExperimentPath(model));
37             if (activeExperimentPath == null)
38                 return null;
39
40             Variable var = Variables.getPossibleVariable(graph, model);
41             if (var == null)
42                 return null;
43             Variable run = var.browsePossible(graph, activeExperimentPath);
44             return run;
45         } catch (DatabaseException e) {
46             Logger.defaultLogError(e);
47             return null;
48         }
49     }
50
51 }