/******************************************************************************* * Copyright (c) 2012, 2013 Association for Decentralized Information Management in * Industry THTH ry. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation *******************************************************************************/ 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; } }