]> gerrit.simantics Code Review - simantics/sysdyn.git/blob
7b3b20bf981c0b074232e54338c2716b5813cf54
[simantics/sysdyn.git] /
1 /*******************************************************************************\r
2  * Copyright (c) 2010 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;\r
13 \r
14 import org.simantics.db.ReadGraph;\r
15 import org.simantics.db.Resource;\r
16 import org.simantics.db.exception.DatabaseException;\r
17 import org.simantics.db.request.Read;\r
18 import org.simantics.sysdyn.SysdynResource;\r
19 import org.simantics.ui.SimanticsUI;\r
20 \r
21 /**\r
22  * Expression type representations\r
23  * @author Teemu Lempinen\r
24  *\r
25  */\r
26 public class ExpressionTypes {\r
27 \r
28         public static enum ExpressionType {Auxiliary, Parameter, Constant, Lookup, WithLookup, Stock, Delay, Empty};\r
29 \r
30         public static ExpressionType[] auxiliaryExpressions = new ExpressionType[] {\r
31                 ExpressionType.Auxiliary, \r
32                 ExpressionType.Parameter, \r
33                 ExpressionType.Constant, \r
34                 ExpressionType.Delay,\r
35                 // ExpressionType.Lookup, \r
36                 ExpressionType.WithLookup};\r
37 \r
38         public static ExpressionType[] valveExpressions = new ExpressionType[] {\r
39                 ExpressionType.Auxiliary, \r
40                 ExpressionType.Parameter, \r
41                 ExpressionType.Constant, \r
42                 ExpressionType.Delay,\r
43                 ExpressionType.WithLookup};\r
44 \r
45         public static ExpressionType[] stockExpressions = new ExpressionType[] {\r
46                 ExpressionType.Stock};\r
47 \r
48         public static ExpressionType getExpressionType(final Resource expression) {\r
49                 try {\r
50                         return SimanticsUI.getSession().syncRequest(new Read<ExpressionType>() {\r
51 \r
52                                 @Override\r
53                                 public ExpressionType perform(ReadGraph graph) throws DatabaseException {\r
54                                         return getExpressionType(graph, expression);\r
55                                 }\r
56                         });\r
57                 } catch (DatabaseException e) {\r
58                         e.printStackTrace();\r
59                         return null;\r
60                 }\r
61 \r
62         }\r
63         \r
64         public static ExpressionType getExpressionType(ReadGraph graph, final Resource expression) throws DatabaseException {\r
65                 ExpressionType et = null;\r
66                 SysdynResource sr = SysdynResource.getInstance(graph);\r
67                 if(graph.isInstanceOf(expression, sr.NormalExpression)) {\r
68                         et = ExpressionType.Auxiliary;\r
69                 } else if (graph.isInstanceOf(expression, sr.StockExpression)) {\r
70                         et = ExpressionType.Stock;\r
71                 } else if (graph.isInstanceOf(expression, sr.ParameterExpression)) {\r
72                         et = ExpressionType.Parameter;\r
73                 } else if (graph.isInstanceOf(expression, sr.ConstantExpression)) {\r
74                         et = ExpressionType.Constant;\r
75                 } else if (graph.isInstanceOf(expression, sr.DelayExpression)) {\r
76                         et = ExpressionType.Delay;\r
77                 } else if (graph.isInstanceOf(expression, sr.LookupExpression)) {\r
78                         et = ExpressionType.Lookup;\r
79                 } else if (graph.isInstanceOf(expression, sr.WithLookupExpression)) {\r
80                         et = ExpressionType.WithLookup;\r
81                 } else {\r
82                         et =  ExpressionType.Empty;\r
83                 }\r
84                 return et;\r
85         }\r
86 \r
87 }\r