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