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