Eclipse plugin development: Show custom MyLyn notification dialog
November 9th, 2009
Here’s an easy way to create a notification from inside eclipse (triggered by your own plugin), without any effort at all. MyLyn-core has a nice popup that looks great cross-platform, fades out and is visible outside the eclipse IDE, even when minimised (and also cross-desktop on ubuntu).
Using this popup is very easy:
- Add org.eclipse.mylyn.commons.ui as dependency for your plugin (see screenshot below)
- Create a class that extends the (internal) class AbstractNotificationPopup (org.eclipse.mylyn.internal.provisional.commons.ui.AbstractNotificationPopup), see code snippet 1. Note the “SupressWarnings” annotation, to get rid of the annoying compiler-warnings bugging us about “restricted” use… We know what we’re doing
- You can show the popup the same way you should treat another Dialog
, have a look at snippet 2.
Code snippet 1
package be.stacktrace.notification; import org.eclipse.mylyn.internal.provisional.commons.ui.AbstractNotificationPopup; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Label; import be.stacktrace.jfarse.Activator; @SuppressWarnings("restriction") public class MyNotificationPopup extends AbstractNotificationPopup { public MyNotificationPopup(Display display) { super(display); } @Override protected void createContentArea(Composite composite) { composite.setLayout(new GridLayout(1, true)); Label testLabel = new Label(composite, SWT.WRAP); testLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); testLabel.setText("Lorem ipsum dolor sit amet, consectetur adipiscing elit. " + "Maecenas nunc elit, vulputate vel sollicitudin nec, vehicula ut est. Sed diam risus, " + "dignissim eu sodales vitae, vestibulum et libero."); testLabel.setBackground(composite.getBackground()); } @Override protected String getPopupShellTitle() { // Return a custom title return "Stacktrace.be "; } @Override protected Image getPopupShellImage(int maximumHeight) { // Use createResource to use a shared Image instance of the ImageDescriptor return (Image) Activator.getImageDescriptor("/icons/information.png") .createResource(Display.getDefault()); } }
Code snippet 2
... MyNotificationPopup popup = new MyNotificationPopup(window.getShell().getDisplay()); popup.create(); popup.open(); ...
Categories: Uncategorized |








Excuse me for commenting OFFTOPIC - which wordpress template are you using? It looks great!!
I’m using SH Trocadero 1.0 by ShinRa, a bit modified using ubuntu-logo on the left-top and stacktrace top-right