Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » FormToolkit best practices
FormToolkit best practices [message #335860] Wed, 06 May 2009 11:50 Go to next message
Eclipse UserFriend
Originally posted by: sakis.kotisis.scigentech.com

Hello,

i was wondering if there are any proven methods to handle the leak of
Color resources in FormToolkit.
Since having just one FormToolkit per RCP is impractical, at the moment we
are trying to use one singleton FormToolkit per plugin and pass it to the
consuming views and editors.

This leaves much to be desired.
I've noticed the FormToolkit(FormColors colors) constructor, and the
following snippet from help on multi-page form editors:


public class SimpleFormEditor extends FormEditor {

public SimpleFormEditor() {
}

protected FormToolkit createToolkit(Display display) {
// Create a toolkit that shares colors between editors.
return new FormToolkit(ExamplesPlugin.getDefault().getFormColors(
display));
}

protected void addPages() {
try {
addPage(new FreeFormPage(this));
addPage(new SecondPage(this));
addPage(new ThirdPage(this));
addPage(new MasterDetailsPage(this));
addPage(new PageWithSubPages(this));
}
catch (PartInitException e) {
//
}
}


Has anyone used this way of initializing FormToolkit instances?

How can i get a hold of the getFormColors(Display display) method?
Could this be used along with a ColorRegistry per plugin?
A ColorRegistry is not provided by default for a new plugin activator.

This JavaDoc part confused me even more:
"Typically, one toolkit object is created per workbench part (for example,
an editor or a form wizard). The toolkit is disposed when the part is
disposed."

It correctly states that the toolkit is disposed along with the part, but
it's resources are not.
Instead, they are leaked. Any new opening of the part creates the
resources anew.

Thank you for any insight.


--
Sakis Kotisis

Senior Software Engineer

SciGen Technologies, Inc.
Re: FormToolkit best practices [message #335861 is a reply to message #335860] Wed, 06 May 2009 12:46 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

I have no information on the form toolkit side, but we often use a
LocalResourceManager in our editors, views, and label providers
(anything that has a dispose lifecycle).

LocalResourceManager manager
= new LocalResourceManager(JFaceResources.getResources());

Then use the createColor(*) methods to get colours from the manager.

In your editor or view dispose() you can call manager.dispose() and it
will clean up colours, fonts, or images that were allocated.

What's more, they will be shared within the program as they are backed
by the JFaceResources ResourceManager.

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclips e.platform.doc.isv/guide/workbench.htm


Re: FormToolkit best practices [message #335862 is a reply to message #335861] Wed, 06 May 2009 13:43 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: sakis.kotisis.scigentech.com

Thank you, Paul.

On Wed, 06 May 2009 15:46:01 +0300, Paul Webster <pwebster@ca.ibm.com>
wrote:

> I have no information on the form toolkit side, but we often use a
> LocalResourceManager in our editors, views, and label providers
> (anything that has a dispose lifecycle).
>
> LocalResourceManager manager
> = new LocalResourceManager(JFaceResources.getResources());
>
> Then use the createColor(*) methods to get colours from the manager.
>
> In your editor or view dispose() you can call manager.dispose() and it
> will clean up colours, fonts, or images that were allocated.
>
> What's more, they will be shared within the program as they are backed
> by the JFaceResources ResourceManager.
>
> PW
>



--
Sakis Kotisis

Senior Software Engineer

SciGen Technologies, Inc.
Re: FormToolkit best practices [message #335864 is a reply to message #335860] Wed, 06 May 2009 14:21 Go to previous message
Eclipse UserFriend
Originally posted by: sakis.kotisis.scigentech.com

Answering my own questions, i 've got the following so far.

I'm instantiating each toolkit through the FormToolkit(FormColors colors)
constructor.

FormColors is provided by the plugin activator:

public FormColors getFormColors() {
if (formColors == null) {
FormToolkit toolkit = new FormToolkit(Display.getCurrent());
formColors = toolkit.getColors();
}
return formColors;
}

This seems to do the trick, and colors are shared for all instances of
FormToolkit in the plugin.
FormColors has to be disposed :

public void stop(BundleContext context) throws Exception {
plugin = null;
formColors.dispose();

super.stop(context);
}

Unfortunately, i found no way to create the FormColors without creating a
new FormToolkit.

On Wed, 06 May 2009 14:50:09 +0300, Sakis Kotisis
<sakis.kotisis@scigentech.com> wrote:

> Hello,
>
> i was wondering if there are any proven methods to handle the leak of
> Color resources in FormToolkit.
> Since having just one FormToolkit per RCP is impractical, at the moment
> we are trying to use one singleton FormToolkit per plugin and pass it to
> the consuming views and editors.
>
> This leaves much to be desired.
> I've noticed the FormToolkit(FormColors colors) constructor, and the
> following snippet from help on multi-page form editors:
>
>
> public class SimpleFormEditor extends FormEditor {
>
> public SimpleFormEditor() {
> }
>
> protected FormToolkit createToolkit(Display display) {
> // Create a toolkit that shares colors between editors.
> return new FormToolkit(ExamplesPlugin.getDefault().getFormColors(
> display));
> }
>
> protected void addPages() {
> try {
> addPage(new FreeFormPage(this));
> addPage(new SecondPage(this));
> addPage(new ThirdPage(this));
> addPage(new MasterDetailsPage(this));
> addPage(new PageWithSubPages(this));
> }
> catch (PartInitException e) {
> //
> }
> }
>
>
> Has anyone used this way of initializing FormToolkit instances?
>
> How can i get a hold of the getFormColors(Display display) method?
> Could this be used along with a ColorRegistry per plugin?
> A ColorRegistry is not provided by default for a new plugin activator.
>
> This JavaDoc part confused me even more:
> "Typically, one toolkit object is created per workbench part (for
> example, an editor or a form wizard). The toolkit is disposed when the
> part is disposed."
>
> It correctly states that the toolkit is disposed along with the part,
> but it's resources are not.
> Instead, they are leaked. Any new opening of the part creates the
> resources anew.
>
> Thank you for any insight.
>
>



--
Sakis Kotisis

Senior Software Engineer

SciGen Technologies, Inc.
Previous Topic:Dynamic Submenus in Dynamic Menus?
Next Topic:M6 Always starting up with wrong workspace
Goto Forum:
  


Current Time: Sat Dec 28 07:07:43 GMT 2024

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

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

Back to the top