Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Custom Widgets how to ?
Custom Widgets how to ? [message #450484] Mon, 14 February 2005 09:26 Go to next message
Michael Borchert is currently offline Michael BorchertFriend
Messages: 27
Registered: July 2009
Junior Member
Maybe this is a silly question. But I want SWT Widgets to have a general
behaviour.
E.g. adding FocusListener to change color when entering and leaving.
In Swing I would do this with subclassing the widgets. How can I do that
with SWT as
it is not allowed to subclass a widget.

Many thanks
Michael
Re: Custom Widgets how to ? [message #450487 is a reply to message #450484] Mon, 14 February 2005 10:38 Go to previous messageGo to next message
Peter Goetz is currently offline Peter GoetzFriend
Messages: 38
Registered: July 2009
Member
Hi Michael,

Michael Borchert wrote:
> Maybe this is a silly question. But I want SWT Widgets to have a general
> behaviour.
> E.g. adding FocusListener to change color when entering and leaving.
> In Swing I would do this with subclassing the widgets. How can I do that
> with SWT as
> it is not allowed to subclass a widget.

we have solved this by encapsulating the real widget in a small wrapper
that we use in our dialogs and windows. This wrapper knows the rights
necessesary to use the widget, handles DataTypes in Widgets (Text) and
controls Backgroundcolors for used widgets or when errors occur.
So far it works fine.

>
> Many thanks
> Michael

HTH, Peter

>
>
Re: Custom Widgets how to ? [message #450488 is a reply to message #450487] Mon, 14 February 2005 10:54 Go to previous messageGo to next message
Michael Borchert is currently offline Michael BorchertFriend
Messages: 27
Registered: July 2009
Junior Member
Thank you very much,

can you please post me an example of such a wrapper ?

Thanks,

Michael

"Peter Goetz" <kingofbrain@web.de> schrieb im Newsbeitrag
news:cupv66$krn$1@www.eclipse.org...
> Hi Michael,
>
> Michael Borchert wrote:
>> Maybe this is a silly question. But I want SWT Widgets to have a general
>> behaviour.
>> E.g. adding FocusListener to change color when entering and leaving.
>> In Swing I would do this with subclassing the widgets. How can I do that
>> with SWT as
>> it is not allowed to subclass a widget.
>
> we have solved this by encapsulating the real widget in a small wrapper
> that we use in our dialogs and windows. This wrapper knows the rights
> necessesary to use the widget, handles DataTypes in Widgets (Text) and
> controls Backgroundcolors for used widgets or when errors occur.
> So far it works fine.
>
>>
>> Many thanks
>> Michael
>
> HTH, Peter
>
>>
Re: Custom Widgets how to ? [message #450489 is a reply to message #450484] Mon, 14 February 2005 11:36 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: ekkehardREMOVE_NO_SPAM.gentz-software.de

subclassing is by default not allowed,
but I think you can do it if you do no strange things

if you subclass and add

protected void checkSubclass() {
// this eliminitates the check and allows subclassing
}

then there'll be no exception.

of course be prepared to change your code if future eclipse releases
change things

regards

ekkehard

Michael Borchert schrieb:
> Maybe this is a silly question. But I want SWT Widgets to have a general
> behaviour.
> E.g. adding FocusListener to change color when entering and leaving.
> In Swing I would do this with subclassing the widgets. How can I do that
> with SWT as
> it is not allowed to subclass a widget.
>
> Many thanks
> Michael
>
>
Re: Custom Widgets how to ? [message #450493 is a reply to message #450489] Mon, 14 February 2005 12:16 Go to previous messageGo to next message
Michael Borchert is currently offline Michael BorchertFriend
Messages: 27
Registered: July 2009
Junior Member
Hello ekkehard,

thank you very much. Very strange behaviour :-)
Did you experience any problems with subclassing ? Or does anyone of the SWT
team give us a hint
why subclassing is normally not allowed ???

Thanks,
Michael

"ekkehard" <ekkehardREMOVE_NO_SPAM@gentz-software.de> schrieb im Newsbeitrag
news:cuq2gn$4rh$1@www.eclipse.org...
> subclassing is by default not allowed,
> but I think you can do it if you do no strange things
>
> if you subclass and add
>
> protected void checkSubclass() {
> // this eliminitates the check and allows subclassing
> }
>
> then there'll be no exception.
>
> of course be prepared to change your code if future eclipse releases
> change things
>
> regards
>
> ekkehard
>
> Michael Borchert schrieb:
>> Maybe this is a silly question. But I want SWT Widgets to have a general
>> behaviour.
>> E.g. adding FocusListener to change color when entering and leaving.
>> In Swing I would do this with subclassing the widgets. How can I do that
>> with SWT as
>> it is not allowed to subclass a widget.
>>
>> Many thanks
>> Michael
Re: Custom Widgets how to ? [message #450502 is a reply to message #450493] Mon, 14 February 2005 16:11 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
see
http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/plat form-swt-home/faq.html#subclassing

"Michael Borchert" <michael.borchert@abovo.de> wrote in message
news:cuq4qn$fet$1@www.eclipse.org...
> Hello ekkehard,
>
> thank you very much. Very strange behaviour :-)
> Did you experience any problems with subclassing ? Or does anyone of the
SWT
> team give us a hint
> why subclassing is normally not allowed ???
>
> Thanks,
> Michael
>
> "ekkehard" <ekkehardREMOVE_NO_SPAM@gentz-software.de> schrieb im
Newsbeitrag
> news:cuq2gn$4rh$1@www.eclipse.org...
> > subclassing is by default not allowed,
> > but I think you can do it if you do no strange things
> >
> > if you subclass and add
> >
> > protected void checkSubclass() {
> > // this eliminitates the check and allows subclassing
> > }
> >
> > then there'll be no exception.
> >
> > of course be prepared to change your code if future eclipse releases
> > change things
> >
> > regards
> >
> > ekkehard
> >
> > Michael Borchert schrieb:
> >> Maybe this is a silly question. But I want SWT Widgets to have a
general
> >> behaviour.
> >> E.g. adding FocusListener to change color when entering and leaving.
> >> In Swing I would do this with subclassing the widgets. How can I do
that
> >> with SWT as
> >> it is not allowed to subclass a widget.
> >>
> >> Many thanks
> >> Michael
>
>
Re: Custom Widgets how to ? [message #450529 is a reply to message #450488] Tue, 15 February 2005 07:55 Go to previous messageGo to next message
Peter Goetz is currently offline Peter GoetzFriend
Messages: 38
Registered: July 2009
Member
Michael Borchert wrote:
> Thank you very much,
>
> can you please post me an example of such a wrapper ?

unfortunately I am not allowed to give the code away. But I can give you
an overview of the structure of our controls.
We have an abstract control which encapsulates an Object (the widget), a
SecurityContext (our class for defining rights), and some other Strings
and booleans to hold the state of the control (enabled, disabled,
read-only, ...). In the abstract control class we define internal
methods to instantiate the right stuff and the widget.
Every one of our control classes inherits from the abstract class. We
have something like MyButton, MyText, MyCombo, ...
The MyText, for example, defines his own instance variables for perhaps
the data type or a regular expression that the input must match. There
are several constructors in the control class to instantiate controls
with and without rights or data type checks plus the necessary
information for swt (parent control and style bits). With these the real
widget is instantiated. The real widget can be got as a reference via a
get method so you can use methods like clearSelection without having to
implement these in the control class and giving it to the widget. But
there are also convenience methods in the control class like setIntValue
to check the input from the user on data integrity.
The layout of the widgets is also done direct on the widgets via the get
method of the control.
That's it. The principles are very simple, we just have a control that
encapsulates the widget and looks for rights, data integrity and other
convenience cases.

I hope that helps you, although you don't get any code from me.

Peter
Re: Custom Widgets how to ? [message #450538 is a reply to message #450484] Tue, 15 February 2005 10:28 Go to previous messageGo to next message
Tiberiu Caprita is currently offline Tiberiu CapritaFriend
Messages: 68
Registered: July 2009
Member
Michael Borchert wrote:

> Maybe this is a silly question. But I want SWT Widgets to have a general
> E.g. adding FocusListener to change color when entering and leaving.
??? Any Control in SWT has a addFocusListener() function.
Just for colors doesn't worth to hack swt.It is enough to have a global
FocusListener and to attach it after any Control creation. If you want
something "global", you can make a class returning the Widgets you need,
having already the necessary listenrs:
class Bla {
private FocusListener pColorListener = ...;

Button createButtonInstance (Composite parent, int style) {
Button wBtn = new Button(parent,style);
wBtn.addFoculListener(pColorListener);
return wBtn;
}
}

Tiberiu
Re: Custom Widgets how to ? [message #450882 is a reply to message #450529] Sat, 19 February 2005 12:16 Go to previous message
Michael Borchert is currently offline Michael BorchertFriend
Messages: 27
Registered: July 2009
Junior Member
Hello Peter,

thank you very much.
I'll try this today, maybe have some other questions.

Michael

"Peter Goetz" <kingofbrain@web.de> schrieb im Newsbeitrag
news:cusa01$j22$1@www.eclipse.org...
> Michael Borchert wrote:
>> Thank you very much,
>>
>> can you please post me an example of such a wrapper ?
>
> unfortunately I am not allowed to give the code away. But I can give you
> an overview of the structure of our controls.
> We have an abstract control which encapsulates an Object (the widget), a
> SecurityContext (our class for defining rights), and some other Strings
> and booleans to hold the state of the control (enabled, disabled,
> read-only, ...). In the abstract control class we define internal methods
> to instantiate the right stuff and the widget.
> Every one of our control classes inherits from the abstract class. We have
> something like MyButton, MyText, MyCombo, ...
> The MyText, for example, defines his own instance variables for perhaps
> the data type or a regular expression that the input must match. There are
> several constructors in the control class to instantiate controls with and
> without rights or data type checks plus the necessary information for swt
> (parent control and style bits). With these the real widget is
> instantiated. The real widget can be got as a reference via a get method
> so you can use methods like clearSelection without having to implement
> these in the control class and giving it to the widget. But there are also
> convenience methods in the control class like setIntValue to check the
> input from the user on data integrity.
> The layout of the widgets is also done direct on the widgets via the get
> method of the control.
> That's it. The principles are very simple, we just have a control that
> encapsulates the widget and looks for rights, data integrity and other
> convenience cases.
>
> I hope that helps you, although you don't get any code from me.
>
> Peter
Previous Topic:SWT and Ant master build file problem
Next Topic:UTF-8 Asian Characters Come out as Rubbish
Goto Forum:
  


Current Time: Sat Sep 26 22:56:34 GMT 2020

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

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

Back to the top