Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » How to display erreor messages?
How to display erreor messages? [message #1587604] Tue, 27 January 2015 12:54 Go to next message
Patrick Marie is currently offline Patrick MarieFriend
Messages: 6
Registered: January 2015
Junior Member
Hello,

I am developing an eclipse plugin for the first time. I need to include some code in this plugin to display error messages when something goes wrong, so that the user executing the plugin gets aware of the problem.
How can it be done?

Patrick
Re: How to display erreor messages? [message #1588062 is a reply to message #1587604] Tue, 27 January 2015 18:32 Go to previous messageGo to next message
Eric Rizzo is currently offline Eric RizzoFriend
Messages: 3070
Registered: July 2009
Senior Member
Have you done any research into how to do this? There are a few different ways to skin that cat, so it would be helpful to know what you've tried, what your UI requirements are, etc.
Re: How to display erreor messages? [message #1589587 is a reply to message #1588062] Wed, 28 January 2015 14:38 Go to previous messageGo to next message
Patrick Marie is currently offline Patrick MarieFriend
Messages: 6
Registered: January 2015
Junior Member
Hi Eric,

I am developing a pattern plugin for generating applications from a template. It uses JET and Java for that purpose. However, when something goes wrong during the generation, I need to display an error message (which I am not able to do for now).
I think of something very simple such as opening a pop-up with the error message inside.
It seems to me that the following instruction could help me:

org.eclipse.jface.dialogs.MessageDialog.openInformation(view, "333", "An error occurred");

But I do not know what to use for "view".
Re: How to display erreor messages? [message #1591129 is a reply to message #1589587] Thu, 29 January 2015 10:34 Go to previous messageGo to next message
Patrick Marie is currently offline Patrick MarieFriend
Messages: 6
Registered: January 2015
Junior Member
I found a way:
javax.swing.JOptionPane.showMessageDialog(null, "<Message>", "<Title>", javax.swing.JOptionPane.OK_OPTION);
Re: How to display erreor messages? [message #1591412 is a reply to message #1591129] Thu, 29 January 2015 14:11 Go to previous messageGo to next message
Eric Rizzo is currently offline Eric RizzoFriend
Messages: 3070
Registered: July 2009
Senior Member
It's not advisable to use Swing in a plugin; the bridge between SWT/JFace and Swing/AWT is flaky and not a good solution if there are other options.
Does your plugin have any other UI components? Modal dialogs are generally discouraged; Eclipse is a broad platform and there can be any number of things going on at any given time; having the user interrupted with a modal dialog is usually the last resort. There are usually better options, but we'd need to know more about your plugin to make further recommendations.
Re: How to display erreor messages? [message #1591637 is a reply to message #1591412] Thu, 29 January 2015 17:02 Go to previous messageGo to next message
Patrick Marie is currently offline Patrick MarieFriend
Messages: 6
Registered: January 2015
Junior Member
My plugin does not have any other UI. It is intended to be used as a pattern in the pattern library of IBM Integration Designer. The code of this plugin uses JET and some Java snippets inside the JET transformation templates. It is in these Java snippets that I sometimes need to display error popups.
The swing instruction works fine and it is the first (and only) one which I was able to use. But if you can advise me a better way to display popups, I would be happy to use it instead of swing.
Re: How to display erreor messages? [message #1591894 is a reply to message #1591637] Thu, 29 January 2015 20:19 Go to previous message
Eric Rizzo is currently offline Eric RizzoFriend
Messages: 3070
Registered: July 2009
Senior Member
Using MessageDialog.openInformation() or openError() is one way, although not the most user-friendly way. If you read the JavaDoc or source code of MessageDialog you'll see that you can pass null as the Shell. Alternatively you can call Display.getCurrent().getActiveShell() to get the currently active Shell.
But as I said, that's kind of a brutish way to handle errors from an otherwise UI-less plugin. One better alternative would be to contribute a Problem Marker to the Problems/Markers view - like what a Java compilation problem does. Imagine if every compilation error produced a modal dialog like you're trying to do; it would be miserable to use.
Previous Topic:Problems tab disagreeing with Console tab
Next Topic:cannot find org.eclipse.e4.rcp to add as feature dependency
Goto Forum:
  


Current Time: Thu Mar 28 13:27:05 GMT 2024

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

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

Back to the top