]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser2/contributions/IsComponentTest.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / modelBrowser2 / contributions / IsComponentTest.java
1 /*******************************************************************************\r
2  * Copyright (c) 2013 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  *     Semantum Oy - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.modeling.ui.modelBrowser2.contributions;\r
13 \r
14 import org.simantics.browsing.ui.model.tests.Test;\r
15 import org.simantics.db.ReadGraph;\r
16 import org.simantics.db.Resource;\r
17 import org.simantics.db.exception.DatabaseException;\r
18 import org.simantics.db.layer0.variable.Variable;\r
19 import org.simantics.structural.stubs.StructuralResource2;\r
20 \r
21 /**\r
22  * @author Tuukka Lehtonen\r
23  */\r
24 public enum IsComponentTest implements Test {\r
25 \r
26         INSTANCE;\r
27 \r
28         public static IsComponentTest get() {\r
29                 return INSTANCE;\r
30         }\r
31 \r
32         @Override\r
33         public boolean isCompatible(Class<?> contentType) {\r
34                 return Variable.class.equals(contentType) ||\r
35                                 Resource.class.equals(contentType);\r
36         }\r
37 \r
38         @Override\r
39         public boolean test(ReadGraph graph, Object content) throws DatabaseException {\r
40                 if (content instanceof Variable) {\r
41                         Variable v = (Variable) content;\r
42                         //System.out.println("Test variable: " + v.getURI(graph));\r
43                         StructuralResource2 STR = StructuralResource2.getInstance(graph);\r
44                         Resource type = v.getPossibleType(graph, STR.Component);\r
45                         //System.out.println("variable component type: " + NameUtils.getURIOrSafeNameInternal(graph, type));\r
46                         return type != null;\r
47                 } else if (content instanceof Resource) {\r
48                         Resource r = (Resource) content;\r
49                         //System.out.println("Test resource: " + NameUtils.getURIOrSafeNameInternal(graph, r));\r
50                         StructuralResource2 STR = StructuralResource2.getInstance(graph);\r
51                         Resource type = graph.getPossibleType(r, STR.Component);\r
52                         //System.out.println("resource component type: " + NameUtils.getURIOrSafeNameInternal(graph, type));\r
53                         return type != null;\r
54                 }\r
55                 return false;\r
56         }\r
57 \r
58 }\r