title: Getting "SWTException: Widget is disposed" when trying to remove drag and drop listeners
body: <p>I have created a custom view in Eclipse which implements a part listener.</p>
  
  <pre><code>public class CodeBuilderView extends ViewPart implements IPartListener
  </code></pre>
  
  <p>I am adding drag and drop support for the view. In order to remove the drag and drop listeners, I have overridden the dispose() method as below.</p>
  
  <pre><code>@Override
  public void dispose()
  {
      getSite().getPage().removePartListener(this);
  
      if(viewDragSource!=null &amp;&amp; viewDragSourceAdapter!=null)
          viewDragSource.removeDragListener(viewDragSourceAdapter);
      if(viewDropTarget!=null &amp;&amp; viewDropTargetAdapter!=null)
          viewDropTarget.removeDropListener(viewDropTargetAdapter);
  
      super.dispose();
  }
  </code></pre>
  
  <p>However I am getting an SWT Exception on the line "viewDragSource.removeDragListener(viewDragSourceAdapter);". I thought it was necessary to dispose of the listeners before disposing the view, and that is exactly what I am doing. Any help would be appreciated.</p>
  
  <p>Stacktrace below:</p>
  
  <pre><code>org.eclipse.swt.SWTException: Widget is disposed
  at org.eclipse.swt.SWT.error(SWT.java:4441)
  at org.eclipse.swt.SWT.error(SWT.java:4356)
  at org.eclipse.swt.SWT.error(SWT.java:4327)
  at org.eclipse.swt.widgets.Widget.error(Widget.java:476)
  at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:348)
  at org.eclipse.swt.widgets.Widget.removeListener(Widget.java:962)
  at org.eclipse.swt.dnd.DragSource.removeDragListener(DragSource.java:685)
  at codebuilder.views.CodeBuilderView.dispose(CodeBuilderView.java:472)
  at org.eclipse.ui.internal.e4.compatibility.CompatibilityPart.invalidate(CompatibilityPart.java:224)
  at org.eclipse.ui.internal.e4.compatibility.CompatibilityPart.destroy(CompatibilityPart.java:373)
  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:601)
  at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:55)
  at org.eclipse.e4.core.internal.di.InjectorImpl.processAnnotated(InjectorImpl.java:888)
  at org.eclipse.e4.core.internal.di.InjectorImpl.processAnnotated(InjectorImpl.java:869)
  at org.eclipse.e4.core.internal.di.InjectorImpl.uninject(InjectorImpl.java:180)
  at org.eclipse.e4.core.internal.di.Requestor.uninject(Requestor.java:158)
  at org.eclipse.e4.core.internal.contexts.ContextObjectSupplier$ContextInjectionListener.update(ContextObjectSupplier.java:82)
  at org.eclipse.e4.core.internal.contexts.TrackableComputationExt.update(TrackableComputationExt.java:107)
  at org.eclipse.e4.core.internal.contexts.EclipseContext.removeListenersTo(EclipseContext.java:464)
  at org.eclipse.e4.core.contexts.ContextInjectionFactory.uninject(ContextInjectionFactory.java:144)
  at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeRemoveGui(PartRenderingEngine.java:942)
  at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$3(PartRenderingEngine.java:862)
  at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$8.run(PartRenderingEngine.java:857)
  at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
  at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.removeGui(PartRenderingEngine.java:841)
  at org.eclipse.e4.ui.workbench.renderers.swt.ElementReferenceRenderer.disposeWidget(ElementReferenceRenderer.java:118)
  at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeRemoveGui(PartRenderingEngine.java:933)
  at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$3(PartRenderingEngine.java:862)
  at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$8.run(PartRenderingEngine.java:857)
  at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
  at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.removeGui(PartRenderingEngine.java:841)
  at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeRemoveGui(PartRenderingEngine.java:894)
  at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$3(PartRenderingEngine.java:862)
  at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$8.run(PartRenderingEngine.java:857)
  at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
  at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.removeGui(PartRenderingEngine.java:841)
  at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeRemoveGui(PartRenderingEngine.java:894)
  at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$3(PartRenderingEngine.java:862)
  at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$8.run(PartRenderingEngine.java:857)
  at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
  at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.removeGui(PartRenderingEngine.java:841)
  at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeRemoveGui(PartRenderingEngine.java:894)
  at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$3(PartRenderingEngine.java:862)
  at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$8.run(PartRenderingEngine.java:857)
  at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
  at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.removeGui(PartRenderingEngine.java:841)
  at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeRemoveGui(PartRenderingEngine.java:894)
  at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$3(PartRenderingEngine.java:862)
  at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$8.run(PartRenderingEngine.java:857)
  at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
  at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.removeGui(PartRenderingEngine.java:841)
  at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeRemoveGui(PartRenderingEngine.java:887)
  at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$3(PartRenderingEngine.java:862)
  at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$8.run(PartRenderingEngine.java:857)
  at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
  at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.removeGui(PartRenderingEngine.java:841)
  at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeRemoveGui(PartRenderingEngine.java:894)
  at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$3(PartRenderingEngine.java:862)
  at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$8.run(PartRenderingEngine.java:857)
  at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
  at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.removeGui(PartRenderingEngine.java:841)
  at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeRemoveGui(PartRenderingEngine.java:894)
  at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$3(PartRenderingEngine.java:862)
  at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$8.run(PartRenderingEngine.java:857)
  at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
  at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.removeGui(PartRenderingEngine.java:841)
  at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeRemoveGui(PartRenderingEngine.java:894)
  at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$3(PartRenderingEngine.java:862)
  at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$8.run(PartRenderingEngine.java:857)
  at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
  at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.removeGui(PartRenderingEngine.java:841)
  at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeRemoveGui(PartRenderingEngine.java:894)
  at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$3(PartRenderingEngine.java:862)
  at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$8.run(PartRenderingEngine.java:857)
  at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
  at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.removeGui(PartRenderingEngine.java:841)
  at org.eclipse.ui.internal.WorkbenchWindow.hardClose(WorkbenchWindow.java:1924)
  at org.eclipse.ui.internal.WorkbenchWindow.busyClose(WorkbenchWindow.java:1547)
  at org.eclipse.ui.internal.WorkbenchWindow.access$15(WorkbenchWindow.java:1514)
  at org.eclipse.ui.internal.WorkbenchWindow$10.run(WorkbenchWindow.java:1579)
  at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
  at org.eclipse.ui.internal.WorkbenchWindow.close(WorkbenchWindow.java:1576)
  at org.eclipse.ui.internal.Workbench$14.run(Workbench.java:1155)
  at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
  at org.eclipse.ui.internal.Workbench.busyClose(Workbench.java:1137)
  at org.eclipse.ui.internal.Workbench.access$21(Workbench.java:1079)
  at org.eclipse.ui.internal.Workbench$19.run(Workbench.java:1410)
  at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
  at org.eclipse.ui.internal.Workbench.close(Workbench.java:1407)
  at org.eclipse.ui.internal.Workbench.close(Workbench.java:1380)
  at org.eclipse.ui.internal.WorkbenchWindow.busyClose(WorkbenchWindow.java:1543)
  at org.eclipse.ui.internal.WorkbenchWindow.access$15(WorkbenchWindow.java:1514)
  at org.eclipse.ui.internal.WorkbenchWindow$10.run(WorkbenchWindow.java:1579)
  at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
  at org.eclipse.ui.internal.WorkbenchWindow.close(WorkbenchWindow.java:1576)
  at org.eclipse.ui.internal.WorkbenchWindow.close(WorkbenchWindow.java:1590)
  at org.eclipse.ui.internal.WorkbenchWindow$6.close(WorkbenchWindow.java:520)
  at org.eclipse.e4.ui.workbench.renderers.swt.WBWRenderer$11.shellClosed(WBWRenderer.java:564)
  at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:98)
  at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
  at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4353)
  at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1061)
  at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1085)
  at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1070)
  at org.eclipse.swt.widgets.Decorations.closeWidget(Decorations.java:308)
  at org.eclipse.swt.widgets.Decorations.WM_CLOSE(Decorations.java:1696)
  at org.eclipse.swt.widgets.Control.windowProc(Control.java:4612)
  at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:339)
  at org.eclipse.swt.widgets.Decorations.windowProc(Decorations.java:1626)
  at org.eclipse.swt.widgets.Shell.windowProc(Shell.java:2075)
  at org.eclipse.swt.widgets.Display.windowProc(Display.java:5023)
  at org.eclipse.swt.internal.win32.OS.DefWindowProcW(Native Method)
  at org.eclipse.swt.internal.win32.OS.DefWindowProc(OS.java:2544)
  at org.eclipse.swt.widgets.Shell.callWindowProc(Shell.java:498)
  at org.eclipse.swt.widgets.Control.windowProc(Control.java:4705)
  at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:339)
  at org.eclipse.swt.widgets.Decorations.windowProc(Decorations.java:1626)
  at org.eclipse.swt.widgets.Shell.windowProc(Shell.java:2075)
  at org.eclipse.swt.widgets.Display.windowProc(Display.java:5023)
  at org.eclipse.swt.internal.win32.OS.DefWindowProcW(Native Method)
  at org.eclipse.swt.internal.win32.OS.DefWindowProc(OS.java:2544)
  at org.eclipse.swt.widgets.Shell.callWindowProc(Shell.java:498)
  at org.eclipse.swt.widgets.Control.windowProc(Control.java:4705)
  at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:339)
  at org.eclipse.swt.widgets.Decorations.windowProc(Decorations.java:1626)
  at org.eclipse.swt.widgets.Shell.windowProc(Shell.java:2075)
  at org.eclipse.swt.widgets.Display.windowProc(Display.java:5023)
  at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
  at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:2549)
  at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3759)
  at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1151)
  at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
  at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1032)
  at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:148)
  at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:636)
  at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
  at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:579)
  at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
  at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:135)
  at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
  at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
  at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
  at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:382)
  at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:236)
  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:601)
  at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:648)
  at org.eclipse.equinox.launcher.Main.basicRun(Main.java:603)
  at org.eclipse.equinox.launcher.Main.run(Main.java:1465)
  at org.eclipse.equinox.launcher.Main.main(Main.java:1438)
  </code></pre>