1 /*******************************************************************************
2 * Copyright (c) 2013 Association for Decentralized Information Management in
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
10 * Semantum Oy - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.modeling.ui.modelBrowser2.contributions;
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;
22 * @author Tuukka Lehtonen
24 public enum IsComponentTest implements Test {
28 public static IsComponentTest get() {
33 public boolean isCompatible(Class<?> contentType) {
34 return Variable.class.equals(contentType) ||
35 Resource.class.equals(contentType);
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));
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));