]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/PossibleActiveValuation.java
Index tokenized lowercase versions of name and types for UI searches
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / request / PossibleActiveValuation.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in 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.db.layer0.request;
13
14 import org.simantics.db.ReadGraph;
15 import org.simantics.db.Resource;
16 import org.simantics.db.common.exception.DebugException;
17 import org.simantics.db.common.request.BinaryRead;
18 import org.simantics.db.exception.AdaptionException;
19 import org.simantics.db.exception.DatabaseException;
20 import org.simantics.db.exception.ResourceNotFoundException;
21 import org.simantics.db.layer0.adapter.Valuations;
22 import org.simantics.layer0.Layer0;
23 import org.simantics.simulation.ontology.SimulationResource;
24
25 public class PossibleActiveValuation extends BinaryRead<Resource, String, Resource> {
26
27     public PossibleActiveValuation(Resource resource) {
28         super(resource, "");
29     }
30
31     public PossibleActiveValuation(Resource resource, String suffix) {
32         super(resource, suffix);
33     }
34
35     @Override
36     public Resource perform(ReadGraph graph) throws DatabaseException {
37
38         try {
39
40             if(!graph.hasStatement(parameter)) return null;
41
42                 Layer0 b = Layer0.getInstance(graph);
43             SimulationResource SIMU = SimulationResource.getInstance(graph);
44
45             String valuationName = null;
46
47             Valuations valuations = graph.adapt(parameter, Valuations.class);
48
49             Resource diagram = graph.syncRequest(new PossibleDiagram(parameter));
50             if(diagram != null) {
51
52                 String valuation = graph.getPossibleRelatedValue(diagram, SIMU.HasActiveExperiment);
53                 if(valuation != null) valuationName = valuation;
54
55             }
56
57             if(valuationName == null) {
58
59                 Resource model = graph.syncRequest(new PossibleModel(parameter));
60                 if (model != null) {
61                     String valuation = graph.syncRequest(new PossibleActiveExperimentPath(model));
62                     if(valuation != null) valuationName = valuation;
63                 }
64
65             }
66
67             if (valuationName == null) {
68
69                 valuationName = "BaseRealization";
70
71             }
72
73             Resource value = valuations.getValue(graph, null, valuationName, parameter2);
74
75             return graph.getSingleObject(value, b.ConsistsOf);
76
77         } catch (ResourceNotFoundException e) {
78             if (DebugException.DEBUG)
79                 e.printStackTrace();
80             return null;
81         } catch (AdaptionException e) {
82             if (DebugException.DEBUG)
83                 e.printStackTrace();
84             return null;
85         } catch (Throwable e) {
86             if (DebugException.DEBUG)
87                 e.printStackTrace();
88             return null;
89         }
90
91     }
92
93 }