1 /*******************************************************************************
\r
2 * Copyright (c) 2013 Association for Decentralized Information Management in
\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
10 * Semantum Oy - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.modeling.ui.modelBrowser2.contributions;
\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
22 * @author Tuukka Lehtonen
\r
24 public enum IsUserDefinedComponentTest implements Test {
\r
28 public static IsUserDefinedComponentTest get() {
\r
33 public boolean isCompatible(Class<?> contentType) {
\r
34 return Variable.class.equals(contentType) ||
\r
35 Resource.class.equals(contentType);
\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 isUserComponentType(graph, type, STR);
\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 isUserComponentType(graph, type, STR);
\r
58 private static boolean isUserComponentType(ReadGraph graph, Resource type, StructuralResource2 STR) throws DatabaseException {
\r
61 Resource definedBy = graph.getPossibleObject(type, STR.IsDefinedBy);
\r
62 if (definedBy != null)
\r
64 boolean procedural = graph.isInstanceOf(type, STR.ProceduralComponentType);
\r