]> gerrit.simantics Code Review - simantics/3d.git/blobdiff - org.simantics.g3d/src/org/simantics/g3d/property/PropertyTabUtil.java
3D framework (Simca 2012)
[simantics/3d.git] / org.simantics.g3d / src / org / simantics / g3d / property / PropertyTabUtil.java
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 (file)
index 0000000..4d006ee
--- /dev/null
@@ -0,0 +1,35 @@
+package org.simantics.g3d.property;\r
+\r
+import java.util.Collections;\r
+import java.util.List;\r
+\r
+import org.simantics.g3d.property.annotations.PropertyContributor;\r
+\r
+public class PropertyTabUtil {\r
+       \r
+       \r
+       @SuppressWarnings("unchecked")\r
+       public static List<PropertyTabContributor> getContributors(Object input) {\r
+               PropertyTabContributorFactory factory = resolveFactory(input.getClass());\r
+               if (factory == null)\r
+                       return Collections.EMPTY_LIST;\r
+               return factory.getContributors(input);\r
+       }\r
+       \r
+       private static PropertyTabContributorFactory resolveFactory(Class<?> clazz) {\r
+               PropertyContributor contributor = clazz.getAnnotation(PropertyContributor.class);\r
+               if (contributor != null)\r
+                       try {\r
+                               return contributor.value().newInstance();\r
+                       } catch (InstantiationException e) {\r
+                               e.printStackTrace();\r
+                       } catch (IllegalAccessException e) {\r
+                               e.printStackTrace();\r
+                       }\r
+               Class<?> superClass = clazz.getSuperclass();\r
+               if (superClass != null)\r
+                       return resolveFactory(superClass);\r
+               return null;\r
+       }\r
+\r
+}\r