]> gerrit.simantics Code Review - simantics/sysdyn.git/blob
3b270819f4054938eae9a1cfca2bb612657e2b7d
[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.Variability;\r
31 \r
32 public class ParameterChildRule implements ChildRule {\r
33 \r
34     @Override\r
35     public boolean isCompatible(Class<?> contentType) {\r
36         return contentType.equals(Resource.class);\r
37     }\r
38 \r
39     @Override\r
40     public Collection<?> getChildren(ReadGraph graph, Object parent) throws DatabaseException {\r
41         ArrayList<ParameterNode> result = new ArrayList<ParameterNode>();\r
42         if(!(parent instanceof Resource))\r
43             return result;\r
44         \r
45         Layer0 L0 = Layer0.getInstance(graph);\r
46         StructuralResource2 STR = StructuralResource2.getInstance(graph);\r
47         SysdynResource sr = SysdynResource.getInstance(graph);\r
48         \r
49         Resource moduleInstance = (Resource) parent;\r
50         \r
51         Resource type = graph.getSingleObject(moduleInstance, L0.InstanceOf);\r
52         Resource configuration = graph.getSingleObject(type, STR.IsDefinedBy);\r
53         SysdynModelManager sdm = SysdynModelManager.getInstance(graph.getSession());\r
54         SysdynModel model = sdm.getModel(graph, configuration);\r
55         \r
56         Resource varConfRes = graph.getSingleObject(moduleInstance, L0.PartOf);\r
57         Configuration varConf = sdm.getModel(graph, varConfRes).getConfiguration();\r
58         \r
59         for(Resource variable : graph.syncRequest(new ObjectsWithType(configuration, L0.ConsistsOf, sr.IndependentVariable))) {\r
60             IElement element = model.getElement(variable);\r
61             if(element instanceof IndependentVariable) \r
62                 if(!Variability.CONTINUOUS.equals(Variability.getVariability((IndependentVariable)element, false, varConf)))\r
63                     result.add(new ParameterNode(moduleInstance, varConf, variable, (IndependentVariable)element));\r
64         }\r
65         \r
66         return result;\r
67 \r
68 \r
69     }\r
70 \r
71     @Override\r
72     public Collection<?> getParents(ReadGraph graph, Object child) throws DatabaseException {\r
73         return new ArrayList<Resource>();\r
74     }\r
75 \r
76 }\r