JFace PreferenceDialog: Widget Disposed exception the second time [message #321484] |
Thu, 18 October 2007 10:12 |
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 #321505 is a reply to message #321486] |
Thu, 18 October 2007 15:01 |
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?
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03047 seconds