Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Widget is diposed Exception
Widget is diposed Exception [message #805288] Thu, 23 February 2012 15:36 Go to next message
Lucy Sakhnenko is currently offline Lucy SakhnenkoFriend
Messages: 41
Registered: March 2011
Member
Hi,

I subclassed the CheckedTreeSelectionDialog to get the selected elements in the form of a tree:


public class MyTreeSelectionDialog extends CheckedTreeSelectionDialog {
	
	public MyTreeSelectionDialog(Shell parent,
			ILabelProvider labelProvider, ITreeContentProvider contentProvider) {
		super(parent, labelProvider, contentProvider);
		
	}
	
	@Override
	protected CheckboxTreeViewer createTreeViewer(Composite parent) {
		// TODO Auto-generated method stub
		return super.createTreeViewer(parent);
	}


	public Map<Object, List<Object>> getCheckedElementsMap() {
	    Map<Object, List<Object>> mapOfCheckedElements = new HashMap<Object, List<Object>>();
	    CheckboxTreeViewer checkboxTreeViewer = getTreeViewer();
	    org.eclipse.swt.widgets.Tree tree = checkboxTreeViewer.getTree();
	  
		for (TreeItem level1 : tree.getItems()) {
			if (level1.getChecked()) {
				List<Object> checkedChildren = new ArrayList<Object>();
				for (TreeItem level2 : level1.getItems()) {
					if (level2.getChecked()) {
						checkedChildren.add(level2);
					}
				}
				mapOfCheckedElements.put(level1, checkedChildren);
			}
		}
		return mapOfCheckedElements;
	}

	

}


But I'm getting the exception:


org.eclipse.swt.SWTException: Failed to execute runnable (org.eclipse.swt.SWTException: Widget is disposed)
	at org.eclipse.swt.SWT.error(SWT.java:4282)
	at org.eclipse.swt.SWT.error(SWT.java:4197)
	at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:138)
	at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:3563)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3212)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2696)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2660)
	at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2494)
	at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:674)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:667)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:123)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:616)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1386)
Caused by: org.eclipse.swt.SWTException: Widget is disposed
	at org.eclipse.swt.SWT.error(SWT.java:4282)
	at org.eclipse.swt.SWT.error(SWT.java:4197)
	at org.eclipse.swt.SWT.error(SWT.java:4168)
	at org.eclipse.swt.widgets.Widget.error(Widget.java:466)
	at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:403)
	at org.eclipse.swt.widgets.Tree.getItems(Tree.java:1610)
	at myproject.ui.model.MyTreeSelectionDialog.getResult(MyTreeSelectionDialog.java:66)
	at altagracia.plugin.popup.actions.ActionbuttonTest$1$2.run(ActionbuttonTest.java:247)
	at org.eclipse.ui.internal.UILockListener.doPendingWork(UILockListener.java:164)
	at org.eclipse.ui.internal.UISynchronizer$3.run(UISynchronizer.java:158)
	at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
	at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135)
	... 23 more




The line where the exception occurs is:

for (TreeItem level1 : tree.getItems()) {


Does anybody know what I can do?

Thank you very much for your help!
Re: Widget is diposed Exception [message #805542 is a reply to message #805288] Thu, 23 February 2012 22:05 Go to previous messageGo to next message
Thorsten Meinl is currently offline Thorsten MeinlFriend
Messages: 85
Registered: July 2009
Member
I have seen such errors when you are trying to access widgets when they
are no longer visible (i.e. disposed). Sometimes this is a timing issue
e.g. someone/something disposed the widget while you are still working
on it.

Am 23.02.2012 16:36, schrieb Lucy Mising name:
> Hi,
> I subclassed the CheckedTreeSelectionDialog to get the selected elements
> in the form of a tree:
>
>
>
> public class MyTreeSelectionDialog extends CheckedTreeSelectionDialog {
>
> public MyTreeSelectionDialog(Shell parent,
> ILabelProvider labelProvider, ITreeContentProvider
> contentProvider) {
> super(parent, labelProvider, contentProvider);
>
> }
>
> @Override
> protected CheckboxTreeViewer createTreeViewer(Composite parent) {
> // TODO Auto-generated method stub
> return super.createTreeViewer(parent);
> }
>
>
> public Map<Object, List<Object>> getCheckedElementsMap() {
> Map<Object, List<Object>> mapOfCheckedElements = new
> HashMap<Object, List<Object>>();
> CheckboxTreeViewer checkboxTreeViewer = getTreeViewer();
> org.eclipse.swt.widgets.Tree tree = checkboxTreeViewer.getTree();
> for (TreeItem level1 : tree.getItems()) {
> if (level1.getChecked()) {
> List<Object> checkedChildren = new ArrayList<Object>();
> for (TreeItem level2 : level1.getItems()) {
> if (level2.getChecked()) {
> checkedChildren.add(level2);
> }
> }
> mapOfCheckedElements.put(level1, checkedChildren);
> }
> }
> return mapOfCheckedElements;
> }
>
>
>
> }
>
>
> But I'm getting the exception:
>
>
>
> org.eclipse.swt.SWTException: Failed to execute runnable
> (org.eclipse.swt.SWTException: Widget is disposed)
> at org.eclipse.swt.SWT.error(SWT.java:4282)
> at org.eclipse.swt.SWT.error(SWT.java:4197)
> at
> org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:138)
>
> at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:3563)
> at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3212)
> at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2696)
> at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2660)
> at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2494)
> at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:674)
> at
> org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
>
> at
> org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:667)
> at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
> at
> org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:123)
>
> at
> org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
>
> at
> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
>
> at
> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
>
> at
> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
>
> at
> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
>
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
>
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>
> at java.lang.reflect.Method.invoke(Method.java:616)
> at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
> at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
> at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
> at org.eclipse.equinox.launcher.Main.main(Main.java:1386)
> Caused by: org.eclipse.swt.SWTException: Widget is disposed
> at org.eclipse.swt.SWT.error(SWT.java:4282)
> at org.eclipse.swt.SWT.error(SWT.java:4197)
> at org.eclipse.swt.SWT.error(SWT.java:4168)
> at org.eclipse.swt.widgets.Widget.error(Widget.java:466)
> at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:403)
> at org.eclipse.swt.widgets.Tree.getItems(Tree.java:1610)
> at
> myproject.ui.model.MyTreeSelectionDialog.getResult(MyTreeSelectionDialog.java:66)
>
> at
> altagracia.plugin.popup.actions.ActionbuttonTest$1$2.run(ActionbuttonTest.java:247)
>
> at
> org.eclipse.ui.internal.UILockListener.doPendingWork(UILockListener.java:164)
>
> at
> org.eclipse.ui.internal.UISynchronizer$3.run(UISynchronizer.java:158)
> at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
> at
> org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135)
>
> ... 23 more
>
>
>
>
> The line where the exception occurs is:
>
>
> for (TreeItem level1 : tree.getItems()) {
>
>
> Does anybody know what I can do?
>
> Thank you very much for your help!
Re: Widget is diposed Exception [message #805956 is a reply to message #805542] Fri, 24 February 2012 10:40 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
I think it's because you call that code after the dialog is closed and so the tree is disposed.
Re: Widget is diposed Exception [message #806069 is a reply to message #805956] Fri, 24 February 2012 14:11 Go to previous message
Lucy Sakhnenko is currently offline Lucy SakhnenkoFriend
Messages: 41
Registered: March 2011
Member
Thanks! That was it!

I overrode the computeResult method which is called after OK is pressed and before the widget is disposed. I'm calling that code inside that method.

Thanks!
Previous Topic:Shared platform for multiple applications
Next Topic:Showing properties view
Goto Forum:
  


Current Time: Sat Nov 28 17:50:36 GMT 2020

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

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

Back to the top