FormToolkit best practices [message #335860] |
Wed, 06 May 2009 11:50 |
Eclipse User |
|
|
|
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 #335862 is a reply to message #335861] |
Wed, 06 May 2009 13:43 |
Eclipse User |
|
|
|
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 |
Eclipse User |
|
|
|
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.
|
|
|
Powered by
FUDForum. Page generated in 0.03237 seconds