]> gerrit.simantics Code Review - simantics/3d.git/blob - 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
1 package org.simantics.g3d.property;\r
2 \r
3 import java.util.Collections;\r
4 import java.util.List;\r
5 \r
6 import org.simantics.g3d.property.annotations.PropertyContributor;\r
7 \r
8 public class PropertyTabUtil {\r
9         \r
10         \r
11         @SuppressWarnings("unchecked")\r
12         public static List<PropertyTabContributor> getContributors(Object input) {\r
13                 PropertyTabContributorFactory factory = resolveFactory(input.getClass());\r
14                 if (factory == null)\r
15                         return Collections.EMPTY_LIST;\r
16                 return factory.getContributors(input);\r
17         }\r
18         \r
19         private static PropertyTabContributorFactory resolveFactory(Class<?> clazz) {\r
20                 PropertyContributor contributor = clazz.getAnnotation(PropertyContributor.class);\r
21                 if (contributor != null)\r
22                         try {\r
23                                 return contributor.value().newInstance();\r
24                         } catch (InstantiationException e) {\r
25                                 e.printStackTrace();\r
26                         } catch (IllegalAccessException e) {\r
27                                 e.printStackTrace();\r
28                         }\r
29                 Class<?> superClass = clazz.getSuperclass();\r
30                 if (superClass != null)\r
31                         return resolveFactory(superClass);\r
32                 return null;\r
33         }\r
34 \r
35 }\r