X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.browsing.ui.model%2Fsrc%2Forg%2Fsimantics%2Fbrowsing%2Fui%2Fmodel%2Ftests%2FInstanceOfTest.java;h=70b6ecaa419854896a7d09675c1f3ea2bdd7a72e;hp=a2c78aded73df959735f9b825cafa885579e4f4c;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/tests/InstanceOfTest.java b/bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/tests/InstanceOfTest.java index a2c78aded..70b6ecaa4 100644 --- a/bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/tests/InstanceOfTest.java +++ b/bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/tests/InstanceOfTest.java @@ -1,70 +1,70 @@ -package org.simantics.browsing.ui.model.tests; - -import org.eclipse.core.runtime.Platform; -import org.osgi.framework.Bundle; -import org.simantics.databoard.Bindings; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.exception.DatabaseException; -import org.simantics.viewpoint.ontology.ViewpointResource; - -/** - * A visual contribution rule test that checks whether the input content is an - * instance of a Java class. The class is specified by identifying the source - * bundle and the class name. - * - * @author Tuukka Lehtonen - */ -public class InstanceOfTest implements Test { - - String bundleName; - String className; - Class clazz; - boolean failed; - - public InstanceOfTest(String bundle, String className) { - this.bundleName = bundle; - this.className = className; - } - - public InstanceOfTest(ReadGraph graph, Resource test) throws DatabaseException { - ViewpointResource VP = ViewpointResource.getInstance(graph); - this.bundleName = graph.getRelatedValue(test, VP.InstanceOfTest_bundleName, Bindings.STRING); - this.className = graph.getRelatedValue(test, VP.InstanceOfTest_className, Bindings.STRING); - } - - private Class resolveClass() { - if (failed) - return null; - if (clazz != null) - return clazz; - Bundle b = Platform.getBundle(bundleName); - if (b == null) { - System.err.println(getClass() + " could not resolve class " + className + ", bundle " + bundleName + " not found in platform"); - failed = true; - return null; - } - try { - this.clazz = b.loadClass(className); - return clazz; - } catch (ClassNotFoundException e) { - System.err.println(getClass() + " could not resolve class " + className + ", from bundle " + bundleName); - failed = true; - return null; - } - } - - @Override - public boolean isCompatible(Class contentType) { - Class clazz = resolveClass(); - return clazz != null && clazz.equals(contentType); - } - - @Override - public boolean test(ReadGraph graph, Object content) - throws DatabaseException { - Class clazz = resolveClass(); - return clazz != null && clazz.isInstance(content); - } - -} +package org.simantics.browsing.ui.model.tests; + +import org.eclipse.core.runtime.Platform; +import org.osgi.framework.Bundle; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.viewpoint.ontology.ViewpointResource; + +/** + * A visual contribution rule test that checks whether the input content is an + * instance of a Java class. The class is specified by identifying the source + * bundle and the class name. + * + * @author Tuukka Lehtonen + */ +public class InstanceOfTest implements Test { + + String bundleName; + String className; + Class clazz; + boolean failed; + + public InstanceOfTest(String bundle, String className) { + this.bundleName = bundle; + this.className = className; + } + + public InstanceOfTest(ReadGraph graph, Resource test) throws DatabaseException { + ViewpointResource VP = ViewpointResource.getInstance(graph); + this.bundleName = graph.getRelatedValue(test, VP.InstanceOfTest_bundleName, Bindings.STRING); + this.className = graph.getRelatedValue(test, VP.InstanceOfTest_className, Bindings.STRING); + } + + private Class resolveClass() { + if (failed) + return null; + if (clazz != null) + return clazz; + Bundle b = Platform.getBundle(bundleName); + if (b == null) { + System.err.println(getClass() + " could not resolve class " + className + ", bundle " + bundleName + " not found in platform"); + failed = true; + return null; + } + try { + this.clazz = b.loadClass(className); + return clazz; + } catch (ClassNotFoundException e) { + System.err.println(getClass() + " could not resolve class " + className + ", from bundle " + bundleName); + failed = true; + return null; + } + } + + @Override + public boolean isCompatible(Class contentType) { + Class clazz = resolveClass(); + return clazz != null && clazz.equals(contentType); + } + + @Override + public boolean test(ReadGraph graph, Object content) + throws DatabaseException { + Class clazz = resolveClass(); + return clazz != null && clazz.isInstance(content); + } + +}