Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » SWTException: Widget is disposed in TableViewer with ObservableListContentProvider
SWTException: Widget is disposed in TableViewer with ObservableListContentProvider [message #1053219] Fri, 03 May 2013 08:12 Go to next message
Simon Scholz is currently offline Simon ScholzFriend
Messages: 73
Registered: April 2012
Location: Germany
Member
Hello,

I have placed two buttons for moving TableItems UP and DOWN besides a TableViewer, which has an ObservableListContentProvider and therefore has an IObservableList as input.

Here is the code for moving the items in the IObservableList
    // The move action can be 1 or -1
    public void moveSelected(List<IViewerItem> currentInput, int moveAction) {
        // get selection
        Collection<IViewerItem> selectedRows = getSelectedRows();
        if (selectedRows == null) {
            return;
        }

        // get range (indices) of selected items
        int count = currentInput.size();
        if (count == 0) {
            return;
        }
        int minRowIndex = count - 1;
        int maxRowIndex = 0;
        for (IViewerItem item : selectedRows) {
            int index = currentInput.indexOf(item);
            if (index < minRowIndex) {
                minRowIndex = index;
            }
            if (index > maxRowIndex) {
                maxRowIndex = index;
            }
        }
        // is move up allowed
        if ((ListFormItem.ONE_POSITION_UP == moveAction) && (minRowIndex < 1)) {
            return;
        }
        // is move down allowed?
        if ((ListFormItem.ONE_POSITION_DOWN == moveAction)
                && (maxRowIndex >= (count - 1))) {
            return;
        }

        // move items
        if (currentInput instanceof IObservableList) {
            Iterator<IViewerItem> iterator = selectedRows.iterator();
            while (iterator.hasNext()) {
                IViewerItem iViewerItem = (IViewerItem) iterator.next();
                int currentIndex = currentInput.lastIndexOf(iViewerItem);
                ((IObservableList) currentInput).move(currentIndex,
                        currentIndex + moveAction);
                viewer.setSelection(new StructuredSelection(iViewerItem));
            }
        }
}


Most of the time this works quite well, but sometimes, when moving the items the following Exception occurs:

org.eclipse.swt.SWTException: Widget is disposed
    at org.eclipse.swt.SWT.error(SWT.java:4083)
    at org.eclipse.swt.SWT.error(SWT.java:3998)
    at org.eclipse.swt.SWT.error(SWT.java:3969)
    at org.eclipse.swt.widgets.Widget.error(Widget.java:468)
    at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:340)
    at org.eclipse.swt.widgets.Widget.getData(Widget.java:525)
    at org.eclipse.jface.viewers.StructuredViewer.disassociate(StructuredViewer.java:639)
    at org.eclipse.jface.viewers.AbstractTableViewer.internalRemove(AbstractTableViewer.java:794)
    at org.eclipse.jface.viewers.AbstractTableViewer.access$0(AbstractTableViewer.java:767)
    at org.eclipse.jface.viewers.AbstractTableViewer$3.run(AbstractTableViewer.java:834)
    at org.eclipse.jface.viewers.StructuredViewer.preservingSelection(StructuredViewer.java:1422)
    at org.eclipse.jface.viewers.StructuredViewer.preservingSelection(StructuredViewer.java:1383)
    at org.eclipse.jface.viewers.AbstractTableViewer.remove(AbstractTableViewer.java:832)
    at org.eclipse.jface.viewers.TableViewer.remove(TableViewer.java:413)
    at org.eclipse.jface.viewers.AbstractTableViewer.remove(AbstractTableViewer.java:856)
    at org.eclipse.jface.internal.databinding.viewers.TableViewerUpdater.remove(TableViewerUpdater.java:36)
    at org.eclipse.jface.databinding.viewers.ObservableListContentProvider$2.handleRemove(ObservableListContentProvider.java:124)
    at org.eclipse.core.databinding.observable.list.ListDiff.accept(ListDiff.java:139)
    at org.eclipse.jface.databinding.viewers.ObservableListContentProvider$Impl.handleListChange(ObservableListContentProvider.java:118)
    at org.eclipse.core.databinding.observable.list.ListChangeEvent.dispatch(ListChangeEvent.java:61)
    at org.eclipse.core.databinding.observable.ChangeManager.fireEvent(ChangeManager.java:119)
    at org.eclipse.core.databinding.observable.list.DecoratingObservableList.fireListChange(DecoratingObservableList.java:59)
    at org.eclipse.core.databinding.observable.list.DecoratingObservableList.handleListChange(DecoratingObservableList.java:97)
    at org.eclipse.core.databinding.observable.list.DecoratingObservableList$1.handleListChange(DecoratingObservableList.java:71)
    at org.eclipse.core.databinding.observable.list.ListChangeEvent.dispatch(ListChangeEvent.java:61)
    at org.eclipse.core.databinding.observable.ChangeManager.fireEvent(ChangeManager.java:119)
    at org.eclipse.core.databinding.observable.list.ObservableList.fireListChange(ObservableList.java:73)
    at org.eclipse.core.internal.databinding.observable.masterdetail.DetailObservableList.access$1(DetailObservableList.java:1)
    at org.eclipse.core.internal.databinding.observable.masterdetail.DetailObservableList$1.handleListChange(DetailObservableList.java:48)
    at org.eclipse.core.databinding.observable.list.ListChangeEvent.dispatch(ListChangeEvent.java:61)
    at org.eclipse.core.databinding.observable.ChangeManager.fireEvent(ChangeManager.java:119)
    at org.eclipse.core.databinding.observable.list.DecoratingObservableList.fireListChange(DecoratingObservableList.java:59)
    at org.eclipse.core.databinding.observable.list.DecoratingObservableList.handleListChange(DecoratingObservableList.java:97)
    at org.eclipse.core.databinding.observable.list.DecoratingObservableList$1.handleListChange(DecoratingObservableList.java:71)
    at org.eclipse.core.databinding.observable.list.ListChangeEvent.dispatch(ListChangeEvent.java:61)
    at org.eclipse.core.databinding.observable.ChangeManager.fireEvent(ChangeManager.java:119)
    at org.eclipse.core.databinding.observable.ChangeSupport.fireEvent(ChangeSupport.java:39)
    at org.eclipse.core.databinding.observable.list.AbstractObservableList.fireListChange(AbstractObservableList.java:114)
    at org.eclipse.core.internal.databinding.property.list.SimplePropertyObservableList.notifyIfChanged(SimplePropertyObservableList.java:567)
    at org.eclipse.core.internal.databinding.property.list.SimplePropertyObservableList.updateList(SimplePropertyObservableList.java:182)
    at org.eclipse.core.internal.databinding.property.list.SimplePropertyObservableList.set(SimplePropertyObservableList.java:428)
    at org.eclipse.core.databinding.observable.list.DecoratingObservableList.set(DecoratingObservableList.java:192)
    at org.eclipse.core.internal.databinding.observable.masterdetail.DetailObservableList.set(DetailObservableList.java:169)
    at org.eclipse.core.databinding.observable.list.DecoratingObservableList.set(DecoratingObservableList.java:192)
    at mypackage.SelectedViewerItemsListener.move(SelectedViewerItemsListener.java:173)
    at mypackage.SelectedViewerItemsListener.moveSelected(SelectedViewerItemsListener.java:150)
    at mypackage.MoveListItemListener.modifyListInput(MoveListItemListener.java:45)
    at mypackage.AbstractModifyListInputListener.widgetSelected(AbstractModifyListInputListener.java:40)
    at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:234)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
    at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4066)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3657)
    at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2640)
    at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2604)
    at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2438)
    at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:671)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
    at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:664)
    at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
    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:369)
    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:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:620)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:575)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1408)
    at org.eclipse.equinox.launcher.Main.main(Main.java:1384)


Does anyone have an idea how to solve this problem or can offer a workaround?

Best regards,

Simon
Re: SWTException: Widget is disposed in TableViewer with ObservableListContentProvider [message #1053878 is a reply to message #1053219] Wed, 08 May 2013 05:26 Go to previous messageGo to next message
Snehil Shrivastava is currently offline Snehil ShrivastavaFriend
Messages: 17
Registered: April 2012
Junior Member
Hello Simon,

In whcih line are you getting this exception?
Re: SWTException: Widget is disposed in TableViewer with ObservableListContentProvider [message #1057987 is a reply to message #1053219] Fri, 10 May 2013 10:50 Go to previous message
Simon Scholz is currently offline Simon ScholzFriend
Messages: 73
Registered: April 2012
Location: Germany
Member
Hello Snehil,

thanks for your reply.

The Exception is caused by this line.
((IObservableList) currentInput).move(currentIndex,
                        currentIndex + moveAction);


The internal list of the TableViewer is updated and by the databinding mechanisms the Table is also updated, because of the update on the list order.

But sporadically the Widget Disposes error occurs.

Best regards,

Simon
Previous Topic:TextViewerUndoManager
Next Topic:how to get markers from document
Goto Forum:
  


Current Time: Tue Dec 23 01:50:19 GMT 2014

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

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