Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Why am I unable to subclass an SWT control?
Why am I unable to subclass an SWT control? [message #467624] Wed, 01 February 2006 23:09 Go to next message
Jon Sorensen is currently offline Jon SorensenFriend
Messages: 24
Registered: July 2009
Junior Member
To whom it may concern,

I wanted to subclass the Combo control so I could improve the API in regards
to associating "data" (an object) with an "item". Unfortunately when I do a
new on my derived class I get a Runtime exception (unable to subclass).

I find this restriction too limiting, especially when an API is not well
thought out and is difficult to use. I realize the SWT makes platform
dependent calls but the interface I added has nothing to do with the
underlying Windowing system.

Jon
Re: Why am I unable to subclass an SWT control? [message #467627 is a reply to message #467624] Wed, 01 February 2006 23:32 Go to previous messageGo to next message
Alex Blewitt is currently offline Alex BlewittFriend
Messages: 946
Registered: July 2009
Senior Member
There's documentation about why subclassing SWT controls is generally not allowed. Google for it, or look at the help pages regarding SWT and subclassing.

You *can* do it, if you assume the risks that it's entirely unsupported and that whenever a new version happens, you may have to change your code. But you'll need to override the checkSubclass() method to return true for your subclass in order to avoid the runtime exception being generated.

However, it sounds like you're working against the ethos of having separate model-view objects; the data shouldn't really be associated with the view widget.

Alex.
Re: Why am I unable to subclass an SWT control? [message #467631 is a reply to message #467624] Thu, 02 February 2006 04:35 Go to previous message
Eclipse UserFriend
Originally posted by: sunil_kamath.nohotspammail.com

Jon <jon@tradescape.biz> wrote:
> To whom it may concern,
>
> I wanted to subclass the Combo control so I could improve the API in
> regards to associating "data" (an object) with an "item".
> Unfortunately when I do a new on my derived class I get a Runtime
> exception (unable to subclass).
>
> I find this restriction too limiting, especially when an API is not
> well thought out and is difficult to use. I realize the SWT makes
> platform dependent calls but the interface I added has nothing to do
> with the underlying Windowing system.
>
Use a ComboViewer instead of subclassing the Combo control.
Your model will contain the data and the Combo will contain the items.
The ComboViewer will manage the mapping between the two.

--
Sunil
Previous Topic:Composite Background Image
Next Topic:Give away focus from Composite
Goto Forum:
  


Current Time: Tue Apr 23 10:41:30 GMT 2024

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

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

Back to the top