1 /*******************************************************************************
\r
2 * Copyright (c) 2012, 2013 Association for Decentralized Information Management in
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.g3d.property;
\r
14 import java.util.Collections;
\r
15 import java.util.List;
\r
17 import org.simantics.g3d.property.annotations.PropertyContributor;
\r
19 public class PropertyTabUtil {
\r
22 @SuppressWarnings("unchecked")
\r
23 public static List<PropertyTabContributor> getContributors(Object input) {
\r
24 PropertyTabContributorFactory factory = resolveFactory(input.getClass());
\r
25 if (factory == null)
\r
26 return Collections.EMPTY_LIST;
\r
27 return factory.getContributors(input);
\r
30 private static PropertyTabContributorFactory resolveFactory(Class<?> clazz) {
\r
31 PropertyContributor contributor = clazz.getAnnotation(PropertyContributor.class);
\r
32 if (contributor != null)
\r
34 return contributor.value().newInstance();
\r
35 } catch (InstantiationException e) {
\r
36 e.printStackTrace();
\r
37 } catch (IllegalAccessException e) {
\r
38 e.printStackTrace();
\r
40 Class<?> superClass = clazz.getSuperclass();
\r
41 if (superClass != null)
\r
42 return resolveFactory(superClass);
\r