Example usage for java.beans BeanInfo getDefaultPropertyIndex

List of usage examples for java.beans BeanInfo getDefaultPropertyIndex

Introduction

In this page you can find the example usage for java.beans BeanInfo getDefaultPropertyIndex.

Prototype

int getDefaultPropertyIndex();

Source Link

Document

A bean may have a default property commonly updated when this bean is customized.

Usage

From source file:org.springframework.richclient.table.renderer.BeanTableCellRenderer.java

public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
        int row, int column) {
    if (value != null) {
        if (beanWrapper == null) {
            beanWrapper = new BeanWrapperImpl(value);
        } else {/*from  w  w  w.j  a va  2  s.  c o m*/
            beanWrapper.setWrappedInstance(value);
        }
        try {
            BeanInfo info = Introspector.getBeanInfo(value.getClass());
            int index = info.getDefaultPropertyIndex();
            if (index != -1) {
                String defaultPropName = beanWrapper.getPropertyDescriptors()[index].getName();
                Object val = beanWrapper.getPropertyValue(defaultPropName);
                TableCellRenderer r = table.getDefaultRenderer(val.getClass());
                return r.getTableCellRendererComponent(table, val, isSelected, hasFocus, row, column);
            }
        } catch (IntrospectionException e) {
            log.debug("Error during introspection of bean: " + e.getMessage(), e);
        }
    }
    return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
}