Skip to main content



      Home
Home » Eclipse Projects » Eclipse 4 » org.eclipse.swt.SWTException: Widget is disposed
org.eclipse.swt.SWTException: Widget is disposed [message #1565115] Thu, 15 January 2015 00:14 Go to next message
Eclipse UserFriend
!MESSAGE Exception while dispatching event org.osgi.service.event.Event [topic=checkListInfo/asyncEvent] to handler ~~.CheckListInfo$2@1722429d
!STACK 0
org.eclipse.swt.SWTException: Widget is disposed
at org.eclipse.swt.SWT.error(SWT.java:4397)
at org.eclipse.swt.SWT.error(SWT.java:4312)
at org.eclipse.swt.SWT.error(SWT.java:4283)
at org.eclipse.swt.widgets.Widget.error(Widget.java:472)
at org.eclipse.swt.widgets.Widget.getDisplay(Widget.java:586)
at ~~.CheckListInfo$2.handleEvent(CheckListInfo.java:98)
at org.eclipse.equinox.internal.event.EventHandlerWrapper.handleEvent(EventHandlerWrapper.java:197)
at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:197)
at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:1)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:340)


A view

BundleContext ctx = FrameworkUtil.getBundle(A.class).getBundleContext();
EventHandler handler = new EventHandler() {
public void handleEvent(final Event event) {
if(parent.getDisplay().getThread() == Thread.currentThread() ) {
}else {
parent.getDisplay().syncExec(new Runnable() {
public void run() {
title_txt.setText(event.getProperty("name").toString());
command_txt.setText(event.getProperty("addr").toString());
}
});
}
}
};
Dictionary<String,String> properties = new Hashtable<String, String>();
properties.put(EventConstants.EVENT_TOPIC, "checkListInfo/*");
ctx.registerService(EventHandler.class, handler, properties);




B view

BundleContext ctx = FrameworkUtil.getBundle(B.class).getBundleContext();
ServiceReference<EventAdmin> ref = ctx.getServiceReference(EventAdmin.class);
EventAdmin eventAdmin = ctx.getService(ref);
Event event = new Event("checkListInfo/a", map);
eventAdmin.postEvent(event);
Re: org.eclipse.swt.SWTException: Widget is disposed [message #1567858 is a reply to message #1565115] Fri, 16 January 2015 11:15 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

when you access SWT Widget, it might be useful to call Widget.isDisposed()

Please provide more details and a specific question if you want more information.

Regards,
Re: org.eclipse.swt.SWTException: Widget is disposed [message #1707199 is a reply to message #1567858] Thu, 03 September 2015 01:43 Go to previous messageGo to next message
Eclipse UserFriend
Hello there!

I just found this old thread and it seems I have the same problem.

What I want to do:
Pass information from one viewpart to another viewpart.

How I do this:
Using osgi evethandler services.

In the sender viewpart I post an event with an attached object like this:
BundleContext ctx = FrameworkUtil.getBundle(ViewLogging.class).getBundleContext();
ServiceReference<EventAdmin> ref = ctx.getServiceReference(EventAdmin.class);
EventAdmin eventAdmin = ctx.getService(ref);
Map<String,Object> properties = new HashMap<String, Object>();
properties.put("ENTRY", msg);
Event event = new Event(ViewTasks.EVENT_TOPIC_JUMP_TO_FNC_IN_TASK_TREE, properties);
eventAdmin.postEvent(event);


In the receiver viepart I create an event handler and subscribe to this event. I'm doing this in the receiver viewpart's createPartControl method.
BundleContext ctx = FrameworkUtil.getBundle(ViewTasks.class).getBundleContext();
EventHandler handler = new EventHandler() {
	public void handleEvent(final Event event) {
		parent.getDisplay().syncExec(new Runnable() {
			public void run() {
				Message msg = (Message)event.getProperty("ENTRY");
				selectTaskFromTree(msg);
			}
		});
	}
};

Dictionary<String,String> properties = new Hashtable<String, String>();
properties.put(EventConstants.EVENT_TOPIC, EVENT_TOPIC_JUMP_TO_FNC_IN_TASK_TREE);
ctx.registerService(EventHandler.class, handler, properties);


Problem:
The problem occurs when the receiver viewpart is not visible. In this case just before I post the event, I call the following:

PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(ViewTasks.ID);


It opens the viewpart and it seems everything is working fine, but I still get the following exception in this case:
org.eclipse.swt.SWTException: Widget is disposed
	at org.eclipse.swt.SWT.error(SWT.java:4397)
	at org.eclipse.swt.SWT.error(SWT.java:4312)
	at org.eclipse.swt.SWT.error(SWT.java:4283)
	at org.eclipse.swt.widgets.Widget.error(Widget.java:472)
	at org.eclipse.swt.widgets.Widget.getDisplay(Widget.java:586)
	at castle.testenv.ViewTasks$4.handleEvent(ViewTasks.java:281)


The exception is raised by the parent.getDisplay() call in the eventHandler.

Can anyone tell me how to to this right? How to avoid this SWTException?
Re: org.eclipse.swt.SWTException: Widget is disposed [message #1707209 is a reply to message #1707199] Thu, 03 September 2015 02:31 Go to previous messageGo to next message
Eclipse UserFriend
Ok, the above suggestion solved the problem, I wasn't read the thread carefully Very Happy.
The fixed eventhandler looks like this:
EventHandler handler = new EventHandler() {
	public void handleEvent(final Event event) {
		if (!parent.isDisposed()) {
			parent.getDisplay().syncExec(new Runnable() {
				public void run() {
					Message msg = (Message)event.getProperty("ENTRY");
					selectTaskFromTree(msg);
				}
			});
		}
	}
};
Re: org.eclipse.swt.SWTException: Widget is disposed [message #1707214 is a reply to message #1707209] Thu, 03 September 2015 02:51 Go to previous messageGo to next message
Eclipse UserFriend
Hey,

we use a pure e4 application and listen with to events that need to be processed on the UI trhead with the following code:

@Inject @Optional
void closeHandler(@UIEventTopic(''TOPIC_STRING'') foo.Bar payload) {
    // Useful work that has access to payload.  The instance of foo.Bar that the event poster placed on the global event bus with the topic ''TOPIC_STRING''
}


For you, there must be a subclass that does the UI think for you Smile Have you checked org.eclipse.e4.ui.services.internal.events.UIEventHandler? This page is also worth reading.

Kon
Re: org.eclipse.swt.SWTException: Widget is disposed [message #1707215 is a reply to message #1707214] Thu, 03 September 2015 03:05 Go to previous message
Eclipse UserFriend
Unfortunatelly my application is not an E4 app. No eventbroker, no dependency injection, no other fancy eclipse4 stuff Sad
But the above method fully solved the communication problem between viewparts

[Updated on: Thu, 03 September 2015 03:06] by Moderator

Previous Topic:Custom IModelResourceHandler
Next Topic:Why does the second perspective show up in a new window?
Goto Forum:
  


Current Time: Sun Jul 27 15:31:16 EDT 2025

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

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

Back to the top