Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Callback for EventLoopException
Callback for EventLoopException [message #915940] Tue, 18 September 2012 08:56 Go to next message
Rudi Missing name is currently offline Rudi Missing nameFriend
Messages: 17
Registered: July 2009
Junior Member
Hello,

we are implementing our first application on the eclipse 4 rcp and everything works fine so far.

Can anybody please tell me what's the e4 way of handling an UnexpectedEventLoopException? In eclipse 3.x there was the class ApplicationWorkbenchAdvisor and a callback method.

public void eventLoopException(final Throwable exception) {}


This callback we used to open an error dialog. How can I configure a callback in e4?

Thank you in advance,
Rudi

Re: Callback for EventLoopException [message #917932 is a reply to message #915940] Thu, 20 September 2012 15:17 Go to previous messageGo to next message
Rudi Missing name is currently offline Rudi Missing nameFriend
Messages: 17
Registered: July 2009
Junior Member
Hi,
this is very important for me. Maybe I should reformulate my question:

How do you handle an UnexpectedEventloopException in e4? By default the exception is written to the log-file but the users dosn't get any feedback. How do you handle this?

Please help...
Rudi
Re: Callback for EventLoopException [message #921824 is a reply to message #917932] Mon, 24 September 2012 13:14 Go to previous messageGo to next message
Brian de Alwis is currently offline Brian de AlwisFriend
Messages: 194
Registered: January 2012
Senior Member

It's internal right now, but you can provide your own implementation of org.eclipse.e4.ui.internal.workbench.swt.IEventLoopAdvisor to the application context. You should be able to set this instance from the @PostContextCreate life cycle annotation.

Brian.


Eclipse Platform committer. Ask me about Eclipse support, training, and consulting.
Re: Callback for EventLoopException [message #922980 is a reply to message #921824] Tue, 25 September 2012 14:07 Go to previous message
Rudi Missing name is currently offline Rudi Missing nameFriend
Messages: 17
Registered: July 2009
Junior Member
Hi Brian,

thank you very much! Do you know coincidentally if another solution will be provided in the future because this is accessing internal packages?

For all those for which IEventLoopAdvisor is not daily business Wink I paste my code here:

public class StartupLifeCycleHandler {

	private static final Logger logger = LogManager.getLogger(StartupLifeCycleHandler.class);

	@PostContextCreate
	public void startUp(final IEclipseContext context, final IApplicationContext applicationContext) {

		final IEventLoopAdvisor eventLoopAdvisor = new IEventLoopAdvisor() {

			@Override
			public void eventLoopIdle(final Display display) {

			}

			@Override
			public void eventLoopException(final Throwable exception) {

				StartupLifeCycleHandler.logger.error(exception.getMessage(), exception);
				MessageDialog.openError(Display.getCurrent().getActiveShell(), "Unexpected Eventloop Exception", StartupLifeCycleHandler.this.getCustomStackTrace(exception));
			}
		};

		StartupLifeCycleHandler.logger.debug("registering custom EventLoopAdvisor");
		context.set(IEventLoopAdvisor.class, eventLoopAdvisor);
	}

	private String getCustomStackTrace(final Throwable throwable) {

		final String newLine = "\n";
		final StringBuilder result = new StringBuilder();
		result.append(throwable.toString());
		result.append(newLine);
		for (final StackTraceElement element : throwable.getStackTrace()) {
			result.append(element);
			result.append(newLine);
		}
		return result.toString();
	}
}


How to register the handler you can find here: marcteufel.wordpress.com/2011/05/05/231/

Regards,
Rudi
Previous Topic:TreeViewer context menu does not show up
Next Topic:Juno build trouble
Goto Forum:
  


Current Time: Sun Nov 23 06:03:50 GMT 2014

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

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