]> gerrit.simantics Code Review - simantics/sysdyn.git/blob
5d88453e0404c8cb7647faa3ccb19a16b258c2d5
[simantics/sysdyn.git] /
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2012 Association for Decentralized Information Management in\r
3  * Industry THTH ry.\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
8  *\r
9  * Contributors:\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
13 \r
14 import java.util.ArrayList;\r
15 import java.util.Collection;\r
16 \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
32 \r
33 public class ParameterChildRule implements ChildRule {\r
34 \r
35     @Override\r
36     public boolean isCompatible(Class<?> contentType) {\r
37         return contentType.equals(Resource.class);\r
38     }\r
39 \r
40     @Override\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
44             return result;\r
45         \r
46         Layer0 L0 = Layer0.getInstance(graph);\r
47         StructuralResource2 STR = StructuralResource2.getInstance(graph);\r
48         SysdynResource sr = SysdynResource.getInstance(graph);\r
49         \r
50         Resource moduleInstance = (Resource) parent;\r
51         \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
56         \r
57         Resource varConfRes = graph.getSingleObject(moduleInstance, L0.PartOf);\r
58         Configuration varConf = sdm.getModel(graph, varConfRes).getConfiguration();\r
59         \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
65         }\r
66         \r
67         return result;\r
68 \r
69 \r
70     }\r
71 \r
72     @Override\r
73     public Collection<?> getParents(ReadGraph graph, Object child) throws DatabaseException {\r
74         return new ArrayList<Resource>();\r
75     }\r
76 \r
77 }\r