Example usage for java.beans PropertyDescriptor setPropertyEditorClass

List of usage examples for java.beans PropertyDescriptor setPropertyEditorClass

Introduction

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

Prototype

public void setPropertyEditorClass(Class<?> propertyEditorClass) 

Source Link

Document

Normally PropertyEditors will be found using the PropertyEditorManager.

Usage

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

protected PropertyDescriptor getPropertyDescriptor(String name) throws IntrospectionException {
    checkAdditionalProperties();//from   ww  w  .j  a  va  2  s .  co m
    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.jmeter.util.ScriptingBeanInfoSupport.java

protected ScriptingBeanInfoSupport(Class<? extends TestBean> beanClass, String[] languageTags,
        ResourceBundle rb) {/*from  ww  w .  j a v a  2 s  .  c  om*/
    super(beanClass);
    PropertyDescriptor p;

    p = property("scriptLanguage"); // $NON-NLS-1$
    p.setValue(NOT_UNDEFINED, Boolean.TRUE);
    p.setValue(DEFAULT, ""); // $NON-NLS-1$
    if (rb != null) {
        p.setValue(RESOURCE_BUNDLE, rb);
    }
    p.setValue(TAGS, languageTags);

    createPropertyGroup("scriptingLanguage", // $NON-NLS-1$
            new String[] { "scriptLanguage" }); // $NON-NLS-1$

    p = property("parameters"); // $NON-NLS-1$
    p.setValue(NOT_UNDEFINED, Boolean.TRUE);
    p.setValue(DEFAULT, ""); // $NON-NLS-1$

    createPropertyGroup("parameterGroup", // $NON-NLS-1$
            new String[] { "parameters" }); // $NON-NLS-1$

    p = property("filename"); // $NON-NLS-1$
    p.setValue(NOT_UNDEFINED, Boolean.TRUE);
    p.setValue(DEFAULT, ""); // $NON-NLS-1$
    p.setPropertyEditorClass(FileEditor.class);

    createPropertyGroup("filenameGroup", // $NON-NLS-1$
            new String[] { "filename" }); // $NON-NLS-1$

    /*
     * If we are creating a JSR223 element, add the cache key property.
     * 
     * Note that this cannot be done in the JSR223BeanInfoSupport class
     * because that causes problems with the group; its properties are
     * not always set up before they are needed. This cause various
     * issues with the GUI:
     * - wrong field attributes (should not allow null)
     * - sometimes GUI is completely mangled
     * - field appears at start rather than at end.
     * - the following warning is logged:
     * jmeter.testbeans.gui.GenericTestBeanCustomizer: 
     * org.apache.jmeter.util.JSR223TestElement#cacheKey does not appear to have been configured
     * 
     * Adding the group here solves these issues, and it's also
     * possible to add the key just before the script panel
     * to which it relates.
     * 
     * It's not yet clear why this should be, but it looks as though
     * createPropertyGroup does not work properly if it is called from
     * any subclasses of this class.
     * 
     */
    if (JSR223TestElement.class.isAssignableFrom(beanClass)) {
        p = property("cacheKey"); // $NON-NLS-1$
        p.setValue(NOT_UNDEFINED, Boolean.TRUE);
        p.setValue(DEFAULT, ""); // $NON-NLS-1$
        p.setPropertyEditorClass(JSR223ScriptCacheCheckboxEditor.class);

        createPropertyGroup("cacheKey_group", // $NON-NLS-1$
                new String[] { "cacheKey" }); // $NON-NLS-1$
    }

    p = property("script"); // $NON-NLS-1$
    p.setValue(NOT_UNDEFINED, Boolean.TRUE);
    p.setValue(DEFAULT, ""); // $NON-NLS-1$
    p.setPropertyEditorClass(TextAreaEditor.class);

    createPropertyGroup("scripting", // $NON-NLS-1$
            new String[] { "script" }); // $NON-NLS-1$

}