]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling/src/org/simantics/modeling/userComponent/TypeConversion.java
Fixed ComponentTypeCommands.setUnit to support unit == null
[simantics/platform.git] / bundles / org.simantics.modeling / src / org / simantics / modeling / userComponent / TypeConversion.java
1 /*******************************************************************************
2  * Copyright (c) 2012 Association for Decentralized Information Management in
3  * Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.modeling.userComponent;
13
14 import gnu.trove.map.hash.THashMap;
15
16 import org.simantics.databoard.Datatypes;
17 import org.simantics.databoard.type.ArrayType;
18 import org.simantics.databoard.type.Datatype;
19
20 public class TypeConversion {
21
22         private static final THashMap<String,Datatype> CONVERSION_MAP = 
23                         new THashMap<String,Datatype>();
24         
25         private static void add(String sclType, Datatype dataType) {
26                 CONVERSION_MAP.put(sclType, dataType);
27                 CONVERSION_MAP.put("[" + sclType + "]", new ArrayType(dataType));
28                 CONVERSION_MAP.put("Array " + sclType, new ArrayType(dataType));
29                 CONVERSION_MAP.put("Vector " + sclType, new ArrayType(dataType));
30         }
31         
32         static {
33                 add("Boolean", Datatypes.BOOLEAN);
34                 add("Integer", Datatypes.INTEGER);
35                 add("Long", Datatypes.LONG);
36                 add("Float", Datatypes.FLOAT);
37                 add("Double", Datatypes.DOUBLE);
38                 add("String", Datatypes.STRING);
39         }
40         
41         /**
42          * This is a workaround solution currently for converting SCL types
43          * to datatypes.
44          */
45         public static Datatype convertSCLTypeToDatatype(String type) {
46                 return CONVERSION_MAP.get(type);
47         }
48         
49 }