properties that are not defined in BeanInfo [message #115409] |
Tue, 17 January 2006 21:01  |
Eclipse User |
|
|
|
Originally posted by: danijel_zecevic.hotmail.com
Hello,
can anyone tell me, how to add PropertyDescriptors that are not created from
BeanInfo.
I nead to add property "name" to my components, so I can generate or rename
fields with this information, but they dont have it. Is there any way for me
to add that property in the way that walue would not come from model but
from other source?
Thank you,
Danijel
|
|
|
|
Re: properties that are not defined in BeanInfo [message #115693 is a reply to message #115680] |
Tue, 24 January 2006 10:33  |
Eclipse User |
|
|
|
Originally posted by: richkulp.us.NO_SPAM.ibm.com
PS: In VE 1.2M1 you can now define fields in the beaninfo also and don't
need override files to declare them. For example from AWT's
RectangleBeanInfo:
public class RectangleBeanInfo extends BaseBeanInfo {
/**
* Gets the bean class.
* @return java.lang.Class
*/
public Class getBeanClass() {
return java.awt.Rectangle.class;
}
/**
* @return java.beans.PropertyDescriptor[] for the x,y, width and height
*/
public java.beans.PropertyDescriptor[] getPropertyDescriptors() {
try {
return new java.beans.PropertyDescriptor[] {
createFieldPropertyDescriptor("x", Rectangle.class.getField("x"),
EMPTY_ARGS), //$NON-NLS-1$ //$NON-NLS-2$
createFieldPropertyDescriptor("y", Rectangle.class.getField("y"),
EMPTY_ARGS), //$NON-NLS-1$ //$NON-NLS-2$
createFieldPropertyDescriptor("width",
Rectangle.class.getField("width"), EMPTY_ARGS), //$NON-NLS-1$ //$NON-NLS-2$
createFieldPropertyDescriptor("height",
Rectangle.class.getField("height"), EMPTY_ARGS) //$NON-NLS-1$ //$NON-NLS-2$
};
} catch (SecurityException e) {
handleException(e);
} catch (NoSuchFieldException e) {
handleException(e);
}
return null;
}
}
--
Thanks,
Rich Kulp
|
|
|
Re: properties that are not defined in BeanInfo [message #611813 is a reply to message #115409] |
Tue, 24 January 2006 07:07  |
Eclipse User |
|
|
|
Hi Danijel,
> can anyone tell me, how to add PropertyDescriptors that are not created
> from
> BeanInfo.
> I nead to add property "name" to my components, so I can generate or
> rename
> fields with this information, but they dont have it. Is there any way for
> me
> to add that property in the way that walue would not come from model but
> from other source?
If you want a property that appears on the Property sheet but isn't defined
in the model (i.e. doesn't have a getter and setter) then you will need to
create a .override file and define an EMF feature. The VE tutorial (linked
to from the VE homepage) talks a bit about .overrides, and for an example of
the kind of feature you want look at something like GridData.override. This
adds features for things that are public fields (i.e. don't have getters and
setters so don't get picked up by Introspection).
Another thing might be that you just want something in the property sheet
similar to how SWT style bits work. When you select an SWT button things
like "border, style" and others that are part of the constructor are fluffed
up by a custom PropertySourceAdapter. For this look at Button.override and
the property source adapter.
Best regards,
Joe Winchester
|
|
|
Re: properties that are not defined in BeanInfo [message #611814 is a reply to message #115680] |
Tue, 24 January 2006 10:33  |
Eclipse User |
|
|
|
Originally posted by: richkulp.us.NO_SPAM.ibm.com
PS: In VE 1.2M1 you can now define fields in the beaninfo also and don't
need override files to declare them. For example from AWT's
RectangleBeanInfo:
public class RectangleBeanInfo extends BaseBeanInfo {
/**
* Gets the bean class.
* @return java.lang.Class
*/
public Class getBeanClass() {
return java.awt.Rectangle.class;
}
/**
* @return java.beans.PropertyDescriptor[] for the x,y, width and height
*/
public java.beans.PropertyDescriptor[] getPropertyDescriptors() {
try {
return new java.beans.PropertyDescriptor[] {
createFieldPropertyDescriptor("x", Rectangle.class.getField("x"),
EMPTY_ARGS), //$NON-NLS-1$ //$NON-NLS-2$
createFieldPropertyDescriptor("y", Rectangle.class.getField("y"),
EMPTY_ARGS), //$NON-NLS-1$ //$NON-NLS-2$
createFieldPropertyDescriptor("width",
Rectangle.class.getField("width"), EMPTY_ARGS), //$NON-NLS-1$ //$NON-NLS-2$
createFieldPropertyDescriptor("height",
Rectangle.class.getField("height"), EMPTY_ARGS) //$NON-NLS-1$ //$NON-NLS-2$
};
} catch (SecurityException e) {
handleException(e);
} catch (NoSuchFieldException e) {
handleException(e);
}
return null;
}
}
--
Thanks,
Rich Kulp
|
|
|
Powered by
FUDForum. Page generated in 0.08738 seconds