Create Custom Widget

SWT Designer allows you to create the views, editors, perspectives, pref pages, composites, etc. that comprise Eclipse SWT & RCP applications and plug-ins.

Moderators: Konstantin.Scheglov, gnebling, Alexander.Mitin, jwren, Eric Clayberg

Create Custom Widget

Postby vishaljohn » Wed Jul 02, 2008 2:17 am

Hi

I want to create a custom control and place in the palette.

Any suggestions in this regard.

Thanks

Vishal John
vishaljohn
 
Posts: 2
Joined: Wed Jul 02, 2008 1:34 am

Re: Create Custom Widget

Postby Eric Clayberg » Wed Jul 02, 2008 3:08 am

vishaljohn wrote:I want to create a custom control and place in the palette. Any suggestions in this regard.

See the FAQ discussion on Custom Widgets and the docs discussion of the Palette and Palette Manager.
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA

Re: Create Custom Widget

Postby vishaljohn » Wed Jul 02, 2008 9:57 pm

Hi Eric,

Thank you very much for the reply.

SWT Control class can be subclassed only within SWT implementaion. It is having package scope.

So I plan to develop a custom class like jfave viewer that encapsulates a standard swt widget.

How can I add this class to the palette. What methods should it have to behave so?

-Vishal John
vishaljohn
 
Posts: 2
Joined: Wed Jul 02, 2008 1:34 am

Re: Create Custom Widget

Postby Eric Clayberg » Thu Jul 03, 2008 3:09 am

You can subclass any SWT widget that you want. It is done all the time.

For a truly custom widget, subclass Composite of Canvas.

As long as your class is a subclass of some Widget subclass and implements a public, two-arg constructor, it should be fine.
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA

Re: Create Custom Widget

Postby jriggins » Tue Aug 26, 2008 12:54 pm

So Eric, are you saying that it is ok to subclass SWT widgets?

I've been looking for a clean way to uniformly configure my SWT widget instances. For instance, I want all my Text widgets to change background color on focus, and I want to have the same default font per widget type. At the same time, I need my change to be usable in WindowBuilder. After reading entry after entry on the web about why you should NEVER subclass widgets (everyone seems to assume though that the reader is looking to add custom functionality rather than configure the widget using the existing API), I figured I'd have to use a factory. But as I understand it, that support is not yet there in WindowBuilder (any idea on when it will be?).

I read this post, and decided to try a few examples with subclassing the widgets, and things seem to work well. I just wanted to make sure that in your opinion that use of subclassing is ok.

Thanks!
Jesse
jriggins
 
Posts: 4
Joined: Tue Aug 26, 2008 12:31 pm

Re: Create Custom Widget

Postby Eric Clayberg » Tue Aug 26, 2008 1:12 pm

As long as you stick to public API in the subclass and avoid referencing any fields directly, you should be in pretty good shape. If you are simply setting some public properties or adding some listeners, it should work fine and be portable across all operating systems. Note that you could also always subclass Composite and fill it with a instance of the widget you want to customize and then expose any API you want via getter/setters (which is the "approved" apporach). Designer itself won't care which way you do it.

Full support for GUI factories will be released later this year and is currently in beta test in our eRCP Designer product.

Image Image Image
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA

Re: Create Custom Widget

Postby jriggins » Tue Aug 26, 2008 2:01 pm

Wow...looks great! I need to finish my RCP app so that I can start on my companion eRCP app :mrgreen:

I tried going the Composite route, but I ended up getting into layout issues...maybe it was just due to my lack of SWT knowledge.... I personally like the subclass solution better for what I'm doing.

Thanks.
jriggins
 
Posts: 4
Joined: Tue Aug 26, 2008 12:31 pm

Re: Create Custom Widget

Postby Eric Clayberg » Tue Aug 26, 2008 3:04 pm

jriggins wrote:I tried going the Composite route, but I ended up getting into layout issues.

You would generally set the Composite to a FillLayout and have it filled completely by its single child widget.
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA


Return to SWT Designer

Who is online

Users browsing this forum: No registered users and 2 guests