]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/IsEnumeratedValue.java
2bccd30834ada4f39bc8ea1b854b54687285e154
[simantics/platform.git] / bundles / org.simantics.browsing.ui.graph.impl / src / org / simantics / browsing / ui / graph / impl / IsEnumeratedValue.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in 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.browsing.ui.graph.impl;\r
13 \r
14 import java.util.Set;\r
15 \r
16 import org.simantics.db.ReadGraph;\r
17 import org.simantics.db.Resource;\r
18 import org.simantics.db.common.request.ResourceRead;\r
19 import org.simantics.db.exception.DatabaseException;\r
20 import org.simantics.layer0.Layer0;\r
21 \r
22 /**\r
23  * @author Tuukka Lehtonen\r
24  */\r
25 public class IsEnumeratedValue extends ResourceRead<Boolean> {\r
26 \r
27     public IsEnumeratedValue(Resource resource) {\r
28         super(resource);\r
29     }\r
30 \r
31     @Override\r
32     public Boolean perform(ReadGraph graph) throws DatabaseException {\r
33         return Boolean.valueOf(isEnumeratedValue(graph, resource));\r
34     }\r
35 \r
36     public static boolean isEnumeratedValue(ReadGraph graph, Resource resource) throws DatabaseException {\r
37         Set<Resource> types = graph.getTypes(resource);\r
38         //if (types.contains(graph.getBuiltins().Boolean))\r
39         //    return true;\r
40         for (Resource type : types)\r
41             if (isEnumeration(graph, type))\r
42                 return true;\r
43         return false;\r
44     }\r
45 \r
46     public static boolean isEnumeration(ReadGraph graph, Resource type) throws DatabaseException {\r
47         return graph.hasStatement(type, Layer0.getInstance(graph).Enumeration, type);\r
48     }\r
49 \r
50 }\r