1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2012 Association for Decentralized Information Management in
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.sysdyn.ui.properties.widgets.modules;
\r
14 import java.util.ArrayList;
\r
15 import java.util.Collection;
\r
17 import org.simantics.browsing.ui.model.children.ChildRule;
\r
18 import org.simantics.db.ReadGraph;
\r
19 import org.simantics.db.Resource;
\r
20 import org.simantics.db.common.request.ObjectsWithType;
\r
21 import org.simantics.db.exception.DatabaseException;
\r
22 import org.simantics.layer0.Layer0;
\r
23 import org.simantics.structural.stubs.StructuralResource2;
\r
24 import org.simantics.sysdyn.SysdynResource;
\r
25 import org.simantics.sysdyn.manager.SysdynModel;
\r
26 import org.simantics.sysdyn.manager.SysdynModelManager;
\r
27 import org.simantics.sysdyn.representation.Configuration;
\r
28 import org.simantics.sysdyn.representation.IElement;
\r
29 import org.simantics.sysdyn.representation.IndependentVariable;
\r
30 import org.simantics.sysdyn.representation.Stock;
\r
31 import org.simantics.sysdyn.representation.Variability;
\r
33 public class ParameterChildRule implements ChildRule {
\r
36 public boolean isCompatible(Class<?> contentType) {
\r
37 return contentType.equals(Resource.class);
\r
41 public Collection<?> getChildren(ReadGraph graph, Object parent) throws DatabaseException {
\r
42 ArrayList<ParameterNode> result = new ArrayList<ParameterNode>();
\r
43 if(!(parent instanceof Resource))
\r
46 Layer0 L0 = Layer0.getInstance(graph);
\r
47 StructuralResource2 STR = StructuralResource2.getInstance(graph);
\r
48 SysdynResource sr = SysdynResource.getInstance(graph);
\r
50 Resource moduleInstance = (Resource) parent;
\r
52 Resource type = graph.getSingleObject(moduleInstance, L0.InstanceOf);
\r
53 Resource configuration = graph.getSingleObject(type, STR.IsDefinedBy);
\r
54 SysdynModelManager sdm = SysdynModelManager.getInstance(graph.getSession());
\r
55 SysdynModel model = sdm.getModel(graph, configuration);
\r
57 Resource varConfRes = graph.getSingleObject(moduleInstance, L0.PartOf);
\r
58 Configuration varConf = sdm.getModel(graph, varConfRes).getConfiguration();
\r
60 for(Resource variable : graph.syncRequest(new ObjectsWithType(configuration, L0.ConsistsOf, sr.IndependentVariable))) {
\r
61 IElement element = model.getElement(variable);
\r
62 if(element instanceof IndependentVariable && !(element instanceof Stock))
\r
63 if(!Variability.CONTINUOUS.equals(Variability.getVariability((IndependentVariable)element, false, varConf)))
\r
64 result.add(new ParameterNode(moduleInstance, varConf, variable, (IndependentVariable)element));
\r
73 public Collection<?> getParents(ReadGraph graph, Object child) throws DatabaseException {
\r
74 return new ArrayList<Resource>();
\r