X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.g3d%2Fsrc%2Forg%2Fsimantics%2Fg3d%2Fproperty%2FPropertyTabUtil.java;fp=org.simantics.g3d%2Fsrc%2Forg%2Fsimantics%2Fg3d%2Fproperty%2FPropertyTabUtil.java;h=4d006eea6a81d563ebcf540bd3936481a030e943;hb=87b3241ec277ba3d8e414b26186a032c9cdcaeed;hp=0000000000000000000000000000000000000000;hpb=1f0bcd66274375f2278d2e6c486cb28257a5f7b2;p=simantics%2F3d.git diff --git a/org.simantics.g3d/src/org/simantics/g3d/property/PropertyTabUtil.java b/org.simantics.g3d/src/org/simantics/g3d/property/PropertyTabUtil.java new file mode 100644 index 00000000..4d006eea --- /dev/null +++ b/org.simantics.g3d/src/org/simantics/g3d/property/PropertyTabUtil.java @@ -0,0 +1,35 @@ +package org.simantics.g3d.property; + +import java.util.Collections; +import java.util.List; + +import org.simantics.g3d.property.annotations.PropertyContributor; + +public class PropertyTabUtil { + + + @SuppressWarnings("unchecked") + public static List getContributors(Object input) { + PropertyTabContributorFactory factory = resolveFactory(input.getClass()); + if (factory == null) + return Collections.EMPTY_LIST; + return factory.getContributors(input); + } + + private static PropertyTabContributorFactory resolveFactory(Class clazz) { + PropertyContributor contributor = clazz.getAnnotation(PropertyContributor.class); + if (contributor != null) + try { + return contributor.value().newInstance(); + } catch (InstantiationException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + Class superClass = clazz.getSuperclass(); + if (superClass != null) + return resolveFactory(superClass); + return null; + } + +}