org.eclipse.swt.SWTException: Widget is disposed [message #1565115] |
Thu, 15 January 2015 00:14  |
Eclipse User |
|
|
|
!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 #1707199 is a reply to message #1567858] |
Thu, 03 September 2015 01:43   |
Eclipse User |
|
|
|
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?
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04157 seconds