Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » ClassCastException from ColorCellEditor adding a Color property to Shapes exampl
ClassCastException from ColorCellEditor adding a Color property to Shapes exampl [message #233867] Thu, 03 May 2007 18:02 Go to next message
Eclipse UserFriend
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 13:08 Go to previous messageGo to next message
Anthony Hunter is currently offline Anthony HunterFriend
Messages: 446
Registered: July 2009
Senior Member
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?
>
Re: ClassCastException from ColorCellEditor adding a Color property to Shapes exampl [message #233964 is a reply to message #233924] Mon, 07 May 2007 15:09 Go to previous message
Eclipse UserFriend
Originally posted by: paul.tamminga.logiclibrary.com

Thanks Anthony, That was it.

I had implemented the property in Shape as a Color, the editor wanted an
RGB.

The hint you gave was a big help. Thanks again.
Previous Topic:why does DirectedGraphLayoutDirectedGraphLayout assigns width and height
Next Topic:Just a random Thank You!!! :-)
Goto Forum:
  


Current Time: Mon Aug 15 16:56:51 GMT 2022

Powered by FUDForum. Page generated in 0.01544 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top