1 /*******************************************************************************
\r
2 * Copyright (c) 2010 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;
\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
22 * Expression type representations
\r
23 * @author Teemu Lempinen
\r
26 public class ExpressionTypes {
\r
28 public static enum ExpressionType {Auxiliary, Parameter, Constant, Lookup, WithLookup, Stock, Delay, Empty};
\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
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
45 public static ExpressionType[] stockExpressions = new ExpressionType[] {
\r
46 ExpressionType.Stock};
\r
48 public static ExpressionType getExpressionType(final Resource expression) {
\r
50 return SimanticsUI.getSession().syncRequest(new Read<ExpressionType>() {
\r
53 public ExpressionType perform(ReadGraph graph) throws DatabaseException {
\r
54 return getExpressionType(graph, expression);
\r
57 } catch (DatabaseException e) {
\r
58 e.printStackTrace();
\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
82 et = ExpressionType.Empty;
\r