Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

org.eclipse.swt.SWTException: "Widget is disposed" from table refresh

The app is an Eclipse 3.6 based RCP (so jface version 3.5.2) running on windows 7.

I have a custom View class that contains a TableViewer and calls refresh() on it. Sometimes, but not very often it results in the stack trace below. It's called from within the UI thread. I suspected the problem was with other code that changes the backing list to the table, but that any code that does this is also run in either a syncExec or asyncExec method so I don't understand how it could be a synchronisation issue between the changing of table items and the refresh of the viewer.

Any ideas what i can do to prevent this happening?

!ENTRY org.eclipse.jface 4 2 2010-10-20 09:22:06.140 !MESSAGE Problems occurred when invoking code from plug-in: "org.eclipse.jface". !STACK 0 org.eclipse.swt.SWTException: Widget is disposed 
at org.eclipse.swt.SWT.error(SWT.java:3884) at org.eclipse.swt.SWT.error(SWT.java:3799) 
at org.eclipse.swt.SWT.error(SWT.java:3770) at org.eclipse.swt.widgets.Widget.error(Widget.java:463) 
at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:336) 
at org.eclipse.swt.widgets.Widget.getData(Widget.java:521) 
at org.eclipse.jface.viewers.AbstractTableViewer.setSelectionToWidget(AbstractTableViewer.java:921) 
at org.eclipse.jface.viewers.StructuredViewer.setSelectionToWidget(StructuredViewer.java:1711) 
at org.eclipse.jface.viewers.StructuredViewer.preservingSelection(StructuredViewer.java:1399) 
at org.eclipse.jface.viewers.StructuredViewer.preservingSelection(StructuredViewer.java:1353) 
at org.eclipse.jface.viewers.StructuredViewer.refresh(StructuredViewer.java:1455) 
at org.eclipse.jface.viewers.ColumnViewer.refresh(ColumnViewer.java:537) 
at org.eclipse.jface.viewers.StructuredViewer.refresh(StructuredViewer.java:1414)
... 
at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:179)
like image 953
Alb Avatar asked Feb 28 '11 16:02

Alb


2 Answers

Seems like refresh() method is called after the viewer is disposed (closed?). You can avoid this exception by checking:

public void refresh() {
   if (viewer != null && !viewer.getControl().isDisposed()) {
      // Actual refresh code
   }
}
like image 72
Michael Spector Avatar answered Sep 20 '22 20:09

Michael Spector


Try use display.isDisposed() like this.

    shell.getDisplay().asyncExec(new Runnable()
    {
        @Override
        public void run ()
        {
            if(!display.isDisposed() && !disposing)
            {
                              //you source code
            }
        }
    });

But remember that isDisposed() return true then disposing end. Thats why you shod use flag

disposing = true;

display.dispose();

disposing = false;

like image 30
Vladislav Avatar answered Sep 18 '22 20:09

Vladislav