ClassCastException from ColorCellEditor adding a Color property to Shapes exampl [message #233867] |
Thu, 03 May 2007 14:02  |
Eclipse User |
|
|
|
Originally posted by: paul.tamminga.logiclibrary.com
A beginner question I'm afraid.
I'm just learning GEF and set out to test my understanding by adding a
"color" property to a Shape in the Shapes example.
The essence of the change is to add another property descriptor to Shape:
descriptors = new IPropertyDescriptor[] {
new TextPropertyDescriptor(XPOS_PROP, "X"),
...
//add a color property
new ColorPropertyDescriptor(COLOR_PROP, "Color"),
};
along with a new getter, setter and changes to the get/setPropertyValue()
methods.
Seems straighforward enough.
When I run the updated example, I see the new color property on the
property sheet, but when I click on it to edit I get a ClassCast exception
in the error log.
The class cast exception is coming out of ColorCellEditor.updateContents
protected void updateContents(Object value) {
RGB rgb = (RGB) value; //throws ClassCast
// XXX: We don't have a value the first time this method is
called".
if (rgb == null) {
rgb = new RGB(0, 0, 0);
}
...
}
value is coming in as null and the cast on the first line is causing the
error. The comment suggest that the method is defending against a null
value. I'm not clear on when you can safely cast a null value.
From the stack It looks like the ColorCellEditor is in the process of
initializing itself and has not yet got around to setting the current
color. I couln't find anything to initialize on ColorPropertyDescriptor to
help the ColorCellEditor have non-null value when it initializes.
This almost looks like a bug in JFace, except that I have a hard time
beleiving I'm the first guy to add a ColorPropertyDescriptor to a GEF
model element. I did upgrade my eclipse from 3.2.1 to 3.2.2 after I saw
the problem and I see the same problem on both versions.
Any ideas?
|
|
|
Re: ClassCastException from ColorCellEditor adding a Color property to Shapes exampl [message #233924 is a reply to message #233867] |
Fri, 04 May 2007 09:08   |
Eclipse User |
|
|
|
Hi Paul,
Check you are implementing all the IPropertySource methods correctly.
If you are getting a ClassCastException in updateContents(), you likely are
not returning an RGB in your getPropertyValue() method.
Cheers...
Anthony
"Paul Tamminga" <paul.tamminga@logiclibrary.com> wrote in message
news:43e7dbe8aa0c4b7e28d540273fbdb8eb$1@www.eclipse.org...
>A beginner question I'm afraid.
> I'm just learning GEF and set out to test my understanding by adding a
> "color" property to a Shape in the Shapes example.
> The essence of the change is to add another property descriptor to Shape:
> descriptors = new IPropertyDescriptor[] { new
> TextPropertyDescriptor(XPOS_PROP, "X"), ...
> //add a color property
> new ColorPropertyDescriptor(COLOR_PROP, "Color"),
> };
>
> along with a new getter, setter and changes to the get/setPropertyValue()
> methods.
> Seems straighforward enough.
>
> When I run the updated example, I see the new color property on the
> property sheet, but when I click on it to edit I get a ClassCast exception
> in the error log.
> The class cast exception is coming out of ColorCellEditor.updateContents
> protected void updateContents(Object value) {
> RGB rgb = (RGB) value; //throws ClassCast
> // XXX: We don't have a value the first time this method is
> called".
> if (rgb == null) {
> rgb = new RGB(0, 0, 0);
> }
> ...
> }
> value is coming in as null and the cast on the first line is causing the
> error. The comment suggest that the method is defending against a null
> value. I'm not clear on when you can safely cast a null value.
> From the stack It looks like the ColorCellEditor is in the process of
> initializing itself and has not yet got around to setting the current
> color. I couln't find anything to initialize on ColorPropertyDescriptor to
> help the ColorCellEditor have non-null value when it initializes.
> This almost looks like a bug in JFace, except that I have a hard time
> beleiving I'm the first guy to add a ColorPropertyDescriptor to a GEF
> model element. I did upgrade my eclipse from 3.2.1 to 3.2.2 after I saw
> the problem and I see the same problem on both versions.
> Any ideas?
>
|
|
|
|
Powered by
FUDForum. Page generated in 0.04522 seconds