Skip Navigation

Creating a Notification with a More Details Link

  1. In a Java editor, create a listener that will react to the More Detailed Content link. Add the code that is shown below.

        This sample code displays the standard Eclipse information dialog. The shell in the active workbench window provides the correct placement and order for the window.

  Listener moreListener = new Listener() {
    public void handleEvent(Event event) {
      Shell shell = Workbench.getInstance().getActiveWorkbenchWindow().getShell();
      MessageDialog.openInformation(shell, "Title", "More detailed content");
    }
  };
  1. Create the Notification entity object that contains all information for the notification.

        The entity object for a More link has the following additional fields:

  • setMoreLabel adds the More label.

  • setMoreListener adds the more details listener that is used when the end-user clicks the label. This listener must also implement the listener interface that SWT provides.

        The following figure shows a notification with a More link.

image034
    final Notification notification = new Notification();
    notification.setWindowTitle("Title");
    notification.setPriority(Priority.LOW);
    notification.setContent("Content");
    notification.setMoreLabel("More");
    notification.setMoreListener(moreListener);
    notification.setLeftSideBarColor(SideBarColor.GREEN);
    notification.setNotificationTime(30000);
  1. Display the notification in a UI thread. If the method that calls createNotification() is already in the SWT UI thread, you do not need the special UiThreadInvoker.

    final INotificationService service = Activator.getDefault().getNotificationService();

    UiThreadInvoker <Object> invoker = new UiThreadInvoker <Object>() {
        protected Object invoke() {
            service.createNotification(notification);
            return null;
        }
    };

    invoker.asyncExec();