Java Code Examples for java.beans.PropertyDescriptor#setPropertyEditorClass()

The following examples show how to use java.beans.PropertyDescriptor#setPropertyEditorClass() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExtendedBeanInfo.java    From blog_demos with Apache License 2.0 6 votes vote down vote up
public static void copyNonMethodProperties(PropertyDescriptor source, PropertyDescriptor target)
		throws IntrospectionException {

	target.setExpert(source.isExpert());
	target.setHidden(source.isHidden());
	target.setPreferred(source.isPreferred());
	target.setName(source.getName());
	target.setShortDescription(source.getShortDescription());
	target.setDisplayName(source.getDisplayName());

	// Copy all attributes (emulating behavior of private FeatureDescriptor#addTable)
	Enumeration<String> keys = source.attributeNames();
	while (keys.hasMoreElements()) {
		String key = keys.nextElement();
		target.setValue(key, source.getValue(key));
	}

	// See java.beans.PropertyDescriptor#PropertyDescriptor(PropertyDescriptor)
	target.setPropertyEditorClass(source.getPropertyEditorClass());
	target.setBound(source.isBound());
	target.setConstrained(source.isConstrained());
}
 
Example 2
Source File: MongoClientConfigurationBeanInfo.java    From mongodb-async-driver with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 * <p>
 * Overridden to return <code>null</code> to trigger normal bean
 * introspection.
 * </p>
 */
@Override
public PropertyDescriptor[] getPropertyDescriptors() {

    try {
        final BeanInfo beanInfo = Introspector.getBeanInfo(
                MongoClientConfiguration.class,
                Introspector.IGNORE_IMMEDIATE_BEANINFO);
        final PropertyDescriptor[] descriptors = beanInfo
                .getPropertyDescriptors();

        for (final PropertyDescriptor descriptor : descriptors) {
            if ("credentials".equalsIgnoreCase(descriptor.getName())) {
                descriptor
                        .setPropertyEditorClass(CredentialListEditor.class);
            }
        }

        return descriptors;
    }
    catch (final IntrospectionException e) {
        // Just use the defaults.
        return super.getPropertyDescriptors();
    }
}
 
Example 3
Source File: PropertyDescriptorUtils.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * See {@link java.beans.FeatureDescriptor}.
 */
public static void copyNonMethodProperties(PropertyDescriptor source, PropertyDescriptor target)
		throws IntrospectionException {

	target.setExpert(source.isExpert());
	target.setHidden(source.isHidden());
	target.setPreferred(source.isPreferred());
	target.setName(source.getName());
	target.setShortDescription(source.getShortDescription());
	target.setDisplayName(source.getDisplayName());

	// Copy all attributes (emulating behavior of private FeatureDescriptor#addTable)
	Enumeration<String> keys = source.attributeNames();
	while (keys.hasMoreElements()) {
		String key = keys.nextElement();
		target.setValue(key, source.getValue(key));
	}

	// See java.beans.PropertyDescriptor#PropertyDescriptor(PropertyDescriptor)
	target.setPropertyEditorClass(source.getPropertyEditorClass());
	target.setBound(source.isBound());
	target.setConstrained(source.isConstrained());
}
 
Example 4
Source File: PropertyDescriptorUtils.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * See {@link java.beans.FeatureDescriptor}.
 */
public static void copyNonMethodProperties(PropertyDescriptor source, PropertyDescriptor target) {
	target.setExpert(source.isExpert());
	target.setHidden(source.isHidden());
	target.setPreferred(source.isPreferred());
	target.setName(source.getName());
	target.setShortDescription(source.getShortDescription());
	target.setDisplayName(source.getDisplayName());

	// Copy all attributes (emulating behavior of private FeatureDescriptor#addTable)
	Enumeration<String> keys = source.attributeNames();
	while (keys.hasMoreElements()) {
		String key = keys.nextElement();
		target.setValue(key, source.getValue(key));
	}

	// See java.beans.PropertyDescriptor#PropertyDescriptor(PropertyDescriptor)
	target.setPropertyEditorClass(source.getPropertyEditorClass());
	target.setBound(source.isBound());
	target.setConstrained(source.isConstrained());
}
 
Example 5
Source File: PlainTextConfigElementBeanInfo.java    From pepper-box with Apache License 2.0 6 votes vote down vote up
/**
* Constructor which creates property group and creates UI for PlainTextConfigElement.
*/
public PlainTextConfigElementBeanInfo() {

    super(PlainTextConfigElement.class);

    //Create property group
    createPropertyGroup("plain_text_load_generator", new String[] {
            PLACE_HOLDER, JSON_SCHEMA
    });

    PropertyDescriptor placeHolderProps = property(PLACE_HOLDER);
    placeHolderProps.setValue(NOT_UNDEFINED, Boolean.TRUE);
    placeHolderProps.setValue(DEFAULT, PropsKeys.MSG_PLACEHOLDER);
    placeHolderProps.setValue(NOT_EXPRESSION, Boolean.TRUE);

    //Create inout Text Area
    PropertyDescriptor p = property(JSON_SCHEMA);
    p.setPropertyEditorClass(TextAreaEditor.class);
    p.setValue(NOT_UNDEFINED, Boolean.TRUE);
}
 
Example 6
Source File: BeanInfoTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public PropertyDescriptor[] getPropertyDescriptors() {
	try {
		PropertyDescriptor pd = new PropertyDescriptor("value", ValueBean.class);
		pd.setPropertyEditorClass(MyNumberEditor.class);
		return new PropertyDescriptor[] {pd};
	}
	catch (IntrospectionException ex) {
		throw new FatalBeanException("Couldn't create PropertyDescriptor", ex);
	}
}
 
Example 7
Source File: SerializedConfigElementBeanInfo.java    From pepper-box with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor which creates property group and creates UI for SerializedConfigElement.
 */
public SerializedConfigElementBeanInfo() {

    super(SerializedConfigElement.class);

    //Create Property group
    createPropertyGroup("serialized_load_generator", new String[] {
            PLACE_HOLDER, CLASS_NAME, OBJ_PROPERTIES
    });

    PropertyDescriptor placeHolderProps = property(PLACE_HOLDER);
    placeHolderProps.setValue(NOT_UNDEFINED, Boolean.TRUE);
    placeHolderProps.setValue(DEFAULT, PropsKeys.MSG_PLACEHOLDER);
    placeHolderProps.setValue(NOT_EXPRESSION, Boolean.TRUE);

    //Create table editor component of jmeter for class field and expression mapping
    TypeEditor tableEditor = TypeEditor.TableEditor;
    PropertyDescriptor tableProperties = property(OBJ_PROPERTIES, tableEditor);
    tableProperties.setValue(TableEditor.CLASSNAME, FieldExpressionMapping.class.getName());
    tableProperties.setValue(TableEditor.HEADERS, new String[]{ "Field Name", "Field Expression" } );
    tableProperties.setValue(TableEditor.OBJECT_PROPERTIES, new String[]{ FieldExpressionMapping.FIELD_NAME, FieldExpressionMapping.FIELD_EXPRESSION } );
    tableProperties.setValue(DEFAULT, new ArrayList<>());
    tableProperties.setValue(NOT_UNDEFINED, Boolean.TRUE);

    //Create class name input textfield
    PropertyDescriptor classNameProps = property(CLASS_NAME);
    classNameProps.setPropertyEditorClass(ClassPropertyEditor.class);
    classNameProps.setValue(NOT_UNDEFINED, Boolean.TRUE);
    classNameProps.setValue(DEFAULT, "<POJO class name>");

}
 
Example 8
Source File: PropertyPanelTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void disabled_testPropertyPanelShallGCEvenIfEditorExists () throws Exception {
    PropertyDescriptor feature = new PropertyDescriptor ("prop", this.getClass ());
    feature.setPropertyEditorClass (Ed.class);
    DefaultPropertyModel model = new DefaultPropertyModel (
        this, feature
    );
    
    PropertyPanel pp = new PropertyPanel (model, PropertyPanel.PREF_CUSTOM_EDITOR);
    addToPanel(pp);
    
    assertTrue ("Ed editor created", pp.getPropertyEditor() instanceof Ed);
    
    Ed ed = (Ed)pp.getPropertyEditor ();
    assertNotNull ("Environment has been attached", ed.env);
    
    //
    // Make sure that the panel listens on changes in env
    //
    Listener panelListener = new Listener ();
    
    pp.addPropertyChangeListener (panelListener);
    ed.env.setState (PropertyEnv.STATE_INVALID);
    panelListener.assertChanges ("Change notified in panel", 1, 0);
    
    removeFromPanel(pp);
    pp.removePropertyChangeListener(panelListener);
    
    WeakReference weak = new WeakReference (pp);
    pp = null;
    model = null;
    feature = null;
    
    assertGC ("Panel should disappear even if we have reference to property editor", weak);
}
 
Example 9
Source File: BeanInfoTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public PropertyDescriptor[] getPropertyDescriptors() {
	try {
		PropertyDescriptor pd = new PropertyDescriptor("value", ValueBean.class);
		pd.setPropertyEditorClass(MyNumberEditor.class);
		return new PropertyDescriptor[] {pd};
	}
	catch (IntrospectionException ex) {
		throw new FatalBeanException("Couldn't create PropertyDescriptor", ex);
	}
}
 
Example 10
Source File: PropertyPanelTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void testStateUpdates () throws Exception {
    PropertyDescriptor feature = new PropertyDescriptor ("prop", this.getClass ());
    feature.setPropertyEditorClass (Ed.class);
    DefaultPropertyModel model = new DefaultPropertyModel (
        this, feature
    );
    
    final PropertyPanel pp = new PropertyPanel (model, PropertyPanel.PREF_CUSTOM_EDITOR);
    
    //The property panel must be displayed - it will not attempt to communicate
    //with the property editor until it is on screen
    SwingUtilities.invokeAndWait(new Runnable() {
        public void run() {
            jf.getContentPane().add(pp);
            System.err.println("  Aded to panel");
            jf.validate();
            jf.repaint();
            System.err.println(" bounds: " + pp.getBounds());
        }
    });
    Thread.currentThread().sleep(1000);
    
    assertTrue ("Ed editor created", pp.getPropertyEditor() instanceof Ed);
    
    Ed ed = (Ed)pp.getPropertyEditor ();
    
    assertNotNull("PropertyPanel returns the right property editor", ed);
    
    assertNotNull("Environment has not been attached", ed.env);
    
    Listener envListener = new Listener ();
    Listener panelListener = new Listener ();
    
    pp.addPropertyChangeListener(panelListener);
    ed.env.addPropertyChangeListener (envListener);
    ed.env.addVetoableChangeListener (envListener);
    
    ed.env.setState (PropertyEnv.STATE_INVALID);
    
    assertEquals ("State of panel is invalid", PropertyEnv.STATE_INVALID, pp.getState ());
    envListener.assertChanges ("Notified in environment", 1, 1);
    panelListener.assertChanges ("Notified in panel", 1, 0);
    
    ed.env.setState (PropertyEnv.STATE_INVALID);
    assertEquals ("Remains invalid", PropertyEnv.STATE_INVALID, pp.getState ());
    envListener.assertChanges ("No changes notified", 0, 0);
    panelListener.assertChanges ("No changes notified in panel", 0, 0);
    
    pp.updateValue();
    
    assertEquals ("Update valud does not change the state if invalid", PropertyEnv.STATE_INVALID, pp.getState ());
    envListener.assertChanges ("Changes notified in env", 0, 0);
    panelListener.assertChanges ("Notified in panel", 0, 0);
    
    ed.env.setState (PropertyEnv.STATE_NEEDS_VALIDATION);
    assertEquals ("Now we need validation", PropertyEnv.STATE_NEEDS_VALIDATION, pp.getState ());
    envListener.assertChanges ("Notified in environment", 1, 1);
    panelListener.assertChanges ("Notified in panel", 1, 0);

    pp.updateValue ();
    assertEquals ("Update from needs validation shall switch to valid state if not vetoed", PropertyEnv.STATE_VALID, pp.getState ());
    envListener.assertChanges ("Notified in environment", 1, 1);
    panelListener.assertChanges ("Notified in panel", 1, 0);
    
    ed.env.setState (PropertyEnv.STATE_NEEDS_VALIDATION);
    assertEquals ("Now we need validation", PropertyEnv.STATE_NEEDS_VALIDATION, pp.getState ());
    envListener.assertChanges ("Notified in environment", 1, 1);
    panelListener.assertChanges ("Notified in panel", 1, 0);
    
    
    envListener.shallVeto = true;
    pp.updateValue ();
    assertTrue ("Was vetoed", !envListener.shallVeto);
    
    assertEquals ("The state remains", PropertyEnv.STATE_NEEDS_VALIDATION, pp.getState ());
    envListener.assertChanges ("No approved property changes", 0, -1);
    panelListener.assertChanges ("No approved property changes", 0, -1);
    
    
    //
    // Now try to do the cleanup
    //
    /*
    DefaultPropertyModel replace = new DefaultPropertyModel (this, "prop");
    pp.setModel (replace);
    
    assertEquals ("Model changed", replace, pp.getModel());
    
    
    WeakReference wEd = new WeakReference (ed);
    WeakReference wEnv = new WeakReference (ed.env);
    
    ed = null;
    
    assertGC ("Property editor should disappear", wEd);
    assertGC ("Environment should disapper", wEnv);*/
}
 
Example 11
Source File: Test7087876.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws IntrospectionException {
    PropertyDescriptor pd = new PropertyDescriptor("value", Bean.class);
    pd.setPropertyEditorClass(Editor.class);
    pd.createPropertyEditor(new Bean());
}
 
Example 12
Source File: Test7087876.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws IntrospectionException {
    PropertyDescriptor pd = new PropertyDescriptor("value", Bean.class);
    pd.setPropertyEditorClass(Editor.class);
    pd.createPropertyEditor(new Bean());
}
 
Example 13
Source File: Test7087876.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws IntrospectionException {
    PropertyDescriptor pd = new PropertyDescriptor("value", Bean.class);
    pd.setPropertyEditorClass(Editor.class);
    pd.createPropertyEditor(new Bean());
}
 
Example 14
Source File: Test7087876.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws IntrospectionException {
    PropertyDescriptor pd = new PropertyDescriptor("value", Bean.class);
    pd.setPropertyEditorClass(Editor.class);
    pd.createPropertyEditor(new Bean());
}
 
Example 15
Source File: Test7087876.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws IntrospectionException {
    PropertyDescriptor pd = new PropertyDescriptor("value", Bean.class);
    pd.setPropertyEditorClass(Editor.class);
    pd.createPropertyEditor(new Bean());
}
 
Example 16
Source File: Test7087876.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws IntrospectionException {
    PropertyDescriptor pd = new PropertyDescriptor("value", Bean.class);
    pd.setPropertyEditorClass(Editor.class);
    pd.createPropertyEditor(new Bean());
}
 
Example 17
Source File: Test7087876.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws IntrospectionException {
    PropertyDescriptor pd = new PropertyDescriptor("value", Bean.class);
    pd.setPropertyEditorClass(Editor.class);
    pd.createPropertyEditor(new Bean());
}
 
Example 18
Source File: Test7087876.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws IntrospectionException {
    PropertyDescriptor pd = new PropertyDescriptor("value", Bean.class);
    pd.setPropertyEditorClass(Editor.class);
    pd.createPropertyEditor(new Bean());
}
 
Example 19
Source File: Test7087876.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws IntrospectionException {
    PropertyDescriptor pd = new PropertyDescriptor("value", Bean.class);
    pd.setPropertyEditorClass(Editor.class);
    pd.createPropertyEditor(new Bean());
}
 
Example 20
Source File: Test7087876.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws IntrospectionException {
    PropertyDescriptor pd = new PropertyDescriptor("value", Bean.class);
    pd.setPropertyEditorClass(Editor.class);
    pd.createPropertyEditor(new Bean());
}