Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Is subclass of Button possible?
Is subclass of Button possible? [message #461743] Thu, 29 September 2005 08:29 Go to next message
hanys is currently offline hanysFriend
Messages: 188
Registered: July 2009
Senior Member
Hi all,
I tried to make a subclass of Button and when I intstantiates it the
exception is thrown.
Is possible sublassing of Button?

Thanks,
John Cage
Re: Is subclass of Button possible? [message #461746 is a reply to message #461743] Thu, 29 September 2005 08:46 Go to previous messageGo to next message
Henrik Skovgaard is currently offline Henrik SkovgaardFriend
Messages: 84
Registered: July 2009
Member
> Is possible sublassing of Button?

Just add

protected void checkSubclass(){}

to your own implementation :-) It's a bit of a hack, but it works.
Re: Is subclass of Button possible? [message #461747 is a reply to message #461746] Thu, 29 September 2005 09:51 Go to previous messageGo to next message
hanys is currently offline hanysFriend
Messages: 188
Registered: July 2009
Senior Member
Thank you,
it works fine :-)

Best Regards,
John Cage
Re: Is subclass of Button possible? [message #461749 is a reply to message #461743] Thu, 29 September 2005 10:05 Go to previous messageGo to next message
Stefan Langer is currently offline Stefan LangerFriend
Messages: 236
Registered: July 2009
Senior Member
You have to override the method isValidSubclass in Widget to return true
in order to allow subclassing but be aware that this is strongly
discouraged. Try to get the functionality you need by delegation.

Regards
Stefan

John Cage wrote:
> Hi all,
> I tried to make a subclass of Button and when I intstantiates it the
> exception is thrown.
> Is possible sublassing of Button?
>
> Thanks,
> John Cage
>
>
Re: Is subclass of Button possible? [message #461833 is a reply to message #461749] Sat, 01 October 2005 23:23 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 97
Registered: July 2009
Member
"Stefan Langer" <eclipse@bettsockentraeger.de> wrote in message
news:dhge8b$3j1$1@news.eclipse.org...
> ... but be aware that this is strongly discouraged.

This is very strange and odd argument that SWT put forwards!
Are we going back to pre-object oriented era? The real power
of object oriented development is with onject hierarchy
(= subclassing). This makes the approach so beautifully simple
and eloquent!

Regards.
Re: Is subclass of Button possible? [message #461838 is a reply to message #461833] Sun, 02 October 2005 12:34 Go to previous messageGo to next message
Stefan Langer is currently offline Stefan LangerFriend
Messages: 236
Registered: July 2009
Senior Member
Following the argumentation of the SWT developer their reasoning for
this is not to go to the pre area it's that since swt uses the native
widgets and simply provides a small wrapper, subclassing it will break
compability in subclasses when the implementation in the native widgets
change. And the native widgets are not under the control of the swt
developers. SO it is better to delegate since the interface of the
wrapper is unlikely to change.
If you really think you don't mind the breakage with future versions go
ahead and override the method.

Stefan

Joe Smith wrote:
> "Stefan Langer" <eclipse@bettsockentraeger.de> wrote in message
> news:dhge8b$3j1$1@news.eclipse.org...
>
>>... but be aware that this is strongly discouraged.
>
>
> This is very strange and odd argument that SWT put forwards!
> Are we going back to pre-object oriented era? The real power
> of object oriented development is with onject hierarchy
> (= subclassing). This makes the approach so beautifully simple
> and eloquent!
>
> Regards.
>
>
Re: Is subclass of Button possible? [message #461841 is a reply to message #461838] Mon, 03 October 2005 03:44 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 97
Registered: July 2009
Member
"Stefan Langer" <eclipse@bettsockentraeger.de> wrote in message
news:dhok39$s0g$1@news.eclipse.org...
> ... subclassing it will break compability in subclasses when the
> implementation in the native widgets change.

Note that native widgets don't change! I never have any problems
with AWT in this aspect. If you avoid some fancy or special APIs,
you don't expect to have problems of this type. The core of
native widgets don't change. No worry about such things.
Just avoid very special stuff.

Regards.
Re: Is subclass of Button possible? [message #462017 is a reply to message #461841] Wed, 05 October 2005 01:45 Go to previous message
Steve Northover is currently offline Steve NorthoverFriend
Messages: 1636
Registered: July 2009
Senior Member
http://www.eclipse.org/swt/faq.php#subclassing

"Joe Smith" <ohcho@tpg.com.au> wrote in message
news:dhq9f6$4r0$1@news.eclipse.org...
>
> "Stefan Langer" <eclipse@bettsockentraeger.de> wrote in message
> news:dhok39$s0g$1@news.eclipse.org...
> > ... subclassing it will break compability in subclasses when the
> > implementation in the native widgets change.
>
> Note that native widgets don't change! I never have any problems
> with AWT in this aspect. If you avoid some fancy or special APIs,
> you don't expect to have problems of this type. The core of
> native widgets don't change. No worry about such things.
> Just avoid very special stuff.
>
> Regards.
>
>
Previous Topic:Two types of Menus?
Next Topic:StyledText(ScrollBars problem)
Goto Forum:
  


Current Time: Fri Mar 29 02:38:45 GMT 2024

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

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

Back to the top