|
|
Re: org.eclipse.swt.SWTException: Widget is disposed [message #1707199 is a reply to message #1567858] |
Thu, 03 September 2015 05:43 |
Laszlo Orban Messages: 5 Registered: June 2015 |
Junior Member |
|
|
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.03779 seconds