Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » JFace PreferenceDialog: Widget Disposed exception the second time
JFace PreferenceDialog: Widget Disposed exception the second time [message #321484] Thu, 18 October 2007 10:12 Go to next message
Eclipse User
Originally posted by: blaxter.gmail.com

Hello, i'm making a simple application which uses the class
PreferenceDialog. This is my first time that i'm using JFace, so i don't
know if i using well this API.

I have created a Menu with an action, something like:
private PreferencesAction _preferencesAction = new PreferencesAction(this);
(...)
MenuManager preferencesMenu = new MenuManager("&Edit");
preferencesMenu.add(_preferencesAction); menuManager.add(preferencesMenu);

That works fine, the PreferencesAction is just like this:

public class PreferencesAction extends Action
{
private PreferenceDialog dlg;

public PreferencesAction(ApplicationWindow window)
{
dlg = buildPreferencesDialog(window.getShell());
}

private PreferenceDialog buildPreferencesDialog(Shell mainShell)
{
setText("&Preferences");
setToolTipText("Preferences");
setAccelerator(SWT.CTRL + 'P');

PreferenceManager mgr = new PreferenceManager();

// Create the nodes
PreferenceNode prefNode = new PreferenceNode(
"Preferences", "Preferences",
null,
SomePreferences.class.getName()
);

// Add the nodes
mgr.addToRoot(prefNode);

// Create the preferences dialog
dlg = new PreferenceDialog(
new Shell(mainShell, SWT.DIALOG_TRIM | SWT.PRIMARY_MODAL),
mgr
);
PreferenceStore ps = new PreferenceStore(PREFERENCES_FILE);
try{
ps.load();
}catch(IOException e){
e.printStackTrace();
}
dlg.setPreferenceStore(ps);

try{
// Save the preferences
ps.save();
}catch(IOException e){
e.printStackTrace();
}
return dlg;
}

@Override
public void run()
{
dlg.open();
}
}

In this way, it works fine only the first time!, the second time that the
preferences window is showed a Exception is throwed! i don't really know
why this happening.

Exception occurred
org.eclipse.swt.SWTException: Widget is disposed
at org.eclipse.swt.SWT.error(SWT.java:3563)
at org.eclipse.swt.SWT.error(SWT.java:3481)
at org.eclipse.swt.SWT.error(SWT.java:3452)
at org.eclipse.swt.widgets.Widget.error(Widget.java:438)
at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:376)
at org.eclipse.swt.widgets.Control.setVisible(Control.java:3719 )
at org.eclipse.jface.dialogs.DialogPage.setVisible(DialogPage.j ava:468)
at org.eclipse.jface.preference.FieldEditorPreferencePage.setVi sible(FieldEditorPreferencePage.java:374)
at org.eclipse.jface.preference.PreferenceDialog.showPage(Prefe renceDialog.java:1280)
at org.eclipse.jface.preference.PreferenceDialog$9.selectionCha nged(PreferenceDialog.java:698)
at org.eclipse.jface.viewers.StructuredViewer$3.run(StructuredV iewer.java:842)
at org.eclipse.jface.util.SafeRunnable$3.run(SafeRunnable.java: 154)
at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:19 9)
at org.eclipse.jface.viewers.StructuredViewer.firePostSelection Changed(StructuredViewer.java:840)
at org.eclipse.jface.viewers.StructuredViewer.setSelection(Stru cturedViewer.java:1642)
at org.eclipse.jface.viewers.TreeViewer.setSelection(TreeViewer .java:1095)
at org.eclipse.jface.preference.PreferenceDialog.selectSavedIte m(PreferenceDialog.java:1009)
at org.eclipse.jface.preference.PreferenceDialog$4.run(Preferen ceDialog.java:369)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator .java:67)
at org.eclipse.jface.preference.PreferenceDialog.createContents (PreferenceDialog.java:365)
at org.eclipse.jface.window.Window.create(Window.java:426)
at org.eclipse.jface.dialogs.Dialog.create(Dialog.java:1081)
at org.eclipse.jface.window.Window.open(Window.java:785)
at com.bicosyes.jfaceTestapp.gui.action.PreferencesAction.run(P referencesAction.java:71)
at org.eclipse.jface.action.Action.runWithEvent(Action.java:498 )
at org.eclipse.jface.action.ActionContributionItem.handleWidget Selection(ActionContributionItem.java:546)
at org.eclipse.jface.action.ActionContributionItem.access$2(Act ionContributionItem.java:490)
at org.eclipse.jface.action.ActionContributionItem$6.handleEven t(ActionContributionItem.java:443)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java :66)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1101)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.ja va:3319)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :2971)
at org.eclipse.jface.window.Window.runEventLoop(Window.java:820 )
at org.eclipse.jface.window.Window.open(Window.java:796)
at com.bicosyes.jfaceTestapp.main(CzParserFCCGUI.java:125)

Does anyone have an idea why this is? thanks!

Cheers,
jesus
Re: JFace PreferenceDialog: Widget Disposed exception the second time [message #321486 is a reply to message #321484] Thu, 18 October 2007 11:16 Go to previous messageGo to next message
Waqas Ilyas is currently offline Waqas Ilyas
Messages: 40
Registered: July 2009
Member
Hi,

In your run method you will have to create the dialog instance every time
you want to open it. The controls are disposed once the dialog is closed.

@Override
public void run()
{
PreferenceDialog dlg = buildPreferencesDialog(window.getShell());
dlg.open();
}
}


Waqas.

"Jes
Re: JFace PreferenceDialog: Widget Disposed exception the second time [message #321505 is a reply to message #321486] Thu, 18 October 2007 15:01 Go to previous messageGo to next message
Eclipse User
Originally posted by: blaxter.gmail.com

El Thu, 18 Oct 2007 16:16:55 +0500, Waqas Ilyas escribió:

> Hi,
>
> In your run method you will have to create the dialog instance every time
> you want to open it. The controls are disposed once the dialog is closed.
>
> @Override
> public void run()
> {
> PreferenceDialog dlg = buildPreferencesDialog(window.getShell());
> dlg.open();
> }
> }
>
>
> Waqas.
>

Thanks for your answer, that way works!
But isn't it a waste of time to create the dialog every time that should be
showed?

I'm working with awt/swing before and i created the dialogs (JDialog
or whatever...) only one time, and before that, just call .setVisible(true)
(or false) method for showing or hiding them. The first time they were
called the interface was created, but after that, all windows go faster.

is there a way of doing that with SWT/JFace?
Re: JFace PreferenceDialog: Widget Disposed exception the second time [message #321526 is a reply to message #321505] Fri, 19 October 2007 03:38 Go to previous messageGo to next message
Waqas Ilyas is currently offline Waqas Ilyas
Messages: 40
Registered: July 2009
Member
Well this is the default behavior for the PreferenceDialog and most other
dialogs. You can extend the dialog class and override buttonPressed(),
okPressed() or cancelPressed() methods to avoid closing and just hiding the
dialog. But that can be problematic as you would see that these methods do
not simply close the dialog but perform other tasks too.

If your dialog is opened very often and performance is visibly affected then
you can extend the dialog, otherwise it is actually good that resources are
freed once a dialog is no more visible.

"Jes
Re: JFace PreferenceDialog: Widget Disposed exception the second time [message #734600 is a reply to message #321486] Sat, 08 October 2011 20:26 Go to previous message
Marco Lopes is currently offline Marco Lopes
Messages: 56
Registered: September 2010
Member
Waqas Ilyas wrote on Thu, 18 October 2007 07:16
Hi,

In your run method you will have to create the dialog instance every time
you want to open it. The controls are disposed once the dialog is closed.

@Override
public void run()
{
PreferenceDialog dlg = buildPreferencesDialog(window.getShell());
dlg.open();
}
}

Waqas.

"Jes


Hi Jes,

I made that conclusion myself, but until now i cannot explain the "memory" effect the PreferenceDialog has (lazy loading???). Maybe you can help.

Please take a look: http://www.eclipse.org/forums/index.php/t/237702/

Thanks.
Previous Topic:Register a PreferencePage at runtime?
Next Topic:Find Next in Console View
Goto Forum:
  


Current Time: Wed Oct 22 06:29:30 GMT 2014

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

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