package com.onaro.sanscreen.client.view.tabular.columns; import java.beans.PropertyDescriptor; import java.text.MessageFormat; import java.util.List; import org.apache.commons.lang3.StringUtils; import org.eclipse.core.runtime.IAdaptable; import com.onaro.commons.beans.BeanUtils; /** * Variation on the {@link PropertyColumnValueRetriever} which reads an additional property * from the bean instance to use as the identifier for the property value. * * @param the type of the bean objects to retrieve the property values from * @param the type of the property value */ public class IdentifierPropertyColumnValueRetriever extends PropertyColumnValueRetriever { protected final List identifierPropertyDescriptors; /** * Create a retriever which reads the value from a property * @param beanClass * @param propertyPath * @param identifierPropertyPath */ public IdentifierPropertyColumnValueRetriever(Class beanClass, String propertyPath, String identifierPropertyPath) { super(beanClass, propertyPath); if (StringUtils.isBlank(identifierPropertyPath) || !BeanUtils.hasPropertyPath(beanClass, identifierPropertyPath)) { throw new IllegalArgumentException( MessageFormat.format("Identifier Property path ''{0}'' not valid for class ''{1}''", //$NON-NLS-1$ identifierPropertyPath, beanClass.getName())); } this.identifierPropertyDescriptors = BeanUtils.getPropertyDescriptorsByPath(beanClass, identifierPropertyPath); } @Override public String getIdentifier(IAdaptable rowObj) { B bean = getBean(rowObj); Object propertyObj = BeanUtils.getPropertyValueByPath(identifierPropertyDescriptors, bean); if (propertyObj == null) { return null; } return propertyObj.toString(); } }