Example usage for java.beans PropertyDescriptor setExpert

List of usage examples for java.beans PropertyDescriptor setExpert

Introduction

In this page you can find the example usage for java.beans PropertyDescriptor setExpert.

Prototype

public void setExpert(boolean expert) 

Source Link

Document

The "expert" flag is used to distinguish between features that are intended for expert users from those that are intended for normal users.

Usage

From source file:com.twinsoft.convertigo.beans.core.MySimpleBeanInfo.java

protected PropertyDescriptor getPropertyDescriptor(String name) throws IntrospectionException {
    checkAdditionalProperties();//from  w w w.j  a  v  a 2 s  .  c  om
    for (int i = 0; i < properties.length; i++) {
        PropertyDescriptor property = properties[i];
        if (name.equals(property.getName())) {
            PropertyDescriptor clone = new PropertyDescriptor(name, property.getReadMethod(),
                    property.getWriteMethod());
            clone.setDisplayName(property.getDisplayName());
            clone.setShortDescription(property.getShortDescription());
            clone.setPropertyEditorClass(property.getPropertyEditorClass());
            clone.setBound(property.isBound());
            clone.setConstrained(property.isConstrained());
            clone.setExpert(property.isExpert());
            clone.setHidden(property.isHidden());
            clone.setPreferred(property.isPreferred());
            for (String attributeName : Collections.list(property.attributeNames())) {
                clone.setValue(attributeName, property.getValue(attributeName));
            }
            return properties[i] = clone;
        }
    }
    return null;
}

From source file:org.apache.openjpa.lib.conf.ConfigurationImpl.java

/**
 * Create a property descriptor for the given value.
 *///from w w  w.  ja v  a  2  s .  co  m
private PropertyDescriptor getPropertyDescriptor(Value val) throws IntrospectionException {
    String prop = val.getProperty();
    prop = prop.substring(prop.lastIndexOf('.') + 1);

    // set up property descriptor
    PropertyDescriptor pd;
    try {
        pd = new PropertyDescriptor(Introspector.decapitalize(prop), getClass());
    } catch (IntrospectionException ie) {
        // if there aren't any methods for this value(i.e., if it's a
        // dynamically-added value), then an IntrospectionException will
        // be thrown. Try to create a PD with no read or write methods.
        pd = new PropertyDescriptor(Introspector.decapitalize(prop), (Method) null, (Method) null);
    }
    pd.setDisplayName(findLocalized(prop + "-name", true, val.getScope()));
    pd.setShortDescription(findLocalized(prop + "-desc", true, val.getScope()));
    pd.setExpert("true".equals(findLocalized(prop + "-expert", false, val.getScope())));

    try {
        pd.setReadMethod(getClass().getMethod("get" + StringUtils.capitalize(prop), (Class[]) null));
        pd.setWriteMethod(getClass().getMethod("set" + StringUtils.capitalize(prop),
                new Class[] { pd.getReadMethod().getReturnType() }));
    } catch (Throwable t) {
        // if an error occurs, it might be because the value is a
        // dynamic property.
    }

    String type = findLocalized(prop + "-type", true, val.getScope());
    if (type != null)
        pd.setValue(ATTRIBUTE_TYPE, type);

    String cat = findLocalized(prop + "-cat", false, val.getScope());
    if (cat != null)
        pd.setValue(ATTRIBUTE_CATEGORY, cat);

    pd.setValue(ATTRIBUTE_XML, toXMLName(prop));

    String order = findLocalized(prop + "-displayorder", false, val.getScope());
    if (order != null)
        pd.setValue(ATTRIBUTE_ORDER, order);

    // collect allowed values from alias keys, listed values, and
    // interface implementors
    Collection<String> allowed = new TreeSet<String>();
    List<String> aliases = Collections.emptyList();
    if (val.getAliases() != null) {
        aliases = Arrays.asList(val.getAliases());
        for (int i = 0; i < aliases.size(); i += 2)
            allowed.add(aliases.get(i));
    }
    String[] vals = Strings.split(findLocalized(prop + "-values", false, val.getScope()), ",", 0);
    for (int i = 0; i < vals.length; i++)
        if (!aliases.contains(vals[i]))
            allowed.add(vals[i]);
    try {
        Class<?> intf = Class.forName(findLocalized(prop + "-interface", true, val.getScope()), false,
                getClass().getClassLoader());
        pd.setValue(ATTRIBUTE_INTERFACE, intf.getName());
        String[] impls = Services.getImplementors(intf);
        for (int i = 0; i < impls.length; i++)
            if (!aliases.contains(impls[i]))
                allowed.add(impls[i]);
    } catch (Throwable t) {
    }
    if (!allowed.isEmpty())
        pd.setValue(ATTRIBUTE_ALLOWED_VALUES, (String[]) allowed.toArray(new String[allowed.size()]));

    return pd;
}